Skip to content

Commit c798360

Browse files
committed
Merge branch 'for-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu
Pull percpu updates from Tejun Heo: "A lot of activities on percpu front. Notable changes are... - percpu allocator now can take @gfp. If @gfp doesn't contain GFP_KERNEL, it tries to allocate from what's already available to the allocator and a work item tries to keep the reserve around certain level so that these atomic allocations usually succeed. This will replace the ad-hoc percpu memory pool used by blk-throttle and also be used by the planned blkcg support for writeback IOs. Please note that I noticed a bug in how @gfp is interpreted while preparing this pull request and applied the fix 6ae833c ("percpu: fix how @gfp is interpreted by the percpu allocator") just now. - percpu_ref now uses longs for percpu and global counters instead of ints. It leads to more sparse packing of the percpu counters on 64bit machines but the overhead should be negligible and this allows using percpu_ref for refcnting pages and in-memory objects directly. - The switching between percpu and single counter modes of a percpu_ref is made independent of putting the base ref and a percpu_ref can now optionally be initialized in single or killed mode. This allows avoiding percpu shutdown latency for cases where the refcounted objects may be synchronously created and destroyed in rapid succession with only a fraction of them reaching fully operational status (SCSI probing does this when combined with blk-mq support). It's also planned to be used to implement forced single mode to detect underflow more timely for debugging. There's a separate branch percpu/for-3.18-consistent-ops which cleans up the duplicate percpu accessors. That branch causes a number of conflicts with s390 and other trees. I'll send a separate pull request w/ resolutions once other branches are merged" * 'for-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/percpu: (33 commits) percpu: fix how @gfp is interpreted by the percpu allocator blk-mq, percpu_ref: start q->mq_usage_counter in atomic mode percpu_ref: make INIT_ATOMIC and switch_to_atomic() sticky percpu_ref: add PERCPU_REF_INIT_* flags percpu_ref: decouple switching to percpu mode and reinit percpu_ref: decouple switching to atomic mode and killing percpu_ref: add PCPU_REF_DEAD percpu_ref: rename things to prepare for decoupling percpu/atomic mode switch percpu_ref: replace pcpu_ prefix with percpu_ percpu_ref: minor code and comment updates percpu_ref: relocate percpu_ref_reinit() Revert "blk-mq, percpu_ref: implement a kludge for SCSI blk-mq stall during probe" Revert "percpu: free percpu allocation info for uniprocessor system" percpu-refcount: make percpu_ref based on longs instead of ints percpu-refcount: improve WARN messages percpu: fix locking regression in the failure path of pcpu_alloc() percpu-refcount: add @gfp to percpu_ref_init() proportions: add @gfp to init functions percpu_counter: add @gfp to percpu_counter_init() percpu_counter: make percpu_counters_lock irq-safe ...
2 parents b211e9d + 6ae833c commit c798360

39 files changed

Lines changed: 879 additions & 444 deletions

‎arch/x86/kvm/mmu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4549,7 +4549,7 @@ int kvm_mmu_module_init(void)
45494549
if (!mmu_page_header_cache)
45504550
goto nomem;
45514551

4552-
if (percpu_counter_init(&kvm_total_used_mmu_pages, 0))
4552+
if (percpu_counter_init(&kvm_total_used_mmu_pages, 0, GFP_KERNEL))
45534553
goto nomem;
45544554

45554555
register_shrinker(&mmu_shrinker);

‎block/blk-mq-sysfs.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ static void blk_mq_sysfs_init(struct request_queue *q)
402402
}
403403
}
404404

