All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: [PATCH 03/21] btrfs: limit write bios to a single ordered extent
Date: Mon,  8 May 2023 09:08:25 -0700	[thread overview]
Message-ID: <20230508160843.133013-4-hch@lst.de> (raw)
In-Reply-To: <20230508160843.133013-1-hch@lst.de>

Currently buffered writeback bios are allowed to span multiple
ordered_extents, although that basically never actually happens since
commit 4a445b7b6178 ("btrfs: don't merge pages into bio if their page
offset is not contiguous").

Supporting bios than span ordered_extents complicates the file
checksumming code, and prevents us from adding an ordered_extent pointer
to the btrfs_bio structure.  Use the existing code to limit a bio to
single ordered_extent for zoned device writes for all writes.

This allows to remove the REQ_BTRFS_ONE_ORDERED flags, and the
handling of multiple ordered_extents in btrfs_csum_one_bio.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/bio.c         |  3 ---
 fs/btrfs/bio.h         |  3 ---
 fs/btrfs/compression.c |  2 --
 fs/btrfs/extent_io.c   |  9 ++-------
 fs/btrfs/file-item.c   | 33 ---------------------------------
 5 files changed, 2 insertions(+), 48 deletions(-)

diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c
index ae30ef638716b0..5f418eeaac070b 100644
--- a/fs/btrfs/bio.c
+++ b/fs/btrfs/bio.c
@@ -471,9 +471,6 @@ static void btrfs_submit_mirrored_bio(struct btrfs_io_context *bioc, int dev_nr)
 static void __btrfs_submit_bio(struct bio *bio, struct btrfs_io_context *bioc,
 			       struct btrfs_io_stripe *smap, int mirror_num)
 {
-	/* Do not leak our private flag into the block layer. */
-	bio->bi_opf &= ~REQ_BTRFS_ONE_ORDERED;
-
 	if (!bioc) {
 		/* Single mirror read/write fast path. */
 		btrfs_bio(bio)->mirror_num = mirror_num;
diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h
index a8eca3a6567320..000e807f785395 100644
--- a/fs/btrfs/bio.h
+++ b/fs/btrfs/bio.h
@@ -91,9 +91,6 @@ static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
 	bbio->end_io(bbio);
 }
 
-/* Bio only refers to one ordered extent. */
-#define REQ_BTRFS_ONE_ORDERED			REQ_DRV
-
 /* Submit using blkcg_punt_bio_submit. */
 #define REQ_BTRFS_CGROUP_PUNT			REQ_FS_PRIVATE
 
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 14f5f25049a0d7..4f85113cbf9f0c 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -295,8 +295,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
 	ASSERT(IS_ALIGNED(start, fs_info->sectorsize) &&
 	       IS_ALIGNED(len, fs_info->sectorsize));
 
-	write_flags |= REQ_BTRFS_ONE_ORDERED;
-
 	cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags,
 				  end_compressed_bio_write);
 	cb->start = start;
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index a1adadd5d25ddb..92e1edfcfb9cb4 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -907,12 +907,9 @@ static void alloc_new_bio(struct btrfs_inode *inode,
 	bio_ctrl->len_to_oe_boundary = U32_MAX;
 
 	/*
-	 * Limit the extent to the ordered boundary for Zone Append.
-	 * Compressed bios aren't submitted directly, so it doesn't apply to
-	 * them.
+	 * Limit data write bios to the ordered boundary.
 	 */
-	if (bio_ctrl->compress_type == BTRFS_COMPRESS_NONE &&
-	    btrfs_use_zone_append(bbio)) {
+	if (bio_ctrl->wbc) {
 		struct btrfs_ordered_extent *ordered;
 
 		ordered = btrfs_lookup_ordered_extent(inode, file_offset);
@@ -922,9 +919,7 @@ static void alloc_new_bio(struct btrfs_inode *inode,
 					ordered->disk_num_bytes - file_offset);
 			btrfs_put_ordered_extent(ordered);
 		}
-	}
 
-	if (bio_ctrl->wbc) {
 		/*
 		 * Pick the last added device to support cgroup writeback.  For
 		 * multi-device file systems this means blk-cgroup policies have
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index e74b9804bcdec8..1c1cb6373f2c30 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -733,8 +733,6 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio)
 	struct bio_vec bvec;
 	int index;
 	unsigned int blockcount;
-	unsigned long total_bytes = 0;
-	unsigned long this_sum_bytes = 0;
 	int i;
 	unsigned nofs_flag;
 
@@ -776,34 +774,6 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio)
 						 - 1);
 
 		for (i = 0; i < blockcount; i++) {
-			if (!(bio->bi_opf & REQ_BTRFS_ONE_ORDERED) &&
-			    !in_range(offset, ordered->file_offset,
-				      ordered->num_bytes)) {
-				unsigned long bytes_left;
-
-				sums->len = this_sum_bytes;
-				this_sum_bytes = 0;
-				btrfs_add_ordered_sum(ordered, sums);
-				btrfs_put_ordered_extent(ordered);
-
-				bytes_left = bio->bi_iter.bi_size - total_bytes;
-
-				nofs_flag = memalloc_nofs_save();
-				sums = kvzalloc(btrfs_ordered_sum_size(fs_info,
-						      bytes_left), GFP_KERNEL);
-				memalloc_nofs_restore(nofs_flag);
-				if (!sums)
-					return BLK_STS_RESOURCE;
-
-				sums->len = bytes_left;
-				ordered = btrfs_lookup_ordered_extent(inode,
-								offset);
-				ASSERT(ordered); /* Logic error */
-				sums->bytenr = (bio->bi_iter.bi_sector << SECTOR_SHIFT)
-					+ total_bytes;
-				index = 0;
-			}
-
 			data = bvec_kmap_local(&bvec);
 			crypto_shash_digest(shash,
 					    data + (i * fs_info->sectorsize),
@@ -812,12 +782,9 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio)
 			kunmap_local(data);
 			index += fs_info->csum_size;
 			offset += fs_info->sectorsize;
-			this_sum_bytes += fs_info->sectorsize;
-			total_bytes += fs_info->sectorsize;
 		}
 
 	}
