diff mbox series

[v2,2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible

Message ID 015a4a2c7afb8ed894f4fb734cb886f01b9feb0c.1716421534.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: enhance function extent_range_clear_dirty_for_io() | expand

Commit Message

Qu Wenruo May 22, 2024, 11:47 p.m. UTC
Although the function is never called for subpage ranges, there is no
harm to make it subpage compatible for the future sector perfect subpage
compression support.

And since we're here, also change it to use folio APIs as the subpage
helper is already folio based.

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

Comments

Qu Wenruo May 23, 2024, 12:49 a.m. UTC | #1
在 2024/5/23 09:17, Qu Wenruo 写道:
> Although the function is never called for subpage ranges, there is no
> harm to make it subpage compatible for the future sector perfect subpage
> compression support.
> 
> And since we're here, also change it to use folio APIs as the subpage
> helper is already folio based.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

This patch is causing hangs for fstests with compression involved.

Please drop the series for now.

Thanks,
Qu
> ---
>   fs/btrfs/inode.c | 15 ++++++++++-----
>   1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 99be256f4f0e..dda47a273813 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -892,15 +892,20 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
>   
>   static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
>   {
> +	struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
> +	const u64 len = end + 1 - start;
>   	unsigned long index = start >> PAGE_SHIFT;
>   	unsigned long end_index = end >> PAGE_SHIFT;
> -	struct page *page;
>   
> +	/* We should not have such large range. */
> +	ASSERT(len < U32_MAX);
>   	while (index <= end_index) {
> -		page = find_get_page(inode->i_mapping, index);
> -		BUG_ON(!page); /* Pages should be in the extent_io_tree */
> -		clear_page_dirty_for_io(page);
> -		put_page(page);
> +		struct folio *folio;
> +
> +		folio = filemap_get_folio(inode->i_mapping, index);
> +		BUG_ON(IS_ERR(folio)); /* Pages should have been locked. */
> +		btrfs_folio_clamp_clear_dirty(fs_info, folio, start, len);
> +		folio_put(folio);
>   		index++;
>   	}
>   }
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 99be256f4f0e..dda47a273813 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -892,15 +892,20 @@  static inline void inode_should_defrag(struct btrfs_inode *inode,
 
 static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
 {
+	struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
+	const u64 len = end + 1 - start;
 	unsigned long index = start >> PAGE_SHIFT;
 	unsigned long end_index = end >> PAGE_SHIFT;
-	struct page *page;
 
+	/* We should not have such large range. */
+	ASSERT(len < U32_MAX);
 	while (index <= end_index) {
-		page = find_get_page(inode->i_mapping, index);
-		BUG_ON(!page); /* Pages should be in the extent_io_tree */
-		clear_page_dirty_for_io(page);
-		put_page(page);
+		struct folio *folio;
+
+		folio = filemap_get_folio(inode->i_mapping, index);
+		BUG_ON(IS_ERR(folio)); /* Pages should have been locked. */
+		btrfs_folio_clamp_clear_dirty(fs_info, folio, start, len);
+		folio_put(folio);
 		index++;
 	}
 }