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 14/16] btrfs: don't redirty the locked page for extent_write_locked_range
Date: Wed, 31 May 2023 08:05:03 +0200	[thread overview]
Message-ID: <20230531060505.468704-15-hch@lst.de> (raw)
In-Reply-To: <20230531060505.468704-1-hch@lst.de>

Instead of redirtying the locked page before calling
extent_write_locked_range, just pass a locked_page argument similar to
many other functions in the btrfs writeback code, and then exclude the
locked page from clearing the dirty bit in extent_write_locked_range.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/extent_io.c | 17 ++++++++++-------
 fs/btrfs/extent_io.h |  3 ++-
 fs/btrfs/inode.c     | 25 ++++++-------------------
 3 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index f4d3c56b29009b..bc061b2ac55a12 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2210,8 +2210,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,
-			      struct writeback_control *wbc)
+int extent_write_locked_range(struct inode *inode, struct page *locked_page,
+			      u64 start, u64 end, struct writeback_control *wbc)
 {
 	bool found_error = false;
 	int first_error = 0;
@@ -2237,14 +2237,17 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
 		int nr = 0;
 
 		page = find_get_page(mapping, cur >> PAGE_SHIFT);
+
 		/*
-		 * All pages in the range are locked since
-		 * btrfs_run_delalloc_range(), thus there is no way to clear
-		 * the page dirty flag.
+		 * All pages have been locked by btrfs_run_delalloc_range(),
+		 * thus the dirty bit can't have been cleared.
 		 */
 		ASSERT(PageLocked(page));
-		ASSERT(PageDirty(page));
-		clear_page_dirty_for_io(page);
+		if (page != locked_page) {
+			/* already cleared by extent_write_cache_pages */
+			ASSERT(PageDirty(page));
+			clear_page_dirty_for_io(page);
+		}
 
 		ret = __extent_writepage_io(BTRFS_I(inode), page, &bio_ctrl,
 					    i_size, &nr);
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index c5fae3a7d911bf..00c468aea010a1 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -178,7 +178,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, struct page *locked_page,
+			      u64 start, u64 end,
 			      struct writeback_control *wbc);
 int extent_writepages(struct address_space *mapping,
 		      struct writeback_control *wbc);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 54b4b241b354fc..68ae20a3f785e3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1088,17 +1088,9 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 cleanup_and_bail_uncompressed:
 	/*
 	 * No compression, but we still need to write the pages in the file
-	 * we've been given so far.  redirty the locked page if it corresponds
-	 * to our extent and set things up for the async work queue to run
-	 * cow_file_range to do the normal delalloc dance.
+	 * we've been given so far.  Set things up for the async work queue to
+	 * run cow_file_range to do the normal delalloc dance.
 	 */
-	if (async_chunk->locked_page &&
-	    (page_offset(async_chunk->locked_page) >= start &&
-	     page_offset(async_chunk->locked_page)) <= end) {
-		__set_page_dirty_nobuffers(async_chunk->locked_page);
-		/* unlocked later on in the async handlers */
-	}
-
 	if (redirty)
 		extent_range_redirty_for_io(&inode->vfs_inode, start, end);
 	add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
@@ -1169,7 +1161,8 @@ static int submit_uncompressed_range(struct btrfs_inode *inode,
 
 	/* All pages will be unlocked, including @locked_page */
 	wbc_attach_fdatawrite_inode(&wbc, &inode->vfs_inode);
-	ret = extent_write_locked_range(&inode->vfs_inode, start, end, &wbc);
+	ret = extent_write_locked_range(&inode->vfs_inode, locked_page, start,
+					end, &wbc);
 	wbc_detach_inode(&wbc);
 	return ret;
 }
@@ -1829,7 +1822,6 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
 {
 	u64 done_offset = end;
 	int ret;
-	bool locked_page_done = false;
 
 	while (start <= end) {
 		ret = cow_file_range(inode, locked_page, start, end, page_started,
@@ -1852,13 +1844,8 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
 			continue;
 		}
 
-		if (!locked_page_done) {
-			__set_page_dirty_nobuffers(locked_page);
-			account_page_redirty(locked_page);
-		}
-		locked_page_done = true;
-		extent_write_locked_range(&inode->vfs_inode, start, done_offset,
-					  wbc);
+		extent_write_locked_range(&inode->vfs_inode, locked_page, start,
+					  done_offset, wbc);
 		start = done_offset + 1;
 	}
 
-- 
2.39.2


  parent reply	other threads:[~2023-05-31  6:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  6:04 writeback fixlets and tidyups v2 Christoph Hellwig
2023-05-31  6:04 ` [PATCH 01/16] btrfs: fix range_end calculation in extent_write_locked_range Christoph Hellwig
2023-05-31  6:04 ` [PATCH 02/16] btrfs: factor out a btrfs_verify_page helper Christoph Hellwig
2023-05-31  6:04 ` [PATCH 03/16] btrfs: fix fsverify read error handling in end_page_read Christoph Hellwig
2023-05-31  6:04 ` [PATCH 04/16] btrfs: don't check PageError in btrfs_verify_page Christoph Hellwig
2023-05-31  6:04 ` [PATCH 05/16] btrfs: don't fail writeback when allocating the compression context fails Christoph Hellwig
2023-05-31  6:04 ` [PATCH 06/16] btrfs: rename cow_file_range_async to run_delalloc_compressed Christoph Hellwig
2023-05-31  6:04 ` [PATCH 07/16] btrfs: don't check PageError in __extent_writepage Christoph Hellwig
2023-05-31  6:04 ` [PATCH 08/16] btrfs: stop setting PageError in the data I/O path Christoph Hellwig
2023-05-31  6:04 ` [PATCH 09/16] btrfs: remove PAGE_SET_ERROR Christoph Hellwig
2023-05-31  6:04 ` [PATCH 10/16] btrfs: remove non-standard extent handling in __extent_writepage_io Christoph Hellwig
2024-02-10  9:39   ` Qu Wenruo
2024-02-12 15:52     ` Christoph Hellwig
2024-02-12 23:06       ` Qu Wenruo
2023-05-31  6:05 ` [PATCH 11/16] btrfs: move nr_to_write to __extent_writepage Christoph Hellwig
2023-05-31  6:05 ` [PATCH 12/16] btrfs: only call __extent_writepage_io from extent_write_locked_range 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
2023-05-31  6:05 ` Christoph Hellwig [this message]
2023-06-05 21:00   ` [PATCH 14/16] btrfs: don't redirty the locked page for extent_write_locked_range David Sterba
2023-05-31  6:05 ` [PATCH 15/16] btrfs: refactor the zoned device handling in cow_file_range Christoph Hellwig
2023-06-06 14:20   ` Naohiro Aota
2023-06-07  7:27     ` Christoph Hellwig
2023-05-31  6:05 ` [PATCH 16/16] btrfs: split page locking out of __process_pages_contig Christoph Hellwig
2023-05-31 16:39 ` writeback fixlets and tidyups v2 Josef Bacik
2023-06-05 21:01 ` David Sterba
2023-06-06  6:24   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2023-05-23  8:13 writeback fixlets and tidyups Christoph Hellwig
2023-05-23  8:13 ` [PATCH 14/16] btrfs: don't redirty the locked page for extent_write_locked_range 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=20230531060505.468704-15-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.