@@ -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