Skip to content

Commit 442761f

Browse files
author
Mike Snitzer
committed
dm: conditionally enable branching for less used features
Use jump_labels to further reduce cost of unlikely branches for zoned block devices, dm-stats and swap_bios throttling. Signed-off-by: Mike Snitzer <[email protected]>
1 parent 563a225 commit 442761f

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

drivers/md/dm-core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/ktime.h>
1414
#include <linux/blk-mq.h>
1515
#include <linux/blk-crypto-profile.h>
16+
#include <linux/jump_label.h>
1617

1718
#include <trace/events/block.h>
1819

@@ -154,6 +155,10 @@ static inline struct dm_stats *dm_get_stats(struct mapped_device *md)
154155
return &md->stats;
155156
}
156157

158+
DECLARE_STATIC_KEY_FALSE(stats_enabled);
159+
DECLARE_STATIC_KEY_FALSE(swap_bios_enabled);
160+
DECLARE_STATIC_KEY_FALSE(zoned_enabled);
161+
157162
static inline bool dm_emulate_zone_append(struct mapped_device *md)
158163
{
159164
if (blk_queue_is_zoned(md->queue))

drivers/md/dm-stats.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ static int dm_stats_create(struct dm_stats *stats, sector_t start, sector_t end,
396396

397397
dm_stats_recalc_precise_timestamps(stats);
398398

399+
if (!static_key_enabled(&stats_enabled.key))
400+
static_branch_enable(&stats_enabled);
401+
399402
mutex_unlock(&stats->mutex);
400403

401404
resume_callback(md);

drivers/md/dm-table.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ int dm_table_add_target(struct dm_table *t, const char *type,
719719
DMWARN("%s: %s: ignoring discards_supported because num_discard_bios is zero.",
720720
dm_device_name(t->md), type);
721721

722+
if (tgt->limit_swap_bios && !static_key_enabled(&swap_bios_enabled.key))
723+
static_branch_enable(&swap_bios_enabled);
724+
722725
return 0;
723726

724727
bad:
@@ -2040,6 +2043,8 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
20402043
r = dm_set_zones_restrictions(t, q);
20412044
if (r)
20422045
return r;
2046+
if (!static_key_enabled(&zoned_enabled.key))
2047+
static_branch_enable(&zoned_enabled);
20432048
}
20442049

20452050
dm_update_crypto_profile(q, t);

drivers/md/dm.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ void dm_issue_global_event(void)
7171
wake_up(&dm_global_eventq);
7272
}
7373

74+
DEFINE_STATIC_KEY_FALSE(stats_enabled);
75+
DEFINE_STATIC_KEY_FALSE(swap_bios_enabled);
76+
DEFINE_STATIC_KEY_FALSE(zoned_enabled);
77+
7478
/*
7579
* One of these is allocated (on-stack) per original bio.
7680
*/
@@ -516,7 +520,8 @@ static void dm_io_acct(bool end, struct mapped_device *md, struct bio *bio,
516520
else
517521
bio_end_io_acct(bio, start_time);
518522

519-
if (unlikely(dm_stats_used(&md->stats)))
523+
if (static_branch_unlikely(&stats_enabled) &&
524+
unlikely(dm_stats_used(&md->stats)))
520525
dm_stats_account_io(&md->stats, bio_data_dir(bio),
521526
bio->bi_iter.bi_sector, bio_sectors(bio),
522527
end, start_time, stats_aux);
@@ -586,7 +591,8 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
586591
io->start_time = jiffies;
587592
io->flags = 0;
588593

589-
dm_stats_record_start(&md->stats, &io->stats_aux);
594+
if (static_branch_unlikely(&stats_enabled))
595+
dm_stats_record_start(&md->stats, &io->stats_aux);
590596

591597
return io;
592598
}
@@ -1012,21 +1018,25 @@ static void clone_endio(struct bio *bio)
10121018
disable_write_zeroes(md);
10131019
}
10141020

1015-
if (unlikely(blk_queue_is_zoned(q)))
1021+
if (static_branch_unlikely(&zoned_enabled) &&
1022+
unlikely(blk_queue_is_zoned(q)))
10161023
dm_zone_endio(io, bio);
10171024

