Skip to content

Commit 2285e14

Browse files
yangerkunMike Snitzer
authored andcommitted
dm-crypt: export sysfs of all workqueues
Once there is a heavy IO load, so many encrypt/decrypt work will occupy all of the cpu, which may lead to the poor performance for other service. So the improved visibility and controls over dm-crypt workqueues, as was offered with commit a2b8b2d ("dm crypt: export sysfs of kcryptd workqueue"), seems necessary. By exporting dm-crypt's workqueues in sysfs, the entry like cpumask/max_active and so on can help us to limit the CPU usage for encrypt/decrypt work. However, commit a2b8b2d did not consider that DM table reload will call .ctr before .dtr, so the reload for dm-crypt failed because the same sysfs name was present. This was the original need for commit 48b0777 ("Revert "dm crypt: export sysfs of kcryptd workqueue""). Reintroduce the use of WQ_SYSFS, and use it for both the IO and crypt workqueues, but make the workqueue names include a unique id (via ida) to allow both old and new sysfs entries to coexist. Signed-off-by: yangerkun <yangerkun@huawei.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 5268de7 commit 2285e14

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

drivers/md/dm-crypt.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
#define DM_MSG_PREFIX "crypt"
4949

50+
static DEFINE_IDA(workqueue_ida);
51+
5052
/*
5153
* context holding the current state of a multi-part conversion
5254
*/
@@ -184,6 +186,7 @@ struct crypt_config {
184186
struct crypto_aead **tfms_aead;
185187
} cipher_tfm;
186188
unsigned int tfms_count;
189+
int workqueue_id;
187190
unsigned long cipher_flags;
188191

189192
/*
@@ -2771,6 +2774,9 @@ static void crypt_dtr(struct dm_target *ti)
27712774
if (cc->crypt_queue)
27722775
destroy_workqueue(cc->crypt_queue);
27732776

2777+
if (cc->workqueue_id)
2778+
ida_free(&workqueue_ida, cc->workqueue_id);
2779+
27742780
crypt_free_tfms(cc);
27752781

27762782
bioset_exit(&cc->bs);
@@ -3232,7 +3238,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
32323238
{
32333239
struct crypt_config *cc;
32343240
const char *devname = dm_table_device_name(ti->table);
3235-
int key_size;
3241+
int key_size, wq_id;
32363242
unsigned int align_mask;
32373243
unsigned int common_wq_flags;
32383244
unsigned long long tmpll;
@@ -3401,25 +3407,33 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
34013407
cc->tag_pool_max_sectors <<= cc->sector_shift;
34023408
}
34033409

3410+
wq_id = ida_alloc_min(&workqueue_ida, 1, GFP_KERNEL);
3411+
if (wq_id < 0) {
3412+
ti->error = "Couldn't get workqueue id";
3413+
ret = wq_id;
3414+
goto bad;
3415+
}
3416+
cc->workqueue_id = wq_id;
3417+
34043418
ret = -ENOMEM;
3405-
common_wq_flags = WQ_MEM_RECLAIM;
3419+
common_wq_flags = WQ_MEM_RECLAIM | WQ_SYSFS;
34063420
if (test_bit(DM_CRYPT_HIGH_PRIORITY, &cc->flags))
34073421
common_wq_flags |= WQ_HIGHPRI;
34083422

3409-
cc->io_queue = alloc_workqueue("kcryptd_io/%s", common_wq_flags, 1, devname);
3423+
cc->io_queue = alloc_workqueue("kcryptd_io-%s-%d", common_wq_flags, 1, devname, wq_id);
34103424
if (!cc->io_queue) {
34113425
ti->error = "Couldn't create kcryptd io queue";
34123426
goto bad;
34133427
}
34143428

34153429
if (test_bit(DM_CRYPT_SAME_CPU, &cc->flags)) {
3416-
cc->crypt_queue = alloc_workqueue("kcryptd/%s",
3430+
cc->crypt_queue = alloc_workqueue("kcryptd-%s-%d",
34173431
common_wq_flags | WQ_CPU_INTENSIVE,
3418-
1, devname);
3432+
1, devname, wq_id);
34193433
} else {
3420-
cc->crypt_queue = alloc_workqueue("kcryptd/%s",
3434+
cc->crypt_queue = alloc_workqueue("kcryptd-%s-%d",
34213435
common_wq_flags | WQ_CPU_INTENSIVE | WQ_UNBOUND,
3422-
num_online_cpus(), devname);
3436+
num_online_cpus(), devname, wq_id);
34233437
}
34243438
if (!cc->crypt_queue) {
34253439
ti->error = "Couldn't create kcryptd queue";

0 commit comments

Comments
 (0)