From patchwork Tue Jul 2 01:01:02 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: 13718779 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 70C644A06 for ; Tue, 2 Jul 2024 01:01:03 +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=1719882063; cv=none; b=pGS+IpOLl3n4xLwWjTmbvly+KI/NymQlOvaK4HtJ2ui55sX24HLU8ywhp+smIcvR07y6JVF47yuow4X3M8tJx+bcobhsMNRo/t+xB0SjkJGQ5OC78Tg9ZsNECjqLhyPNXXsefEJsUTNuX+OtF+pMe/HxNFIJ3QoYTix8YLEVF/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882063; c=relaxed/simple; bh=nvwtKB4gUF1veTOF9c47AD1dCudnk1PZGRTjwfc7C94=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Du7MvCKsGvg0MzAIOzOj29RbFOR59cxCb3Elp7Y5ElRVBkJWhLjlnrro3LpciLYLrn3hZR+stqsWew6P+WvMCFRNbozQOnTV0dCSaFWfziGUzvya0Dw6l2CBptwb+YkUz/AQKGDTH+3UO64Y0w1cyg+kXkOexea/NyhJj/HQyRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dO2Thm24; 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="dO2Thm24" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEEF0C116B1; Tue, 2 Jul 2024 01:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882063; bh=nvwtKB4gUF1veTOF9c47AD1dCudnk1PZGRTjwfc7C94=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dO2Thm24w7AhA65lhRKMRtrU/rBXqlngGK3S6azYSodrehxLI/j5NBkFfa3nDJCVG napSPfZDrWW6Wg7TYAOZ2pCYXLt8KtQ2UXV+SZn4ccsYWPWRbvF6ot3FSrLyAcf2Ab qUE22leikcpbSUEOoq6R24BVEDQCwFLnQF8okdjTB0Oh4zzFgLWVkaappfNFkhTdAm 8DBM+5NYPCNhm3rzqyfTh6iU4h930qgvJTBrM7Nbl6TBSfq3U9EsuXqHxevioVizqe 2qqz1UyeEmERtd6HEcIIrcJWGNaSJksXBsmUDqp4tOWbrRygLdUWDJtxPJWv+7WLsZ 0qQdrx8fuvb3g== Date: Mon, 01 Jul 2024 18:01:02 -0700 Subject: [PATCH 1/8] xfs_scrub: move FITRIM to phase 8 From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118144.2007602.9357076180672124914.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 Issuing discards against the filesystem should be the *last* thing that xfs_scrub does, after everything else has been checked, repaired, and found to be clean. If we can't satisfy all those conditions, we have no business telling the storage to discard itself. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/Makefile | 1 + scrub/phase4.c | 30 ++---------------------- scrub/phase8.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scrub/xfs_scrub.h | 3 ++ 4 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 scrub/phase8.c diff --git a/scrub/Makefile b/scrub/Makefile index c11c2b5fe84e..8ccc67d01df3 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -68,6 +68,7 @@ phase4.c \ phase5.c \ phase6.c \ phase7.c \ +phase8.c \ progress.c \ read_verify.c \ repair.c \ diff --git a/scrub/phase4.c b/scrub/phase4.c index 9080d38818f7..451101811c9b 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -227,16 +227,6 @@ repair_everything( return action_list_process(ctx, ctx->fs_repair_list, XRM_FINAL_WARNING); } -/* Trim the unused areas of the filesystem if the caller asked us to. */ -static void -trim_filesystem( - struct scrub_ctx *ctx) -{ - if (want_fstrim) - fstrim(ctx); - progress_add(1); -} - /* Fix everything that needs fixing. */ int phase4_func( @@ -248,7 +238,7 @@ phase4_func( if (action_list_empty(ctx->fs_repair_list) && action_list_empty(ctx->file_repair_list)) - goto maybe_trim; + return 0; /* * Check the resource usage counters early. Normally we do this during @@ -281,20 +271,7 @@ phase4_func( if (ret) return ret; - ret = repair_everything(ctx); - if (ret) - return ret; - - /* - * If errors remain on the filesystem, do not trim anything. We don't - * have any threads running, so it's ok to skip the ctx lock here. - */ - if (ctx->corruptions_found || ctx->unfixable_errors != 0) - return 0; - -maybe_trim: - trim_filesystem(ctx); - return 0; + return repair_everything(ctx); } /* Estimate how much work we're going to do. */ @@ -307,10 +284,9 @@ phase4_estimate( { unsigned long long need_fixing; - /* Everything on the repair list plus FSTRIM. */ + /* Everything on the repair lis. */ need_fixing = action_list_length(ctx->fs_repair_list) + action_list_length(ctx->file_repair_list); - need_fixing++; *items = need_fixing; *nr_threads = scrub_nproc(ctx) + 1; diff --git a/scrub/phase8.c b/scrub/phase8.c new file mode 100644 index 000000000000..07726b5b8691 --- /dev/null +++ b/scrub/phase8.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "xfs.h" +#include +#include +#include +#include +#include "list.h" +#include "libfrog/paths.h" +#include "libfrog/workqueue.h" +#include "xfs_scrub.h" +#include "common.h" +#include "progress.h" +#include "scrub.h" +#include "repair.h" +#include "vfs.h" +#include "atomic.h" + +/* Phase 8: Trim filesystem. */ + +/* Trim the unused areas of the filesystem if the caller asked us to. */ +static void +trim_filesystem( + struct scrub_ctx *ctx) +{ + fstrim(ctx); + progress_add(1); +} + +/* Trim the filesystem, if desired. */ +int +phase8_func( + struct scrub_ctx *ctx) +{ + if (action_list_empty(ctx->fs_repair_list) && + action_list_empty(ctx->file_repair_list)) + goto maybe_trim; + + /* + * If errors remain on the filesystem, do not trim anything. We don't + * have any threads running, so it's ok to skip the ctx lock here. + */ + if (ctx->corruptions_found || ctx->unfixable_errors != 0) + return 0; + +maybe_trim: + trim_filesystem(ctx); + return 0; +} + +/* Estimate how much work we're going to do. */ +int +phase8_estimate( + struct scrub_ctx *ctx, + uint64_t *items, + unsigned int *nr_threads, + int *rshift) +{ + *items = 1; + *nr_threads = 1; + *rshift = 0; + return 0; +} diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index ed86d0093db3..6272a36879e7 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -98,6 +98,7 @@ int phase4_func(struct scrub_ctx *ctx); int phase5_func(struct scrub_ctx *ctx); int phase6_func(struct scrub_ctx *ctx); int phase7_func(struct scrub_ctx *ctx); +int phase8_func(struct scrub_ctx *ctx); /* Progress estimator functions */ unsigned int scrub_estimate_ag_work(struct scrub_ctx *ctx); @@ -112,5 +113,7 @@ int phase5_estimate(struct scrub_ctx *ctx, uint64_t *items, unsigned int *nr_threads, int *rshift); int phase6_estimate(struct scrub_ctx *ctx, uint64_t *items, unsigned int *nr_threads, int *rshift); +int phase8_estimate(struct scrub_ctx *ctx, uint64_t *items, + unsigned int *nr_threads, int *rshift); #endif /* XFS_SCRUB_XFS_SCRUB_H_ */ From patchwork Tue Jul 2 01:01:18 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: 13718780 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 D95AE6FCB for ; Tue, 2 Jul 2024 01:01:18 +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=1719882078; cv=none; b=sicWN8fyKUu+HAYGVhAXiItAvnBn/ExC/iKtyac0Nw3XOpbrtF1sWp6Pfy2bZmp3Wc/z50zWko+TQLIlQqljlO2wHnHoZLN4Xnj/axe1K7qTm8NiJlwVIGtnHktwDcIpGe2lyU4O88PccWUr0JgUXqUFKXxdgGebWYozwcFANvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882078; c=relaxed/simple; bh=HA2KUZaGZn7GFSRg6DeoN0KrghPDL0zaGve03FwuEvw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nOhSKSoboWfWb41LPmqVrtSnq/v+ul03hNGQVVFeLK6eP/fzTDOlsW34ijfL55pzPV4UGi2DHrwFkEfMPVrj8lQHsLuaSJopgHeh2VJdjdFKdAcIldgEO7HmCXjBzFcYZU51dgcliK6556wdbf49wGVHV9JNojYpFZDOizUbFRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K9/zX6D1; 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="K9/zX6D1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B575AC116B1; Tue, 2 Jul 2024 01:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882078; bh=HA2KUZaGZn7GFSRg6DeoN0KrghPDL0zaGve03FwuEvw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=K9/zX6D1CRyX5TK2MdLPLCvbm42nigD/GC4QLtaUy/uJHuUf/Z9HgW7L//bV6+Hhn CRR1ets7OphWRAcvlE7JxAKaA222d/d666Ka58oNEQ1dfksjRtonFZ7pUP2p8l8L33 f0sLuA1WqwrAg+KxVxckSIEezb1xoi9iQTd9xCHYV9EEgmR10HSEJNr3JbEeDJQuPO 3djw2QbR3wNYu0h5j3MfWkuge15giygYOaIaEwmywI63gwChueOe6AgKTDSRdjJC4G BqNHY/K/87Uy+669ejPHCRY8c2KQtbGwo5jFOkCHyUMDTYSuYg8rNzpNhTuAWZQylx /MX/ANV739k6g== Date: Mon, 01 Jul 2024 18:01:18 -0700 Subject: [PATCH 2/8] xfs_scrub: ignore phase 8 if the user disabled fstrim From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118160.2007602.9433733356692574496.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 If the user told us to skip trimming the filesystem, don't run the phase at all. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index e49538ca1cdd..edf58d07bde2 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -249,6 +249,7 @@ struct phase_rusage { /* Operations for each phase. */ #define DATASCAN_DUMMY_FN ((void *)1) #define REPAIR_DUMMY_FN ((void *)2) +#define FSTRIM_DUMMY_FN ((void *)3) struct phase_ops { char *descr; int (*fn)(struct scrub_ctx *ctx); @@ -429,6 +430,11 @@ run_scrub_phases( .fn = phase7_func, .must_run = true, }, + { + .descr = _("Trim filesystem storage."), + .fn = FSTRIM_DUMMY_FN, + .estimate_work = phase8_estimate, + }, { NULL }, @@ -449,6 +455,8 @@ run_scrub_phases( /* Turn on certain phases if user said to. */ if (sp->fn == DATASCAN_DUMMY_FN && scrub_data) { sp->fn = phase6_func; + } else if (sp->fn == FSTRIM_DUMMY_FN && want_fstrim) { + sp->fn = phase8_func; } else if (sp->fn == REPAIR_DUMMY_FN && ctx->mode == SCRUB_MODE_REPAIR) { sp->descr = _("Repair filesystem."); @@ -458,7 +466,8 @@ run_scrub_phases( /* Skip certain phases unless they're turned on. */ if (sp->fn == REPAIR_DUMMY_FN || - sp->fn == DATASCAN_DUMMY_FN) + sp->fn == DATASCAN_DUMMY_FN || + sp->fn == FSTRIM_DUMMY_FN) continue; /* Allow debug users to force a particular phase. */ From patchwork Tue Jul 2 01:01:33 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: 13718781 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 DB3D879CC for ; Tue, 2 Jul 2024 01:01:34 +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=1719882094; cv=none; b=WItpp27TmMt+TtvKUvwLiCWSViRqIY2TuXzyRcHknxVEsVPVR6w0gooRsVBkt5K/r+5VFcnEEH5XZqzf7ZOdz01nB/X6pfuW/iX8abPH+xVLGZ55rRIDQ5khti3eZcxrqZflWH++jKFptzAtZuhpxqalRUNdvLnYy5MusqZsdV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882094; c=relaxed/simple; bh=h8ZknGA35SG77MkKDlgnS5XBTHsnmWttLMnpEx5Xiq0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m+4/+IjBNvmCrlf3Znmv+8UK33211AIIdPD/ZBcme1m+5KekhW4m+iW5OOQdgGuEjwROtsGjxgyn8ymWNDr8O4btiofUmKyV1fFseGaLU/i5Yn4xoQqB6kpzLVxwHDMqWTKIxtJ9YLypRHSP9ardMzXVVzUqlq5pLwA3Biwr9k8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b1+a1jag; 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="b1+a1jag" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62E9BC116B1; Tue, 2 Jul 2024 01:01:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882094; bh=h8ZknGA35SG77MkKDlgnS5XBTHsnmWttLMnpEx5Xiq0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=b1+a1jagoJ0Uro82Q4lrcKqmlh7UBUophq3mvhRZyAzBd7tGYkQrlyMTT2wQBHGz/ OYzCJ6L9/MhA+tsBpZH7Yk9H27mCBw/TDQ3MYUFYSLx6jCSV9BQM8YTkWrB3T+pnUF au8cWc8FDMpXUiM3STiSBhzHrkZ9bNXEGuwd/DFWH4w8pSnOCjOn4avDFMLTyZfSx/ k2vqzbaOSIETYZh1xlsNlJOVRsRSSfKE8a4DOJN0xSCAVz0w/jpYItyMyYnQtlPkJR MAxOEbDguEnZbes3CrhgbYcJJ++AoqSyAlOW6F8Sv5yvMu549nxPhAK+mM26ykxX4I zJNiCHHbAO6rg== Date: Mon, 01 Jul 2024 18:01:33 -0700 Subject: [PATCH 3/8] xfs_scrub: collapse trim_filesystem From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118175.2007602.6970743462017002792.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 Collapse this two-line helper into the main function since it's trivial. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index 07726b5b8691..e577260a93dd 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -21,15 +21,6 @@ /* Phase 8: Trim filesystem. */ -/* Trim the unused areas of the filesystem if the caller asked us to. */ -static void -trim_filesystem( - struct scrub_ctx *ctx) -{ - fstrim(ctx); - progress_add(1); -} - /* Trim the filesystem, if desired. */ int phase8_func( @@ -47,7 +38,8 @@ phase8_func( return 0; maybe_trim: - trim_filesystem(ctx); + fstrim(ctx); + progress_add(1); return 0; } From patchwork Tue Jul 2 01:01:49 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: 13718785 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 72524BE49 for ; Tue, 2 Jul 2024 01:01:50 +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=1719882110; cv=none; b=dZ7q4LSQXzkfBCS38qr7eAkRDPCuFrQPVNGyqEAMK4LvKn/0WfR+BFguxMpN11uI5ZhHB6OpXLytuL24UKZPQFXJjASGIKqK1LSmBdO2xK75Pp3TWmplCK7rByZAmq/+TINgL/te0/GN0Yof4DQGXGyfWjdn85IL8ZUBH7Hwj6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882110; c=relaxed/simple; bh=zEtc0sBjoiCx2y6nVyxJf0NjaIYKMOe6NJQ9UpEyipM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T0+QwTlT7b6JO06uV8stCfTXH051k21A3xhm+lvbrfeyi+T9Bht0r2rDvGrhQyNOFB/PCt+WJnJ5gT6wrDRCxWUWpyagPcUteRHK2WrxGX5LSSbLS0Yvb0kbq9dShFujzYKM4nCHPJRPBbE/a7KfdR+pZ63cr6R5dScExf8rsA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JGC2kino; 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="JGC2kino" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07F31C4AF11; Tue, 2 Jul 2024 01:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882110; bh=zEtc0sBjoiCx2y6nVyxJf0NjaIYKMOe6NJQ9UpEyipM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JGC2kinofvMLDTvFN9c4pTJqNUIvuiolk8/pgGrVwwuTc+Qg0J89XQTdcbUSdwDSY yANCdL0LqOMaT/dMRy4+ucB4DjsrjdW4BPJMdkT5Km51XhQXW4r9WA9XWTsgR6p6uX VLhiExDHpPI0bI5lQ4pHfhOpLeaLBCmGBI2QCI01QiGb9bwTqBsQCA2S1mN65Z4hbu +8/MPZgReeM7JujkZ+tKyCFDxgoMQXlwRZsg4g3b9ATjmemJuox0E5k1UyWapzzLhZ Zb6xEJfYwmBPJPWkJSn9x3wuYAW5M0xQTwU38imbK29a5tM0iwTEnaSl66xgwn4Jzl BJ625K5pJtkog== Date: Mon, 01 Jul 2024 18:01:49 -0700 Subject: [PATCH 4/8] xfs_scrub: fix the work estimation for phase 8 From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118191.2007602.10091096037746377494.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 If there are latent errors on the filesystem, we aren't going to do any work during phase 8 and it makes no sense to add that into the work estimate for the progress bar. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index e577260a93dd..dfe62e8d97be 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -21,23 +21,35 @@ /* Phase 8: Trim filesystem. */ -/* Trim the filesystem, if desired. */ -int -phase8_func( +static inline bool +fstrim_ok( struct scrub_ctx *ctx) { - if (action_list_empty(ctx->fs_repair_list) && - action_list_empty(ctx->file_repair_list)) - goto maybe_trim; - /* * If errors remain on the filesystem, do not trim anything. We don't * have any threads running, so it's ok to skip the ctx lock here. */ - if (ctx->corruptions_found || ctx->unfixable_errors != 0) + if (!action_list_empty(ctx->fs_repair_list)) + return false; + if (!action_list_empty(ctx->file_repair_list)) + return false; + + if (ctx->corruptions_found != 0) + return false; + if (ctx->unfixable_errors != 0) + return false; + + return true; +} + +/* Trim the filesystem, if desired. */ +int +phase8_func( + struct scrub_ctx *ctx) +{ + if (!fstrim_ok(ctx)) return 0; -maybe_trim: fstrim(ctx); progress_add(1); return 0; @@ -51,7 +63,11 @@ phase8_estimate( unsigned int *nr_threads, int *rshift) { - *items = 1; + *items = 0; + + if (fstrim_ok(ctx)) + *items = 1; + *nr_threads = 1; *rshift = 0; return 0; From patchwork Tue Jul 2 01:02:05 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: 13718786 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 D1C888479 for ; Tue, 2 Jul 2024 01:02:05 +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=1719882125; cv=none; b=A0vWPjl1R89kWUzTYoLjRrhjsUmtlbvkKaD4ROqF07jPLcbKuW73fgS8SxnPd3jyLnn+07tqKTN4/EoTlGfBgaNWueayPTrttts5emT5rJ5QVcq2D1n0Kt4ibE6qm5gZy7bpoHb21FKH/za97LFXEAGyiT9Areth28T9uK7oFSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882125; c=relaxed/simple; bh=Ql6JuC9gZKl6vIqFlVeAsvSE6tzWZZkq8SvKFDoopQw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y885zYry2LIheWLIShvHbTw3i6suELsMsxBowFjTMqcWh37wtLR1Z/7EkIWygAne0yzJ5u1m7nzqk9dvrMEmncmpVCfVRO4beGvXdV/WOrfzuPLcbo8HZ56+qzYdmb+N6Y0HC9JbSywl7Zmb7lBcMPhwmJFTwRejw7mawSBdcSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=irgmiefY; 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="irgmiefY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD099C116B1; Tue, 2 Jul 2024 01:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882125; bh=Ql6JuC9gZKl6vIqFlVeAsvSE6tzWZZkq8SvKFDoopQw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=irgmiefYXkDjFUsX3P73wvMytFjbVQzHgErR83nvfPJGHyCG4a+2OGrbOL+1h+GnN S6rRBF1cOx7BQBqI75j/uMTrRGEcp9qgz3+rghZSkRc5MEWAFZMI2KhotfaeQcYsjT ztqPL7sXPy5s4aHv7ZwUhgsiB4PwvGhaZqYtLlz3Kh4BRBheVbzfvPcfYcSTzoyM7m Lsw2e1glmZL7lUgK4JfHuQckDW/UJ75MOrjMNhnhG+SkLdnll/2/6iJ+cY+HW3VJ6p 2ea6c54Ms5ro2184LitPBqIgonbq32wXldq323zohMLS9Q8d1k4R14MxuWPj59SyyE DIpF560PFoP7g== Date: Mon, 01 Jul 2024 18:02:05 -0700 Subject: [PATCH 5/8] xfs_scrub: report FITRIM errors properly From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118206.2007602.14308985688503230669.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 Move the error reporting for the FITRIM ioctl out of vfs.c and into phase8.c. This makes it so that IO errors encountered during trim are counted as runtime errors instead of being dropped silently. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 12 +++++++++++- scrub/vfs.c | 12 +++++++----- scrub/vfs.h | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index dfe62e8d97be..288800a76cff 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -47,10 +47,20 @@ int phase8_func( struct scrub_ctx *ctx) { + int error; + if (!fstrim_ok(ctx)) return 0; - fstrim(ctx); + error = fstrim(ctx); + if (error == EOPNOTSUPP) + return 0; + + if (error) { + str_liberror(ctx, error, _("fstrim")); + return error; + } + progress_add(1); return 0; } diff --git a/scrub/vfs.c b/scrub/vfs.c index 9e459d6243fa..bcfd4f42ca8b 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -296,15 +296,17 @@ struct fstrim_range { #endif /* Call FITRIM to trim all the unused space in a filesystem. */ -void +int fstrim( struct scrub_ctx *ctx) { struct fstrim_range range = {0}; - int error; range.len = ULLONG_MAX; - error = ioctl(ctx->mnt.fd, FITRIM, &range); - if (error && errno != EOPNOTSUPP && errno != ENOTTY) - perror(_("fstrim")); + if (ioctl(ctx->mnt.fd, FITRIM, &range) == 0) + return 0; + if (errno == EOPNOTSUPP || errno == ENOTTY) + return EOPNOTSUPP; + + return errno; } diff --git a/scrub/vfs.h b/scrub/vfs.h index 1ac41e5aac07..a8a4d72e290a 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); -void fstrim(struct scrub_ctx *ctx); +int fstrim(struct scrub_ctx *ctx); #endif /* XFS_SCRUB_VFS_H_ */ From patchwork Tue Jul 2 01:02:20 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: 13718787 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 DDDBC4436 for ; Tue, 2 Jul 2024 01:02:21 +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=1719882141; cv=none; b=OOF1JAUymfh2VR6IVWTD0IGUgM3UU9zCofO6XrKSodtERidomzhfXeP1s7FZmS/GPl31CZNlT79OfTdrGEg1bjtH9nK76hk9FXKc5K4D5oiI3lXuXcOS44ScLI+4NvqcQp1Ix633sBp/fpTfk42oHXOh6VBy5Q1+xJRzW39egEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882141; c=relaxed/simple; bh=xrHmCbNuD+wu+2KGIw6mQnwDWS9+OomNxHBfO/yalAY=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nGa4Jyj9bkLaa1KlHOdjWJHomeAbNqMP5+HMsK/WfuCVA0u/+xwxlmEwPA5KUtYlFd6IiBLhN6gGLJ5+SSHSo3ZMpvy7xcrd/VR71hsakC+ICZIaofsx6vh6H/r3guA2rmoVBeP+a6jHqZEBuDB0S3E/Mv3k0n7FMuFyRTF7D8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TyauPU/h; 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="TyauPU/h" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58713C116B1; Tue, 2 Jul 2024 01:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882141; bh=xrHmCbNuD+wu+2KGIw6mQnwDWS9+OomNxHBfO/yalAY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=TyauPU/hpOnRsAKza3CaWcQEomI7Mif5dwAddZDMh5gQM4B/STcm5wTfN4fvLV+Vy BVq3YdRTwXmYHEScG13TJZzHkNFYh5XCJrTPj+tJ+kHDYRDydd0yzp+Cm9cs/P/cOt 8q6/j0iqDPY0WPgVs0OOVBL8dZ6GRqthXJHmEksI1Nfa1sX2UWaWbYbMVba9E8VwQS hdEgDk/Q+3TaSOvoUQC0/cFDak6JeN0PiXZl/oFZnKXRh5GR/oTAIDM2A6ahy1iKSf pOi5dxXRHK848ddbPFw8cet+0dCNBJanQqITAf4arhNIhBUOggaHnQ6Hlu5SQVnxlW iLdkO0rgxE03A== Date: Mon, 01 Jul 2024 18:02:20 -0700 Subject: [PATCH 6/8] xfs_scrub: don't call FITRIM after runtime errors From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118222.2007602.19270694956927614.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 Don't call FITRIM if there have been runtime errors -- we don't want to touch anything after any kind of unfixable problem. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scrub/phase8.c b/scrub/phase8.c index 288800a76cff..75400c968595 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -39,6 +39,9 @@ fstrim_ok( if (ctx->unfixable_errors != 0) return false; + if (ctx->runtime_errors != 0) + return false; + return true; } From patchwork Tue Jul 2 01:02:36 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: 13718788 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 8BF8E4C8B for ; Tue, 2 Jul 2024 01:02:37 +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=1719882157; cv=none; b=c3m2tjLcNbSzh4O02Vxuy4ZeBV9HSDc3jRsv6JZXlewNIOkNZOCPTYkxSnaVacgkhwfx9vK6CzteKPYD1jeUO/MbhOleaMzl98XP+TMxeRexexfXW5TlBLPYRIHby/4T55qdKUAN78ixauNqUeZQ+lVTbk7HLqYo/phxPkG7kI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882157; c=relaxed/simple; bh=l2Zn3oyirNmNSuwJp95Z7HkdP56rQZIrg26yVwmqY0Q=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kkGL/gTEaoMONoOq/aEeMYeF8j7l4Ad4prFLvBbHCTz0BRRYlGb/ZFQcQggJFQgUaaiOzpuUjsoWZRxWp0p85UqEJOnQqdJYUC/q8VZyrLljOBJ/5VidFhkfh+o9OpJwRwmKsJT/Z6IWqvz7whgQEN7XyMjkLWXJSWy/tewEFCk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QfEaPcEA; 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="QfEaPcEA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 093AEC116B1; Tue, 2 Jul 2024 01:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882157; bh=l2Zn3oyirNmNSuwJp95Z7HkdP56rQZIrg26yVwmqY0Q=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QfEaPcEAUevKOkQAViaGXJu/+TGbzwcF7UzPxiXwkBiJkjxyU+ZUURHunsUUWzVqu YJd8vjILHsdmRoakd6eqJzbt3mMG25yT1XUjwRhqFwpETdTy56OYwm+XmX/GIr73GI lZ0gOMtAImJzDZC+akayEDlMcwcF4/58rWIWq76U83m5wHE3F4+Q6ihTlpSbRE/8hS 2Ej3HPF2e1327qDfiI9GLj/a9lxjin594eOmmnekngLCqUwVDq5zOSDpXLgxmviYCv TD5ORcHQYPHOXxxVLjbwFfTbqih7AK/JZPnLrUDKSgMZ1AX/jBIEu/3ZfkfaHB5RaK etujUt0udBOfA== Date: Mon, 01 Jul 2024 18:02:36 -0700 Subject: [PATCH 7/8] xfs_scrub: don't trim the first agbno of each AG for better performance From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118237.2007602.9576505614542313879.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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 On a 10TB filesystem where the free space in each AG is heavily fragmented, I noticed some very high runtimes on a FITRIM call for the entire filesystem. xfs_scrub likes to report progress information on each phase of the scrub, which means that a strace for the entire filesystem: ioctl(3, FITRIM, {start=0x0, len=10995116277760, minlen=0}) = 0 <686.209839> shows that scrub is uncommunicative for the entire duration. Reducing the size of the FITRIM requests to a single AG at a time produces lower times for each individual call, but even this isn't quite acceptable, because the time between progress reports are still very high: Strace for the first 4x 1TB AGs looks like (2): ioctl(3, FITRIM, {start=0x0, len=1099511627776, minlen=0}) = 0 <68.352033> ioctl(3, FITRIM, {start=0x10000000000, len=1099511627776, minlen=0}) = 0 <68.760323> ioctl(3, FITRIM, {start=0x20000000000, len=1099511627776, minlen=0}) = 0 <67.235226> ioctl(3, FITRIM, {start=0x30000000000, len=1099511627776, minlen=0}) = 0 <69.465744> I then had the idea to limit the length parameter of each call to a smallish amount (~11GB) so that we could report progress relatively quickly, but much to my surprise, each FITRIM call still took ~68 seconds! Unfortunately, the by-length fstrim implementation handles this poorly because it walks the entire free space by length index (cntbt), which is a very inefficient way to walk a subset of an AG. Therefore, we created a second implementation that will walk the bnobt and perform the trims in block number order. This implementation avoids the worst problems of the original code, though it lacks the desirable attribute of freeing the biggest chunks first. On the other hand, this second implementation will be much easier to constrain the system call latency, and makes it much easier to report fstrim progress to anyone who's running xfs_scrub. Skip the first block of each AG to ensure that we get the sub-AG algorithm. Signed-off-by: Darrick J. Wong --- scrub/phase8.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++--------- scrub/vfs.c | 10 ++++++--- scrub/vfs.h | 2 +- 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index 75400c968595..e5f5619a80b5 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -45,29 +45,73 @@ fstrim_ok( return true; } -/* Trim the filesystem, if desired. */ -int -phase8_func( - struct scrub_ctx *ctx) +/* Trim a certain range of the filesystem. */ +static int +fstrim_fsblocks( + struct scrub_ctx *ctx, + uint64_t start_fsb, + uint64_t fsbcount) { + uint64_t start = cvt_off_fsb_to_b(&ctx->mnt, start_fsb); + uint64_t len = cvt_off_fsb_to_b(&ctx->mnt, fsbcount); int error; - if (!fstrim_ok(ctx)) - return 0; - - error = fstrim(ctx); + error = fstrim(ctx, start, len); if (error == EOPNOTSUPP) return 0; - if (error) { - str_liberror(ctx, error, _("fstrim")); + char descr[DESCR_BUFSZ]; + + snprintf(descr, sizeof(descr) - 1, + _("fstrim start 0x%llx len 0x%llx"), + (unsigned long long)start, + (unsigned long long)len); + str_liberror(ctx, error, descr); return error; } + return 0; +} + +/* Trim each AG on the data device. */ +static int +fstrim_datadev( + struct scrub_ctx *ctx) +{ + struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; + uint64_t fsbno; + int error; + + for (fsbno = 0; fsbno < geo->datablocks; fsbno += geo->agblocks) { + uint64_t fsbcount; + + /* + * Skip the first block of each AG to ensure that we get the + * partial-AG discard implementation. This means that we can + * report trim progress to userspace in units smaller than + * entire AGs. + */ + fsbcount = min(geo->datablocks - (fsbno + 1), geo->agblocks - 1); + error = fstrim_fsblocks(ctx, fsbno + 1, fsbcount); + if (error) + return error; + } + progress_add(1); return 0; } +/* Trim the filesystem, if desired. */ +int +phase8_func( + struct scrub_ctx *ctx) +{ + if (!fstrim_ok(ctx)) + return 0; + + return fstrim_datadev(ctx); +} + /* Estimate how much work we're going to do. */ int phase8_estimate( diff --git a/scrub/vfs.c b/scrub/vfs.c index bcfd4f42ca8b..cc958ba9438e 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -298,11 +298,15 @@ struct fstrim_range { /* Call FITRIM to trim all the unused space in a filesystem. */ int fstrim( - struct scrub_ctx *ctx) + struct scrub_ctx *ctx, + uint64_t start, + uint64_t len) { - struct fstrim_range range = {0}; + struct fstrim_range range = { + .start = start, + .len = len, + }; - range.len = ULLONG_MAX; if (ioctl(ctx->mnt.fd, FITRIM, &range) == 0) return 0; if (errno == EOPNOTSUPP || errno == ENOTTY) diff --git a/scrub/vfs.h b/scrub/vfs.h index a8a4d72e290a..1af8d80d1de6 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); +int fstrim(struct scrub_ctx *ctx, uint64_t start, uint64_t len); #endif /* XFS_SCRUB_VFS_H_ */ From patchwork Tue Jul 2 01:02:52 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: 13718789 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 D2A0E7462 for ; Tue, 2 Jul 2024 01:02:52 +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=1719882172; cv=none; b=gFFxiu0W5myeVMVLwpNe+cwI2+zfSM+VjLWOk6oTO63tTvzZnbdU6YDV6GztS0gNvZU1EWmXOHj+wp1rthyUHnNhqd+5R0zptM7RrkXuQYDdZmjzIlo5bJMwwiunEdwjxYNvHgtEJn6ulcpORgTWKZLsYRz/ZcsEYzDjCPcfKfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719882172; c=relaxed/simple; bh=RvS2mnRF1v6vBgSDTyVADgbiosGhmbT8sHw1VVt5Guw=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lDIhzSZ9MiNfeKsgL50PB5oaQ3ysAeS4h+7U7JcbZPd3GKVagiJdbxjyi4jVMwVIxVTzUqwoNLrXQDIRZiMfW196PEOABZcMJJKswi1nw9ts4ueGaPmGo6kbDN6HhbpfRNDWf3StRRdi99k0pMkA/xwUhtFckAgWkSEwSxkayUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m3QyehWE; 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="m3QyehWE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FAE6C116B1; Tue, 2 Jul 2024 01:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719882172; bh=RvS2mnRF1v6vBgSDTyVADgbiosGhmbT8sHw1VVt5Guw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=m3QyehWEjRnQh9640mhj4ULtkuVV0DtY6TdJ6THMKwLxQp26QeXF5uxNxf7/bHFSD URKwfUj/lbX14J5RUYCwwUMxmm6ZBIOePRN+hr1Zfl0j0AWqSEInhtIxbOOD1cAUQu S9Q1dtI8+whW8CnCAtuML6I4nrmmxa7h2Bpy3NI2AHxHEzJMpM6/tlQhUI/LiFlHHt GGIcRyIO8JVcOfu0ZV20psBgPJIFIjYcL1U9k2DonPzQle95mdDVcRqvY85dCwK3R0 gS/KIY5zANdlX+kX+tnmcyunr2oAScaozV6YfOesfCRXw8DQWgZPwA1qUhS9NCGFLG NNHZTpukBn/yQ== Date: Mon, 01 Jul 2024 18:02:52 -0700 Subject: [PATCH 8/8] xfs_scrub: improve progress meter for phase 8 fstrimming From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org, hch@lst.de Message-ID: <171988118250.2007602.17910306565917298331.stgit@frogsfrogsfrogs> In-Reply-To: <171988118118.2007602.12196117098152792537.stgit@frogsfrogsfrogs> References: <171988118118.2007602.12196117098152792537.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, progress reporting in phase 8 is awful, because we stall at 0% until jumping to 100%. Since we're now performing sub-AG fstrim calls to limit the latency impacts to the rest of the system, we might as well limit the FSTRIM scan size so that we can report status updates to the user more regularly. Doing so also facilitates CPU usage control during phase 8. Signed-off-by: Darrick J. Wong --- scrub/phase8.c | 59 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index e5f5619a80b5..ae6d965c75e1 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -45,6 +45,13 @@ fstrim_ok( return true; } +/* + * Limit the amount of fstrim scanning that we let the kernel do in a single + * call so that we can implement decent progress reporting and CPU resource + * control. Pick a prime number of gigabytes for interest. + */ +#define FSTRIM_MAX_BYTES (11ULL << 30) + /* Trim a certain range of the filesystem. */ static int fstrim_fsblocks( @@ -56,18 +63,31 @@ fstrim_fsblocks( uint64_t len = cvt_off_fsb_to_b(&ctx->mnt, fsbcount); int error; - error = fstrim(ctx, start, len); - if (error == EOPNOTSUPP) - return 0; - if (error) { - char descr[DESCR_BUFSZ]; - - snprintf(descr, sizeof(descr) - 1, - _("fstrim start 0x%llx len 0x%llx"), - (unsigned long long)start, - (unsigned long long)len); - str_liberror(ctx, error, descr); - return error; + while (len > 0) { + uint64_t run; + + run = min(len, FSTRIM_MAX_BYTES); + + error = fstrim(ctx, start, run); + if (error == EOPNOTSUPP) { + /* Pretend we finished all the work. */ + progress_add(len); + return 0; + } + if (error) { + char descr[DESCR_BUFSZ]; + + snprintf(descr, sizeof(descr) - 1, + _("fstrim start 0x%llx run 0x%llx"), + (unsigned long long)start, + (unsigned long long)run); + str_liberror(ctx, error, descr); + return error; + } + + progress_add(run); + len -= run; + start += run; } return 0; @@ -91,13 +111,13 @@ fstrim_datadev( * report trim progress to userspace in units smaller than * entire AGs. */ + progress_add(geo->blocksize); fsbcount = min(geo->datablocks - (fsbno + 1), geo->agblocks - 1); error = fstrim_fsblocks(ctx, fsbno + 1, fsbcount); if (error) return error; } - progress_add(1); return 0; } @@ -120,12 +140,13 @@ phase8_estimate( unsigned int *nr_threads, int *rshift) { - *items = 0; - - if (fstrim_ok(ctx)) - *items = 1; - + if (fstrim_ok(ctx)) { + *items = cvt_off_fsb_to_b(&ctx->mnt, + ctx->mnt.fsgeom.datablocks); + } else { + *items = 0; + } *nr_threads = 1; - *rshift = 0; + *rshift = 30; /* GiB */ return 0; }