Skip to content

Commit c663e04

Browse files
ntsironsnitm
authored andcommitted
dm kcopyd: Increase default sub-job size to 512KB
Currently, kcopyd has a sub-job size of 64KB and a maximum number of 8 sub-jobs. As a result, for any kcopyd job, we have a maximum of 512KB of I/O in flight. This upper limit to the amount of in-flight I/O under-utilizes fast devices and results in decreased throughput, e.g., when writing to a snapshotted thin LV with I/O size less than the pool's block size (so COW is performed using kcopyd). Increase kcopyd's default sub-job size to 512KB, so we have a maximum of 4MB of I/O in flight for each kcopyd job. This results in an up to 96% improvement of bandwidth when writing to a snapshotted thin LV, with I/O sizes less than the pool's block size. Also, add dm_mod.kcopyd_subjob_size_kb module parameter to allow users to fine tune the sub-job size of kcopyd. The default value of this parameter is 512KB and the maximum allowed value is 1024KB. We evaluate the performance impact of the change by running the snap_breaking_throughput benchmark, from the device mapper test suite [1]. The benchmark: 1. Creates a 1G thin LV 2. Provisions the thin LV 3. Takes a snapshot of the thin LV 4. Writes to the thin LV with: dd if=/dev/zero of=/dev/vg/thin_lv oflag=direct bs=<I/O size> Running this benchmark with various thin pool block sizes and dd I/O sizes (all combinations triggering the use of kcopyd) we get the following results: +-----------------+-------------+------------------+-----------------+ | Pool block size | dd I/O size | BW before (MB/s) | BW after (MB/s) | +-----------------+-------------+------------------+-----------------+ | 1 MB | 256 KB | 242 | 280 | | 1 MB | 512 KB | 238 | 295 | | | | | | | 2 MB | 256 KB | 238 | 354 | | 2 MB | 512 KB | 241 | 380 | | 2 MB | 1 MB | 245 | 394 | | | | | | | 4 MB | 256 KB | 248 | 412 | | 4 MB | 512 KB | 234 | 432 | | 4 MB | 1 MB | 251 | 474 | | 4 MB | 2 MB | 257 | 504 | | | | | | | 8 MB | 256 KB | 239 | 420 | | 8 MB | 512 KB | 256 | 431 | | 8 MB | 1 MB | 264 | 467 | | 8 MB | 2 MB | 264 | 502 | | 8 MB | 4 MB | 281 | 537 | +-----------------+-------------+------------------+-----------------+ [1] https://github.com/jthornber/device-mapper-test-suite Signed-off-by: Nikos Tsironis <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 3ee2548 commit c663e04

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

drivers/md/dm-kcopyd.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,27 @@
2828

2929
#include "dm-core.h"
3030

31-
#define SUB_JOB_SIZE 128
3231
#define SPLIT_COUNT 8
3332
#define MIN_JOBS 8
34-
#define RESERVE_PAGES (DIV_ROUND_UP(SUB_JOB_SIZE << SECTOR_SHIFT, PAGE_SIZE))
33+
34+
#define DEFAULT_SUB_JOB_SIZE_KB 512
35+
#define MAX_SUB_JOB_SIZE_KB 1024
36+
37+
static unsigned kcopyd_subjob_size_kb = DEFAULT_SUB_JOB_SIZE_KB;
38+
39+
module_param(kcopyd_subjob_size_kb, uint, S_IRUGO | S_IWUSR);
40+
MODULE_PARM_DESC(kcopyd_subjob_size_kb, "Sub-job size for dm-kcopyd clients");
41+
42+
static unsigned dm_get_kcopyd_subjob_size(void)
43+
{
44+
unsigned sub_job_size_kb;
45+
46+
sub_job_size_kb = __dm_get_module_param(&kcopyd_subjob_size_kb,
47+
DEFAULT_SUB_JOB_SIZE_KB,
48+
MAX_SUB_JOB_SIZE_KB);
49+
50+
return sub_job_size_kb << 1;
51+
}
3552

3653
/*-----------------------------------------------------------------
3754
* Each kcopyd client has its own little pool of preallocated
@@ -41,6 +58,7 @@ struct dm_kcopyd_client {
4158
struct page_list *pages;
4259
unsigned nr_reserved_pages;
4360
unsigned nr_free_pages;
61+
unsigned sub_job_size;
4462

4563
struct dm_io_client *io_client;
4664

@@ -693,8 +711,8 @@ static void segment_complete(int read_err, unsigned long write_err,
693711
progress = job->progress;
694712
count = job->source.count - progress;
695713
if (count) {
696-
if (count > SUB_JOB_SIZE)
697-
count = SUB_JOB_SIZE;
714+
if (count > kc->sub_job_size)
715+
count = kc->sub_job_size;
698716

699717
job->progress += count;
700718
}
@@ -821,7 +839,7 @@ void dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
821839
job->master_job = job;
822840
job->write_offset = 0;
823841

824-
if (job->source.count <= SUB_JOB_SIZE)
842+
if (job->source.count <= kc->sub_job_size)
825843
dispatch_job(job);
826844
else {
827845
job->progress = 0;
@@ -888,6 +906,7 @@ int kcopyd_cancel(struct kcopyd_job *job, int block)
888906
struct dm_kcopyd_client *dm_kcopyd_client_create(struct dm_kcopyd_throttle *throttle)
889907
{
890908
int r;
909+
unsigned reserve_pages;
891910
struct dm_kcopyd_client *kc;
892911

893912
kc = kzalloc(sizeof(*kc), GFP_KERNEL);
@@ -912,9 +931,12 @@ struct dm_kcopyd_client *dm_kcopyd_client_create(struct dm_kcopyd_throttle *thro
912931
goto bad_workqueue;
913932
}
914933

934+
kc->sub_job_size = dm_get_kcopyd_subjob_size();
935+
reserve_pages = DIV_ROUND_UP(kc->sub_job_size << SECTOR_SHIFT, PAGE_SIZE);
936+
915937
kc->pages = NULL;
916938
kc->nr_reserved_pages = kc->nr_free_pages = 0;
917-
r = client_reserve_pages(kc, RESERVE_PAGES);
939+
r = client_reserve_pages(kc, reserve_pages);
918940
if (r)
919941
goto bad_client_pages;
920942

0 commit comments

Comments
 (0)