From patchwork Fri May 26 01:48:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDA09C7EE29 for ; Fri, 26 May 2023 01:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233393AbjEZBsw (ORCPT ); Thu, 25 May 2023 21:48:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjEZBsv (ORCPT ); Thu, 25 May 2023 21:48:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2137B189 for ; Thu, 25 May 2023 18:48:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A1D0A64868 for ; Fri, 26 May 2023 01:48:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 101E7C433D2; Fri, 26 May 2023 01:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065729; bh=x2TUMRNzmxXGWMmc9elf40ST55C6jMh16ecytyCj76A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AOhC51xxNdeiPy7JbSeIA9Hp4dgTIccNZgKNFjK9tMIZ3vuoQhkcHCEQzGcsMPDV4 mkQcDqvOkND6CqQxWcu8RTqxI+swi9UyOG/qmO4IL0L1rFjckME2ow0IjTqQHLIbZi FIwOULsHKBX7r0DgbE6Zl9iExbo4U9PqAvbrogv0YzTpU+yltpBuHWONjA+ui339S2 r0w/039OjC3dDN6wdYHUS2SREZ/gPzREjHAfBZ5a2nwMUDn8T9mN/2NvGc/Bh1CiDW MWVe68lgUVqLuM0KlxDkGBZpXij0Pyt4jbeUTS3XdczaE5AHYhqA85iXLchK9nZGj1 s5k0136qw4law== Date: Thu, 25 May 2023 18:48:48 -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 Message-ID: <168506073093.3744829.8869002123198312230.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 --- 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 db60689c1dc..f6f8ebdc814 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -60,6 +60,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 cb0354b44cb..14efe27d92c 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -223,16 +223,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( @@ -244,7 +234,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 @@ -277,20 +267,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. */ @@ -303,10 +280,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 00000000000..c6dabbd5eed --- /dev/null +++ b/scrub/phase8.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2018-2023 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 acfe6175bdb..4f1e7e02d87 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -97,6 +97,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); @@ -111,5 +112,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 Fri May 26 01:49:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256152 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AD64C77B7E for ; Fri, 26 May 2023 01:49:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229567AbjEZBtH (ORCPT ); Thu, 25 May 2023 21:49:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjEZBtG (ORCPT ); Thu, 25 May 2023 21:49:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C65D618D for ; Thu, 25 May 2023 18:49:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C70363B77 for ; Fri, 26 May 2023 01:49:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6691C433EF; Fri, 26 May 2023 01:49:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065744; bh=kV3h+H4QlwayHE7T7fLtHBCNkXrrsnmReCaWJZBP66o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=PW5kvv/SD2We4ZqVRscUA89k+eTVEyh44eTlqdZ4tT+9V0CklG0RpRx+Q6GNHk+yU 0tEnqyxnivKlRlU+ku+YIWOO/g8Yl4X6KO4Z9zi+bF2qlwGSZoNdMzW3mRnDaXU/Pg I233qQaywm3b16lfthPOTbNJp0wJXAau03ZNxF2RnT09Ka6qDfppxYRsFlpvPTnoeo 8XYlmmDQ+LusTQGkybUOEwGPd82BV0kL0RF50My8VvKM8H0GAyC2/r3pCoU7hi1qUP FYXODewZr+ekbV9EKl5UMAdrvfKOv/FHOyPJ8n1zllrtHIpyDzJu6920OY7HbsTjxv FB8f8/mSRzHvQ== Date: Thu, 25 May 2023 18:49:04 -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 Message-ID: <168506073106.3744829.4305123730916746991.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 --- 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 6c090a6dd88..73f82ef0c8d 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -246,6 +246,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); @@ -426,6 +427,11 @@ run_scrub_phases( .fn = phase7_func, .must_run = true, }, + { + .descr = _("Trim filesystem storage."), + .fn = FSTRIM_DUMMY_FN, + .estimate_work = phase8_estimate, + }, { NULL }, @@ -446,6 +452,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."); @@ -455,7 +463,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 Fri May 26 01:49:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF1D5C7EE29 for ; Fri, 26 May 2023 01:49:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbjEZBtW (ORCPT ); Thu, 25 May 2023 21:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjEZBtW (ORCPT ); Thu, 25 May 2023 21:49:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66B1E189 for ; Thu, 25 May 2023 18:49:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E62CB63B77 for ; Fri, 26 May 2023 01:49:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 599AFC433D2; Fri, 26 May 2023 01:49:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065760; bh=uU+HJWrN+sNdZRqvW2pvoxk6RgzbH6Q+BoNwREvUj4o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jSNmnCBHt9h2Sco6W2NYNXERQaEG+yrK11b7DoaoKxcl1Jeb/T5fyArJCuc5ddFSN jbUvVSkpM3mJoQPC5AbdToMf0FsNf1RBv9hSHDDABmBqirer3OXxNXZ66QRRrzyGpq Dpe+ccI4zzGLgGjnx/9UVO0EDfnrGb82X3mVR2DyxHf5XClCRPK87wkvSWPnUYbn/8 KegRZw2ATfAdy9pMRpmBSsxx1Poc/8+FC4GASIVd+pd3ICL+NoPlzWSZHX7Om/NYVV doHhY037H+mscNi4Nmoy+oGFettcKNQ8GxnIMfDJwUVEqHSN9wkT3hTyfyfLiG4mpu FHOoph39MVUxg== Date: Thu, 25 May 2023 18:49:19 -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 Message-ID: <168506073120.3744829.10203214850894975371.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Collapse this two-line helper into the main function since it's trivial. Signed-off-by: Darrick J. Wong --- scrub/phase8.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index c6dabbd5eed..76648b30842 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 Fri May 26 01:49:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A3C3C77B7E for ; Fri, 26 May 2023 01:49:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbjEZBti (ORCPT ); Thu, 25 May 2023 21:49:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjEZBth (ORCPT ); Thu, 25 May 2023 21:49:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC71189 for ; Thu, 25 May 2023 18:49:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7D8F261B63 for ; Fri, 26 May 2023 01:49:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE71AC433EF; Fri, 26 May 2023 01:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065775; bh=IQTQ8zuW+nfhUvw0Oz2bs/YFNjYsTmvHLlMUtT6xUhk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SSa+dEZ9wk43Cf2yPjNAqat4nr16N9hRZzFrArINlkHmnBGiJrT3mcPUgz9HW+cEv /g0cKnQOrHGBi7U2CiB3BoNwm1XW5RQWbZfU6+oBNZeKkgfdUpKeQQql/yzJqHfi7O 7fRk3cEXaZvlahec8zIn095IUkeO44XHPArq7IvA73G/zD07SH25EWx3nwHWvvxjDG pHhpRA+ixXivHdG54Qq49JRfxR/umuodwPS0T7blNIioTxoRbVfm0uDotOQBrMxVYq azEhQPrTfXJ20U1bC0yytbMpRR5/VEiVgHfq/+/6UvGWYGAyTN9P91064aEZumLFp2 K7aqUfwP5pNkA== Date: Thu, 25 May 2023 18:49:35 -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 Message-ID: <168506073133.3744829.18094717757505490219.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 --- scrub/phase8.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index 76648b30842..6ad948ff6bf 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 Fri May 26 01:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 559CBC7EE2E for ; Fri, 26 May 2023 01:50:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjEZBuA (ORCPT ); Thu, 25 May 2023 21:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242018AbjEZBtx (ORCPT ); Thu, 25 May 2023 21:49:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71001189 for ; Thu, 25 May 2023 18:49:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 06B6064868 for ; Fri, 26 May 2023 01:49:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69729C433EF; Fri, 26 May 2023 01:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065791; bh=d55PfCOLQB11NOPHYawjNN7Yx/g2pXe9NR2+2fqbQsY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WPa/s+QILo/oZl9V2auNrHnqfs/2Cu/duw8M7ogO3NdcZ1T9VCHftQcIjUgeeI0uM 8+GoyAaGAJDS7vfnDDxW795kZrrz4aACGaGfLosG/YGJc50t37pNhTUwzyZl9vJLhv s+qgqY1ZbOUHI2vtA8UMI0EORjAPjDH7BXHwqtAiZwf3g4HqX3/ziU/Cmca5Cv3skf xWE7Syv5Q0/75Vy1tINhnuet1484iClnDmgmuSECmyC9yVslDamHbUPzHW3YC5ORBT soietc54McavDCKNj/7hIpXL3Vm6jnCdYlOS47wpo85h+fL9+FXzkpSihF4A5sBCPT t+sUQZh9UZ6Ng== Date: Thu, 25 May 2023 18:49:51 -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 Message-ID: <168506073147.3744829.12988251688048250604.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 --- 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 6ad948ff6bf..3e174e400ba 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 e4d56d1d380..5366e005746 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 f79b1997a5b..e512df647b4 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 Fri May 26 01:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256156 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DB56C77B7E for ; Fri, 26 May 2023 01:50:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbjEZBuJ (ORCPT ); Thu, 25 May 2023 21:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbjEZBuI (ORCPT ); Thu, 25 May 2023 21:50:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A51199 for ; Thu, 25 May 2023 18:50:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8279364868 for ; Fri, 26 May 2023 01:50:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E86A2C433EF; Fri, 26 May 2023 01:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065807; bh=z98nm415xg1dJfZnpsM7dKoE1Vz2/v+jIbqkIHA85R0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cr3WgeEMoRHvw0vSM+8wI+SIHOaYaHcsCoaPhHLB5r3jQJLBFdk0C4Ol8w9Tj1XrG a9y5RSXH6LNn5h0dwgHg6z98CttmP3OYu1b1eQgVVh9w76N66YVhLffQRI45gQ3ExP NqSItfp/Kvl6BCsHZVcHTxxhdIrD8UpS6xhNAG+M3mgdw4NqzF78Ig42eFZxiRS5IO 734jBO6fdO/3Vigc9HU1MtFF+sHqav3ZKSQJXWuFuHyRaDDmHr3wfyK/l0sFSbf8vx SCllhFqfMyWrH8KA/dLmlqsgIx7uJFxMIWQFa6LIU5vS6r0vFlydAFMeRw14GmiL7C 3GNXaQXdvyTzg== Date: Thu, 25 May 2023 18:50:06 -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 Message-ID: <168506073160.3744829.12683524760674073752.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 --- scrub/phase8.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scrub/phase8.c b/scrub/phase8.c index 3e174e400ba..d21f62099b9 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 Fri May 26 01:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 331F6C77B7E for ; Fri, 26 May 2023 01:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbjEZBua (ORCPT ); Thu, 25 May 2023 21:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjEZBu3 (ORCPT ); Thu, 25 May 2023 21:50:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8270219D for ; Thu, 25 May 2023 18:50:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1FED560B6C for ; Fri, 26 May 2023 01:50:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F9C6C433EF; Fri, 26 May 2023 01:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065822; bh=EOoLb40hMpq/REU+q2IPQ/tfvrOlaftIoEjCIsN4JQM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=I+BZnwdR1qBqYjQNlRLdWdplAz8j4viX2RqdeDSJJgsKJf7hxY9f6CFeT26obHEPK ByYW2XV3kj5gGs5iV2KBFw/j4rspiT+zWNPsCqAQoRgqxKHGWPyrBDybBlUZdmXGCU k7Olmv7/iC0DC0/rrwCViKmMgROCZpb3tN0vlAD5V+PbcvbwV4uLQLvI1VXlOAZvXw L+fu0z37SiUZGvdjJCZOEV3Wy+76arwdVw52XeaETO7jXdYSfbDcW7/6U26l+V0cCR 14ofrrpDEYfmx5bRq/Nr7s/zs1UF9CX55SjNJTvDWyXLW4mY7aHsFXS9m7KpW+C/ZP c0APHbI0Nft0w== Date: Thu, 25 May 2023 18:50:22 -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 Message-ID: <168506073174.3744829.17181628429493007273.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong XFS issues discard IOs while holding the free space btree and the AGF buffers locked. If the discard IOs are slow or the free space is extremely fragmented, this can lead to long stalls for every other thread trying to access that AG. On a 10TB high performance flash storage device with a severely fragmented free space btree in every AG, this results in many threads tripping the hangcheck warnings while waiting for the AGF. This happens even after we've run fstrim a few times and waited for the nvme namespace utilization counters to stabilize. Strace for the entire 10TB looks like: ioctl(3, FITRIM, {start=0x0, len=10995116277760, minlen=0}) = 0 <686.209839> 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 lock hold times are still high enough to cause stall warnings: 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> The fstrim code has to synchronize discards with block allocations, so we must hold the AGF lock while issuing discard IOs. Breaking up the calls into smaller start/len segments ought to reduce the lock hold time and allow other threads a chance to make progress. Unfortunately, the current fstrim implementation handles this poorly because it walks the entire free space by length index (cntbt) and it's not clear if we can cycle the AGF periodically to reduce latency because there's no less-than btree lookup. The first solution I thought of was to limit latency by scanning parts of an AG at a time, but this doesn't solve the stalling problem when the free space is heavily fragmented because each sub-AG scan has to walk the entire cntbt to find free space that fits within the given range. In fact, this dramatically increases the runtime! Ultimately, I forked the kernel implementations -- for full AG fstrims, it still trims by length. However, for a sub-AG scan, it will walk the bnobt and perform the trims in block number order. Since the cursor has an obviously monotonically increasing value, it is easy to cycle the AGF periodically to allow other threads to do work. This implementation avoids the worst problems of the original code, though it lacks the desirable attribute of freeing the biggest chunks first. This second algorithm is what we want for xfs_scrub, which generally runs as a background service. 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 | 63 +++++++++++++++++++++++++++++++++++++++++++++++--------- scrub/vfs.c | 10 ++++++--- scrub/vfs.h | 2 +- 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index d21f62099b9..ac64c82980e 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -45,29 +45,72 @@ 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, which cycles the AGF lock + * to prevent foreground threads from stalling. + */ + fsbcount = min(geo->datablocks - fsbno + 1, geo->agblocks); + 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 5366e005746..c47db5890a5 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 e512df647b4..db222d9c7ee 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 Fri May 26 01:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13256158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71EE5C7EE29 for ; Fri, 26 May 2023 01:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbjEZBuk (ORCPT ); Thu, 25 May 2023 21:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjEZBuk (ORCPT ); Thu, 25 May 2023 21:50:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D882189 for ; Thu, 25 May 2023 18:50:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B74FD64C3E for ; Fri, 26 May 2023 01:50:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27FE6C433EF; Fri, 26 May 2023 01:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685065838; bh=CP3ZZQhRfVIVvl6orSYqsq/BrtGUdqvdULFwwwx+q8A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sEoUyBvQu9JZY5tEIfOj3T7+Kxs9YPOMYtsUBi1yTMTflOD6JjEAM5QBWw5qm+PK5 CjtjcTJYC3Rb4oInbnI3qb8NlEfueJ1VuiXmsAIrWmfdJEimWr0IE5qE2deHaybDvT FzY/5Nw4P2sp2s4VhCp7LzsQO1VreXb6lRRu4QC2XuzSkFpetlI1BCbPpInPRe4NeP T1L4DE3vg9y/0pHOD/mIPo7RUWI4Gfl4otHoUIICFyl1WugJsw6XyxkyysIe+7yvb0 XbvdkkYLGRlUyU7qWVghrc4z7A5s8qciy74uzVmQlkUJ1/DqgsupcoDNuZx5ryMmHf aa8dkf3gC4xBA== Date: Thu, 25 May 2023 18:50:37 -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 Message-ID: <168506073187.3744829.17413889298796078259.stgit@frogsfrogsfrogs> In-Reply-To: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> References: <168506073077.3744829.468307851541842353.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 ac64c82980e..5d2a57c83f9 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; @@ -90,13 +110,13 @@ fstrim_datadev( * partial-AG discard implementation, which cycles the AGF lock * to prevent foreground threads from stalling. */ + progress_add(geo->blocksize); fsbcount = min(geo->datablocks - fsbno + 1, geo->agblocks); error = fstrim_fsblocks(ctx, fsbno + 1, fsbcount); if (error) return error; } - progress_add(1); return 0; } @@ -119,12 +139,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; }