@@ -71,6 +71,10 @@ void dm_issue_global_event(void)
71
71
wake_up (& dm_global_eventq );
72
72
}
73
73
74
+ DEFINE_STATIC_KEY_FALSE (stats_enabled );
75
+ DEFINE_STATIC_KEY_FALSE (swap_bios_enabled );
76
+ DEFINE_STATIC_KEY_FALSE (zoned_enabled );
77
+
74
78
/*
75
79
* One of these is allocated (on-stack) per original bio.
76
80
*/
@@ -516,7 +520,8 @@ static void dm_io_acct(bool end, struct mapped_device *md, struct bio *bio,
516
520
else
517
521
bio_end_io_acct (bio , start_time );
518
522
519
- if (unlikely (dm_stats_used (& md -> stats )))
523
+ if (static_branch_unlikely (& stats_enabled ) &&
524
+ unlikely (dm_stats_used (& md -> stats )))
520
525
dm_stats_account_io (& md -> stats , bio_data_dir (bio ),
521
526
bio -> bi_iter .bi_sector , bio_sectors (bio ),
522
527
end , start_time , stats_aux );
@@ -586,7 +591,8 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
586
591
io -> start_time = jiffies ;
587
592
io -> flags = 0 ;
588
593
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 );
590
596
591
597
return io ;
592
598
}
@@ -1012,21 +1018,25 @@ static void clone_endio(struct bio *bio)
1012
1018
disable_write_zeroes (md );
1013
1019
}
1014
1020
1015
- if (unlikely (blk_queue_is_zoned (q )))
1021
+ if (static_branch_unlikely (& zoned_enabled ) &&
1022
+ unlikely (blk_queue_is_zoned (q )))
1016
1023
dm_zone_endio (io , bio );
1017
1024
1018
1025
if (endio ) {
1019
1026
int r = endio (ti , bio , & error );
1020
1027
switch (r ) {
1021
1028
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
1030
1040
error = BLK_STS_DM_REQUEUE ;
1031
1041
fallthrough ;
1032
1042
case DM_ENDIO_DONE :
@@ -1040,7 +1050,8 @@ static void clone_endio(struct bio *bio)
1040
1050
}
1041
1051
}
1042
1052
1043
- if (unlikely (swap_bios_limit (ti , bio )))
1053
+ if (static_branch_unlikely (& swap_bios_enabled ) &&
1054
+ unlikely (swap_bios_limit (ti , bio )))
1044
1055
up (& md -> swap_bios_semaphore );
1045
1056
1046
1057
free_tio (bio );
@@ -1295,21 +1306,25 @@ static void __map_bio(struct bio *clone)
1295
1306
dm_io_inc_pending (io );
1296
1307
tio -> old_sector = clone -> bi_iter .bi_sector ;
1297
1308
1298
- if (unlikely (swap_bios_limit (ti , clone ))) {
1309
+ if (static_branch_unlikely (& swap_bios_enabled ) &&
1310
+ unlikely (swap_bios_limit (ti , clone ))) {
1299
1311
int latch = get_swap_bios ();
1300
1312
if (unlikely (latch != md -> swap_bios ))
1301
1313
__set_swap_bios_limit (md , latch );
1302
1314
down (& md -> swap_bios_semaphore );
1303
1315
}
1304
1316
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
1313
1328
r = ti -> type -> map (ti , clone );
1314
1329
1315
1330
switch (r ) {
@@ -1329,7 +1344,8 @@ static void __map_bio(struct bio *clone)
1329
1344
break ;
1330
1345
case DM_MAPIO_KILL :
1331
1346
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 )))
1333
1349
up (& md -> swap_bios_semaphore );
1334
1350
free_tio (clone );
1335
1351
if (r == DM_MAPIO_KILL )
@@ -1565,7 +1581,8 @@ static void init_clone_info(struct clone_info *ci, struct mapped_device *md,
1565
1581
ci -> sector_count = bio_sectors (bio );
1566
1582
1567
1583
/* 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 ))
1569
1586
ci -> sector_count = 0 ;
1570
1587
}
1571
1588
0 commit comments