Skip to content

Commit cdb2497

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move the io_stat flag setting to queue_limits
Move the io_stat flag into the queue_limits feature field so that it can be set atomically with the queue frozen. Simplify md and dm to set the flag unconditionally instead of avoiding setting a simple flag for cases where it already is set by other means, which is a bit pointless. 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-17-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 39a9f1c commit cdb2497

File tree

8 files changed

+26
-24
lines changed

8 files changed

+26
-24
lines changed

block/blk-mq-debugfs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static const char *const blk_queue_flag_name[] = {
8484
QUEUE_FLAG_NAME(NOMERGES),
8585
QUEUE_FLAG_NAME(SAME_COMP),
8686
QUEUE_FLAG_NAME(FAIL_IO),
87-
QUEUE_FLAG_NAME(IO_STAT),
8887
QUEUE_FLAG_NAME(NOXMERGES),
8988
QUEUE_FLAG_NAME(SYNCHRONOUS),
9089
QUEUE_FLAG_NAME(SAME_FORCE),

block/blk-mq.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4116,7 +4116,11 @@ struct request_queue *blk_mq_alloc_queue(struct blk_mq_tag_set *set,
41164116
struct request_queue *q;
41174117
int ret;
41184118

4119-
q = blk_alloc_queue(lim ? lim : &default_lim, set->numa_node);
4119+
if (!lim)
4120+
lim = &default_lim;
4121+
lim->features |= BLK_FEAT_IO_STAT;
4122+
4123+
q = blk_alloc_queue(lim, set->numa_node);
41204124
if (IS_ERR(q))
41214125
return q;
41224126
q->queuedata = queuedata;

block/blk-sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ queue_##name##_store(struct request_queue *q, const char *page, size_t count) \
324324

325325
QUEUE_SYSFS_FEATURE(rotational, BLK_FEAT_ROTATIONAL)
326326
QUEUE_SYSFS_FEATURE(add_random, BLK_FEAT_ADD_RANDOM)
327-
QUEUE_SYSFS_BIT_FNS(iostats, IO_STAT, 0);
327+
QUEUE_SYSFS_FEATURE(iostats, BLK_FEAT_IO_STAT)
328328
QUEUE_SYSFS_BIT_FNS(stable_writes, STABLE_WRITES, 0);
329329
#undef QUEUE_SYSFS_BIT_FNS
330330

drivers/md/dm-table.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,12 @@ int dm_split_args(int *argc, char ***argvp, char *input)
579579
return 0;
580580
}
581581

582+
static void dm_set_stacking_limits(struct queue_limits *limits)
583+
{
584+
blk_set_stacking_limits(limits);
585+
limits->features |= BLK_FEAT_IO_STAT;
586+
}
587+
582588
/*
583589
* Impose necessary and sufficient conditions on a devices's table such
584590
* that any incoming bio which respects its logical_block_size can be
@@ -617,7 +623,7 @@ static int validate_hardware_logical_block_alignment(struct dm_table *t,
617623
for (i = 0; i < t->num_targets; i++) {
618624
ti = dm_table_get_target(t, i);
619625

620-
blk_set_stacking_limits(&ti_limits);
626+
dm_set_stacking_limits(&ti_limits);
621627

622628
/* combine all target devices' limits */
623629
if (ti->type->iterate_devices)
@@ -1591,7 +1597,7 @@ int dm_calculate_queue_limits(struct dm_table *t,
15911597
unsigned int zone_sectors = 0;
15921598
bool zoned = false;
15931599

1594-
blk_set_stacking_limits(limits);
1600+
dm_set_stacking_limits(limits);
15951601

15961602
t->integrity_supported = true;
15971603
for (unsigned int i = 0; i < t->num_targets; i++) {
@@ -1604,7 +1610,7 @@ int dm_calculate_queue_limits(struct dm_table *t,
16041610
for (unsigned int i = 0; i < t->num_targets; i++) {
16051611
struct dm_target *ti = dm_table_get_target(t, i);
16061612

1607-
blk_set_stacking_limits(&ti_limits);
1613+
dm_set_stacking_limits(&ti_limits);
16081614

16091615
if (!ti->type->iterate_devices) {
16101616
/* Set I/O hints portion of queue limits */

drivers/md/dm.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,22 +2386,15 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
23862386
struct table_device *td;
23872387
int r;
23882388

2389-
switch (type) {
2390-
case DM_TYPE_REQUEST_BASED:
2389+
WARN_ON_ONCE(type == DM_TYPE_NONE);
2390+
2391+
if (type == DM_TYPE_REQUEST_BASED) {
23912392
md->disk->fops = &dm_rq_blk_dops;
23922393
r = dm_mq_init_request_queue(md, t);
23932394
if (r) {
23942395
DMERR("Cannot initialize queue for request-based dm mapped device");
23952396
return r;
23962397
}
2397-
break;
2398-
case DM_TYPE_BIO_BASED:
2399-
case DM_TYPE_DAX_BIO_BASED:
2400-
blk_queue_flag_set(QUEUE_FLAG_IO_STAT, md->queue);
2401-
break;
2402-
case DM_TYPE_NONE:
2403-
WARN_ON_ONCE(true);
2404-
break;
24052398
}
24062399

24072400
r = dm_calculate_queue_limits(t, &limits);

drivers/md/md.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5787,7 +5787,8 @@ struct mddev *md_alloc(dev_t dev, char *name)
57875787
int unit;
57885788
int error;
57895789
struct queue_limits lim = {
5790-
.features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA,
5790+
.features = BLK_FEAT_WRITE_CACHE | BLK_FEAT_FUA |
5791+
BLK_FEAT_IO_STAT,
57915792
};
57925793

57935794
/*
@@ -6152,8 +6153,6 @@ int md_run(struct mddev *mddev)
61526153
if (!mddev_is_dm(mddev)) {
61536154
struct request_queue *q = mddev->gendisk->queue;
61546155

6155-
blk_queue_flag_set(QUEUE_FLAG_IO_STAT, q);
6156-
61576156
/* Set the NOWAIT flags if all underlying devices support it */
61586157
if (nowait)
61596158
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, q);

drivers/nvme/host/multipath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +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;
541542
if (head->ids.csi != NVME_CSI_ZNS)
542543
lim.max_zone_append_sectors = 0;
543544

@@ -550,7 +551,6 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
550551
ctrl->subsys->instance, head->instance);
551552

552553
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, head->disk->queue);
553-
blk_queue_flag_set(QUEUE_FLAG_IO_STAT, head->disk->queue);
554554
/*
555555
* This assumes all controllers that refer to a namespace either
556556
* support poll queues or not. That is not a strict guarantee,

include/linux/blkdev.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ enum {
295295

296296
/* contributes to the random number pool */
297297
BLK_FEAT_ADD_RANDOM = (1u << 3),
298+
299+
/* do disk/partitions IO accounting */
300+
BLK_FEAT_IO_STAT = (1u << 4),
298301
};
299302

300303
/*
@@ -558,7 +561,6 @@ struct request_queue {
558561
#define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */
559562
#define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */
560563
#define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */
561-
#define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */
562564
#define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */
563565
#define QUEUE_FLAG_SYNCHRONOUS 11 /* always completes in submit context */
564566
#define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */
@@ -577,8 +579,7 @@ struct request_queue {
577579
#define QUEUE_FLAG_SQ_SCHED 30 /* single queue style io dispatch */
578580
#define QUEUE_FLAG_SKIP_TAGSET_QUIESCE 31 /* quiesce_tagset skip the queue*/
579581

580-
#define QUEUE_FLAG_MQ_DEFAULT ((1UL << QUEUE_FLAG_IO_STAT) | \
581-
(1UL << QUEUE_FLAG_SAME_COMP) | \
582+
#define QUEUE_FLAG_MQ_DEFAULT ((1UL << QUEUE_FLAG_SAME_COMP) | \
582583
(1UL << QUEUE_FLAG_NOWAIT))
583584

584585
void blk_queue_flag_set(unsigned int flag, struct request_queue *q);
@@ -592,7 +593,7 @@ bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q);
592593
#define blk_queue_noxmerges(q) \
593594
test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
594595
#define blk_queue_nonrot(q) ((q)->limits.features & BLK_FEAT_ROTATIONAL)
595-
#define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
596+
#define blk_queue_io_stat(q) ((q)->limits.features & BLK_FEAT_IO_STAT)
596597
#define blk_queue_zone_resetall(q) \
597598
test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags)
598599
#define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags)

0 commit comments

Comments
 (0)