405+
/* see blk_register_queue() */
406+
void blk_mq_finish_init(struct request_queue *q)
407+
{
408+
percpu_ref_switch_to_percpu(&q->mq_usage_counter);
409+
}
410+
405411
int blk_mq_register_disk(struct gendisk *disk)
406412
{
407413
struct device *dev = disk_to_dev(disk);

‎block/blk-mq.c‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,7 @@ void blk_mq_freeze_queue(struct request_queue *q)
119119
spin_unlock_irq(q->queue_lock);
120120

121121
if (freeze) {
122-
/*
123-
* XXX: Temporary kludge to work around SCSI blk-mq stall.
124-
* SCSI synchronously creates and destroys many queues
125-
* back-to-back during probe leading to lengthy stalls.
126-
* This will be fixed by keeping ->mq_usage_counter in
127-
* atomic mode until genhd registration, but, for now,
128-
* let's work around using expedited synchronization.
129-
*/
130-
__percpu_ref_kill_expedited(&q->mq_usage_counter);
131-
122+
percpu_ref_kill(&q->mq_usage_counter);
132123
blk_mq_run_queues(q, false);
133124
}
134125
wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
@@ -1804,7 +1795,12 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
18041795
if (!q)
18051796
goto err_hctxs;
18061797

1807-
if (percpu_ref_init(&q->mq_usage_counter, blk_mq_usage_counter_release))
1798+
/*
1799+
* Init percpu_ref in atomic mode so that it's faster to shutdown.
1800+
* See blk_register_queue() for details.
1801+
*/
1802+
if (percpu_ref_init(&q->mq_usage_counter, blk_mq_usage_counter_release,
1803+
PERCPU_REF_INIT_ATOMIC, GFP_KERNEL))
18081804
goto err_map;
18091805

18101806
setup_timer(&q->timeout, blk_mq_rq_timer, (unsigned long) q);

‎block/blk-sysfs.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,19 @@ int blk_register_queue(struct gendisk *disk)
551551
return -ENXIO;
552552

553553
/*
554-
* Initialization must be complete by now. Finish the initial
555-
* bypass from queue allocation.
554+
* SCSI probing may synchronously create and destroy a lot of
555+
* request_queues for non-existent devices. Shutting down a fully
556+
* functional queue takes measureable wallclock time as RCU grace
557+
* periods are involved. To avoid excessive latency in these
558+
* cases, a request_queue starts out in a degraded mode which is
559+
* faster to shut down and is made fully functional here as
560+
* request_queues for non-existent devices never get registered.
556561
*/
557562
if (!blk_queue_init_done(q)) {
558563
queue_flag_set_unlocked(QUEUE_FLAG_INIT_DONE, q);
559564
blk_queue_bypass_end(q);
565+
if (q->mq_ops)
566+
blk_mq_finish_init(q);
560567
}
561568

562569
ret = blk_trace_init_sysfs(dev);

‎drivers/target/target_core_tpg.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ int core_tpg_add_lun(
819819
{
820820
int ret;
821821

822-
ret = percpu_ref_init(&lun->lun_ref, core_tpg_lun_ref_release);
822+
ret = percpu_ref_init(&lun->lun_ref, core_tpg_lun_ref_release, 0,
823+
GFP_KERNEL);
823824
if (ret < 0)
824825
return ret;
825826

‎fs/aio.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
661661

662662
INIT_LIST_HEAD(&ctx->active_reqs);
663663

664-
if (percpu_ref_init(&ctx->users, free_ioctx_users))
664+
if (percpu_ref_init(&ctx->users, free_ioctx_users, 0, GFP_KERNEL))
665665
goto err;
666666

667-
if (percpu_ref_init(&ctx->reqs, free_ioctx_reqs))
667+
if (percpu_ref_init(&ctx->reqs, free_ioctx_reqs, 0, GFP_KERNEL))
668668
goto err;
669669

670670
ctx->cpu = alloc_percpu(struct kioctx_cpu);

‎fs/btrfs/disk-io.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ static struct btrfs_subvolume_writers *btrfs_alloc_subvolume_writers(void)
11831183
if (!writers)
11841184
return ERR_PTR(-ENOMEM);
11851185

1186-
ret = percpu_counter_init(&writers->counter, 0);
1186+
ret = percpu_counter_init(&writers->counter, 0, GFP_KERNEL);
11871187
if (ret < 0) {
11881188
kfree(writers);
11891189
return ERR_PTR(ret);
@@ -2188,21 +2188,21 @@ int open_ctree(struct super_block *sb,
21882188
goto fail_srcu;
21892189
}
21902190

2191-
ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0);
2191+
ret = percpu_counter_init(&fs_info->dirty_metadata_bytes, 0, GFP_KERNEL);
21922192
if (ret) {
21932193
err = ret;
21942194
goto fail_bdi;
21952195
}
21962196
fs_info->dirty_metadata_batch = PAGE_CACHE_SIZE *
21972197
(1 + ilog2(nr_cpu_ids));
21982198

2199-
ret = percpu_counter_init(&fs_info->delalloc_bytes, 0);
2199+
ret = percpu_counter_init(&fs_info->delalloc_bytes, 0, GFP_KERNEL);
22002200
if (ret) {
22012201
err = ret;
22022202
goto fail_dirty_metadata_bytes;
22032203
}
22042204

2205-
ret = percpu_counter_init(&fs_info->bio_counter, 0);
2205+
ret = percpu_counter_init(&fs_info->bio_counter, 0, GFP_KERNEL);
22062206
if (ret) {
22072207
err = ret;
22082208
goto fail_delalloc_bytes;

‎fs/btrfs/extent-tree.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
34943494
if (!found)
34953495
return -ENOMEM;
34963496

3497-
ret = percpu_counter_init(&found->total_bytes_pinned, 0);
3497+
ret = percpu_counter_init(&found->total_bytes_pinned, 0, GFP_KERNEL);
34983498
if (ret) {
34993499
kfree(found);
35003500
return ret;

‎fs/ext2/super.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,14 +1067,14 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
10671067
ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
10681068

10691069
err = percpu_counter_init(&sbi->s_freeblocks_counter,
1070-
ext2_count_free_blocks(sb));
1070+
ext2_count_free_blocks(sb), GFP_KERNEL);
10711071
if (!err) {
10721072
err = percpu_counter_init(&sbi->s_freeinodes_counter,
1073-
ext2_count_free_inodes(sb));
1073+
ext2_count_free_inodes(sb), GFP_KERNEL);
10741074
}
10751075
if (!err) {
10761076
err = percpu_counter_init(&sbi->s_dirs_counter,
1077-
ext2_count_dirs(sb));
1077+
ext2_count_dirs(sb), GFP_KERNEL);
10781078
}
10791079
if (err) {
10801080
ext2_msg(sb, KERN_ERR, "error: insufficient memory");

‎fs/ext3/super.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,14 +2039,14 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
20392039
goto failed_mount2;
20402040
}
20412041
err = percpu_counter_init(&sbi->s_freeblocks_counter,
2042-
ext3_count_free_blocks(sb));
2042+
ext3_count_free_blocks(sb), GFP_KERNEL);
20432043
if (!err) {
20442044
err = percpu_counter_init(&sbi->s_freeinodes_counter,
2045-
ext3_count_free_inodes(sb));
2045+
ext3_count_free_inodes(sb), GFP_KERNEL);
20462046
}
20472047
if (!err) {
20482048
err = percpu_counter_init(&sbi->s_dirs_counter,
2049-
ext3_count_dirs(sb));
2049+
ext3_count_dirs(sb), GFP_KERNEL);
20502050
}
20512051
if (err) {
20522052
ext3_msg(sb, KERN_ERR, "error: insufficient memory");

0 commit comments

Comments
 (0)