* [PATCH v2 0/3] btrfs: enhance function extent_range_clear_dirty_for_io()
@ 2024-05-22 23:47 Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 1/3] btrfs: move extent_range_clear_dirty_for_io() into inode.c Qu Wenruo
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Qu Wenruo @ 2024-05-22 23:47 UTC (permalink / raw)
To: linux-btrfs
[Changelog]
v2:
- Split the original patch into 3
- Return the error from filemap_get_folio() to be future-proof
- Enhance the comments for the new ASSERT() on
extent_range_clear_dirty_for_io() error
In fact, even if some pages are missing, we do not need to handle the
error at compress_file_range(), as btrfs_compress_folios() and each
compression routine would handle the missing folio correctly.
Thus the new ASSERT() is only an early warning for developers.
This is a preparation for the (near) future support of sector perfect
subpage compression support. (the current one requires full page
alignment).
The function extent_range_clear_dirty_for_io() is just a simple start.
Qu Wenruo (3):
btrfs: move extent_range_clear_dirty_for_io() into inode.c
btrfs: make extent_range_clear_dirty_for_io() subpage compatible
btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io()
fs/btrfs/extent_io.c | 15 ---------------
fs/btrfs/extent_io.h | 1 -
fs/btrfs/inode.c | 36 +++++++++++++++++++++++++++++++++++-
3 files changed, 35 insertions(+), 17 deletions(-)
--
2.45.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] btrfs: move extent_range_clear_dirty_for_io() into inode.c
2024-05-22 23:47 [PATCH v2 0/3] btrfs: enhance function extent_range_clear_dirty_for_io() Qu Wenruo
@ 2024-05-22 23:47 ` Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 3/3] btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io() Qu Wenruo
2 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2024-05-22 23:47 UTC (permalink / raw)
To: linux-btrfs
The function is only utilized inside inode.c by compress_file_range(),
so move it to inode.c and unexport it.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/extent_io.c | 15 ---------------
fs/btrfs/extent_io.h | 1 -
fs/btrfs/inode.c | 15 +++++++++++++++
3 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 7275bd919a3e..4af16c09dd88 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -164,21 +164,6 @@ void __cold extent_buffer_free_cachep(void)
kmem_cache_destroy(extent_buffer_cache);
}
-void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
-{
- unsigned long index = start >> PAGE_SHIFT;
- unsigned long end_index = end >> PAGE_SHIFT;
- struct page *page;
-
- 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);
- index++;
- }
-}
-
static void process_one_page(struct btrfs_fs_info *fs_info,
struct page *page, struct page *locked_page,
unsigned long page_ops, u64 start, u64 end)
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index dca6b12769ec..7c2f1bbc6b67 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -350,7 +350,6 @@ void extent_buffer_bitmap_clear(const struct extent_buffer *eb,
void set_extent_buffer_dirty(struct extent_buffer *eb);
void set_extent_buffer_uptodate(struct extent_buffer *eb);
void clear_extent_buffer_uptodate(struct extent_buffer *eb);
-void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end);
void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
struct page *locked_page,
struct extent_state **cached,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 000809e16aba..99be256f4f0e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -890,6 +890,21 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
btrfs_add_inode_defrag(NULL, inode, small_write);
}
+static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
+{
+ unsigned long index = start >> PAGE_SHIFT;
+ unsigned long end_index = end >> PAGE_SHIFT;
+ struct page *page;
+
+ 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);
+ index++;
+ }
+}
+
/*
* Work queue call back to started compression on a file and pages.
*
--
2.45.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible
2024-05-22 23:47 [PATCH v2 0/3] btrfs: enhance function extent_range_clear_dirty_for_io() Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 1/3] btrfs: move extent_range_clear_dirty_for_io() into inode.c Qu Wenruo
@ 2024-05-22 23:47 ` Qu Wenruo
2024-05-23 0:49 ` Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 3/3] btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io() Qu Wenruo
2 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2024-05-22 23:47 UTC (permalink / raw)
To: linux-btrfs
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(-)
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++;
}
}
--
2.45.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io()
2024-05-22 23:47 [PATCH v2 0/3] btrfs: enhance function extent_range_clear_dirty_for_io() Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 1/3] btrfs: move extent_range_clear_dirty_for_io() into inode.c Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible Qu Wenruo
@ 2024-05-22 23:47 ` Qu Wenruo
2 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2024-05-22 23:47 UTC (permalink / raw)
To: linux-btrfs
Previously we have BUG_ON() inside extent_range_clear_dirty_for_io(), as
we expect all involved folios are still locked, thus no folio should be
missing.
However for extent_range_clear_dirty_for_io() itself, we can skip the
missing folio and handling the remaining ones, and return an error if
there is anything wrong.
So this patch would remove the BUG_ON() and let the caller to handle the
error.
In the caller we do not have a quick way to cleanup the error, but all
the compression routines would handle the missing folio as an error and
properly error out, so we only need to do an ASSERT() for developers,
meanwhile for non-debug build the compression routine would handle the
error correctly.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/inode.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index dda47a273813..18b833e58d19 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -890,24 +890,29 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
btrfs_add_inode_defrag(NULL, inode, small_write);
}
-static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end)
+static int 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;
+ int ret = 0;
/* We should not have such large range. */
ASSERT(len < U32_MAX);
- while (index <= end_index) {
+ for (unsigned long index = start >> PAGE_SHIFT;
+ index <= end_index; index++) {
struct folio *folio;
folio = filemap_get_folio(inode->i_mapping, index);
- BUG_ON(IS_ERR(folio)); /* Pages should have been locked. */
+ if (IS_ERR(folio)) {
+ if (!ret)
+ ret = PTR_ERR(folio);
+ continue;
+ }
btrfs_folio_clamp_clear_dirty(fs_info, folio, start, len);
folio_put(folio);
- index++;
}
+ return ret;
}
/*
@@ -951,7 +956,16 @@ static void compress_file_range(struct btrfs_work *work)
* Otherwise applications with the file mmap'd can wander in and change
* the page contents while we are compressing them.
*/
- extent_range_clear_dirty_for_io(&inode->vfs_inode, start, end);
+ ret = extent_range_clear_dirty_for_io(&inode->vfs_inode, start, end);
+
+ /*
+ * All the folios should have been locked thus no failure.
+ *
+ * And even some folios are missing, btrfs_compress_folios()
+ * would handle them correctly, so here just do an ASSERT() check for
+ * early logic errors.
+ */
+ ASSERT(ret == 0);
/*
* We need to save i_size before now because it could change in between
--
2.45.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible
2024-05-22 23:47 ` [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible Qu Wenruo
@ 2024-05-23 0:49 ` Qu Wenruo
0 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2024-05-23 0:49 UTC (permalink / raw)
To: linux-btrfs
在 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++;
> }
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-23 0:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-22 23:47 [PATCH v2 0/3] btrfs: enhance function extent_range_clear_dirty_for_io() Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 1/3] btrfs: move extent_range_clear_dirty_for_io() into inode.c Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible Qu Wenruo
2024-05-23 0:49 ` Qu Wenruo
2024-05-22 23:47 ` [PATCH v2 3/3] btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io() Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox