Skip to content

Commit 5c5d0d7

Browse files
LongPing WeiMikulas Patocka
authored andcommitted
dm-verity: support block number limits for different ioprio classes
Calling verity_verify_io in bh for IO of all sizes is not suitable for embedded devices. From our tests, it can improve the performance of 4K synchronise random reads. For example: ./fio --name=rand_read --ioengine=psync --rw=randread --bs=4K \ --direct=1 --numjobs=8 --runtime=60 --time_based --group_reporting \ --filename=/dev/block/mapper/xx-verity But it will degrade the performance of 512K synchronise sequential reads on our devices. For example: ./fio --name=read --ioengine=psync --rw=read --bs=512K --direct=1 \ --numjobs=8 --runtime=60 --time_based --group_reporting \ --filename=/dev/block/mapper/xx-verity A parameter array is introduced by this change. And users can modify the default config by /sys/module/dm_verity/parameters/use_bh_bytes. The default limits for NONE/RT/BE is set to 8192. The default limits for IDLE is set to 0. Call verity_verify_io directly when verity_end_io is not in hardirq. Signed-off-by: LongPing Wei <weilongping@oppo.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent d43929e commit 5c5d0d7

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

Documentation/admin-guide/device-mapper/verity.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,15 @@ root_hash_sig_key_desc <key_description>
151151
already in the secondary trusted keyring.
152152

153153
try_verify_in_tasklet
154-
If verity hashes are in cache, verify data blocks in kernel tasklet instead
155-
of workqueue. This option can reduce IO latency.
154+
If verity hashes are in cache and the IO size does not exceed the limit,
155+
verify data blocks in bottom half instead of workqueue. This option can
156+
reduce IO latency. The size limits can be configured via
157+
/sys/module/dm_verity/parameters/use_bh_bytes. The four parameters
158+
correspond to limits for IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT,
159+
IOPRIO_CLASS_BE and IOPRIO_CLASS_IDLE in turn.
160+
For example:
161+
<none>,<rt>,<be>,<idle>
162+
4096,4096,4096,4096
156163

157164
Theory of operation
158165
===================

drivers/md/dm-verity-target.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define DM_VERITY_ENV_VAR_NAME "DM_VERITY_ERR_BLOCK_NR"
3131

3232
#define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144
33+
#define DM_VERITY_USE_BH_DEFAULT_BYTES 8192
3334

3435
#define DM_VERITY_MAX_CORRUPTED_ERRS 100
3536

@@ -49,6 +50,15 @@ static unsigned int dm_verity_prefetch_cluster = DM_VERITY_DEFAULT_PREFETCH_SIZE
4950

5051
module_param_named(prefetch_cluster, dm_verity_prefetch_cluster, uint, 0644);
5152

53+
static unsigned int dm_verity_use_bh_bytes[4] = {
54+
DM_VERITY_USE_BH_DEFAULT_BYTES, // IOPRIO_CLASS_NONE
55+
DM_VERITY_USE_BH_DEFAULT_BYTES, // IOPRIO_CLASS_RT
56+
DM_VERITY_USE_BH_DEFAULT_BYTES, // IOPRIO_CLASS_BE
57+
0 // IOPRIO_CLASS_IDLE
58+
};
59+
60+
module_param_array_named(use_bh_bytes, dm_verity_use_bh_bytes, uint, NULL, 0644);
61+
5262
static DEFINE_STATIC_KEY_FALSE(use_bh_wq_enabled);
5363

5464
/* Is at least one dm-verity instance using ahash_tfm instead of shash_tfm? */
@@ -669,9 +679,17 @@ static void verity_bh_work(struct work_struct *w)
669679
verity_finish_io(io, errno_to_blk_status(err));
670680
}
671681

682+
static inline bool verity_use_bh(unsigned int bytes, unsigned short ioprio)
683+
{
684+
return ioprio <= IOPRIO_CLASS_IDLE &&
685+
bytes <= READ_ONCE(dm_verity_use_bh_bytes[ioprio]);
686+
}
687+
672688
static void verity_end_io(struct bio *bio)
673689
{
674690
struct dm_verity_io *io = bio->bi_private;
691+
unsigned short ioprio = IOPRIO_PRIO_CLASS(bio->bi_ioprio);
692+
unsigned int bytes = io->n_blocks << io->v->data_dev_block_bits;
675693

676694
if (bio->bi_status &&
677695
(!verity_fec_is_enabled(io->v) ||
@@ -681,9 +699,14 @@ static void verity_end_io(struct bio *bio)
681699
return;
682700
}
683701

684-
if (static_branch_unlikely(&use_bh_wq_enabled) && io->v->use_bh_wq) {
685-
INIT_WORK(&io->bh_work, verity_bh_work);
686-
queue_work(system_bh_wq, &io->bh_work);
702+
if (static_branch_unlikely(&use_bh_wq_enabled) && io->v->use_bh_wq &&
703+
verity_use_bh(bytes, ioprio)) {
704+
if (in_hardirq() || irqs_disabled()) {
705+
INIT_WORK(&io->bh_work, verity_bh_work);
706+
queue_work(system_bh_wq, &io->bh_work);
707+
} else {
708+
verity_bh_work(&io->bh_work);
709+
}
687710
} else {
688711
INIT_WORK(&io->work, verity_work);
689712
queue_work(io->v->verify_wq, &io->work);

0 commit comments

Comments
 (0)