Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs: utilize cached extent map for data writeback
Date: Thu,  8 Aug 2024 15:36:00 +0930	[thread overview]
Message-ID: <f1232d0ffc8ae7389206d4cc9210afc77cfcacac.1723096922.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1723096922.git.wqu@suse.com>

Unlike data read, we never really utilize the cached extent_map for data
write.

This means we will do the costly extent map lookup for each sector we
need to write back.

Change it to utilize the same function, __get_extent_map(), just like
the data read path, to reduce the overhead of extent map lookup.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/extent_io.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index d4ad98488c03..9492cd9d4f04 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1357,7 +1357,8 @@ static int submit_one_sector(struct btrfs_inode *inode,
 	/* @filepos >= i_size case should be handled by the caller. */
 	ASSERT(filepos < i_size);
 
-	em = btrfs_get_extent(inode, NULL, filepos, sectorsize);
+	em = __get_extent_map(&inode->vfs_inode, NULL, filepos, sectorsize,
+			      &bio_ctrl->em_cached);
 	if (IS_ERR(em))
 		return PTR_ERR_OR_ZERO(em);
 
@@ -2320,6 +2321,7 @@ void extent_write_locked_range(struct inode *inode, const struct folio *locked_f
 		cur = cur_end + 1;
 	}
 
+	free_extent_map(bio_ctrl.em_cached);
 	submit_write_bio(&bio_ctrl, found_error ? ret : 0);
 }
 
@@ -2338,6 +2340,7 @@ int btrfs_writepages(struct address_space *mapping, struct writeback_control *wb
 	 */
 	btrfs_zoned_data_reloc_lock(BTRFS_I(inode));
 	ret = extent_write_cache_pages(mapping, &bio_ctrl);
+	free_extent_map(bio_ctrl.em_cached);
 	submit_write_bio(&bio_ctrl, ret);
 	btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
 	return ret;
-- 
2.45.2


  parent reply	other threads:[~2024-08-08  6:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08  6:05 [PATCH 0/2] btrfs: reduce extent map lookup overhead for data write Qu Wenruo
2024-08-08  6:05 ` [PATCH 1/2] btrfs: introduce extent_map::em_cached member Qu Wenruo
2024-08-08 11:36   ` Filipe Manana
2024-08-08 23:13     ` Qu Wenruo
2024-08-08  6:06 ` Qu Wenruo [this message]
2024-08-08 11:39   ` [PATCH 2/2] btrfs: utilize cached extent map for data writeback Filipe Manana
2024-08-08 10:16 ` [PATCH 0/2] btrfs: reduce extent map lookup overhead for data write Filipe Manana
2024-08-29 18:00 ` David Sterba
2024-08-29 21:40   ` 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=f1232d0ffc8ae7389206d4cc9210afc77cfcacac.1723096922.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox