Skip to content

dm-crypt: limit the size of encryption requests

JIRA: https://issues.redhat.com/browse/RHEL-49548
Tested: cryptsetup tests and the bug reproducer
Upstream Status: kernel/git/device-mapper/linux-dm.git

commit 0d815e3400e631d227a3a95968b8c8e7e0c0ef9e
Author: Mikulas Patocka mpatocka@redhat.com
Date: Wed Jul 3 15:00:29 2024 +0200

dm-crypt: limit the size of encryption requests  

There was a performance regression reported where dm-crypt would perform  
worse on new kernels than on old kernels. The reason is that the old  
kernels split the bios to NVMe request size (that is usually 65536 or  
131072 bytes) and the new kernels pass the big bios through dm-crypt and  
split them underneath.  

If a big 1MiB bio is passed to dm-crypt, dm-crypt processes it on a single  
core without parallelization and this is what causes the performance  
degradation.  

This commit introduces new tunable variables  
/sys/module/dm_crypt/parameters/max_read_size and  
/sys/module/dm_crypt/parameters/max_write_size that specify the maximum  
bio size for dm-crypt. Bios larger than this value are split, so that  
they can be encrypted in parallel by multiple cores. If these variables  
are '0', a default 131072 is used.  

Splitting bios may cause performance regressions in other workloads - if  
this happens, the user should increase the value in max_read_size and  
max_write_size variables.  

max_read_size:  
128k    2399MiB/s  
256k    2368MiB/s  
512k    1986MiB/s  
1024    1790MiB/s  

max_write_size:  
128k    1712MiB/s  
256k    1651MiB/s  
512k    1537MiB/s  
1024k   1332MiB/s  

Note that if you run dm-crypt inside a virtual machine, you may need to do  
"echo numa >/sys/module/workqueue/parameters/default_affinity_scope" to  
improve performance.  

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>  
Tested-by: Laurence Oberman <loberman@redhat.com>  

Signed-off-by: Benjamin Marzinski bmarzins@redhat.com

Edited by Benjamin Marzinski

Merge request reports

Loading