]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_scrub: use histograms to speed up phase 8 on the realtime volume
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:41 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:35 +0000 (18:01 -0800)
Use the same statistical methods that we use on the data volume to
compute the minimum threshold size for fstrims on the realtime volume.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
scrub/phase7.c
scrub/phase8.c
scrub/xfs_scrub.c
scrub/xfs_scrub.h

index 475d8f157eeccae4c157fec977709cfa3cc24c07..01097b67879878b1e46077435f48f6f7cdd92819 100644 (file)
@@ -31,6 +31,7 @@ struct summary_counts {
 
        /* Free space histogram, in fsb */
        struct histogram        datadev_hist;
+       struct histogram        rtdev_hist;
 };
 
 /*
@@ -56,6 +57,7 @@ summary_count_init(
        struct summary_counts   *counts = data;
 
        init_freesp_hist(&counts->datadev_hist);
+       init_freesp_hist(&counts->rtdev_hist);
 }
 
 /* Record block usage. */
@@ -83,6 +85,8 @@ count_block_summary(
                blocks = cvt_b_to_off_fsbt(&ctx->mnt, fsmap->fmr_length);
                if (fsmap->fmr_device == ctx->fsinfo.fs_datadev)
                        hist_add(&counts->datadev_hist, blocks);
+               else if (fsmap->fmr_device == ctx->fsinfo.fs_rtdev)
+                       hist_add(&counts->rtdev_hist, blocks);
                return 0;
        }
 
@@ -124,7 +128,9 @@ add_summaries(
        total->agbytes += item->agbytes;
 
        hist_import(&total->datadev_hist, &item->datadev_hist);
+       hist_import(&total->rtdev_hist, &item->rtdev_hist);
        hist_free(&item->datadev_hist);
+       hist_free(&item->rtdev_hist);
        return 0;
 }
 
@@ -195,6 +201,7 @@ phase7_func(
 
        /* Preserve free space histograms for phase 8. */
        hist_move(&ctx->datadev_hist, &totalcount.datadev_hist);
+       hist_move(&ctx->rtdev_hist, &totalcount.rtdev_hist);
 
        /* Scan the whole fs. */
        error = scrub_count_all_inodes(ctx, &counted_inodes);
index adb177ecdafbeb90445684d442cc3abfe96510a9..e8c72d8eb851afc1f9d852b8a28cf1a3b8a6c193 100644 (file)
@@ -211,13 +211,17 @@ fstrim_rtdev(
        struct scrub_ctx        *ctx)
 {
        struct xfs_fsop_geom    *geo = &ctx->mnt.fsgeom;
+       uint64_t                minlen_fsb;
+
+       minlen_fsb = fstrim_compute_minlen(ctx, &ctx->rtdev_hist);
 
        /*
         * The fstrim ioctl pretends that the realtime volume is in the address
         * space immediately after the data volume.  Ignore EINVAL if someone
         * tries to run us on an older kernel.
         */
-       return fstrim_fsblocks(ctx, geo->datablocks, geo->rtblocks, 0, true);
+       return fstrim_fsblocks(ctx, geo->datablocks, geo->rtblocks,
+                       minlen_fsb, true);
 }
 
 /* Trim the filesystem, if desired. */
index 3e7d9138f97ec20b9f9538d39aefa213ac9e8f30..90897cc26cd71d7d2ce3d30eb5f38f4cd107e713 100644 (file)
@@ -728,6 +728,7 @@ main(
        int                     error;
 
        hist_init(&ctx.datadev_hist);
+       hist_init(&ctx.rtdev_hist);
 
        fprintf(stdout, "EXPERIMENTAL xfs_scrub program in use! Use at your own risk!\n");
        fflush(stdout);
@@ -960,6 +961,7 @@ out_unicrash:
        unicrash_unload();
 
        hist_free(&ctx.datadev_hist);
+       hist_free(&ctx.rtdev_hist);
 
        /*
         * If we're being run as a service, the return code must fit the LSB
index 5d336cb55c742255b3879b0116d6f775fa4f7848..6ee359f4cebd476373760c00575fd81ce2ca4174 100644 (file)
@@ -101,6 +101,7 @@ struct scrub_ctx {
 
        /* Free space histograms, in fsb */
        struct histogram        datadev_hist;
+       struct histogram        rtdev_hist;
 
        /*
         * Pick the largest value for fstrim minlen such that we trim at least