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 13/16] btrfs: don't treat zoned writeback as being from an async helper thread
Date: Tue, 23 May 2023 10:13:19 +0200	[thread overview]
Message-ID: <20230523081322.331337-14-hch@lst.de> (raw)
In-Reply-To: <20230523081322.331337-1-hch@lst.de>

When extent_write_locked_range was originally added, it was only used
writing back compressed pages from an async helper thread.  But it is
now also used for writing back pages on zoned devices, where it is
called directly from the ->writepage context.  In this case we want to
to be able to pass on the writeback_control instead of creating a new
one, and more importantly want to use all the normal cgroup interaction
instead of potentially deferring writeback to another helper.

Fixes: 898793d992c2 ("btrfs: zoned: write out partially allocated region")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/extent_io.c | 20 +++++++-------------
 fs/btrfs/extent_io.h |  3 ++-
 fs/btrfs/inode.c     | 20 +++++++++++++++-----
 3 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index cca47909953d6a..885089afb43ecf 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2209,7 +2209,8 @@ static int extent_write_cache_pages(struct address_space *mapping,
  * already been ran (aka, ordered extent inserted) and all pages are still
  * locked.
  */
-int extent_write_locked_range(struct inode *inode, u64 start, u64 end)
+int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
+			      struct writeback_control *wbc)
 {
 	bool found_error = false;
 	int first_error = 0;
@@ -2219,22 +2220,16 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end)
 	const u32 sectorsize = fs_info->sectorsize;
 	loff_t i_size = i_size_read(inode);
 	u64 cur = start;
-	struct writeback_control wbc_writepages = {
-		.sync_mode	= WB_SYNC_ALL,
-		.range_start	= start,
-		.range_end	= end,
-		.no_cgroup_owner = 1,
-	};
 	struct btrfs_bio_ctrl bio_ctrl = {
-		.wbc = &wbc_writepages,
-		/* We're called from an async helper function */
-		.opf = REQ_OP_WRITE | REQ_BTRFS_CGROUP_PUNT |
-			wbc_to_write_flags(&wbc_writepages),
+		.wbc = wbc,
+		.opf = REQ_OP_WRITE | wbc_to_write_flags(wbc),
 	};
 
+	if (wbc->no_cgroup_owner)
+		bio_ctrl.opf |= REQ_BTRFS_CGROUP_PUNT;
+
 	ASSERT(IS_ALIGNED(start, sectorsize) && IS_ALIGNED(end + 1, sectorsize));
 
-	wbc_attach_fdatawrite_inode(&wbc_writepages, inode);
 	while (cur <= end) {
 		u64 cur_end = min(round_down(cur, PAGE_SIZE) + PAGE_SIZE - 1, end);
 		struct page *page;
@@ -2274,7 +2269,6 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end)
 
 	submit_write_bio(&bio_ctrl, found_error ? ret : 0);
 
-	wbc_detach_inode(&wbc_writepages);
 	if (found_error)
 		return first_error;
 	return ret;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 4317fceeffaddb..eb97043672ebec 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -177,7 +177,8 @@ int try_release_extent_mapping(struct page *page, gfp_t mask);
 int try_release_extent_buffer(struct page *page);
 
 int btrfs_read_folio(struct file *file, struct folio *folio);
-int extent_write_locked_range(struct inode *inode, u64 start, u64 end);
+int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
+			      struct writeback_control *wbc);
 int extent_writepages(struct address_space *mapping,
 		      struct writeback_control *wbc);
 int btree_write_cache_pages(struct address_space *mapping,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2e6673cdb47bd3..ed137746af82ee 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1133,6 +1133,12 @@ static int submit_uncompressed_range(struct btrfs_inode *inode,
 	unsigned long nr_written = 0;
 	int page_started = 0;
 	int ret;
+	struct writeback_control wbc = {
+		.sync_mode		= WB_SYNC_ALL,
+		.range_start		= start,
+		.range_end		= end,
+		.no_cgroup_owner	= 1,
+	};
 
 	/*
 	 * Call cow_file_range() to run the delalloc range directly, since we
@@ -1162,7 +1168,10 @@ static int submit_uncompressed_range(struct btrfs_inode *inode,
 	}
 
 	/* All pages will be unlocked, including @locked_page */
-	return extent_write_locked_range(&inode->vfs_inode, start, end);
+	wbc_attach_fdatawrite_inode(&wbc, &inode->vfs_inode);
+	ret = extent_write_locked_range(&inode->vfs_inode, start, end, &wbc);
+	wbc_detach_inode(&wbc);
+	return ret;
 }
 
 static int submit_one_async_extent(struct btrfs_inode *inode,
@@ -1815,7 +1824,8 @@ static bool run_delalloc_compressed(struct btrfs_inode *inode,
 static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
 				       struct page *locked_page, u64 start,
 				       u64 end, int *page_started,
-				       unsigned long *nr_written)
+				       unsigned long *nr_written,
+				       struct writeback_control *wbc)
 {
 	u64 done_offset = end;
 	int ret;
@@ -1847,8 +1857,8 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
 			account_page_redirty(locked_page);
 		}
 		locked_page_done = true;
-		extent_write_locked_range(&inode->vfs_inode, start, done_offset);
-
+		extent_write_locked_range(&inode->vfs_inode, start, done_offset,
+					  wbc);
 		start = done_offset + 1;
 	}
 