10181025
if (endio) {
10191026
int r = endio(ti, bio, &error);
10201027
switch (r) {
10211028
case DM_ENDIO_REQUEUE:
1022-
/*
1023-
* Requeuing writes to a sequential zone of a zoned
1024-
* target will break the sequential write pattern:
1025-
* fail such IO.
1026-
*/
1027-
if (WARN_ON_ONCE(dm_is_zone_write(md, bio)))
1028-
error = BLK_STS_IOERR;
1029-
else
1029+
if (static_branch_unlikely(&zoned_enabled)) {
1030+
/*
1031+
* Requeuing writes to a sequential zone of a zoned
1032+
* target will break the sequential write pattern:
1033+
* fail such IO.
1034+
*/
1035+
if (WARN_ON_ONCE(dm_is_zone_write(md, bio)))
1036+
error = BLK_STS_IOERR;
1037+
else
1038+
error = BLK_STS_DM_REQUEUE;
1039+
} else
10301040
error = BLK_STS_DM_REQUEUE;
10311041
fallthrough;
10321042
case DM_ENDIO_DONE:
@@ -1040,7 +1050,8 @@ static void clone_endio(struct bio *bio)
10401050
}
10411051
}
10421052

1043-
if (unlikely(swap_bios_limit(ti, bio)))
1053+
if (static_branch_unlikely(&swap_bios_enabled) &&
1054+
unlikely(swap_bios_limit(ti, bio)))
10441055
up(&md->swap_bios_semaphore);
10451056

10461057
free_tio(bio);
@@ -1295,21 +1306,25 @@ static void __map_bio(struct bio *clone)
12951306
dm_io_inc_pending(io);
12961307
tio->old_sector = clone->bi_iter.bi_sector;
12971308

1298-
if (unlikely(swap_bios_limit(ti, clone))) {
1309+
if (static_branch_unlikely(&swap_bios_enabled) &&
1310+
unlikely(swap_bios_limit(ti, clone))) {
12991311
int latch = get_swap_bios();
13001312
if (unlikely(latch != md->swap_bios))
13011313
__set_swap_bios_limit(md, latch);
13021314
down(&md->swap_bios_semaphore);
13031315
}
13041316

1305-
/*
1306-
* Check if the IO needs a special mapping due to zone append emulation
1307-
* on zoned target. In this case, dm_zone_map_bio() calls the target
1308-
* map operation.
1309-
*/
1310-
if (unlikely(dm_emulate_zone_append(md)))
1311-
r = dm_zone_map_bio(tio);
1312-
else
1317+
if (static_branch_unlikely(&zoned_enabled)) {
1318+
/*
1319+
* Check if the IO needs a special mapping due to zone append
1320+
* emulation on zoned target. In this case, dm_zone_map_bio()
1321+
* calls the target map operation.
1322+
*/
1323+
if (unlikely(dm_emulate_zone_append(md)))
1324+
r = dm_zone_map_bio(tio);
1325+
else
1326+
r = ti->type->map(ti, clone);
1327+
} else
13131328
r = ti->type->map(ti, clone);
13141329

13151330
switch (r) {
@@ -1329,7 +1344,8 @@ static void __map_bio(struct bio *clone)
13291344
break;
13301345
case DM_MAPIO_KILL:
13311346
case DM_MAPIO_REQUEUE:
1332-
if (unlikely(swap_bios_limit(ti, clone)))
1347+
if (static_branch_unlikely(&swap_bios_enabled) &&
1348+
unlikely(swap_bios_limit(ti, clone)))
13331349
up(&md->swap_bios_semaphore);
13341350
free_tio(clone);
13351351
if (r == DM_MAPIO_KILL)
@@ -1565,7 +1581,8 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md,
15651581
ci->sector_count = bio_sectors(bio);
15661582

15671583
/* Shouldn't happen but sector_count was being set to 0 so... */
1568-
if (WARN_ON_ONCE(op_is_zone_mgmt(bio_op(bio)) && ci->sector_count))
1584+
if (static_branch_unlikely(&zoned_enabled) &&
1585+
WARN_ON_ONCE(op_is_zone_mgmt(bio_op(bio)) && ci->sector_count))
15691586
ci->sector_count = 0;
15701587
}
15711588

0 commit comments

Comments
 (0)