From 15b94e08e84095195eee8c83be65c5f3361532e8 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Wed, 26 Jul 2023 22:00:29 +0300 Subject: [PATCH] LU-16985 utils: adaptive bufsize for mirroring if bandwidth limit is requested, then change default bufsize to make I/O rather smooth than like a saw. Fixes: 23224e03dc ("LU-16587 utils: give lfs migrate a larger buffer") Signed-off-by: Alex Zhuravlev Change-Id: Ibc8e7d30ded201a4ff3d699530f5c9f8be5ce7f1 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51773 Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Tested-by: jenkins Tested-by: Maloo --- lustre/utils/lfs.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 381d940..54b7a23 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -816,7 +816,8 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int), long stats_interval_sec, off_t file_size_bytes) { struct llapi_layout *layout; - size_t buf_size = 64 * 1024 * 1024; + size_t buf_size = 64 * ONE_MB; + uint64_t stripe_size = ONE_MB; void *buf = NULL; off_t pos = 0; off_t data_end = 0; @@ -831,8 +832,6 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int), layout = llapi_layout_get_by_fd(fd_src, 0); if (layout) { - uint64_t stripe_size; - rc = llapi_layout_stripe_size_get(layout, &stripe_size); if (rc == 0) { /* We like big bufs */ @@ -846,6 +845,11 @@ static int migrate_copy_data(int fd_src, int fd_dst, int (*check_file)(int), llapi_layout_free(layout); } + /* limit transfer size to what can be sent in one second */ + if (bandwidth_bytes_sec && bandwidth_bytes_sec < buf_size) + buf_size = (bandwidth_bytes_sec + stripe_size - 1) & + ~(stripe_size - 1); + /* Use a page-aligned buffer for direct I/O */ rc = posix_memalign(&buf, page_size, buf_size); if (rc != 0) -- 1.8.3.1