-	this_sum_bytes = 0;
 	btrfs_add_ordered_sum(ordered, sums);
 	btrfs_put_ordered_extent(ordered);
 	return 0;
-- 
2.39.2


  parent reply	other threads:[~2023-05-08 16:08 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 16:08 add an ordered_extent pointer to struct btrfs_bio Christoph Hellwig
2023-05-08 16:08 ` [PATCH 01/21] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Christoph Hellwig
2023-05-08 16:08 ` [PATCH 02/21] btrfs: fix file_offset for REQ_BTRFS_ONE_ORDERED bios that get split Christoph Hellwig
2023-05-08 22:17   ` Johannes Thumshirn
2023-05-08 16:08 ` Christoph Hellwig [this message]
2023-05-08 22:40   ` [PATCH 03/21] btrfs: limit write bios to a single ordered extent Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 04/21] btrfs: merge the two calls to btrfs_add_ordered_extent in run_delalloc_nocow Christoph Hellwig
2023-05-08 16:08 ` [PATCH 05/21] btrfs: pass an ordered_extent to btrfs_reloc_clone_csums Christoph Hellwig
2023-05-08 23:30   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 06/21] btrfs: pass an ordered_extent to btrfs_submit_compressed_write Christoph Hellwig
2023-05-08 23:39   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 07/21] btrfs: reorder btrfs_extract_ordered_extent Christoph Hellwig
2023-05-08 23:45   ` Johannes Thumshirn
2023-05-09  0:04   ` Naohiro Aota
2023-05-08 16:08 ` [PATCH 08/21] btrfs: return the new ordered_extent from btrfs_split_ordered_extent Christoph Hellwig
2023-05-08 23:51   ` Johannes Thumshirn
2023-05-09  0:11   ` Naohiro Aota
2023-05-08 16:08 ` [PATCH 09/21] btrfs: remove btrfs_add_ordered_extent Christoph Hellwig
2023-05-08 23:55   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 10/21] btrfs: add a is_data_bio helper Christoph Hellwig
2023-05-09  0:00   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 11/21] btrfs: open code btrfs_bio_end_io in btrfs_dio_submit_io Christoph Hellwig
2023-05-09  0:03   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 12/21] btrfs: add an ordered_extent pointer to struct btrfs_bio Christoph Hellwig
2023-05-09  0:12   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 13/21] btrfs: use bbio->ordered in btrfs_csum_one_bio Christoph Hellwig
2023-05-09  0:14   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 14/21] btrfs: use bbio->ordered for zone append completions Christoph Hellwig
2023-05-09  0:16   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 15/21] btrfs: factor out a can_finish_ordered_extent helper Christoph Hellwig
2023-05-09  0:17   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 16/21] btrfs: factor out a btrfs_queue_ordered_fn helper Christoph Hellwig
2023-05-09  0:19   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 17/21] btrfs: add a btrfs_finish_ordered_extent helper Christoph Hellwig
2023-05-09  0:22   ` Johannes Thumshirn
2023-05-09 13:12     ` Christoph Hellwig
2023-05-10 13:16       ` David Sterba
2023-05-08 16:08 ` [PATCH 18/21] btrfs: use btrfs_finish_ordered_extent to complete compressed writes Christoph Hellwig
2023-05-09 15:48   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 19/21] btrfs: use btrfs_finish_ordered_extent to complete direct writes Christoph Hellwig
2023-05-09 15:50   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 20/21] btrfs: open code end_extent_writepage in end_bio_extent_writepage Christoph Hellwig
2023-05-09 15:55   ` Johannes Thumshirn
2023-05-08 16:08 ` [PATCH 21/21] btrfs: use btrfs_finish_ordered_extent to complete buffered writes Christoph Hellwig
2023-05-09 15:56   ` Johannes Thumshirn
2023-05-10 16:32 ` add an ordered_extent pointer to struct btrfs_bio David Sterba
2023-05-11 17:56   ` David Sterba
2023-05-12 13:32     ` Christoph Hellwig
2023-05-15  6:40 ` Christoph Hellwig
2023-05-15 11:12   ` David Sterba

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=20230508160843.133013-4-hch@lst.de \
    --to=hch@lst.de \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.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.