Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

percpu_counter: add @gfp to percpu_counter_init()

Percpu allocator now supports allocation mask. Add @gfp to
percpu_counter_init() so that !GFP_KERNEL allocation masks can be used
with percpu_counters too.

We could have left percpu_counter_init() alone and added
percpu_counter_init_gfp(); however, the number of users isn't that
high and introducing _gfp variants to all percpu data structures would
be quite ugly, so let's just do the conversion. This is the one with
the most users. Other percpu data structures are a lot easier to
convert.

This patch doesn't make any functional difference.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Jan Kara <jack@suse.cz>
Acked-by: "David S. Miller" <davem@davemloft.net>
Cc: x86@kernel.org
Cc: Jens Axboe <axboe@kernel.dk>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>

Tejun Heo 908c7f19 ebd8fef3

+49 -42
+1 -1
arch/x86/kvm/mmu.c
··· 4534 4534 if (!mmu_page_header_cache) 4535 4535 goto nomem; 4536 4536 4537 - if (percpu_counter_init(&kvm_total_used_mmu_pages, 0)) 4537 + if (percpu_counter_init(&kvm_total_used_mmu_pages, 0, GFP_KERNEL)) 4538 4538 goto nomem; 4539 4539 4540 4540 register_shrinker(&mmu_shrinker);
+4 -4
fs/btrfs/disk-io.c
··· 1180 1180 if (!writers) 1181 1181 return ERR_PTR(-ENOMEM); 1182 1182 1183 - ret = percpu_counter_init(&writers->counter, 0); 1183 + ret = percpu_counter_init(&writers->counter, 0, GFP_KERNEL); 1184 1184 if (ret < 0) { 1185 1185 kfree(writers); 1186 1186 return ERR_PTR(ret); ··· 2185 2185 goto fail_srcu; 2186 2186 } 2187 2187 2188 - ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0); 2188 + ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL); 2189 2189 if (ret) { 2190 2190 err = ret; 2191 2191 goto fail_bdi; ··· 2193 2193 fs_info->dirty_metadata_batch = PAGE_CACHE_SIZE * 2194 2194 (1 + ilog2(nr_cpu_ids)); 2195 2195 2196 - ret = percpu_counter_init(&fs_info->delalloc_bytes, 0); 2196 + ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL); 2197 2197 if (ret) { 2198 2198 err = ret; 2199 2199 goto fail_dirty_metadata_bytes; 2200 2200 } 2201 2201 2202 - ret = percpu_counter_init(&fs_info->bio_counter, 0); 2202 + ret = percpu_counter_init(&fs_info->bio_counter, 0, GFP_KERNEL); 2203 2203 if (ret) { 2204 2204 err = ret; 2205 2205 goto fail_delalloc_bytes;
+1 -1
fs/btrfs/extent-tree.c
··· 3493 3493 if (!found) 3494 3494 return -ENOMEM; 3495 3495 3496 - ret = percpu_counter_init(&found->total_bytes_pinned, 0); 3496 + ret = percpu_counter_init(&found->total_bytes_pinned, 0, GFP_KERNEL); 3497 3497 if (ret) { 3498 3498 kfree(found); 3499 3499 return ret;
+3 -3
fs/ext2/super.c
··· 1067 1067 ext2_rsv_window_add(sb, &sbi->s_rsv_window_head); 1068 1068 1069 1069 err = percpu_counter_init(&sbi->s_freeblocks_counter, 1070 - ext2_count_free_blocks(sb)); 1070 + ext2_count_free_blocks(sb), GFP_KERNEL); 1071 1071 if (!err) { 1072 1072 err = percpu_counter_init(&sbi->s_freeinodes_counter, 1073 - ext2_count_free_inodes(sb)); 1073 + ext2_count_free_inodes(sb), GFP_KERNEL); 1074 1074 } 1075 1075 if (!err) { 1076 1076 err = percpu_counter_init(&sbi->s_dirs_counter, 1077 - ext2_count_dirs(sb)); 1077 + ext2_count_dirs(sb), GFP_KERNEL); 1078 1078 } 1079 1079 if (err) { 1080 1080 ext2_msg(sb, KERN_ERR, "error: insufficient memory");
+3 -3
fs/ext3/super.c
··· 2039 2039 goto failed_mount2; 2040 2040 } 2041 2041 err = percpu_counter_init(&sbi->s_freeblocks_counter, 2042 - ext3_count_free_blocks(sb)); 2042 + ext3_count_free_blocks(sb), GFP_KERNEL); 2043 2043 if (!err) { 2044 2044 err = percpu_counter_init(&sbi->s_freeinodes_counter, 2045 - ext3_count_free_inodes(sb)); 2045 + ext3_count_free_inodes(sb), GFP_KERNEL); 2046 2046 } 2047 2047 if (!err) { 2048 2048 err = percpu_counter_init(&sbi->s_dirs_counter, 2049 - ext3_count_dirs(sb)); 2049 + ext3_count_dirs(sb), GFP_KERNEL); 2050 2050 } 2051 2051 if (err) { 2052 2052 ext3_msg(sb, KERN_ERR, "error: insufficient memory");
+9 -5
fs/ext4/super.c
··· 3891 3891 /* Register extent status tree shrinker */ 3892 3892 ext4_es_register_shrinker(sbi); 3893 3893 3894 - if ((err = percpu_counter_init(&sbi->s_extent_cache_cnt, 0)) != 0) { 3894 + err = percpu_counter_init(&sbi->s_extent_cache_cnt, 0, GFP_KERNEL); 3895 + if (err) { 3895 3896 ext4_msg(sb, KERN_ERR, "insufficient memory"); 3896 3897 goto failed_mount3; 3897 3898 } ··· 4106 4105 block = ext4_count_free_clusters(sb); 4107 4106 ext4_free_blocks_count_set(sbi->s_es, 4108 4107 EXT4_C2B(sbi, block)); 4109 - err = percpu_counter_init(&sbi->s_freeclusters_counter, block); 4108 + err = percpu_counter_init(&sbi->s_freeclusters_counter, block, 4109 + GFP_KERNEL); 4110 4110 if (!err) { 4111 4111 unsigned long freei = ext4_count_free_inodes(sb); 4112 4112 sbi->s_es->s_free_inodes_count = cpu_to_le32(freei); 4113 - err = percpu_counter_init(&sbi->s_freeinodes_counter, freei); 4113 + err = percpu_counter_init(&sbi->s_freeinodes_counter, freei, 4114 + GFP_KERNEL); 4114 4115 } 4115 4116 if (!err) 4116 4117 err = percpu_counter_init(&sbi->s_dirs_counter, 4117 - ext4_count_dirs(sb)); 4118 + ext4_count_dirs(sb), GFP_KERNEL); 4118 4119 if (!err) 4119 - err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0); 4120 + err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0, 4121 + GFP_KERNEL); 4120 4122 if (err) { 4121 4123 ext4_msg(sb, KERN_ERR, "insufficient memory"); 4122 4124 goto failed_mount6;
+1 -1
fs/file_table.c
··· 331 331 332 332 n = (mempages * (PAGE_SIZE / 1024)) / 10; 333 333 files_stat.max_files = max_t(unsigned long, n, NR_FILE); 334 - percpu_counter_init(&nr_files, 0); 334 + percpu_counter_init(&nr_files, 0, GFP_KERNEL); 335 335 }
+1 -1
fs/quota/dquot.c
··· 2725 2725 panic("Cannot create dquot hash table"); 2726 2726 2727 2727 for (i = 0; i < _DQST_DQSTAT_LAST; i++) { 2728 - ret = percpu_counter_init(&dqstats.counter[i], 0); 2728 + ret = percpu_counter_init(&dqstats.counter[i], 0, GFP_KERNEL); 2729 2729 if (ret) 2730 2730 panic("Cannot create dquot stat counters"); 2731 2731 }
+2 -1
fs/super.c
··· 175 175 goto fail; 176 176 177 177 for (i = 0; i < SB_FREEZE_LEVELS; i++) { 178 - if (percpu_counter_init(&s->s_writers.counter[i], 0) < 0) 178 + if (percpu_counter_init(&s->s_writers.counter[i], 0, 179 + GFP_KERNEL) < 0) 179 180 goto fail; 180 181 lockdep_init_map(&s->s_writers.lock_map[i], sb_writers_name[i], 181 182 &type->s_writers_key[i], 0);
+6 -4
include/linux/percpu_counter.h
··· 12 12 #include <linux/threads.h> 13 13 #include <linux/percpu.h> 14 14 #include <linux/types.h> 15 + #include <linux/gfp.h> 15 16 16 17 #ifdef CONFIG_SMP 17 18 ··· 27 26 28 27 extern int percpu_counter_batch; 29 28 30 - int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, 29 + int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, gfp_t gfp, 31 30 struct lock_class_key *key); 32 31 33 - #define percpu_counter_init(fbc, value) \ 32 + #define percpu_counter_init(fbc, value, gfp) \ 34 33 ({ \ 35 34 static struct lock_class_key __key; \ 36 35 \ 37 - __percpu_counter_init(fbc, value, &__key); \ 36 + __percpu_counter_init(fbc, value, gfp, &__key); \ 38 37 }) 39 38 40 39 void percpu_counter_destroy(struct percpu_counter *fbc); ··· 90 89 s64 count; 91 90 }; 92 91 93 - static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount) 92 + static inline int percpu_counter_init(struct percpu_counter *fbc, s64 amount, 93 + gfp_t gfp) 94 94 { 95 95 fbc->count = amount; 96 96 return 0;
+1 -1
include/net/dst_ops.h
··· 63 63 64 64 static inline int dst_entries_init(struct dst_ops *dst) 65 65 { 66 - return percpu_counter_init(&dst->pcpuc_entries, 0); 66 + return percpu_counter_init(&dst->pcpuc_entries, 0, GFP_KERNEL); 67 67 } 68 68 69 69 static inline void dst_entries_destroy(struct dst_ops *dst)
+1 -1
include/net/inet_frag.h
··· 151 151 152 152 static inline void init_frag_mem_limit(struct netns_frags *nf) 153 153 { 154 - percpu_counter_init(&nf->mem, 0); 154 + percpu_counter_init(&nf->mem, 0, GFP_KERNEL); 155 155 } 156 156 157 157 static inline unsigned int sum_frag_mem_limit(struct netns_frags *nf)
+2 -2
lib/flex_proportions.c
··· 40 40 41 41 p->period = 0; 42 42 /* Use 1 to avoid dealing with periods with 0 events... */ 43 - err = percpu_counter_init(&p->events, 1); 43 + err = percpu_counter_init(&p->events, 1, GFP_KERNEL); 44 44 if (err) 45 45 return err; 46 46 seqcount_init(&p->sequence); ··· 172 172 { 173 173 int err; 174 174 175 - err = percpu_counter_init(&pl->events, 0); 175 + err = percpu_counter_init(&pl->events, 0, GFP_KERNEL); 176 176 if (err) 177 177 return err; 178 178 pl->period = 0;
+2 -2
lib/percpu_counter.c
··· 112 112 } 113 113 EXPORT_SYMBOL(__percpu_counter_sum); 114 114 115 - int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, 115 + int __percpu_counter_init(struct percpu_counter *fbc, s64 amount, gfp_t gfp, 116 116 struct lock_class_key *key) 117 117 { 118 118 unsigned long flags __maybe_unused; ··· 120 120 raw_spin_lock_init(&fbc->lock); 121 121 lockdep_set_class(&fbc->lock, key); 122 122 fbc->count = amount; 123 - fbc->counters = alloc_percpu(s32); 123 + fbc->counters = alloc_percpu_gfp(s32, gfp); 124 124 if (!fbc->counters) 125 125 return -ENOMEM; 126 126
+3 -3
lib/proportions.c
··· 83 83 pd->index = 0; 84 84 pd->pg[0].shift = shift; 85 85 mutex_init(&pd->mutex); 86 - err = percpu_counter_init(&pd->pg[0].events, 0); 86 + err = percpu_counter_init(&pd->pg[0].events, 0, GFP_KERNEL); 87 87 if (err) 88 88 goto out; 89 89 90 - err = percpu_counter_init(&pd->pg[1].events, 0); 90 + err = percpu_counter_init(&pd->pg[1].events, 0, GFP_KERNEL); 91 91 if (err) 92 92 percpu_counter_destroy(&pd->pg[0].events); 93 93 ··· 193 193 raw_spin_lock_init(&pl->lock); 194 194 pl->shift = 0; 195 195 pl->period = 0; 196 - return percpu_counter_init(&pl->events, 0); 196 + return percpu_counter_init(&pl->events, 0, GFP_KERNEL); 197 197 } 198 198 199 199 void prop_local_destroy_percpu(struct prop_local_percpu *pl)
+1 -1
mm/backing-dev.c
··· 455 455 bdi_wb_init(&bdi->wb, bdi); 456 456 457 457 for (i = 0; i < NR_BDI_STAT_ITEMS; i++) { 458 - err = percpu_counter_init(&bdi->bdi_stat[i], 0); 458 + err = percpu_counter_init(&bdi->bdi_stat[i], 0, GFP_KERNEL); 459 459 if (err) 460 460 goto err; 461 461 }
+1 -1
mm/mmap.c
··· 3196 3196 { 3197 3197 int ret; 3198 3198 3199 - ret = percpu_counter_init(&vm_committed_as, 0); 3199 + ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL); 3200 3200 VM_BUG_ON(ret); 3201 3201 } 3202 3202
+1 -1
mm/nommu.c
··· 539 539 { 540 540 int ret; 541 541 542 - ret = percpu_counter_init(&vm_committed_as, 0); 542 + ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL); 543 543 VM_BUG_ON(ret); 544 544 vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC); 545 545 }
+1 -1
mm/shmem.c
··· 2993 2993 #endif 2994 2994 2995 2995 spin_lock_init(&sbinfo->stat_lock); 2996 - if (percpu_counter_init(&sbinfo->used_blocks, 0)) 2996 + if (percpu_counter_init(&sbinfo->used_blocks, 0, GFP_KERNEL)) 2997 2997 goto failed; 2998 2998 sbinfo->free_inodes = sbinfo->max_inodes; 2999 2999
+1 -1
net/dccp/proto.c
··· 1115 1115 1116 1116 BUILD_BUG_ON(sizeof(struct dccp_skb_cb) > 1117 1117 FIELD_SIZEOF(struct sk_buff, cb)); 1118 - rc = percpu_counter_init(&dccp_orphan_count, 0); 1118 + rc = percpu_counter_init(&dccp_orphan_count, 0, GFP_KERNEL); 1119 1119 if (rc) 1120 1120 goto out_fail; 1121 1121 rc = -ENOBUFS;
+2 -2
net/ipv4/tcp.c
··· 3188 3188 3189 3189 BUILD_BUG_ON(sizeof(struct tcp_skb_cb) > sizeof(skb->cb)); 3190 3190 3191 - percpu_counter_init(&tcp_sockets_allocated, 0); 3192 - percpu_counter_init(&tcp_orphan_count, 0); 3191 + percpu_counter_init(&tcp_sockets_allocated, 0, GFP_KERNEL); 3192 + percpu_counter_init(&tcp_orphan_count, 0, GFP_KERNEL); 3193 3193 tcp_hashinfo.bind_bucket_cachep = 3194 3194 kmem_cache_create("tcp_bind_bucket", 3195 3195 sizeof(struct inet_bind_bucket), 0,
+1 -1
net/ipv4/tcp_memcontrol.c
··· 32 32 res_parent = &parent_cg->memory_allocated; 33 33 34 34 res_counter_init(&cg_proto->memory_allocated, res_parent); 35 - percpu_counter_init(&cg_proto->sockets_allocated, 0); 35 + percpu_counter_init(&cg_proto->sockets_allocated, 0, GFP_KERNEL); 36 36 37 37 return 0; 38 38 }
+1 -1
net/sctp/protocol.c
··· 1341 1341 if (!sctp_chunk_cachep) 1342 1342 goto err_chunk_cachep; 1343 1343 1344 - status = percpu_counter_init(&sctp_sockets_allocated, 0); 1344 + status = percpu_counter_init(&sctp_sockets_allocated, 0, GFP_KERNEL); 1345 1345 if (status) 1346 1346 goto err_percpu_counter_init; 1347 1347