Skip to content

Commit 8023e14

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the poll flag to queue_limits
Move the poll flag into the queue_limits feature field so that it can be set atomically with the queue frozen. Stacking drivers are simplified in that they now can simply set the flag, and blk_stack_limits will clear it when the features is not supported by any of the underlying devices. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20240617060532.127975-22-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f467fee commit 8023e14

File tree

8 files changed

+45
-76
lines changed

8 files changed

+45
-76
lines changed

block/blk-core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void submit_bio_noacct(struct bio *bio)
791791
}
792792
}
793793

794-
if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
794+
if (!(q->limits.features & BLK_FEAT_POLL))
795795
bio_clear_polled(bio);
796796

797797
switch (bio_op(bio)) {
@@ -915,8 +915,7 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
915915
return 0;
916916

917917
q = bdev_get_queue(bdev);
918-
if (cookie == BLK_QC_T_NONE ||
919-
!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
918+
if (cookie == BLK_QC_T_NONE || !(q->limits.features & BLK_FEAT_POLL))
920919
return 0;
921920

922921
blk_flush_plug(current->plug, false);

block/blk-mq-debugfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ static const char *const blk_queue_flag_name[] = {
8787
QUEUE_FLAG_NAME(NOXMERGES),
8888
QUEUE_FLAG_NAME(SAME_FORCE),
8989
QUEUE_FLAG_NAME(INIT_DONE),
90-
QUEUE_FLAG_NAME(POLL),
9190
QUEUE_FLAG_NAME(STATS),
9291
QUEUE_FLAG_NAME(REGISTERED),
9392
QUEUE_FLAG_NAME(QUIESCED),

block/blk-mq.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,6 +4109,12 @@ void blk_mq_release(struct request_queue *q)
41094109
blk_mq_sysfs_deinit(q);
41104110
}
41114111

4112+
static bool blk_mq_can_poll(struct blk_mq_tag_set *set)
4113+
{
4114+
return set->nr_maps > HCTX_TYPE_POLL &&
4115+
set->map[HCTX_TYPE_POLL].nr_queues;
4116+
}
4117+
41124118
struct request_queue *blk_mq_alloc_queue(struct blk_mq_tag_set *set,
41134119
struct queue_limits *lim, void *queuedata)
41144120
{
@@ -4119,6 +4125,8 @@ struct request_queue *blk_mq_alloc_queue(struct blk_mq_tag_set *set,
41194125
if (!lim)
41204126
lim = &default_lim;
41214127
lim->features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
4128+
if (blk_mq_can_poll(set))
4129+
lim->features |= BLK_FEAT_POLL;
41224130

41234131
q = blk_alloc_queue(lim, set->numa_node);
41244132
if (IS_ERR(q))
@@ -4273,17 +4281,6 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,
42734281
mutex_unlock(&q->sysfs_lock);
42744282
}
42754283

4276-
static void blk_mq_update_poll_flag(struct request_queue *q)
4277-
{
4278-
struct blk_mq_tag_set *set = q->tag_set;
4279-
4280-
if (set->nr_maps > HCTX_TYPE_POLL &&
4281-
set->map[HCTX_TYPE_POLL].nr_queues)
4282-
blk_queue_flag_set(QUEUE_FLAG_POLL, q);
4283-
else
4284-
blk_queue_flag_clear(QUEUE_FLAG_POLL, q);
4285-
}
4286-
42874284
int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
42884285
struct request_queue *q)
42894286
{
@@ -4311,7 +4308,6 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
43114308
q->tag_set = set;
43124309

43134310
q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT;
4314-
blk_mq_update_poll_flag(q);
43154311

43164312
INIT_DELAYED_WORK(&q->requeue_work, blk_mq_requeue_work);
43174313
INIT_LIST_HEAD(&q->flush_list);
@@ -4798,8 +4794,10 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
47984794
fallback:
47994795
blk_mq_update_queue_map(set);
48004796
list_for_each_entry(q, &set->tag_list, tag_set_list) {
4797+
struct queue_limits lim;
4798+
48014799
blk_mq_realloc_hw_ctxs(set, q);
4802-
blk_mq_update_poll_flag(q);
4800+
48034801
if (q->nr_hw_queues != set->nr_hw_queues) {
48044802
int i = prev_nr_hw_queues;
48054803

@@ -4811,6 +4809,13 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
48114809
set->nr_hw_queues = prev_nr_hw_queues;
48124810
goto fallback;
48134811
}
4812+
lim = queue_limits_start_update(q);
4813+
if (blk_mq_can_poll(set))
4814+
lim.features |= BLK_FEAT_POLL;
4815+
else
4816+
lim.features &= ~BLK_FEAT_POLL;
4817+
if (queue_limits_commit_update(q, &lim) < 0)
4818+
pr_warn("updating the poll flag failed\n");
48144819
blk_mq_map_swqueue(q);
48154820
}
48164821

block/blk-settings.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,15 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
460460
t->features |= (b->features & BLK_FEAT_INHERIT_MASK);
461461

462462
/*
463-
* BLK_FEAT_NOWAIT needs to be supported both by the stacking driver
464-
* and all underlying devices. The stacking driver sets the flag
465-
* before stacking the limits, and this will clear the flag if any
466-
* of the underlying devices does not support it.
463+
* BLK_FEAT_NOWAIT and BLK_FEAT_POLL need to be supported both by the
464+
* stacking driver and all underlying devices. The stacking driver sets
465+
* the flags before stacking the limits, and this will clear the flags
466+
* if any of the underlying devices does not support it.
467467
*/
468468
if (!(b->features & BLK_FEAT_NOWAIT))
469469
t->features &= ~BLK_FEAT_NOWAIT;
470+
if (!(b->features & BLK_FEAT_POLL))
471+
t->features &= ~BLK_FEAT_POLL;
470472

471473
t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
472474
t->max_user_sectors = min_not_zero(t->max_user_sectors,

block/blk-sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,13 @@ static ssize_t queue_poll_delay_store(struct request_queue *q, const char *page,
394394

395395
static ssize_t queue_poll_show(struct request_queue *q, char *page)
396396
{
397-
return queue_var_show(test_bit(QUEUE_FLAG_POLL, &q->queue_flags), page);
397+
return queue_var_show(q->limits.features & BLK_FEAT_POLL, page);
398398
}
399399

400400
static ssize_t queue_poll_store(struct request_queue *q, const char *page,
401401
size_t count)
402402
{
403-
if (!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
403+
if (!(q->limits.features & BLK_FEAT_POLL))
404404
return -EINVAL;
405405
pr_info_ratelimited("writes to the poll attribute are ignored.\n");
406406
pr_info_ratelimited("please use driver specific parameters instead.\n");

drivers/md/dm-table.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int dm_split_args(int *argc, char ***argvp, char *input)
582582
static void dm_set_stacking_limits(struct queue_limits *limits)
583583
{
584584
blk_set_stacking_limits(limits);
585-
limits->features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
585+
limits->features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT | BLK_FEAT_POLL;
586586
}
587587

588588
/*
@@ -1024,14 +1024,13 @@ bool dm_table_request_based(struct dm_table *t)
10241024
return __table_type_request_based(dm_table_get_type(t));
10251025
}
10261026

1027-
static bool dm_table_supports_poll(struct dm_table *t);
1028-
10291027
static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *md)
10301028
{
10311029
enum dm_queue_mode type = dm_table_get_type(t);
10321030
unsigned int per_io_data_size = 0, front_pad, io_front_pad;
10331031
unsigned int min_pool_size = 0, pool_size;
10341032
struct dm_md_mempools *pools;
1033+
unsigned int bioset_flags = 0;
10351034

10361035
if (unlikely(type == DM_TYPE_NONE)) {
10371036
DMERR("no table type is set, can't allocate mempools");
@@ -1048,6 +1047,9 @@ static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *
10481047
goto init_bs;
10491048
}
10501049

1050+
if (md->queue->limits.features & BLK_FEAT_POLL)
1051+
bioset_flags |= BIOSET_PERCPU_CACHE;
1052+
10511053
for (unsigned int i = 0; i < t->num_targets; i++) {
10521054
struct dm_target *ti = dm_table_get_target(t, i);
10531055

@@ -1060,8 +1062,7 @@ static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *
10601062

10611063
io_front_pad = roundup(per_io_data_size,
10621064
__alignof__(struct dm_io)) + DM_IO_BIO_OFFSET;
1063-
if (bioset_init(&pools->io_bs, pool_size, io_front_pad,
1064-
dm_table_supports_poll(t) ? BIOSET_PERCPU_CACHE : 0))
1065+
if (bioset_init(&pools->io_bs, pool_size, io_front_pad, bioset_flags))
10651066
goto out_free_pools;
10661067
if (t->integrity_supported &&
10671068
bioset_integrity_create(&pools->io_bs, pool_size))
@@ -1404,14 +1405,6 @@ struct dm_target *dm_table_find_target(struct dm_table *t, sector_t sector)
14041405
return &t->targets[(KEYS_PER_NODE * n) + k];
14051406
}
14061407

1407-
static int device_not_poll_capable(struct dm_target *ti, struct dm_dev *dev,
1408-
sector_t start, sector_t len, void *data)
1409-
{
1410-
struct request_queue *q = bdev_get_queue(dev->bdev);
1411-
1412-
return !test_bit(QUEUE_FLAG_POLL, &q->queue_flags);
1413-
}
1414-
14151408
/*
14161409
* type->iterate_devices() should be called when the sanity check needs to
14171410
* iterate and check all underlying data devices. iterate_devices() will
@@ -1459,19 +1452,6 @@ static int count_device(struct dm_target *ti, struct dm_dev *dev,
14591452
return 0;
14601453
}
14611454

1462-
static bool dm_table_supports_poll(struct dm_table *t)
1463-
{
1464-
for (unsigned int i = 0; i < t->num_targets; i++) {
1465-
struct dm_target *ti = dm_table_get_target(t, i);
1466-
1467-
if (!ti->type->iterate_devices ||
1468-
ti->type->iterate_devices(ti, device_not_poll_capable, NULL))
1469-
return false;
1470-
}
1471-
1472-
return true;
1473-
}
1474-
14751455
/*
14761456
* Check whether a table has no data devices attached using each
14771457
* target's iterate_devices method.
@@ -1817,6 +1797,13 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18171797
if (!dm_table_supports_nowait(t))
18181798
limits->features &= ~BLK_FEAT_NOWAIT;
18191799

1800+
/*
1801+
* The current polling impementation does not support request based
1802+
* stacking.
1803+
*/
1804+
if (!__table_type_bio_based(t->type))
1805+
limits->features &= ~BLK_FEAT_POLL;
1806+
18201807
if (!dm_table_supports_discards(t)) {
18211808
limits->max_hw_discard_sectors = 0;
18221809
limits->discard_granularity = 0;
@@ -1858,21 +1845,6 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18581845
return r;
18591846

18601847
dm_update_crypto_profile(q, t);
1861-
1862-
/*
1863-
* Check for request-based device is left to
1864-
* dm_mq_init_request_queue()->blk_mq_init_allocated_queue().
1865-
*
1866-
* For bio-based device, only set QUEUE_FLAG_POLL when all
1867-
* underlying devices supporting polling.
1868-
*/
1869-
if (__table_type_bio_based(t->type)) {
1870-
if (dm_table_supports_poll(t))
1871-
blk_queue_flag_set(QUEUE_FLAG_POLL, q);
1872-
else
1873-
blk_queue_flag_clear(QUEUE_FLAG_POLL, q);
1874-
}
1875-
18761848
return 0;
18771849
}
18781850

drivers/nvme/host/multipath.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
538538

539539
blk_set_stacking_limits(&lim);
540540
lim.dma_alignment = 3;
541-
lim.features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT;
541+
lim.features |= BLK_FEAT_IO_STAT | BLK_FEAT_NOWAIT | BLK_FEAT_POLL;
542542
if (head->ids.csi != NVME_CSI_ZNS)
543543
lim.max_zone_append_sectors = 0;
544544

@@ -549,16 +549,6 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
549549
head->disk->private_data = head;
550550
sprintf(head->disk->disk_name, "nvme%dn%d",
551551
ctrl->subsys->instance, head->instance);
552-
553-
/*
554-
* This assumes all controllers that refer to a namespace either
555-
* support poll queues or not. That is not a strict guarantee,
556-
* but if the assumption is wrong the effect is only suboptimal
557-
* performance but not correctness problem.
558-
*/
559-
if (ctrl->tagset->nr_maps > HCTX_TYPE_POLL &&
560-
ctrl->tagset->map[HCTX_TYPE_POLL].nr_queues)
561-
blk_queue_flag_set(QUEUE_FLAG_POLL, head->disk->queue);
562552
return 0;
563553
}
564554

include/linux/blkdev.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ enum {
310310

311311
/* supports DAX */
312312
BLK_FEAT_DAX = (1u << 8),
313+
314+
/* supports I/O polling */
315+
BLK_FEAT_POLL = (1u << 9),
313316
};
314317

315318
/*
@@ -577,7 +580,6 @@ struct request_queue {
577580
#define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */
578581
#define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
579582
#define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */
580-
#define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */
581583
#define QUEUE_FLAG_STATS 20 /* track IO start and completion times */
582584
#define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */
583585
#define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */

0 commit comments

Comments
 (0)