@@ -2422,7 +2432,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
 
 	if (zoned)
 		ret = run_delalloc_zoned(inode, locked_page, start, end,
-					 page_started, nr_written);
+					 page_started, nr_written, wbc);
 	else
 		ret = cow_file_range(inode, locked_page, start, end,
 				     page_started, nr_written, 1, NULL);
-- 
2.39.2


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

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-23  8:13 writeback fixlets and tidyups Christoph Hellwig
2023-05-23  8:13 ` [PATCH 01/16] btrfs: fix range_end calculation in extent_write_locked_range Christoph Hellwig
2023-05-29 17:13   ` David Sterba
2023-05-30 13:13     ` David Sterba
2023-05-30 14:23       ` Christoph Hellwig
2023-05-23  8:13 ` [PATCH 02/16] btrfs: factor out a btrfs_verify_page helper Christoph Hellwig
2023-05-23  9:23   ` Qu Wenruo
2023-05-23 11:38     ` Christoph Hellwig
2023-05-23 10:16   ` Anand Jain
2023-05-23 11:39     ` Christoph Hellwig
2023-05-23 11:47       ` Anand Jain
2023-05-23 11:54         ` Christoph Hellwig
2023-05-29 17:34   ` David Sterba
2023-05-23  8:13 ` [PATCH 03/16] btrfs: unify fsverify vs other read error handling in end_page_read Christoph Hellwig
2023-05-29 17:39   ` David Sterba
2023-05-23  8:13 ` [PATCH 04/16] btrfs: don't check PageError in btrfs_verify_page Christoph Hellwig
2023-05-23  8:13 ` [PATCH 05/16] btrfs: don't fail writeback when allocating the compression context fails Christoph Hellwig
2023-05-23  8:13 ` [PATCH 06/16] btrfs: rename cow_file_range_async to run_delalloc_compressed Christoph Hellwig
2023-05-23 10:23   ` Anand Jain
2023-05-23  8:13 ` [PATCH 07/16] btrfs: don't check PageError in __extent_writepage Christoph Hellwig
2023-05-23  8:13 ` [PATCH 08/16] btrfs: stop setting PageError in the data I/O path Christoph Hellwig
2023-05-29 17:52   ` David Sterba
2023-05-30  5:45     ` Christoph Hellwig
2023-05-30  6:08       ` Matthew Wilcox
2023-05-30 13:34         ` David Sterba
2023-05-30 14:26           ` Christoph Hellwig
2023-05-30 13:23   ` David Sterba
2023-05-30 14:24     ` Christoph Hellwig
2023-05-23  8:13 ` [PATCH 09/16] btrfs: remove PAGE_SET_ERROR Christoph Hellwig
2023-05-23  8:13 ` [PATCH 10/16] btrfs: remove non-standard extent handling in __extent_writepage_io Christoph Hellwig
2023-05-23  8:13 ` [PATCH 11/16] btrfs: move nr_to_write to __extent_writepage Christoph Hellwig
2023-05-23 10:30   ` Anand Jain
2023-05-23  8:13 ` [PATCH 12/16] btrfs: only call __extent_writepage_io from extent_write_locked_range Christoph Hellwig
2023-05-23  8:13 ` Christoph Hellwig [this message]
2023-05-23  8:13 ` [PATCH 14/16] btrfs: don't redirty the locked page for extent_write_locked_range Christoph Hellwig
2023-05-23  8:13 ` [PATCH 15/16] btrfs: refactor the zoned device handling in cow_file_range Christoph Hellwig
2023-05-23  8:13 ` [PATCH 16/16] btrfs: split page locking out of __process_pages_contig Christoph Hellwig
2023-05-23 23:27   ` kernel test robot
2023-05-31  6:04 writeback fixlets and tidyups v2 Christoph Hellwig
2023-05-31  6:05 ` [PATCH 13/16] btrfs: don't treat zoned writeback as being from an async helper thread Christoph Hellwig

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=20230523081322.331337-14-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.