From patchwork Tue Jul 2 01:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718790 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA4F779CC for ; Tue, 2 Jul 2024 01:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882188; cv=none; b=OSP0llOehwhcF98C2oBFpmfGGgYyC+hltn5aUiukto9+NUb1sB8b/fYSJZy/e2oX6pUcYV5PI2RhlYaFANV5r4Obj4NOkpbOVeFnwCZ92uked/lOiSSBUk130EAgUnPIHnhNWKgTgO5QE3k49+x58LPKgyGLLAwpqe5PK8uhzkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882188; c=relaxed/simple; bh=8OiNnEgeFBUd8TAombgh+LgLcf+/N6lYGmiKqyNCRqM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FQXhUFGm1iojno3TERyG21yXXN/AFBorfiNFH51a/1bldQgJHybM/dcmAASlWKfNdDHLChOVly9AEVRjSRRF/eAytOOMjQlgRrF402Yj3BX5VyNf2CjjIHyV4klloJuhdl9pwQ7qzo+5WJ6hcFJBaQXu2Bfb1plDfXZdlPK50sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZG5r41Eb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZG5r41Eb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CECFC116B1; Tue, 2 Jul 2024 01:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882188; bh=8OiNnEgeFBUd8TAombgh+LgLcf+/N6lYGmiKqyNCRqM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZG5r41Eb7fiQw3KY2h1Li1u7Bk/I0f4tyt43OFTUyon8bUdjZ34B8cKBwvNRXm9ZU iwG2AVZt0cGF9vDGaJ81J15K9Qdf5gUocJl3hoQA04iqzR8naMmSfNDVDp36WUeMd7 aZLj+i1sgZ/ka3Q835rq8dFt5EDqRzzBQM3AhUoqEKPIA/5q3LNlufDdJt6N1pvVO8 0E3xTAVcl2Lz7xqMlzeJLfhZsNYGbTK0w5iBb0iMzOgpWjj0eEOCSYJ5B34p6jpBmU pPVdvhngC4myp2ZTbQmzYY0SkjJDnUq+38cPr9eZMt1HlKJF3cRw36FtLdqj40kXwh hgStJoUIdkSJA== Date: Mon, 01 Jul 2024 18:03:07 -0700 Subject: [PATCH 1/7] libfrog: hoist free space histogram code From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118595.2007921.8810266640574883670.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Combine the two free space histograms in xfs_db and xfs_spaceman into a single implementation. Signed-off-by: Darrick J. Wong --- db/freesp.c | 83 +++++-------------------------- libfrog/Makefile | 2 + libfrog/histogram.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++ libfrog/histogram.h | 50 +++++++++++++++++++ spaceman/freesp.c | 93 +++++++++-------------------------- 5 files changed, 225 insertions(+), 138 deletions(-) create mode 100644 libfrog/histogram.c create mode 100644 libfrog/histogram.h diff --git a/db/freesp.c b/db/freesp.c index 883741e66fee..7a2da002a138 100644 --- a/db/freesp.c +++ b/db/freesp.c @@ -12,14 +12,7 @@ #include "output.h" #include "init.h" #include "malloc.h" - -typedef struct histent -{ - int low; - int high; - long long count; - long long blocks; -} histent_t; +#include "libfrog/histogram.h" static void addhistent(int h); static void addtohist(xfs_agnumber_t agno, xfs_agblock_t agbno, @@ -46,13 +39,10 @@ static int alignment; static int countflag; static int dumpflag; static int equalsize; -static histent_t *hist; -static int histcount; +static struct histogram freesp_hist; static int multsize; static int seen1; static int summaryflag; -static long long totblocks; -static long long totexts; static const cmdinfo_t freesp_cmd = { "freesp", NULL, freesp_f, 0, -1, 0, @@ -93,18 +83,13 @@ freesp_f( if (inaglist(agno)) scan_ag(agno); } - if (histcount) + if (hist_buckets(&freesp_hist)) printhist(); - if (summaryflag) { - dbprintf(_("total free extents %lld\n"), totexts); - dbprintf(_("total free blocks %lld\n"), totblocks); - dbprintf(_("average free extent size %g\n"), - (double)totblocks / (double)totexts); - } + if (summaryflag) + hist_summarize(&freesp_hist); if (aglist) xfree(aglist); - if (hist) - xfree(hist); + hist_free(&freesp_hist); return 0; } @@ -132,10 +117,9 @@ init( int speced = 0; agcount = countflag = dumpflag = equalsize = multsize = optind = 0; - histcount = seen1 = summaryflag = 0; - totblocks = totexts = 0; + seen1 = summaryflag = 0; aglist = NULL; - hist = NULL; + while ((c = getopt(argc, argv, "A:a:bcde:h:m:s")) != EOF) { switch (c) { case 'A': @@ -163,7 +147,7 @@ init( speced = 1; break; case 'h': - if (speced && !histcount) + if (speced && hist_buckets(&freesp_hist) == 0) return usage(); addhistent(atoi(optarg)); speced = 1; @@ -339,14 +323,7 @@ static void addhistent( int h) { - hist = xrealloc(hist, (histcount + 1) * sizeof(*hist)); - if (h == 0) - h = 1; - hist[histcount].low = h; - hist[histcount].count = hist[histcount].blocks = 0; - histcount++; - if (h == 1) - seen1 = 1; + hist_add_bucket(&freesp_hist, h); } static void @@ -355,30 +332,12 @@ addtohist( xfs_agblock_t agbno, xfs_extlen_t len) { - int i; - if (alignment && (XFS_AGB_TO_FSB(mp,agno,agbno) % alignment)) return; if (dumpflag) dbprintf("%8d %8d %8d\n", agno, agbno, len); - totexts++; - totblocks += len; - for (i = 0; i < histcount; i++) { - if (hist[i].high >= len) { - hist[i].count++; - hist[i].blocks += len; - break; - } - } -} - -static int -hcmp( - const void *a, - const void *b) -{ - return ((histent_t *)a)->low - ((histent_t *)b)->low; + hist_add(&freesp_hist, len); } static void @@ -387,6 +346,7 @@ histinit( { int i; + hist_init(&freesp_hist); if (equalsize) { for (i = 1; i < maxlen; i += equalsize) addhistent(i); @@ -396,27 +356,12 @@ histinit( } else { if (!seen1) addhistent(1); - qsort(hist, histcount, sizeof(*hist), hcmp); - } - for (i = 0; i < histcount; i++) { - if (i < histcount - 1) - hist[i].high = hist[i + 1].low - 1; - else - hist[i].high = maxlen; } + hist_prepare(&freesp_hist, maxlen); } static void printhist(void) { - int i; - - dbprintf("%7s %7s %7s %7s %6s\n", - _("from"), _("to"), _("extents"), _("blocks"), _("pct")); - for (i = 0; i < histcount; i++) { - if (hist[i].count) - dbprintf("%7d %7d %7lld %7lld %6.2f\n", hist[i].low, - hist[i].high, hist[i].count, hist[i].blocks, - hist[i].blocks * 100.0 / totblocks); - } + hist_print(&freesp_hist); } diff --git a/libfrog/Makefile b/libfrog/Makefile index 53e3c3492377..acfa228bc8ec 100644 --- a/libfrog/Makefile +++ b/libfrog/Makefile @@ -20,6 +20,7 @@ convert.c \ crc32.c \ file_exchange.c \ fsgeom.c \ +histogram.c \ list_sort.c \ linux.c \ logging.c \ @@ -45,6 +46,7 @@ dahashselftest.h \ div64.h \ file_exchange.h \ fsgeom.h \ +histogram.h \ logging.h \ paths.h \ projects.h \ diff --git a/libfrog/histogram.c b/libfrog/histogram.c new file mode 100644 index 000000000000..553ba3d7c6e8 --- /dev/null +++ b/libfrog/histogram.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. + * Copyright (c) 2012 Red Hat, Inc. + * Copyright (c) 2017-2024 Oracle. + * All Rights Reserved. + */ +#include "xfs.h" +#include +#include +#include "platform_defs.h" +#include "libfrog/histogram.h" + +/* Create a new bucket with the given low value. */ +int +hist_add_bucket( + struct histogram *hs, + long long bucket_low) +{ + struct histent *buckets; + + if (hs->nr_buckets == INT_MAX) + return EFBIG; + + buckets = realloc(hs->buckets, + (hs->nr_buckets + 1) * sizeof(struct histent)); + if (!buckets) + return errno; + + hs->buckets = buckets; + hs->buckets[hs->nr_buckets].low = bucket_low; + hs->buckets[hs->nr_buckets].count = buckets[hs->nr_buckets].blocks = 0; + hs->nr_buckets++; + return 0; +} + +/* Add an observation to the histogram. */ +void +hist_add( + struct histogram *hs, + long long len) +{ + unsigned int i; + + hs->totexts++; + hs->totblocks += len; + for (i = 0; i < hs->nr_buckets; i++) { + if (hs->buckets[i].high >= len) { + hs->buckets[i].count++; + hs->buckets[i].blocks += len; + break; + } + } +} + +static int +histent_cmp( + const void *a, + const void *b) +{ + const struct histent *ha = a; + const struct histent *hb = b; + + if (ha->low < hb->low) + return -1; + if (ha->low > hb->low) + return 1; + return 0; +} + +/* Prepare a histogram for bucket configuration. */ +void +hist_init( + struct histogram *hs) +{ + memset(hs, 0, sizeof(struct histogram)); +} + +/* Prepare a histogram to receive data observations. */ +void +hist_prepare( + struct histogram *hs, + long long maxlen) +{ + unsigned int i; + + qsort(hs->buckets, hs->nr_buckets, sizeof(struct histent), histent_cmp); + + for (i = 0; i < hs->nr_buckets; i++) { + if (i < hs->nr_buckets - 1) + hs->buckets[i].high = hs->buckets[i + 1].low - 1; + else + hs->buckets[i].high = maxlen; + } +} + +/* Free all data associated with a histogram. */ +void +hist_free( + struct histogram *hs) +{ + free(hs->buckets); + memset(hs, 0, sizeof(struct histogram)); +} + +/* Dump a histogram to stdout. */ +void +hist_print( + const struct histogram *hs) +{ + unsigned int i; + + printf("%7s %7s %7s %7s %6s\n", + _("from"), _("to"), _("extents"), _("blocks"), _("pct")); + for (i = 0; i < hs->nr_buckets; i++) { + if (hs->buckets[i].count == 0) + continue; + + printf("%7lld %7lld %7lld %7lld %6.2f\n", + hs->buckets[i].low, hs->buckets[i].high, + hs->buckets[i].count, hs->buckets[i].blocks, + hs->buckets[i].blocks * 100.0 / hs->totblocks); + } +} + +/* Summarize the contents of the histogram. */ +void +hist_summarize( + const struct histogram *hs) +{ + printf(_("total free extents %lld\n"), hs->totexts); + printf(_("total free blocks %lld\n"), hs->totblocks); + printf(_("average free extent size %g\n"), + (double)hs->totblocks / (double)hs->totexts); +} diff --git a/libfrog/histogram.h b/libfrog/histogram.h new file mode 100644 index 000000000000..2e2b169a79b0 --- /dev/null +++ b/libfrog/histogram.h @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. + * Copyright (c) 2012 Red Hat, Inc. + * Copyright (c) 2017-2024 Oracle. + * All Rights Reserved. + */ +#ifndef __LIBFROG_HISTOGRAM_H__ +#define __LIBFROG_HISTOGRAM_H__ + +struct histent +{ + /* Low and high size of this bucket */ + long long low; + long long high; + + /* Count of observations recorded */ + long long count; + + /* Sum of blocks recorded */ + long long blocks; +}; + +struct histogram { + /* Sum of all blocks recorded */ + long long totblocks; + + /* Count of all observations recorded */ + long long totexts; + + struct histent *buckets; + + /* Number of buckets */ + unsigned int nr_buckets; +}; + +int hist_add_bucket(struct histogram *hs, long long bucket_low); +void hist_add(struct histogram *hs, long long len); +void hist_init(struct histogram *hs); +void hist_prepare(struct histogram *hs, long long maxlen); +void hist_free(struct histogram *hs); +void hist_print(const struct histogram *hs); +void hist_summarize(const struct histogram *hs); + +static inline unsigned int hist_buckets(const struct histogram *hs) +{ + return hs->nr_buckets; +} + +#endif /* __LIBFROG_HISTOGRAM_H__ */ diff --git a/spaceman/freesp.c b/spaceman/freesp.c index f5177cb4ee5d..97c92b131a89 100644 --- a/spaceman/freesp.c +++ b/spaceman/freesp.c @@ -15,76 +15,52 @@ #include "libfrog/paths.h" #include "space.h" #include "input.h" - -struct histent -{ - long long low; - long long high; - long long count; - long long blocks; -}; +#include "libfrog/histogram.h" static int agcount; static xfs_agnumber_t *aglist; -static struct histent *hist; +static struct histogram freesp_hist; static int dumpflag; static long long equalsize; static long long multsize; -static int histcount; static int seen1; static int summaryflag; static int gflag; static bool rtflag; -static long long totblocks; -static long long totexts; static cmdinfo_t freesp_cmd; -static void +static inline void addhistent( long long h) { - if (histcount == INT_MAX) { + int error; + + error = hist_add_bucket(&freesp_hist, h); + if (error == EFBIG) { printf(_("Too many histogram buckets.\n")); return; } - hist = realloc(hist, (histcount + 1) * sizeof(*hist)); + if (error) { + printf("%s\n", strerror(error)); + return; + } + if (h == 0) h = 1; - hist[histcount].low = h; - hist[histcount].count = hist[histcount].blocks = 0; - histcount++; if (h == 1) seen1 = 1; } -static void +static inline void addtohist( xfs_agnumber_t agno, xfs_agblock_t agbno, off_t len) { - long i; - if (dumpflag) printf("%8d %8d %8"PRId64"\n", agno, agbno, len); - totexts++; - totblocks += len; - for (i = 0; i < histcount; i++) { - if (hist[i].high >= len) { - hist[i].count++; - hist[i].blocks += len; - break; - } - } -} - -static int -hcmp( - const void *a, - const void *b) -{ - return ((struct histent *)a)->low - ((struct histent *)b)->low; + hist_add(&freesp_hist, len); } static void @@ -93,6 +69,7 @@ histinit( { long long i; + hist_init(&freesp_hist); if (equalsize) { for (i = 1; i < maxlen; i += equalsize) addhistent(i); @@ -102,29 +79,14 @@ histinit( } else { if (!seen1) addhistent(1); - qsort(hist, histcount, sizeof(*hist), hcmp); - } - for (i = 0; i < histcount; i++) { - if (i < histcount - 1) - hist[i].high = hist[i + 1].low - 1; - else - hist[i].high = maxlen; } + hist_prepare(&freesp_hist, maxlen); } -static void +static inline void printhist(void) { - int i; - - printf("%7s %7s %7s %7s %6s\n", - _("from"), _("to"), _("extents"), _("blocks"), _("pct")); - for (i = 0; i < histcount; i++) { - if (hist[i].count) - printf("%7lld %7lld %7lld %7lld %6.2f\n", hist[i].low, - hist[i].high, hist[i].count, hist[i].blocks, - hist[i].blocks * 100.0 / totblocks); - } + hist_print(&freesp_hist); } static int @@ -255,10 +217,8 @@ init( int speced = 0; /* only one of -b -e -h or -m */ agcount = dumpflag = equalsize = multsize = optind = gflag = 0; - histcount = seen1 = summaryflag = 0; - totblocks = totexts = 0; + seen1 = summaryflag = 0; aglist = NULL; - hist = NULL; rtflag = false; while ((c = getopt(argc, argv, "a:bde:gh:m:rs")) != EOF) { @@ -287,7 +247,7 @@ init( gflag++; break; case 'h': - if (speced && !histcount) + if (speced && hist_buckets(&freesp_hist) == 0) goto many_spec; /* addhistent increments histcount */ x = cvt_s64(optarg, 0); @@ -345,18 +305,13 @@ freesp_f( if (inaglist(agno)) scan_ag(agno); } - if (histcount && !gflag) + if (hist_buckets(&freesp_hist) > 0 && !gflag) printhist(); - if (summaryflag) { - printf(_("total free extents %lld\n"), totexts); - printf(_("total free blocks %lld\n"), totblocks); - printf(_("average free extent size %g\n"), - (double)totblocks / (double)totexts); - } + if (summaryflag) + hist_summarize(&freesp_hist); if (aglist) free(aglist); - if (hist) - free(hist); + hist_free(&freesp_hist); return 0; } From patchwork Tue Jul 2 01:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718791 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 617E87F9 for ; Tue, 2 Jul 2024 01:03:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882206; cv=none; b=fx/0/jZGr2BQXl+wsmiVNs9GU929drdw25k/+nY4r8W1YzAPQk9xoKP48Vjs5JVNWHEvoXLd04B/A5eG3n7OesRFPHEDLw6ujcmPOj27WlabcHLCcbDSRHE3zcLOd8PdIZ/x5TixbR+V17wlw/CsZUjtIrcl+ClrEQ0AZM58KHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882206; c=relaxed/simple; bh=BJaBuP9/+7y7BRf6uecBYx5BGvmWVdNByK7uptCqtL4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=st+YUj5DoyLJnvdH3OgFTt/Z0He9c3RVBuxm0K3MpLTdNncwguX/kKyqBe0LxgShgVNW6wSzP/7kPz6cp9SpLHIbO0q3xRO5qwTlWZpeLWY56cXjq6Vy1RirC4kwfY8XJbMflgletJlqhCqGm3v1tLWm4Z/IDT10fJiZRBin7KI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YNKTyetf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YNKTyetf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F20DEC116B1; Tue, 2 Jul 2024 01:03:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882204; bh=BJaBuP9/+7y7BRf6uecBYx5BGvmWVdNByK7uptCqtL4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YNKTyetffTA5xtzOIZZbDfN/8Lf76wL1Y/AnKE/40eKM03o0Lz2xdpv5w2ERb8ia6 PFHZQXKo5KFsjMoypYjRX4Voi0XSxJYRfy/ECF2m7UapijHg17qREnjLcehip9tQ3z LMbxs579VxmzoVGX+kaV8/6Uwv+91PQCF7n4Oy6N6+X7ldCACyml36i5+d5RUah85l FHvxIjps+e3uglsjTMHTSUs7QNPvc7gKmImOqkP1OhmGKcTmTORVBpz+QibkBNY3zY ypE5AoQqTg1h5OJRgbAcdZHJr3vvtKpvQ5zuJQqKHoN/Scyv3WyCg+cQvSVC+WFYbu PQ6TH31QInFYg== Date: Mon, 01 Jul 2024 18:03:23 -0700 Subject: [PATCH 2/7] libfrog: print wider columns for free space histogram From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118610.2007921.16808669892190727395.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong The values reported here can reach very large values, so compute the column width dynamically. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/histogram.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/libfrog/histogram.c b/libfrog/histogram.c index 553ba3d7c6e8..5053d5eafc26 100644 --- a/libfrog/histogram.c +++ b/libfrog/histogram.c @@ -108,17 +108,41 @@ void hist_print( const struct histogram *hs) { + unsigned int from_w, to_w, extents_w, blocks_w; unsigned int i; - printf("%7s %7s %7s %7s %6s\n", - _("from"), _("to"), _("extents"), _("blocks"), _("pct")); + from_w = to_w = extents_w = blocks_w = 7; + for (i = 0; i < hs->nr_buckets; i++) { + char buf[256]; + + if (!hs->buckets[i].count) + continue; + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].low); + from_w = max(from_w, strlen(buf)); + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].high); + to_w = max(to_w, strlen(buf)); + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].count); + extents_w = max(extents_w, strlen(buf)); + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].blocks); + blocks_w = max(blocks_w, strlen(buf)); + } + + printf("%*s %*s %*s %*s %6s\n", + from_w, _("from"), to_w, _("to"), extents_w, _("extents"), + blocks_w, _("blocks"), _("pct")); for (i = 0; i < hs->nr_buckets; i++) { if (hs->buckets[i].count == 0) continue; - printf("%7lld %7lld %7lld %7lld %6.2f\n", - hs->buckets[i].low, hs->buckets[i].high, - hs->buckets[i].count, hs->buckets[i].blocks, + printf("%*lld %*lld %*lld %*lld %6.2f\n", + from_w, hs->buckets[i].low, + to_w, hs->buckets[i].high, + extents_w, hs->buckets[i].count, + blocks_w, hs->buckets[i].blocks, hs->buckets[i].blocks * 100.0 / hs->totblocks); } } From patchwork Tue Jul 2 01:03:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718792 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19BAE4436 for ; Tue, 2 Jul 2024 01:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882220; cv=none; b=l4ISdgGxITG6T75Zdnr10leVXPlqK1vjakmaqa9q/J8LNZDRO3hxAjNcUaUzcmJ2oDKQ1WJK3mtN2ZzirDNRlHq8jcaJMYZS+06YDxjQxM3iKGsKMX5JChAKqELWeiWardcH59ZLU9SCJP7kbW7Ohs9BBmp/8/HBH9K39A/T6C0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882220; c=relaxed/simple; bh=6tZ4XRI8M1dk5wLJfDlL53AyNHNpEzIzYY67lG/sfGo=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Eo+wc2WyK2TlkMlokAvEMzfrw8MGnfQNNp265p8iPGdKjFYEDe3cBpC3XW312qhm/QXfLEfJN5u2CVTf/YsOyDymu4J6fZRcSbUGB5hBYwIM6Yh+5bfY9dkgvIwYbwsKgrm6p0J9sIBqyqGsctyQMDSpLdeF1WKSbtJspRFPX2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K3bKTUrH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K3bKTUrH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A23E1C116B1; Tue, 2 Jul 2024 01:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882219; bh=6tZ4XRI8M1dk5wLJfDlL53AyNHNpEzIzYY67lG/sfGo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=K3bKTUrHyjCGjE9lCQ+OxM/T8qYTQN6NGWyJJRGLw40iRCfsmVYLzeqLp2b+vRR3g 7y6Y+1QCPRA3vk2iCoBlNZ6N0xfkaw6gruVwQQQcVvXNixBKHmeeld3fxtamGt5e6X F46JuxdUZcH5WgFF9mB2Z85bu4V/EWGk2xKGPhiNe6cU05MNJ9llYfQH9bphaRQh0K lGyW8G1sI/Nb6YLhlySdoG1Aw4UBMWXvKgoSoGFDQySQ9BH/yxd2JN9Vy+lvK8LHkL l5Fam3OLhE/Xp8z2wcYPe1mOKAhD5tV0me8GyJ2XNBDHzvBIBM/SYYjkTgkpcGvin8 x7HRd4Lh9cLlw== Date: Mon, 01 Jul 2024 18:03:39 -0700 Subject: [PATCH 3/7] libfrog: print cdf of free space buckets From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118625.2007921.7225855318666248252.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Print the cumulative distribution function of the free space buckets in reverse order. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/histogram.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/libfrog/histogram.c b/libfrog/histogram.c index 5053d5eafc26..bed79e35b021 100644 --- a/libfrog/histogram.c +++ b/libfrog/histogram.c @@ -103,13 +103,64 @@ hist_free( memset(hs, 0, sizeof(struct histogram)); } +/* + * Compute the CDF of the free space in decreasing order of extent length. + * This enables users to determine how much free space is not in the long tail + * of small extents, e.g. 98% of the free space extents are larger than 31 + * blocks. + */ +static int +hist_cdf( + const struct histogram *hs, + struct histogram *cdf) +{ + struct histent *buckets; + int i = hs->nr_buckets - 1; + + ASSERT(cdf->nr_buckets == 0); + ASSERT(hs->nr_buckets < INT_MAX); + + if (hs->nr_buckets == 0) + return 0; + + buckets = calloc(hs->nr_buckets, sizeof(struct histent)); + if (!buckets) + return errno; + + memset(cdf, 0, sizeof(struct histogram)); + cdf->buckets = buckets; + + cdf->buckets[i].count = hs->buckets[i].count; + cdf->buckets[i].blocks = hs->buckets[i].blocks; + i--; + + while (i >= 0) { + cdf->buckets[i].count = hs->buckets[i].count + + cdf->buckets[i + 1].count; + + cdf->buckets[i].blocks = hs->buckets[i].blocks + + cdf->buckets[i + 1].blocks; + i--; + } + + return 0; +} + /* Dump a histogram to stdout. */ void hist_print( const struct histogram *hs) { + struct histogram cdf = { }; unsigned int from_w, to_w, extents_w, blocks_w; unsigned int i; + int error; + + error = hist_cdf(hs, &cdf); + if (error) { + printf(_("histogram cdf: %s\n"), strerror(error)); + return; + } from_w = to_w = extents_w = blocks_w = 7; for (i = 0; i < hs->nr_buckets; i++) { @@ -131,20 +182,24 @@ hist_print( blocks_w = max(blocks_w, strlen(buf)); } - printf("%*s %*s %*s %*s %6s\n", + printf("%*s %*s %*s %*s %6s %6s %6s\n", from_w, _("from"), to_w, _("to"), extents_w, _("extents"), - blocks_w, _("blocks"), _("pct")); + blocks_w, _("blocks"), _("pct"), _("blkcdf"), _("extcdf")); for (i = 0; i < hs->nr_buckets; i++) { if (hs->buckets[i].count == 0) continue; - printf("%*lld %*lld %*lld %*lld %6.2f\n", + printf("%*lld %*lld %*lld %*lld %6.2f %6.2f %6.2f\n", from_w, hs->buckets[i].low, to_w, hs->buckets[i].high, extents_w, hs->buckets[i].count, blocks_w, hs->buckets[i].blocks, - hs->buckets[i].blocks * 100.0 / hs->totblocks); + hs->buckets[i].blocks * 100.0 / hs->totblocks, + cdf.buckets[i].blocks * 100.0 / hs->totblocks, + cdf.buckets[i].count * 100.0 / hs->totexts); } + + hist_free(&cdf); } /* Summarize the contents of the histogram. */ From patchwork Tue Jul 2 01:03:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718793 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AD6D4C8B for ; Tue, 2 Jul 2024 01:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882235; cv=none; b=nR+Cl7t2F8hc3lnM7VngWbpxt5kVYt5UmrgHnVVdBXMtEorVvtdhEeoV7BJh8oxg/9IeeQtpffHNMatN5pbrjdKNtKlg2jH6t4TqqyQDbuCGYQb28djfsQBcqDJ3gXRMY3QjI4KvaPlmKMI9AYb7PZ7YLWSkReo4XEVDO11UyeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882235; c=relaxed/simple; bh=KFwFQklbWd9f5c9uK0Q1C6XnTbnGywE9zS2wzG9jnSU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A4ZL2NNGRCT7dKHDMMgPv1Cs9+Ui8AEgCLLUbxpGsq+npRbZgJEeITVz0PtiI6d3ErzwVfKkzLrsW++10xGByPYuHIZwHoCRxgdjHhOEWb4C5jAzS6bRRaJ9G2b5Xx7pZQpARjp2uGxf6AhfQ5i4FaqyLwFFtv5AJFbN8M+lsJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kkq1Y+pN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kkq1Y+pN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B7AAC116B1; Tue, 2 Jul 2024 01:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882235; bh=KFwFQklbWd9f5c9uK0Q1C6XnTbnGywE9zS2wzG9jnSU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Kkq1Y+pNeakQYYpkHeZ4dJ+vSs/3N5VdalfA+6Ys8r8srbqOEKiwzwl05npmLYeCX u2RhiBoemikn2w+rc1UVh68439FCevpOOD67VNO8L65oQHdmUsqyYc8QznM/yGVgHf 4xc5m+WEhQ+bvYtO8i3gsQmnGrzb5zAY0wZW8BMC9bLNriyCVv/b+JKBCIxh+uZeLr ZR+IfDA3t0mG5ujO+duXH4a9OwHXzbpCW5VWALn0B4TwHicrNPwu2M8q/s1gLViHQx kBZaZ889RNpHtdnVUT4sW034fafQNf1+kY9zzoCCHIB+/VIdeV5H4wWEvt2NglJbUi q6vGgwW+PongQ== Date: Mon, 01 Jul 2024 18:03:54 -0700 Subject: [PATCH 4/7] xfs_scrub: don't close stdout when closing the progress bar From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118640.2007921.1141459290194402070.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong When we're tearing down the progress bar file stream, check that it's not an alias of stdout before closing it. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index edf58d07bde2..adf9d13e5090 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -878,7 +878,7 @@ main( if (ctx.runtime_errors) ret |= SCRUB_RET_OPERROR; phase_end(&all_pi, 0); - if (progress_fp) + if (progress_fp && fileno(progress_fp) != 1) fclose(progress_fp); out_unicrash: unicrash_unload(); From patchwork Tue Jul 2 01:04:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718794 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 088F87462 for ; Tue, 2 Jul 2024 01:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882251; cv=none; b=JqlYdoNFUPwlJCHOkfJkWj+p7OK20mvDxxkA3FM/QC3mkFztpa3BNQ6VjYeSMbVB0SlnaudyKLi4mR4kSMbn7z8V2NoyWcBPV0tYuso0pKcQ+e2eoXkw5ttraw/bmmEghHLQW3FPuEqTMjtDX4pevosJPRsB2pZwmHU2xEs1AMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882251; c=relaxed/simple; bh=wsi9lUn02PXj7trVw16TbeljPEw1vzlqXH8L/eiIQvM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fxgt6inOlXqk5lamNRlcshadqJwEdDjFN7JNl2D701gBceEmxej0dpdDfCss3WlUiGu4i0h9HDA4ZaoVhr9+vGTFWp5Gl1QILVej3EKlHDWblL3q3PYttAa40D6RpBC3n83YldDYbLASuY5I3l+E8z1HOEisWciv9+6U8v1O0bA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KpQ3wo1U; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KpQ3wo1U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8916C116B1; Tue, 2 Jul 2024 01:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882250; bh=wsi9lUn02PXj7trVw16TbeljPEw1vzlqXH8L/eiIQvM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KpQ3wo1UCXbzE97cL3ePWQfmXIarhGJeUjOutVLQ+KUnSkTJMrPxLJCUMQVb5oOON wC/qto6sR4ywjpVJXubcF0useuQ2SvEUIW2wHfyE20aYNArsAolxhDSovP7uW0Xu8j 6jQr3UMw8yC4sI1NWtBZwz/lX3Yic+Q+vBi45QzlXlJluFDh1cDInWXO2m0s4TGJEW uQeYMnjDPH3E/eImwFaK1t+N+T+4HNaLsmZAzpLBE35/Sf0I9B7XkdBBDbIU9XmtUc 9LSA/Q/sCTU7oGj/TtZNTBdgl0XcS8PpKyOzCw2AK0HBdaSgWojOe79aBApfNCn5Y+ wWpmtptdNd8fg== Date: Mon, 01 Jul 2024 18:04:10 -0700 Subject: [PATCH 5/7] xfs_scrub: remove pointless spacemap.c arguments From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118656.2007921.16506722349320949924.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Remove unused parameters from the full-device spacemap scan functions. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/spacemap.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scrub/spacemap.c b/scrub/spacemap.c index 9cefe074c6f6..e35756db2eed 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -132,7 +132,6 @@ scan_ag_rmaps( static void scan_dev_rmaps( struct scrub_ctx *ctx, - int idx, dev_t dev, struct scan_blocks *sbx) { @@ -170,7 +169,7 @@ scan_rt_rmaps( { struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; - scan_dev_rmaps(ctx, agno, ctx->fsinfo.fs_rtdev, arg); + scan_dev_rmaps(ctx, ctx->fsinfo.fs_rtdev, arg); } /* Iterate all the reverse mappings of the log device. */ @@ -182,7 +181,7 @@ scan_log_rmaps( { struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; - scan_dev_rmaps(ctx, agno, ctx->fsinfo.fs_logdev, arg); + scan_dev_rmaps(ctx, ctx->fsinfo.fs_logdev, arg); } /* @@ -210,8 +209,7 @@ scrub_scan_all_spacemaps( return ret; } if (ctx->fsinfo.fs_rt) { - ret = -workqueue_add(&wq, scan_rt_rmaps, - ctx->mnt.fsgeom.agcount + 1, &sbx); + ret = -workqueue_add(&wq, scan_rt_rmaps, 0, &sbx); if (ret) { sbx.aborted = true; str_liberror(ctx, ret, _("queueing rtdev fsmap work")); @@ -219,8 +217,7 @@ scrub_scan_all_spacemaps( } } if (ctx->fsinfo.fs_log) { - ret = -workqueue_add(&wq, scan_log_rmaps, - ctx->mnt.fsgeom.agcount + 2, &sbx); + ret = -workqueue_add(&wq, scan_log_rmaps, 0, &sbx); if (ret) { sbx.aborted = true; str_liberror(ctx, ret, _("queueing logdev fsmap work")); From patchwork Tue Jul 2 01:04:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718795 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3126C132 for ; Tue, 2 Jul 2024 01:04:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882266; cv=none; b=EA7dRQOPNmV/dG2h4jRIOyzM6R9WAro0BiZwfqMHg1WzVayYJpTEIqH7OKBzbVmpWzSBCDsoWRu+fCcL9Rws31En/J4Zq8qp9MLjY6IVjyMGQysmfXw/+uyGrLQhJmXhZb6BSL2FlRCefoQMFuyonmHQTI6IplJNIEnVHvydVPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882266; c=relaxed/simple; bh=hjkG/USXRFx/5t0h03PoZbLvABYaepk/rLn196qHK6w=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dYDjuXWTKt8w7x533HXKtYpPSxU5QwOlJbcmiwWl20jfMCaGBfaX7ABRql1yBC8BzmClQgPL8fNwZgPoLzIirixS0vy2g8Mdj4s2lYJLjsuhFLJnyVQei1lJp8diLOP628l15dCXpb72ehWYTD4P8CO35p31rP8vHraR5WOh5j8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GNX+azM/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GNX+azM/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79386C116B1; Tue, 2 Jul 2024 01:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882266; bh=hjkG/USXRFx/5t0h03PoZbLvABYaepk/rLn196qHK6w=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=GNX+azM/rwHyBa+qTO9aApL5qxAgNy/HTSnrVO07S/PvpT4Sx0TF1JVk+w61H/WHc K8uMlBY+fmytcmhenTCVAM1CxNRUTmqmpzZLkiewAcOg+n9yDYBqj7qdsFzXEIlzxQ kgYkbcmM51LZZlpQUczvqEJ7DOg8AlMcMpueN18lZVRzmi3cIWLGZVHgxCHpiU+omH PsxEsUkxjpBRueMfM0jJT+JZ8Hbct5nccXPS5F3faYawdKEgshXI25UpFdm2bO8Nf2 L6oOb7iiXvWaQdO/jWZVJjBASpqUTUVknLOuyFghGKBquftOznjZ8yzejYHeLx9q5q rvLGGGDoV+fxQ== Date: Mon, 01 Jul 2024 18:04:26 -0700 Subject: [PATCH 6/7] xfs_scrub: collect free space histograms during phase 7 From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118672.2007921.6461553875020192436.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Collect a histogram of free space observed during phase 7. We'll put this information to use in the next patch. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/histogram.c | 38 ++++++++++++++++++++++++++++++++++++++ libfrog/histogram.h | 3 +++ scrub/phase7.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- scrub/xfs_scrub.c | 5 +++++ scrub/xfs_scrub.h | 4 ++++ 5 files changed, 95 insertions(+), 2 deletions(-) diff --git a/libfrog/histogram.c b/libfrog/histogram.c index bed79e35b021..54e2bac0f731 100644 --- a/libfrog/histogram.c +++ b/libfrog/histogram.c @@ -212,3 +212,41 @@ hist_summarize( printf(_("average free extent size %g\n"), (double)hs->totblocks / (double)hs->totexts); } + +/* Copy the contents of src to dest. */ +void +hist_import( + struct histogram *dest, + const struct histogram *src) +{ + unsigned int i; + + ASSERT(dest->nr_buckets == src->nr_buckets); + + dest->totblocks += src->totblocks; + dest->totexts += src->totexts; + + for (i = 0; i < dest->nr_buckets; i++) { + ASSERT(dest->buckets[i].low == src->buckets[i].low); + ASSERT(dest->buckets[i].high == src->buckets[i].high); + + dest->buckets[i].count += src->buckets[i].count; + dest->buckets[i].blocks += src->buckets[i].blocks; + } +} + +/* + * Move the contents of src to dest and reinitialize src. dst must not + * contain any observations or buckets. + */ +void +hist_move( + struct histogram *dest, + struct histogram *src) +{ + ASSERT(dest->nr_buckets == 0); + ASSERT(dest->totexts == 0); + + memcpy(dest, src, sizeof(struct histogram)); + hist_init(src); +} diff --git a/libfrog/histogram.h b/libfrog/histogram.h index 2e2b169a79b0..ec788344d4c2 100644 --- a/libfrog/histogram.h +++ b/libfrog/histogram.h @@ -47,4 +47,7 @@ static inline unsigned int hist_buckets(const struct histogram *hs) return hs->nr_buckets; } +void hist_import(struct histogram *dest, const struct histogram *src); +void hist_move(struct histogram *dest, struct histogram *src); + #endif /* __LIBFROG_HISTOGRAM_H__ */ diff --git a/scrub/phase7.c b/scrub/phase7.c index cce5ede00122..475d8f157eec 100644 --- a/scrub/phase7.c +++ b/scrub/phase7.c @@ -12,6 +12,7 @@ #include "libfrog/ptvar.h" #include "libfrog/fsgeom.h" #include "libfrog/scrub.h" +#include "libfrog/histogram.h" #include "list.h" #include "xfs_scrub.h" #include "common.h" @@ -27,8 +28,36 @@ struct summary_counts { unsigned long long rbytes; /* rt dev bytes */ unsigned long long next_phys; /* next phys bytes we see? */ unsigned long long agbytes; /* freespace bytes */ + + /* Free space histogram, in fsb */ + struct histogram datadev_hist; }; +/* + * Initialize a free space histogram. Unsharded realtime volumes can be up to + * 2^52 blocks long, so we allocate enough buckets to handle that. + */ +static inline void +init_freesp_hist( + struct histogram *hs) +{ + unsigned int i; + + hist_init(hs); + for (i = 0; i < 53; i++) + hist_add_bucket(hs, 1ULL << i); + hist_prepare(hs, 1ULL << 53); +} + +static void +summary_count_init( + void *data) +{ + struct summary_counts *counts = data; + + init_freesp_hist(&counts->datadev_hist); +} + /* Record block usage. */ static int count_block_summary( @@ -48,8 +77,14 @@ count_block_summary( if (fsmap->fmr_device == ctx->fsinfo.fs_logdev) return 0; if ((fsmap->fmr_flags & FMR_OF_SPECIAL_OWNER) && - fsmap->fmr_owner == XFS_FMR_OWN_FREE) + fsmap->fmr_owner == XFS_FMR_OWN_FREE) { + uint64_t blocks; + + 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); return 0; + } len = fsmap->fmr_length; @@ -87,6 +122,9 @@ add_summaries( total->dbytes += item->dbytes; total->rbytes += item->rbytes; total->agbytes += item->agbytes; + + hist_import(&total->datadev_hist, &item->datadev_hist); + hist_free(&item->datadev_hist); return 0; } @@ -118,6 +156,8 @@ phase7_func( int ip; int error; + summary_count_init(&totalcount); + /* Check and fix the summary metadata. */ scrub_item_init_fs(&sri); scrub_item_schedule_group(&sri, XFROG_SCRUB_GROUP_SUMMARY); @@ -136,7 +176,7 @@ phase7_func( } error = -ptvar_alloc(scrub_nproc(ctx), sizeof(struct summary_counts), - NULL, &ptvar); + summary_count_init, &ptvar); if (error) { str_liberror(ctx, error, _("setting up block counter")); return error; @@ -153,6 +193,9 @@ phase7_func( } ptvar_free(ptvar); + /* Preserve free space histograms for phase 8. */ + hist_move(&ctx->datadev_hist, &totalcount.datadev_hist); + /* Scan the whole fs. */ error = scrub_count_all_inodes(ctx, &counted_inodes); if (error) { diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index adf9d13e5090..2894f6148e10 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -18,6 +18,7 @@ #include "descr.h" #include "unicrash.h" #include "progress.h" +#include "libfrog/histogram.h" /* * XFS Online Metadata Scrub (and Repair) @@ -669,6 +670,8 @@ main( int ret = SCRUB_RET_SUCCESS; int error; + hist_init(&ctx.datadev_hist); + fprintf(stdout, "EXPERIMENTAL xfs_scrub program in use! Use at your own risk!\n"); fflush(stdout); @@ -883,6 +886,8 @@ main( out_unicrash: unicrash_unload(); + hist_free(&ctx.datadev_hist); + /* * If we're being run as a service, the return code must fit the LSB * init script action error guidelines, which is to say that we diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index 6272a36879e7..1a28f0cc847e 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -7,6 +7,7 @@ #define XFS_SCRUB_XFS_SCRUB_H_ #include "libfrog/fsgeom.h" +#include "libfrog/histogram.h" extern char *progname; @@ -86,6 +87,9 @@ struct scrub_ctx { unsigned long long preens; bool scrub_setup_succeeded; bool preen_triggers[XFS_SCRUB_TYPE_NR]; + + /* Free space histograms, in fsb */ + struct histogram datadev_hist; }; /* Phase helper functions */ From patchwork Tue Jul 2 01:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13718796 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 657D27F9 for ; Tue, 2 Jul 2024 01:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882282; cv=none; b=mCO29VAe9qvvRuQ9JJQLHSBAVkBztVYLmML3UzVvEs9IhTrvebM7xmGtVrIC3nDjWE7Aos+vhD7ovM4Rt92HKZWogS+x0HuiDDpmb1rGRF70wWgnw91fgle0P/W4f4pJwkxOd/YIpi2by6NJOyYZcL5oMc4rwE/VofxFeC3LaBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882282; c=relaxed/simple; bh=7Apcpxe/g/fbmiP5c6cvjt7ooUIVmNLzMWR+hdld2JM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MyrQz35kLZiaE6l/EV5GKeyALXWCwEzNCGC9CbDHMFU9AyTbzjbMhLhnq2DCdYURMiMh0SfCtdFY56KTo14XgOflsNtyuFv7S7oPsxcsHihoW453BCQVQ1HdcOe6SAaOYI4Vu/ie4e6ofbq0f9TyiL3B1hg5LgsQj/fwL+Q50nI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rDaKxZob; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rDaKxZob" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3843CC116B1; Tue, 2 Jul 2024 01:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882282; bh=7Apcpxe/g/fbmiP5c6cvjt7ooUIVmNLzMWR+hdld2JM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rDaKxZobXdAh8nKJ4lsNPjw71SilzV4lw52CVgM02iRyKG+5WwO4MunTapS+j9mw5 H9CCTjEw+Uy2OVCNTU0H/EVBmDcha9nhCRxinDZZIbe8ECK7/ahnr5iJZ1nCeFboA7 x14TY8wDSFbBFR5Btsf89nRoZcHRtQtow0//nJn0oLA9S7rI4J5ZduEC+685zhH24O u0Sv/K7QVXMcudIWAlH/CemwuTV7V5uaSE9+igDMjTrupvdAEvNVuvCvlVufV56C/r 26FCJRfAK8a16o2xOXCwcDw7UgECHcMNfuynY9JuUjq/880l3F9B+u0zxM2wDvqJ8r d36SXPOopfOQA== Date: Mon, 01 Jul 2024 18:04:41 -0700 Subject: [PATCH 7/7] xfs_scrub: tune fstrim minlen parameter based on free space histograms From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118687.2007921.1260012940783338117.stgit@frogsfrogsfrogs> In-Reply-To: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> References: <171988118569.2007921.18066484659815583228.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Currently, phase 8 runs very slowly on filesystems with a lot of small free space extents. To reduce the amount of time spent on fstrim activities during phase 8, we want to balance estimated runtime against completeness of the trim. In short, the goal is to reduce runtime by avoiding small trim requests. At the start of phase 8, a CDF is computed in decreasing order of extent length from the histogram buckets created during the fsmap scan in phase 7. A point corresponding to the fstrim percentage target is chosen from the CDF and mapped back to a histogram bucket, and free space extents smaller than that amount are ommitted from fstrim. On my aging /home filesystem, the free space histogram reported by xfs_spaceman looks like this: from to extents blocks pct blkcdf extcdf 1 1 121953 121953 0.04 100.00 100.00 2 3 124741 299694 0.09 99.96 81.16 4 7 113492 593763 0.18 99.87 61.89 8 15 109215 1179524 0.36 99.69 44.36 16 31 76972 1695455 0.52 99.33 27.48 32 63 48655 2219667 0.68 98.82 15.59 64 127 31398 2876898 0.88 98.14 8.08 128 255 8014 1447920 0.44 97.27 3.23 256 511 4142 1501758 0.46 96.82 1.99 512 1023 2433 1768732 0.54 96.37 1.35 1024 2047 1795 2648460 0.81 95.83 0.97 2048 4095 1429 4206103 1.28 95.02 0.69 4096 8191 1045 6162111 1.88 93.74 0.47 8192 16383 791 9242745 2.81 91.87 0.31 16384 32767 473 10883977 3.31 89.06 0.19 32768 65535 272 12385566 3.77 85.74 0.12 65536 131071 192 18098739 5.51 81.98 0.07 131072 262143 108 20675199 6.29 76.47 0.04 262144 524287 80 29061285 8.84 70.18 0.03 524288 1048575 39 29002829 8.83 61.33 0.02 1048576 2097151 25 36824985 11.21 52.51 0.01 2097152 4194303 32 101727192 30.95 41.30 0.01 4194304 8388607 7 34007410 10.35 10.35 0.00 From this table, we see that free space extents that are 16 blocks or longer constitute 99.3% of the free space in the filesystem but only 27.5% of the extents. If we set the fstrim minlen parameter to 16 blocks, that means that we can trim over 99% of the space in one third of the time it would take to trim everything. Add a new -o fstrim_pct= option to xfs_scrub just in case there are users out there who want a different percentage. For example, accepting a 95% trim would net us a speed increase of nearly two orders of magnitude, ignoring system call overhead. Setting it to 100% will trim everything, just like fstrim(8). Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/histogram.c | 2 + libfrog/histogram.h | 1 + man/man8/xfs_scrub.8 | 16 +++++++++++ scrub/phase8.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++--- scrub/vfs.c | 4 ++- scrub/vfs.h | 2 + scrub/xfs_scrub.c | 38 +++++++++++++++++++++++++ scrub/xfs_scrub.h | 12 ++++++++ 8 files changed, 141 insertions(+), 9 deletions(-) diff --git a/libfrog/histogram.c b/libfrog/histogram.c index 54e2bac0f731..61ecda16ffef 100644 --- a/libfrog/histogram.c +++ b/libfrog/histogram.c @@ -109,7 +109,7 @@ hist_free( * of small extents, e.g. 98% of the free space extents are larger than 31 * blocks. */ -static int +int hist_cdf( const struct histogram *hs, struct histogram *cdf) diff --git a/libfrog/histogram.h b/libfrog/histogram.h index ec788344d4c2..ecac66d240da 100644 --- a/libfrog/histogram.h +++ b/libfrog/histogram.h @@ -39,6 +39,7 @@ void hist_add(struct histogram *hs, long long len); void hist_init(struct histogram *hs); void hist_prepare(struct histogram *hs, long long maxlen); void hist_free(struct histogram *hs); +int hist_cdf(const struct histogram *hs, struct histogram *cdf); void hist_print(const struct histogram *hs); void hist_summarize(const struct histogram *hs); diff --git a/man/man8/xfs_scrub.8 b/man/man8/xfs_scrub.8 index 404baba696e1..b9f253e1b079 100644 --- a/man/man8/xfs_scrub.8 +++ b/man/man8/xfs_scrub.8 @@ -100,6 +100,22 @@ The supported are: .RS 1.0i .TP +.BI fstrim_pct= percentage +To constrain the amount of time spent on fstrim activities during phase 8, +this program tries to balance estimated runtime against completeness of the +trim. +In short, the program avoids small trim requests to save time. + +During phase 7, a log-scale histogram of free space extents is constructed. +At the start of phase 8, a CDF is computed in decreasing order of extent +length from the histogram buckets. +A point corresponding to the fstrim percentage target is chosen from the CDF +and mapped back to a histogram bucket. +Free space extents at least as long as the bucket size are trimmed. +Smaller extents are ignored. + +By default, the percentage threshold is 99%. +.TP .BI iwarn Treat informational messages as warnings. This will result in a nonzero return code, and a higher logging level. diff --git a/scrub/phase8.c b/scrub/phase8.c index ae6d965c75e1..6bb9317afecc 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -11,6 +11,7 @@ #include "list.h" #include "libfrog/paths.h" #include "libfrog/workqueue.h" +#include "libfrog/histogram.h" #include "xfs_scrub.h" #include "common.h" #include "progress.h" @@ -57,10 +58,12 @@ static int fstrim_fsblocks( struct scrub_ctx *ctx, uint64_t start_fsb, - uint64_t fsbcount) + uint64_t fsbcount, + uint64_t minlen_fsb) { uint64_t start = cvt_off_fsb_to_b(&ctx->mnt, start_fsb); uint64_t len = cvt_off_fsb_to_b(&ctx->mnt, fsbcount); + uint64_t minlen = cvt_off_fsb_to_b(&ctx->mnt, minlen_fsb); int error; while (len > 0) { @@ -68,7 +71,7 @@ fstrim_fsblocks( run = min(len, FSTRIM_MAX_BYTES); - error = fstrim(ctx, start, run); + error = fstrim(ctx, start, run, minlen); if (error == EOPNOTSUPP) { /* Pretend we finished all the work. */ progress_add(len); @@ -78,9 +81,10 @@ fstrim_fsblocks( char descr[DESCR_BUFSZ]; snprintf(descr, sizeof(descr) - 1, - _("fstrim start 0x%llx run 0x%llx"), + _("fstrim start 0x%llx run 0x%llx minlen 0x%llx"), (unsigned long long)start, - (unsigned long long)run); + (unsigned long long)run, + (unsigned long long)minlen); str_liberror(ctx, error, descr); return error; } @@ -93,6 +97,64 @@ fstrim_fsblocks( return 0; } +/* Compute a suitable minlen parameter for fstrim. */ +static uint64_t +fstrim_compute_minlen( + const struct scrub_ctx *ctx, + const struct histogram *freesp_hist) +{ + struct histogram cdf; + uint64_t ret = 0; + double blk_threshold = 0; + unsigned int i; + unsigned int ag_max_usable; + int error; + + /* + * The kernel will reject a minlen that's larger than m_ag_max_usable. + * We can't calculate or query that value directly, so we guesstimate + * that it's 95% of the AG size. + */ + ag_max_usable = ctx->mnt.fsgeom.agblocks * 95 / 100; + + if (freesp_hist->totexts == 0) + goto out; + + if (debug > 1) + hist_print(freesp_hist); + + /* Insufficient samples to make a meaningful histogram */ + if (freesp_hist->totexts < freesp_hist->nr_buckets * 10) + goto out; + + hist_init(&cdf); + error = hist_cdf(freesp_hist, &cdf); + if (error) + goto out_free; + + blk_threshold = freesp_hist->totblocks * ctx->fstrim_block_pct; + for (i = 1; i < freesp_hist->nr_buckets; i++) { + if (cdf.buckets[i].blocks < blk_threshold) { + ret = freesp_hist->buckets[i - 1].low; + break; + } + } + +out_free: + hist_free(&cdf); +out: + if (debug > 1) + printf(_("fstrim minlen %lld threshold %lld ag_max_usable %u\n"), + (unsigned long long)ret, + (unsigned long long)blk_threshold, + ag_max_usable); + if (ret > ag_max_usable) + ret = ag_max_usable; + if (ret == 1) + ret = 0; + return ret; +} + /* Trim each AG on the data device. */ static int fstrim_datadev( @@ -100,8 +162,11 @@ fstrim_datadev( { struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; uint64_t fsbno; + uint64_t minlen_fsb; int error; + minlen_fsb = fstrim_compute_minlen(ctx, &ctx->datadev_hist); + for (fsbno = 0; fsbno < geo->datablocks; fsbno += geo->agblocks) { uint64_t fsbcount; @@ -113,7 +178,7 @@ fstrim_datadev( */ progress_add(geo->blocksize); fsbcount = min(geo->datablocks - (fsbno + 1), geo->agblocks - 1); - error = fstrim_fsblocks(ctx, fsbno + 1, fsbcount); + error = fstrim_fsblocks(ctx, fsbno + 1, fsbcount, minlen_fsb); if (error) return error; } diff --git a/scrub/vfs.c b/scrub/vfs.c index cc958ba9438e..22c19485a2da 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -300,11 +300,13 @@ int fstrim( struct scrub_ctx *ctx, uint64_t start, - uint64_t len) + uint64_t len, + uint64_t minlen) { struct fstrim_range range = { .start = start, .len = len, + .minlen = minlen, }; if (ioctl(ctx->mnt.fd, FITRIM, &range) == 0) diff --git a/scrub/vfs.h b/scrub/vfs.h index 1af8d80d1de6..f0cfd53c27be 100644 --- a/scrub/vfs.h +++ b/scrub/vfs.h @@ -24,6 +24,6 @@ typedef int (*scan_fs_tree_dirent_fn)(struct scrub_ctx *, const char *, int scan_fs_tree(struct scrub_ctx *ctx, scan_fs_tree_dir_fn dir_fn, scan_fs_tree_dirent_fn dirent_fn, void *arg); -int fstrim(struct scrub_ctx *ctx, uint64_t start, uint64_t len); +int fstrim(struct scrub_ctx *ctx, uint64_t start, uint64_t len, uint64_t minlen); #endif /* XFS_SCRUB_VFS_H_ */ diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index 2894f6148e10..296d814eceeb 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -622,11 +622,13 @@ report_outcome( */ enum o_opt_nums { IWARN = 0, + FSTRIM_PCT, O_MAX_OPTS, }; static char *o_opts[] = { [IWARN] = "iwarn", + [FSTRIM_PCT] = "fstrim_pct", [O_MAX_OPTS] = NULL, }; @@ -635,8 +637,11 @@ parse_o_opts( struct scrub_ctx *ctx, char *p) { + double dval; + while (*p != '\0') { char *val; + char *endp; switch (getsubopt(&p, o_opts, &val)) { case IWARN: @@ -647,6 +652,35 @@ parse_o_opts( } info_is_warning = true; break; + case FSTRIM_PCT: + if (!val) { + fprintf(stderr, + _("-o fstrim_pct requires a parameter\n")); + usage(); + } + + errno = 0; + dval = strtod(val, &endp); + + if (*endp) { + fprintf(stderr, + _("-o fstrim_pct must be a floating point number\n")); + usage(); + } + if (errno) { + fprintf(stderr, + _("-o fstrim_pct: %s\n"), + strerror(errno)); + usage(); + } + if (dval <= 0 || dval > 100) { + fprintf(stderr, + _("-o fstrim_pct must be larger than 0 and less than 100\n")); + usage(); + } + + ctx->fstrim_block_pct = dval / 100.0; + break; default: usage(); break; @@ -659,7 +693,9 @@ main( int argc, char **argv) { - struct scrub_ctx ctx = {0}; + struct scrub_ctx ctx = { + .fstrim_block_pct = FSTRIM_BLOCK_PCT_DEFAULT, + }; struct phase_rusage all_pi; char *mtab = NULL; FILE *progress_fp = NULL; diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index 1a28f0cc847e..7d48f4bad9ce 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -90,8 +90,20 @@ struct scrub_ctx { /* Free space histograms, in fsb */ struct histogram datadev_hist; + + /* + * Pick the largest value for fstrim minlen such that we trim at least + * this much space per volume. + */ + double fstrim_block_pct; }; +/* + * Trim only enough free space extents (in order of decreasing length) to + * ensure that this percentage of the free space is trimmed. + */ +#define FSTRIM_BLOCK_PCT_DEFAULT (99.0 / 100.0) + /* Phase helper functions */ void xfs_shutdown_fs(struct scrub_ctx *ctx); int scrub_cleanup(struct scrub_ctx *ctx);