Whamcloud - gitweb
LU-16985 utils: adaptive bufsize for mirroring 73/51773/5
authorAlex Zhuravlev <bzzz@whamcloud.com>
Wed, 26 Jul 2023 19:00:29 +0000 (22:00 +0300)
committerOleg Drokin <green@whamcloud.com>
Mon, 7 Aug 2023 03:50:44 +0000 (03:50 +0000)
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 <bzzz@whamcloud.com>
Change-Id: Ibc8e7d30ded201a4ff3d699530f5c9f8be5ce7f1
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51773
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/lfs.c

index 381d940..54b7a23 100644 (file)
@@ -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)