public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Qu Wenruo <wqu@suse.com>,
	Michel Palleau <michel.palleau@gmail.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	David Sterba <dsterba@suse.com>, Sasha Levin <sashal@kernel.org>,
	clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.10 06/13] btrfs: scrub: update last_physical after scrubbing one stripe
Date: Tue, 13 Aug 2024 22:14:37 -0400	[thread overview]
Message-ID: <20240814021451.4129952-6-sashal@kernel.org> (raw)
In-Reply-To: <20240814021451.4129952-1-sashal@kernel.org>

From: Qu Wenruo <wqu@suse.com>

[ Upstream commit 63447b7dd40c6a9ae8d3bb70c11f4c46731823e3 ]

Currently sctx->stat.last_physical only got updated in the following
cases:

- When the last stripe of a non-RAID56 chunk is scrubbed
  This implies a pitfall, if the last stripe is at the chunk boundary,
  and we finished the scrub of the whole chunk, we won't update
  last_physical at all until the next chunk.

- When a P/Q stripe of a RAID56 chunk is scrubbed

This leads the following two problems:

- sctx->stat.last_physical is not updated for a almost full chunk
  This is especially bad, affecting scrub resume, as the resume would
  start from last_physical, causing unnecessary re-scrub.

- "btrfs scrub status" will not report any progress for a long time

Fix the problem by properly updating @last_physical after each stripe is
scrubbed.

And since we're here, for the sake of consistency, use spin lock to
protect the update of @last_physical, just like all the remaining
call sites touching sctx->stat.

Reported-by: Michel Palleau <michel.palleau@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CAMFk-+igFTv2E8svg=cQ6o3e6CrR5QwgQ3Ok9EyRaEvvthpqCQ@mail.gmail.com/
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/btrfs/scrub.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 9712169593980..731d7d562db1a 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1875,6 +1875,9 @@ static int flush_scrub_stripes(struct scrub_ctx *sctx)
 		stripe = &sctx->stripes[i];
 
 		wait_scrub_stripe_io(stripe);
+		spin_lock(&sctx->stat_lock);
+		sctx->stat.last_physical = stripe->physical + stripe_length(stripe);
+		spin_unlock(&sctx->stat_lock);
 		scrub_reset_stripe(stripe);
 	}
 out:
@@ -2143,7 +2146,9 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
 					 cur_physical, &found_logical);
 		if (ret > 0) {
 			/* No more extent, just update the accounting */
+			spin_lock(&sctx->stat_lock);
 			sctx->stat.last_physical = physical + logical_length;
+			spin_unlock(&sctx->stat_lock);
 			ret = 0;
 			break;
 		}
@@ -2340,6 +2345,10 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
 			stripe_logical += chunk_logical;
 			ret = scrub_raid56_parity_stripe(sctx, scrub_dev, bg,
 							 map, stripe_logical);
+			spin_lock(&sctx->stat_lock);
+			sctx->stat.last_physical = min(physical + BTRFS_STRIPE_LEN,
+						       physical_end);
+			spin_unlock(&sctx->stat_lock);
 			if (ret)
 				goto out;
 			goto next;
-- 
2.43.0


  parent reply	other threads:[~2024-08-14  2:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14  2:14 [PATCH AUTOSEL 6.10 01/13] ASoC: amd: yc: Support mic on HP 14-em0002la Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 02/13] spi: hisi-kunpeng: Add validation for the minimum value of speed_hz Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 03/13] platform/x86/amd: pmf: Add quirk for ROG Ally X Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 04/13] platform/x86/amd/pmf: Add new ACPI ID AMDI0107 Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 05/13] btrfs: factor out stripe length calculation into a helper Sasha Levin
2024-08-14  2:14 ` Sasha Levin [this message]
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 07/13] btrfs: fix qgroup reserve leaks in cow_file_range Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 08/13] i2c: Fix conditional for substituting empty ACPI functions Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 09/13] virtio-net: check feature before configuring the vq coalescing command Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 10/13] dma-debug: avoid deadlock between dma debug vs printk and netconsole Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 11/13] net: usb: qmi_wwan: add MeiG Smart SRM825L Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 12/13] ASoC: amd: yc: Support mic on Lenovo Thinkpad E14 Gen 6 Sasha Levin
2024-08-14  2:14 ` [PATCH AUTOSEL 6.10 13/13] ASoC: codecs: ES8326: button detect issue Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240814021451.4129952-6-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michel.palleau@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox