Skip to content

Commit b945a46

Browse files
adam900710kdave
authored andcommitted
btrfs: make page Ordered bit to be subpage compatible
This involves the following modification: - Ordered extent creation This is done in process_one_page(), now PAGE_SET_ORDERED will call subpage helper to do the work. - endio functions This is done in btrfs_mark_ordered_io_finished(). - btrfs_invalidatepage() - btrfs_cleanup_ordered_extents() Use the subpage page helper, and add an extra branch to exit if the locked page have covered the full range. Now the usage of page Ordered flag for ordered extent accounting is fully subpage compatible. Tested-by: Ritesh Harjani <riteshh@linux.ibm.com> # [ppc64] Tested-by: Anand Jain <anand.jain@oracle.com> # [aarch64] Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 6f17400 commit b945a46

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

fs/btrfs/extent_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ static int process_one_page(struct btrfs_fs_info *fs_info,
18271827
len = end + 1 - start;
18281828

18291829
if (page_ops & PAGE_SET_ORDERED)
1830-
SetPageOrdered(page);
1830+
btrfs_page_clamp_set_ordered(fs_info, page, start, len);
18311831

18321832
if (page == locked_page)
18331833
return 1;

fs/btrfs/inode.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "block-group.h"
5252
#include "space-info.h"
5353
#include "zoned.h"
54+
#include "subpage.h"
5455

5556
struct btrfs_iget_args {
5657
u64 ino;
@@ -191,18 +192,22 @@ static inline void btrfs_cleanup_ordered_extents(struct btrfs_inode *inode,
191192
* range, then __endio_write_update_ordered() will handle
192193
* the ordered extent accounting for the range.
193194
*/
194-
ClearPageOrdered(page);
195+
btrfs_page_clamp_clear_ordered(inode->root->fs_info, page,
196+
offset, bytes);
195197
put_page(page);
196198
}
197199

200+
/* The locked page covers the full range, nothing needs to be done */
201+
if (bytes + offset <= page_offset(locked_page) + PAGE_SIZE)
202+
return;
198203
/*
199204
* In case this page belongs to the delalloc range being instantiated
200205
* then skip it, since the first page of a range is going to be
201206
* properly cleaned up by the caller of run_delalloc_range
202207
*/
203208
if (page_start >= offset && page_end <= (offset + bytes - 1)) {
204-
offset += PAGE_SIZE;
205-
bytes -= PAGE_SIZE;
209+
bytes = offset + bytes - page_offset(locked_page) - PAGE_SIZE;
210+
offset = page_offset(locked_page) + PAGE_SIZE;
206211
}
207212

208213
return __endio_write_update_ordered(inode, offset, bytes, false);
@@ -8339,6 +8344,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,
83398344
unsigned int length)
83408345
{
83418346
struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
8347+
struct btrfs_fs_info *fs_info = inode->root->fs_info;
83428348
struct extent_io_tree *tree = &inode->io_tree;
83438349
struct extent_state *cached_state = NULL;
83448350
u64 page_start = page_offset(page);
@@ -8374,6 +8380,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,
83748380
struct btrfs_ordered_extent *ordered;
83758381
bool delete_states;
83768382
u64 range_end;
8383+
u32 range_len;
83778384

83788385
ordered = btrfs_lookup_first_ordered_range(inode, cur,
83798386
page_end + 1 - cur);
@@ -8400,7 +8407,9 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,
84008407

84018408
range_end = min(ordered->file_offset + ordered->num_bytes - 1,
84028409
page_end);
8403-
if (!PageOrdered(page)) {
8410+
ASSERT(range_end + 1 - cur < U32_MAX);
8411+
range_len = range_end + 1 - cur;
8412+
if (!btrfs_page_test_ordered(fs_info, page, cur, range_len)) {
84048413
/*
84058414
* If Ordered (Private2) is cleared, it means endio has
84068415
* already been executed for the range.
@@ -8410,7 +8419,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,
84108419
delete_states = false;
84118420
goto next;
84128421
}
8413-
ClearPageOrdered(page);
8422+
btrfs_page_clear_ordered(fs_info, page, cur, range_len);
84148423

84158424
/*
84168425
* IO on this page will never be started, so we need to account

fs/btrfs/ordered-data.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "compression.h"
1717
#include "delalloc-space.h"
1818
#include "qgroup.h"
19+
#include "subpage.h"
1920

2021
static struct kmem_cache *btrfs_ordered_extent_cache;
2122

@@ -395,11 +396,11 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode,
395396
*
396397
* If there's no such bit, we need to skip to next range.
397398
*/
398-
if (!PageOrdered(page)) {
399+
if (!btrfs_page_test_ordered(fs_info, page, cur, len)) {
399400
cur += len;
400401
continue;
401402
}
402-
ClearPageOrdered(page);
403+
btrfs_page_clear_ordered(fs_info, page, cur, len);
403404
}
404405

405406
/* Now we're fine to update the accounting */

0 commit comments

Comments
 (0)