All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 13/14] btrfs: avoid recording full stripe write into write-intent bitmaps
Date: Mon, 25 Jul 2022 13:38:01 +0800	[thread overview]
Message-ID: <441b7bd4a0966c9f1d7ef17dea7a2e875440a728.1658726692.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1658726692.git.wqu@suse.com>

Full stripe write can happen in the following cases:

- Writing into a completely new stripe
  In this case, even if powerloss happened, we won't have any committed
  metadata referring the new full stripe.

  Thus we don't need to recover.

- Writing into a NODATACOW range
  In this case, although in theory we should recovery after power loss,
  but NODATACOW implies NODATASUM, thus we have no way to determine
  which data is correct.

  Thus we don't need to and can't recover either.

So just avoid recording full stripe write into write-intent bitmaps.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/raid56.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 0a0a2a1e96c3..37e5fd5df1f9 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -818,8 +818,13 @@ static void rbio_orig_end_io(struct btrfs_raid_bio *rbio, blk_status_t err)
 	if (rbio->generic_bio_cnt)
 		btrfs_bio_counter_sub(rbio->bioc->fs_info, rbio->generic_bio_cnt);
 
-	/* Clear the write-intent bitmap range for write operation. */
-	if (rbio->operation == BTRFS_RBIO_WRITE)
+	/*
+	 * Clear the write-intent bitmap range for write operation.
+	 * For full stripe write we didn't record it into write-intent thus no
+	 * need to clear the bits for full stripe write.
+	 */
+	if (rbio->operation == BTRFS_RBIO_WRITE &&
+	    rbio->bio_list_bytes < rbio->nr_data * BTRFS_STRIPE_LEN)
 		btrfs_write_intent_clear_dirty(rbio->bioc->fs_info,
 				       rbio->bioc->raid_map[0],
 				       rbio->nr_data * BTRFS_STRIPE_LEN);
@@ -1342,13 +1347,19 @@ static noinline void finish_rmw(struct btrfs_raid_bio *rbio)
 	atomic_set(&rbio->stripes_pending, bio_list_size(&bio_list));
 	BUG_ON(atomic_read(&rbio->stripes_pending) == 0);
 
-	/* Update the write intent bitmap before we start submitting bios. */
-	btrfs_write_intent_mark_dirty(bioc->fs_info, rbio->bioc->raid_map[0],
-				     rbio->nr_data * BTRFS_STRIPE_LEN, &event);
-	ret = btrfs_write_intent_writeback(bioc->fs_info, event);
+	/*
+	 * Update the write intent bitmap if it's a sub-stripe write,
+	 * before we start submitting bios.
+	 */
+	if (rbio->bio_list_bytes < rbio->nr_data * BTRFS_STRIPE_LEN) {
+		btrfs_write_intent_mark_dirty(bioc->fs_info,
+				rbio->bioc->raid_map[0],
+				rbio->nr_data * BTRFS_STRIPE_LEN, &event);
+		ret = btrfs_write_intent_writeback(bioc->fs_info, event);
+		if (ret < 0)
+			goto cleanup;
+	}
 
-	if (ret < 0)
-		goto cleanup;
 	while ((bio = bio_list_pop(&bio_list))) {
 		bio->bi_end_io = raid_write_end_io;
 
-- 
2.37.0


  parent reply	other threads:[~2022-07-25  5:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-25  5:37 [PATCH 00/14] btrfs: introduce write-intent bitmaps for RAID56 Qu Wenruo
2022-07-25  5:37 ` [PATCH 01/14] btrfs: introduce new compat RO flag, EXTRA_SUPER_RESERVED Qu Wenruo
2022-07-25  5:37 ` [PATCH 02/14] btrfs: introduce a new experimental compat RO flag, WRITE_INTENT_BITMAP Qu Wenruo
2022-07-25  5:37 ` [PATCH 03/14] btrfs: introduce the on-disk format of btrfs write intent bitmaps Qu Wenruo
2022-07-25  5:37 ` [PATCH 04/14] btrfs: load/create write-intent bitmaps at mount time Qu Wenruo
2022-07-25  5:37 ` [PATCH 05/14] btrfs: write-intent: write the newly created bitmaps to all disks Qu Wenruo
2022-07-25  5:37 ` [PATCH 06/14] btrfs: write-intent: introduce an internal helper to set bits for a range Qu Wenruo
2022-07-25  5:37 ` [PATCH 07/14] btrfs: write-intent: introduce an internal helper to clear " Qu Wenruo
2022-07-25  5:37 ` [PATCH 08/14] btrfs: selftests: add selftests for write-intent bitmaps Qu Wenruo
2022-07-25  5:37 ` [PATCH 09/14] btrfs: write back write intent bitmap after barrier_all_devices() Qu Wenruo
2022-07-25  5:37 ` [PATCH 10/14] btrfs: update and writeback the write-intent bitmap for RAID56 write Qu Wenruo
2022-07-25  5:37 ` [PATCH 11/14] btrfs: raid56: clear write-intent bimaps when a full stripe finishes Qu Wenruo
2022-07-25  5:38 ` [PATCH 12/14] btrfs: warn and clear bitmaps if there is dirty bitmap at mount time Qu Wenruo
2022-07-25  5:38 ` Qu Wenruo [this message]
2022-07-25  5:38 ` [PATCH 14/14] btrfs: scrub the full stripe which had sub-stripe write " Qu Wenruo
2022-08-03  0:29 ` [PATCH 00/14] btrfs: introduce write-intent bitmaps for RAID56 me
2022-08-03  0:58   ` Qu Wenruo
2022-08-03  9:11     ` Goffredo Baroncelli
2022-08-03  9:39       ` Qu Wenruo
2022-08-03 21:00       ` me
2022-08-03  8:48 ` Goffredo Baroncelli
2022-08-03  9:52   ` Qu Wenruo

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=441b7bd4a0966c9f1d7ef17dea7a2e875440a728.1658726692.git.wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.