btrfs: migrate extent_buffer::pages[] to folio and more cleanups
v2 cover btrfs: migrate extent_buffer::pages[] to folio and more cleanups
[CHANGELOG]
v2:
- Adda new patch to do more cleanups for metadata page pointers usage
This patchset would migrate extent_buffer::pages[] to folios[], then cleanup the existing metadata page pointer usage to proper folios ones.
This cleanup would help future higher order folios usage for metadata in the following aspects:
- No more need to iterate through the remaining pages for page flags We just call folio_set/mark/start_*() helpers, for the single folio. The helper would only set the flag (mostly for the leading page).
- Single bio_add_folio() call for the whole eb
- Better filio helpers naming PageUptodate() compared to folio_test_uptodate().
The first patch would do a very simple conversion, then the 2nd patch do the prepartion for the higher order folio situation.
There are two locations which won't be converted to folios yet:
- Subpage code
There is no meaning to support higher order folio for subpage. The two conditions are just conflicting with each other.
- Data page pointers
That would be more useful in the future, before we going to support multi-page sectorsize.
However the 2nd one would also add a new corner case:
- Order mismatch in filemap and eb folios
Unforatunately I don't have a better plan other than re-allocate the folios to the same order.
Maybe in the future we would have better ways to handle it? Like migrating the pages to the higher order one?
Qu Wenruo (2):
btrfs: migrate extent_buffer::pages[] to folio
btrfs: cleanup metadata page pointer usage
fs/btrfs/accessors.c | 20 +- fs/btrfs/accessors.h | 4 +- fs/btrfs/ctree.c | 2 +- fs/btrfs/disk-io.c | 25 +- fs/btrfs/extent_io.c | 402 ++++++++++++++++++------------- fs/btrfs/extent_io.h | 21 +- fs/btrfs/inode.c | 2 +- fs/btrfs/subpage.c | 60 ++--- fs/btrfs/subpage.h | 11 +- fs/btrfs/tests/extent-io-tests.c | 4 +- 10 files changed, 322 insertions(+), 229 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 btrfs: migrate extent_buffer::pages[] to folio
For now extent_buffer::pages[] are still only accept single page pointer, thus we can migrate to folios pretty easily.
As for single page, page and folio are 1:1 mapped, including their page flags.
This patch would just do the conversion from struct page to struct folio, providing the first step to higher order folio in the future.
This conversion is pretty simple:
- extent_buffer::pages[] -> extent_buffer::folios[]
- page_address(eb->pages[i]) -> folio_address(eb->pages[i])
- eb->pages[i] -> folio_page(eb->folios[i], 0)
There would be more specific cleanups preparing for the incoming higher order folio support.
--- fs/btrfs/accessors.c | 20 ++--- fs/btrfs/accessors.h | 4 +- fs/btrfs/ctree.c | 2 +- fs/btrfs/disk-io.c | 19 ++--- fs/btrfs/extent_io.c | 123 ++++++++++++++++++------------- fs/btrfs/extent_io.h | 7 +- fs/btrfs/tests/extent-io-tests.c | 4 +- 7 files changed, 103 insertions(+), 76 deletions(-)
fs/btrfs/accessors.c +10 -10
@@ -27,7 +27,7 @@ static bool check_setget_bounds(const struct extent_buffer *eb,void btrfs_init_map_token (struct btrfs_map_token *token,struct extent_buffer *eb) { token->eb = eb; - token->kaddr =page_address (eb->pages[0 ]); + token->kaddr =folio_address (eb->folios[0 ]); token->offset =0 ; }
@@ -50,7 +50,7 @@ void btrfs_init_map_token(struct btrfs_map_token *token, struct extent_buffer *e* an offset into the extent buffer page array, cast to a specific type. This * gives us all the type checking. * -* The extent buffer pages stored in the array pages do not form a contiguous +* The extent buffer pages stored in the array folios may not form a contiguous * phyusical range, but the API functions assume the linear offset to the range * from 0 to metadata node size. */
@@ -74,13 +74,13 @@ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ member_offset + size <= token->offset + PAGE_SIZE) { \ return get_unaligned_le##bits(token->kaddr + oip); \ } \ - token->kaddr = page_address(token->eb->pages[idx]); \ + token->kaddr = folio_address(token->eb->folios[idx]); \ token->offset = idx << PAGE_SHIFT; \ if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE ) \ return get_unaligned_le##bits(token->kaddr + oip); \ \ memcpy(lebytes, token->kaddr + oip, part); \ - token->kaddr = page_address(token->eb->pages[idx + 1]); \ + token->kaddr = folio_address(token->eb->folios[idx + 1]); \ token->offset = (idx + 1) << PAGE_SHIFT; \ memcpy(lebytes + part, token->kaddr, size - part); \ return get_unaligned_le##bits(lebytes); \
@@ -91,7 +91,7 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \const unsigned long member_offset = (unsigned long )ptr + off; \const unsigned long oip =get_eb_offset_in_page (eb, member_offset); \const unsigned long idx =get_eb_page_index (member_offset); \ -char *kaddr =page_address (eb->pages[idx]); \ +char *kaddr =folio_address (eb->folios[idx]); \ const int size = sizeof(u##bits); \ const int part = PAGE_SIZE - oip; \ u8 lebytes[sizeof(u##bits)]; \
@@ -101,7 +101,7 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \ return get_unaligned_le##bits(kaddr + oip); \ \ memcpy(lebytes, kaddr + oip, part); \ - kaddr = page_address(eb->pages[idx + 1]); \ + kaddr = folio_address(eb->folios[idx + 1]); \ memcpy(lebytes + part, kaddr, size - part); \ return get_unaligned_le##bits(lebytes); \ } \
@@ -125,7 +125,7 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \ put_unaligned_le##bits(val, token->kaddr + oip); \ return; \ } \ - token->kaddr = page_address(token->eb->pages[idx]); \ + token->kaddr = folio_address(token->eb->folios[idx]); \ token->offset = idx << PAGE_SHIFT; \ if (INLINE_EXTENT_BUFFER_PAGES == 1 || oip + size <= PAGE_SIZE) { \ put_unaligned_le##bits(val, token->kaddr + oip); \
@@ -133,7 +133,7 @@ void btrfs_set_token_##bits(struct btrfs_map_token *token, \ } \ put_unaligned_le##bits(val, lebytes); \ memcpy(token->kaddr + oip, lebytes, part); \ - token->kaddr = page_address(token->eb->pages[idx + 1]); \ + token->kaddr = folio_address(token->eb->folios[idx + 1]); \ token->offset = (idx + 1) << PAGE_SHIFT; \ memcpy(token->kaddr, lebytes + part, size - part); \ } \
@@ -143,7 +143,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \const unsigned long member_offset = (unsigned long )ptr + off; \const unsigned long oip =get_eb_offset_in_page (eb, member_offset); \const unsigned long idx =get_eb_page_index (member_offset); \ -char *kaddr =page_address (eb->pages[idx]); \ +char *kaddr =folio_address (eb->folios[idx]); \ const int size = sizeof(u##bits); \ const int part = PAGE_SIZE - oip; \ u8 lebytes[sizeof(u##bits)]; \
@@ -156,7 +156,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \ \ put_unaligned_le##bits(val, lebytes); \ memcpy(kaddr + oip, lebytes, part); \ - kaddr = page_address(eb->pages[idx + 1]); \ + kaddr = folio_address(eb->folios[idx + 1]); \ memcpy(kaddr, lebytes + part, size - part); \ }
fs/btrfs/accessors.h +2 -2
@@ -90,14 +90,14 @@ static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\#define BTRFS_SETGET_HEADER_FUNCS (name, type, member, bits) \ static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ { \ - const type *p = page_address(eb->pages[0]) + \ + const type *p = folio_address(eb->folios[0]) + \ offset_in_page(eb->start); \ return get_unaligned_le##bits(&p->member); \ } \ static inline void btrfs_set_##name(const struct extent_buffer *eb, \ u##bits val) \ { \ - type *p = page_address(eb->pages[0]) + offset_in_page(eb->start); \ + type *p = folio_address(eb->folios[0]) + offset_in_page(eb->start); \ put_unaligned_le##bits(val, &p->member); \ }
fs/btrfs/ctree.c +1 -1
@@ -832,7 +832,7 @@ int btrfs_bin_search(struct extent_buffer *eb, int first_slot,if (oip + key_size <=PAGE_SIZE ) {const unsigned long idx =get_eb_page_index (offset); -char *kaddr =page_address (eb->pages[idx]); +char *kaddr =folio_address (eb->folios[idx]); oip =get_eb_offset_in_page (eb, offset); tmp = (struct btrfs_disk_key *)(kaddr + oip);
fs/btrfs/disk-io.c +10 -9
@@ -89,7 +89,7 @@ static void csum_tree_block(struct extent_buffer *buf, u8 *result) first_page_part = fs_info->nodesize; num_pages =1 ; }else { - kaddr =page_address (buf->pages[0 ]); + kaddr =folio_address (buf->folios[0 ]); first_page_part =min_t (u32,PAGE_SIZE , fs_info->nodesize); num_pages =num_extent_pages (buf); }
@@ -98,7 +98,7 @@ static void csum_tree_block(struct extent_buffer *buf, u8 *result) first_page_part - BTRFS_CSUM_SIZE);for (i =1 ; i < num_pages &&INLINE_EXTENT_BUFFER_PAGES >1 ; i++) { - kaddr =page_address (buf->pages[i]); + kaddr =folio_address (buf->folios[i]);crypto_shash_update (shash, kaddr,PAGE_SIZE ); }memset (result,0 ,BTRFS_CSUM_SIZE );
@@ -184,13 +184,14 @@ static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb,return -EROFS ;for (i =0 ; i < num_pages; i++) { -struct page *p = eb->pages[i]; -u64 start =max_t (u64, eb->start,page_offset (p)); -u64 end =min_t (u64, eb->start + eb->len,page_offset (p) +PAGE_SIZE ); +u64 start =max_t (u64, eb->start,folio_pos (eb->folios[i])); +u64 end =min_t (u64, eb->start + eb->len, +folio_pos (eb->folios[i]) +PAGE_SIZE );u32 len = end - start; ret =btrfs_repair_io_failure (fs_info,0 , start, len, - start, p,offset_in_page (start), mirror_num); + start,folio_page (eb->folios[i],0 ), +offset_in_page (start), mirror_num);if (ret)break ; }
@@ -277,8 +278,8 @@ blk_status_t btree_csum_one_bio(struct btrfs_bio *bbio)if (WARN_ON_ONCE (found_start != eb->start))return BLK_STS_IOERR ; -if (WARN_ON (!btrfs_page_test_uptodate (fs_info, eb->pages[0 ], eb->start, - eb->len))) +if (WARN_ON (!btrfs_page_test_uptodate (fs_info,folio_page (eb->folios[0 ],0 ), + eb->start, eb->len)))return BLK_STS_IOERR ; ASSERT(memcmp_extent_buffer(eb, fs_info->fs_devices->metadata_uuid,
@@ -387,7 +388,7 @@ int btrfs_validate_extent_buffer(struct extent_buffer *eb, }csum_tree_block (eb, result); - header_csum =page_address (eb->pages[0 ]) + + header_csum =folio_address (eb->folios[0 ]) +get_eb_offset_in_page (eb, offsetof(struct btrfs_header , csum));if (memcmp (result, header_csum, csum_size) !=0 ) {
fs/btrfs/extent_io.c +72 -51
358 lines not on this page · raw message
fs/btrfs/extent_io.h +6 -1
@@ -94,7 +94,12 @@ struct extent_buffer {struct rw_semaphore lock; -struct page *pages[INLINE_EXTENT_BUFFER_PAGES ]; +/* +* Pointers to all the folios of the extent buffer. +* +* For now the folio is always order 0 (aka, a single page). +*/ +struct folio *folios[INLINE_EXTENT_BUFFER_PAGES ];#ifdef CONFIG_BTRFS_DEBUG struct list_head leak_list;pid_t lock_owner;
fs/btrfs/tests/extent-io-tests.c +2 -2
@@ -652,7 +652,7 @@ static void dump_eb_and_memory_contents(struct extent_buffer *eb, void *memory, const char *test_name) {for (int i =0 ; i < eb->len; i++) { -struct page *page = eb->pages[i >>PAGE_SHIFT ]; +struct page *page =folio_page (eb->folios[i >>PAGE_SHIFT ],0 );void *addr =page_address (page) +offset_in_page (i);if (memcmp (addr, memory + i,1 ) !=0 ) {
@@ -668,7 +668,7 @@ static int verify_eb_and_memory(struct extent_buffer *eb, void *memory, const char *test_name) {for (int i =0 ; i < (eb->len >>PAGE_SHIFT ); i++) { -void *eb_addr =page_address (eb->pages[i]); +void *eb_addr =folio_address (eb->folios[i]);if (memcmp (memory + (i <<PAGE_SHIFT ), eb_addr,PAGE_SIZE ) !=0 ) {dump_eb_and_memory_contents (eb, memory, test_name);
Signature · 1 line
2.43.0
PATCH v2 2/2 btrfs: cleanup metadata page pointer usage
In reply to Qu WenruoAlthough we have migrated extent_buffer::pages[] to folios[], we're still mostly using the folio_page() help to grab the page.
This patch would do the following cleanups for metadata:
- Introduce num_extent_folios() helper
This is to replace most num_extent_pages() callers.
- Use num_extent_folios() to iterate future large folios This allows us to use things like bio_add_folio()/bio_add_folio_nofail(), and only set the needed flags for the folio (aka the leading/tailing page), which reduces the loop iteration to 1 for large folios.
- Change metadata related functions to use folio pointers Including their function name, involving:
* attach_extent_buffer_page()
* detach_extent_buffer_page()
* page_range_has_eb()
* btrfs_release_extent_buffer_pages()
* btree_clear_page_dirty()
* btrfs_page_inc_eb_refs()
* btrfs_page_dec_eb_refs()
- Change btrfs_is_subpage() to accept an address_space pointer This is to allow both page->mapping and folio->mapping to be utilized. As data is still using the old per-page code, and may keep so for a while.
- Special corner case place holder for future order mismatches between extent buffer and inode filemap
For now it's just a block of comments and a dead ASSERT(), no real handling yet.
The subpage code would still go page, just because subpage and large folio are conflicting conditions, thus we don't need to bother subpage with higher order folios at all. Just folio_page(folio, 0) would be enough.
--- fs/btrfs/disk-io.c | 6 + fs/btrfs/extent_io.c | 319 ++++++++++++++++++++++++------------------- fs/btrfs/extent_io.h | 14 ++ fs/btrfs/inode.c | 2 +- fs/btrfs/subpage.c | 60 ++++---- fs/btrfs/subpage.h | 11 +- 6 files changed, 239 insertions(+), 173 deletions(-)
fs/btrfs/disk-io.c +6 -0
@@ -97,6 +97,12 @@ static void csum_tree_block(struct extent_buffer *buf, u8 *result)crypto_shash_update (shash, kaddr +BTRFS_CSUM_SIZE , first_page_part -BTRFS_CSUM_SIZE ); +/* +* Multiple single-page folios case would reach here. +* +* nodesize <= PAGE_SIZE and large folio all handled by above +* crypto_shash_update() already. +*/ for (i =1 ; i < num_pages &&INLINE_EXTENT_BUFFER_PAGES >1 ; i++) { kaddr =folio_address (buf->folios[i]);crypto_shash_update (shash, kaddr,PAGE_SIZE );
fs/btrfs/extent_io.c +179 -140
673 lines not on this page · raw message
fs/btrfs/extent_io.h +14 -0
@@ -243,6 +243,20 @@ static inline int num_extent_pages(const struct extent_buffer *eb)return (eb->len >>PAGE_SHIFT ) ?:1 ; } +/* +* This can only be determined at runtime by checking eb::folios[0]. +* +* As we can have either one large folio covering the whole eb +* (either nodesize <= PAGE_SIZE, or high order folio), or multiple +* single-paged folios. +*/ +static inline int num_extent_folios (const struct extent_buffer *eb) +{ +if (folio_order (eb->folios[0 ])) +return 1 ; +return num_extent_pages (eb); +} +static inline int extent_buffer_uptodate (const struct extent_buffer *eb) {return test_bit (EXTENT_BUFFER_UPTODATE , &eb->bflags);
fs/btrfs/inode.c +1 -1
@@ -7863,7 +7863,7 @@ static void wait_subpage_spinlock(struct page *page)struct folio *folio =page_folio (page);struct btrfs_subpage *subpage; -if (!btrfs_is_subpage (fs_info, page)) +if (!btrfs_is_subpage (fs_info, page->mapping))return ;ASSERT (folio_test_private (folio) &&folio_get_private (folio));
fs/btrfs/subpage.c +33 -27
165 lines not on this page · raw message
fs/btrfs/subpage.h +6 -5
@@ -73,7 +73,8 @@ enum btrfs_subpage_type { BTRFS_SUBPAGE_DATA, }; -bool btrfs_is_subpage (const struct btrfs_fs_info *fs_info,struct page *page); +bool btrfs_is_subpage (const struct btrfs_fs_info *fs_info, +struct address_space *mapping);void btrfs_init_subpage_info (struct btrfs_subpage_info *subpage_info,u32 sectorsize); int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
@@ -86,10 +87,10 @@ struct btrfs_subpage *btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info, enum btrfs_subpage_type type);void btrfs_free_subpage (struct btrfs_subpage *subpage); -void btrfs_page_inc_eb_refs (const struct btrfs_fs_info *fs_info, -struct page *page); -void btrfs_page_dec_eb_refs (const struct btrfs_fs_info *fs_info, -struct page *page); +void btrfs_folio_inc_eb_refs (const struct btrfs_fs_info *fs_info, +struct folio *folio); +void btrfs_folio_dec_eb_refs (const struct btrfs_fs_info *fs_info, +struct folio *folio);void btrfs_subpage_start_reader (const struct btrfs_fs_info *fs_info,struct page *page,u64 start,u32 len);
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] btrfs: cleanup metadata page pointer usage
Quoted 34 lines · Qu Wenruo
Although we have migrated extent_buffer::pages[] to folios[], we're still mostly using the
folio_page()help to grab the page.This patch would do the following cleanups for metadata:
- Introduce
num_extent_folios()helper
This is to replace mostnum_extent_pages()callers.- Use
num_extent_folios()to iterate future large folios This allows us to use things like bio_add_folio()/bio_add_folio_nofail(), and only set the needed flags for the folio (aka the leading/tailing page), which reduces the loop iteration to 1 for large folios.- Change metadata related functions to use folio pointers Including their function name, involving:
*attach_extent_buffer_page()
*detach_extent_buffer_page()
*page_range_has_eb()
*btrfs_release_extent_buffer_pages()
*btree_clear_page_dirty()
*btrfs_page_inc_eb_refs()
*btrfs_page_dec_eb_refs()- Change
btrfs_is_subpage()to accept anaddress_spacepointer This is to allow bothpage->mappingandfolio->mappingto be utilized. As data is still using the old per-page code, and may keep so for a while.- Special corner case place holder for future order mismatches between extent buffer and inode filemap
For now it's just a block of comments and a deadASSERT(), no real handling yet.
Quoted 6 lines
The subpage code would still go page, just because subpage and large folio are conflicting conditions, thus we don't need to bother subpage with higher order folios at all. Just
folio_page(folio, 0)would be enough.Signed-off-by Qu Wenruo <[email protected]>
KASAN reports some problems:
[ 228.984474] Btrfs loaded, debug=on, assert=on, ref-verify=on, zoned=yes, fsverity=yes [ 228.986241] BTRFS: selftest: sectorsize: 4096 nodesize: 4096 [ 228.987192] BTRFS: selftest: running btrfs free space cache tests [ 228.988141] BTRFS: selftest: running extent only tests [ 228.989096] BTRFS: selftest: running bitmap only tests [ 228.990108] BTRFS: selftest: running bitmap and extent tests [ 228.991396] BTRFS: selftest: running space stealing from bitmap to extent tests [ 228.993137] BTRFS: selftest: running bytes index tests [ 228.994741] BTRFS: selftest: running extent buffer operation tests [ 228.995875] BTRFS: selftest: running btrfs_split_item tests [ 228.997062] ================================================================== [ 228.998388] BUG: KASAN: global-out-of-bounds in alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.000005] Read of size 8 at addr ffffffffc07f32e8 by task modprobe/13543 [ 229.000973] [ 229.001294] CPU: 2 PID: 13543 Comm: modprobe Tainted: G O 6.7.0-rc4-default+ #2250 [ 229.002556] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 [ 229.004054] Call Trace: [ 229.004489] <TASK> [ 229.004913] dump_stack_lvl+0x46/0x70 [ 229.005546] print_address_description.constprop.0+0x30/0x420 [ 229.006431] print_report+0xb0/0x260 [ 229.007023] ? kasan_addr_to_slab+0x9/0xc0 [ 229.007685] kasan_report+0xbe/0xf0 [ 229.008275] ? alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.009212] ? alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.010113] alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.010932] ? btrfs_alloc_page_array+0x100/0x100 [btrfs] [ 229.011816] ? is_module_address+0x11/0x30 [ 229.012488] ? static_obj+0x73/0xa0 [ 229.013054] ? lockdep_init_map_type+0xe8/0x360 [ 229.013751] ? __raw_spin_lock_init+0x73/0x90 [ 229.014426] ? __alloc_extent_buffer+0x14a/0x190 [btrfs] [ 229.015225] __alloc_dummy_extent_buffer+0x2e/0x2b0 [btrfs] [ 229.016121] test_btrfs_split_item+0xcf/0x7d0 [btrfs] [ 229.016995] ? btrfs_test_free_space_cache+0x1e0/0x1e0 [btrfs] [ 229.017872] ? info_print_prefix+0x100/0x100 [ 229.018523] ? btrfs_test_free_space_cache+0xda/0x1e0 [btrfs] [ 229.019461] ? __kmem_cache_free+0xfa/0x200 [ 229.020064] btrfs_run_sanity_tests+0x78/0x140 [btrfs] [ 229.020976] init_btrfs_fs+0x38/0x220 [btrfs] [ 229.021867] ? btrfs_interface_init+0x20/0x20 [btrfs] [ 229.022818] do_one_initcall+0xc3/0x3b0 [ 229.023473] ? trace_event_raw_event_initcall_level+0x150/0x150 [ 229.024436] ? __kmem_cache_alloc_node+0x1b5/0x2e0 [ 229.025279] ? do_init_module+0x38/0x3b0 [ 229.025806] ? kasan_unpoison+0x40/0x60 [ 229.026477] do_init_module+0x135/0x3b0 [ 229.027134] load_module+0x11c1/0x13c0 [ 229.027766] ? layout_and_allocate.isra.0+0x280/0x280 [ 229.028435] ? kernel_read_file+0x252/0x3f0 [ 229.029060] ? __ia32_sys_fsconfig+0x70/0x70 [ 229.029755] ? init_module_from_file+0xd1/0x130 [ 229.030489] init_module_from_file+0xd1/0x130 [ 229.031184] ? __do_sys_init_module+0x1a0/0x1a0 [ 229.031954] ? idempotent_init_module+0x3b9/0x3d0 [ 229.032727] ? do_raw_spin_unlock+0x84/0xf0 [ 229.033393] idempotent_init_module+0x1ac/0x3d0 [ 229.034101] ? init_module_from_file+0x130/0x130 [ 229.034837] ? __fget_files+0xfd/0x1e0 [ 229.035449] __x64_sys_finit_module+0x72/0xb0 [ 229.037902] do_syscall_64+0x41/0xe0 [ 229.038495] entry_SYSCALL_64_after_hwframe+0x46/0x4e [ 229.039314] RIP: 0033:0x7f07839f53dd [ 229.042725] RSP: 002b:00007fff7eb94c18 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [ 229.043642] RAX: ffffffffffffffda RBX: 00005574ab37ba20 RCX: 00007f07839f53dd [ 229.044833] RDX: 0000000000000000 RSI: 00005574ab372c5a RDI: 000000000000000e [ 229.046002] RBP: 00005574ab372c5a R08: 0000000000000000 R09: 00005574ab37baa0 [ 229.047195] R10: 00005574ab37f850 R11: 0000000000000246 R12: 0000000000040000 [ 229.048275] R13: 0000000000000000 R14: 00005574ab3841b0 R15: 00005574ab37b480 [ 229.049320] </TASK> [ 229.049767] [ 229.050124] The buggy address belongs to the variable: [ 229.050961] __func__.1+0x288/0xffffffffffeeafa0 [btrfs] [ 229.051928] [ 229.052205] Memory state around the buggy address: [ 229.052971] ffffffffc07f3180: f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9 00 00 00 00 [ 229.054075] ffffffffc07f3200: 00 00 00 00 03 f9 f9 f9 f9 f9 f9 f9 00 00 00 03 [ 229.055173] >ffffffffc07f3280: f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9 00 07 f9 f9 [ 229.056210] ^ [ 229.057066] ffffffffc07f3300: f9 f9 f9 f9 00 00 00 00 04 f9 f9 f9 f9 f9 f9 f9 [ 229.058152] ffffffffc07f3380: 00 00 00 02 f9 f9 f9 f9 00 00 03 f9 f9 f9 f9 f9 [ 229.059119] ================================================================== [ 229.060341] Disabling lock debugging due to kernel taint [ 229.061254] BUG: unable to handle page fault for address: 00006b636f6c5f7a [ 229.062383] #PF: supervisor read access in kernel mode [ 229.063232] #PF: error_code(0x0000) - not-present page [ 229.064079] PGD 0 P4D 0 [ 229.064544] Oops: 0000 [#1] PREEMPT SMP KASAN [ 229.065296] CPU: 2 PID: 13543 Comm: modprobe Tainted: G B O 6.7.0-rc4-default+ #2250 [ 229.066783] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 [ 229.068574] RIP: 0010:folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.072394] RSP: 0018:ffff88800294f840 EFLAGS: 00010282 [ 229.073281] RAX: 0000000000000000 RBX: 00006b636f6c5f72 RCX: ffffffffc05c5c12 [ 229.074409] RDX: 0000000000000000 RSI: 0000000000000008 RDI: 00006b636f6c5f7a [ 229.075488] RBP: 00006b636f6c5f72 R08: 0000000000000001 R09: fffffbfff37183f8 [ 229.076600] R10: ffffffff9b8c1fc7 R11: 0000000000000001 R12: 0000000000000000 [ 229.077723] R13: ffff88801d1e4008 R14: 0000000000001000 R15: ffffffffc08b0228 [ 229.078905] FS: 00007f07838e5740(0000) GS:ffff88806ce00000(0000) knlGS:0000000000000000 [ 229.080262] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 229.081228] CR2: 00006b636f6c5f7a CR3: 000000000598a000 CR4: 00000000000006b0 [ 229.082417] Call Trace: [ 229.082849] <TASK> [ 229.083289] ? __die+0x1f/0x60 [ 229.083896] ? page_fault_oops+0x71/0xa0 [ 229.084629] ? exc_page_fault+0x69/0xd0 [ 229.085354] ? asm_exc_page_fault+0x22/0x30 [ 229.086130] ? folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.087170] ? folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.088173] __alloc_dummy_extent_buffer+0x5b/0x2b0 [btrfs] [ 229.089206] test_btrfs_split_item+0xcf/0x7d0 [btrfs] [ 229.090139] ? btrfs_test_free_space_cache+0x1e0/0x1e0 [btrfs] [ 229.091192] ? info_print_prefix+0x100/0x100 [ 229.091900] ? btrfs_test_free_space_cache+0xda/0x1e0 [btrfs] [ 229.092924] ? __kmem_cache_free+0xfa/0x200 [ 229.093604] btrfs_run_sanity_tests+0x78/0x140 [btrfs] [ 229.094544] init_btrfs_fs+0x38/0x220 [btrfs] [ 229.095401] ? btrfs_interface_init+0x20/0x20 [btrfs] [ 229.096325] do_one_initcall+0xc3/0x3b0 [ 229.096948] ? trace_event_raw_event_initcall_level+0x150/0x150 [ 229.097765] ? __kmem_cache_alloc_node+0x1b5/0x2e0 [ 229.098594] ? do_init_module+0x38/0x3b0 [ 229.099189] ? kasan_unpoison+0x40/0x60 [ 229.099794] do_init_module+0x135/0x3b0 [ 229.100479] load_module+0x11c1/0x13c0 [ 229.101095] ? layout_and_allocate.isra.0+0x280/0x280 [ 229.101874] ? kernel_read_file+0x252/0x3f0 [ 229.102481] ? __ia32_sys_fsconfig+0x70/0x70 [ 229.103189] ? init_module_from_file+0xd1/0x130 [ 229.103918] init_module_from_file+0xd1/0x130 [ 229.104615] ? __do_sys_init_module+0x1a0/0x1a0 [ 229.105352] ? idempotent_init_module+0x3b9/0x3d0 [ 229.106118] ? do_raw_spin_unlock+0x84/0xf0 [ 229.106787] idempotent_init_module+0x1ac/0x3d0 [ 229.107592] ? init_module_from_file+0x130/0x130 [ 229.108413] ? __fget_files+0xfd/0x1e0 [ 229.108979] __x64_sys_finit_module+0x72/0xb0 [ 229.109686] do_syscall_64+0x41/0xe0 [ 229.110286] entry_SYSCALL_64_after_hwframe+0x46/0x4e [ 229.111074] RIP: 0033:0x7f07839f53dd [ 229.114183] RSP: 002b:00007fff7eb94c18 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [ 229.115057] RAX: ffffffffffffffda RBX: 00005574ab37ba20 RCX: 00007f07839f53dd [ 229.116099] RDX: 0000000000000000 RSI: 00005574ab372c5a RDI: 000000000000000e [ 229.117162] RBP: 00005574ab372c5a R08: 0000000000000000 R09: 00005574ab37baa0 [ 229.118178] R10: 00005574ab37f850 R11: 0000000000000246 R12: 0000000000040000 [ 229.119254] R13: 0000000000000000 R14: 00005574ab3841b0 R15: 00005574ab37b480 [ 229.120183] </TASK> [ 229.120582] Modules linked in: btrfs(O+) blake2b_generic libcrc32c xor lzo_compress lzo_decompress raid6_pq zstd_decompress zstd_compress xxhash zstd_common loop [ 229.122735] CR2: 00006b636f6c5f7a [ 229.123266] ---[ end trace 0000000000000000 ]--- [ 229.123916] RIP: 0010:folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.127469] RSP: 0018:ffff88800294f840 EFLAGS: 00010282 [ 229.128273] RAX: 0000000000000000 RBX: 00006b636f6c5f72 RCX: ffffffffc05c5c12 [ 229.129305] RDX: 0000000000000000 RSI: 0000000000000008 RDI: 00006b636f6c5f7a [ 229.130327] RBP: 00006b636f6c5f72 R08: 0000000000000001 R09: fffffbfff37183f8 [ 229.131362] R10: ffffffff9b8c1fc7 R11: 0000000000000001 R12: 0000000000000000 [ 229.132442] R13: ffff88801d1e4008 R14: 0000000000001000 R15: ffffffffc08b0228 [ 229.133657] FS: 00007f07838e5740(0000) GS:ffff88806ce00000(0000) knlGS:0000000000000000 [ 229.134887] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 229.135776] CR2: 00006b636f6c5f7a CR3: 000000000598a000 CR4: 00000000000006b0
Re: [PATCH v2 2/2] btrfs: cleanup metadata page pointer usage
Quoted 44 lines · David Sterba
Quoted 34 lines · Qu Wenruo
Although we have migrated extent_buffer::pages[] to folios[], we're still mostly using the
folio_page()help to grab the page.This patch would do the following cleanups for metadata:
- Introduce
num_extent_folios()helper
This is to replace mostnum_extent_pages()callers.- Use
num_extent_folios()to iterate future large folios This allows us to use things like bio_add_folio()/bio_add_folio_nofail(), and only set the needed flags for the folio (aka the leading/tailing page), which reduces the loop iteration to 1 for large folios.- Change metadata related functions to use folio pointers Including their function name, involving:
*attach_extent_buffer_page()
*detach_extent_buffer_page()
*page_range_has_eb()
*btrfs_release_extent_buffer_pages()
*btree_clear_page_dirty()
*btrfs_page_inc_eb_refs()
*btrfs_page_dec_eb_refs()- Change
btrfs_is_subpage()to accept anaddress_spacepointer This is to allow bothpage->mappingandfolio->mappingto be utilized. As data is still using the old per-page code, and may keep so for a while.- Special corner case place holder for future order mismatches between extent buffer and inode filemap
For now it's just a block of comments and a deadASSERT(), no real handling yet.Quoted 6 lines
The subpage code would still go page, just because subpage and large folio are conflicting conditions, thus we don't need to bother subpage with higher order folios at all. Just
folio_page(folio, 0)would be enough.Signed-off-by Qu Wenruo <[email protected]>KASAN reports some problems:
Quoted 12 lines
[ 228.984474] Btrfs loaded, debug=on, assert=on, ref-verify=on, zoned=yes, fsverity=yes [ 228.986241] BTRFS: selftest: sectorsize: 4096 nodesize: 4096 [ 228.987192] BTRFS: selftest: running btrfs free space cache tests [ 228.988141] BTRFS: selftest: running extent only tests [ 228.989096] BTRFS: selftest: running bitmap only tests [ 228.990108] BTRFS: selftest: running bitmap and extent tests [ 228.991396] BTRFS: selftest: running space stealing from bitmap to extent tests [ 228.993137] BTRFS: selftest: running bytes index tests [ 228.994741] BTRFS: selftest: running extent buffer operation tests [ 228.995875] BTRFS: selftest: running btrfs_split_item tests [ 228.997062] ================================================================== [ 228.998388] BUG: KASAN: global-out-of-bounds in alloc_eb_folio_array+0xd6/0x180 [btrfs]
Unfortunately I failed to reproduce here, even I have enabled KASAN and always have selftest enabled.
Quoted 1 line
[ 229.000005] Read of size 8 at addr ffffffffc07f32e8 by task modprobe/13543
The address looks like stack address, and since it's not reported from btrfs_alloc_page_array(), it must be the
"eb->folios[i] = page_folio(page_array[i]);" line.
But I failed to see any obvious problem here.
Any extra clue for debugging?
Thanks,
Qu
Quoted 147 lines
[ 229.000973] [ 229.001294] CPU: 2 PID: 13543 Comm: modprobe Tainted: G O 6.7.0-rc4-default+ #2250 [ 229.002556] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 [ 229.004054] Call Trace: [ 229.004489] <TASK> [ 229.004913] dump_stack_lvl+0x46/0x70 [ 229.005546] print_address_description.constprop.0+0x30/0x420 [ 229.006431] print_report+0xb0/0x260 [ 229.007023] ? kasan_addr_to_slab+0x9/0xc0 [ 229.007685] kasan_report+0xbe/0xf0 [ 229.008275] ? alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.009212] ? alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.010113] alloc_eb_folio_array+0xd6/0x180 [btrfs] [ 229.010932] ? btrfs_alloc_page_array+0x100/0x100 [btrfs] [ 229.011816] ? is_module_address+0x11/0x30 [ 229.012488] ? static_obj+0x73/0xa0 [ 229.013054] ? lockdep_init_map_type+0xe8/0x360 [ 229.013751] ? __raw_spin_lock_init+0x73/0x90 [ 229.014426] ? __alloc_extent_buffer+0x14a/0x190 [btrfs] [ 229.015225] __alloc_dummy_extent_buffer+0x2e/0x2b0 [btrfs] [ 229.016121] test_btrfs_split_item+0xcf/0x7d0 [btrfs] [ 229.016995] ? btrfs_test_free_space_cache+0x1e0/0x1e0 [btrfs] [ 229.017872] ? info_print_prefix+0x100/0x100 [ 229.018523] ? btrfs_test_free_space_cache+0xda/0x1e0 [btrfs] [ 229.019461] ? __kmem_cache_free+0xfa/0x200 [ 229.020064] btrfs_run_sanity_tests+0x78/0x140 [btrfs] [ 229.020976] init_btrfs_fs+0x38/0x220 [btrfs] [ 229.021867] ? btrfs_interface_init+0x20/0x20 [btrfs] [ 229.022818] do_one_initcall+0xc3/0x3b0 [ 229.023473] ? trace_event_raw_event_initcall_level+0x150/0x150 [ 229.024436] ? __kmem_cache_alloc_node+0x1b5/0x2e0 [ 229.025279] ? do_init_module+0x38/0x3b0 [ 229.025806] ? kasan_unpoison+0x40/0x60 [ 229.026477] do_init_module+0x135/0x3b0 [ 229.027134] load_module+0x11c1/0x13c0 [ 229.027766] ? layout_and_allocate.isra.0+0x280/0x280 [ 229.028435] ? kernel_read_file+0x252/0x3f0 [ 229.029060] ? __ia32_sys_fsconfig+0x70/0x70 [ 229.029755] ? init_module_from_file+0xd1/0x130 [ 229.030489] init_module_from_file+0xd1/0x130 [ 229.031184] ? __do_sys_init_module+0x1a0/0x1a0 [ 229.031954] ? idempotent_init_module+0x3b9/0x3d0 [ 229.032727] ? do_raw_spin_unlock+0x84/0xf0 [ 229.033393] idempotent_init_module+0x1ac/0x3d0 [ 229.034101] ? init_module_from_file+0x130/0x130 [ 229.034837] ? __fget_files+0xfd/0x1e0 [ 229.035449] __x64_sys_finit_module+0x72/0xb0 [ 229.037902] do_syscall_64+0x41/0xe0 [ 229.038495] entry_SYSCALL_64_after_hwframe+0x46/0x4e [ 229.039314] RIP: 0033:0x7f07839f53dd [ 229.042725] RSP: 002b:00007fff7eb94c18 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [ 229.043642] RAX: ffffffffffffffda RBX: 00005574ab37ba20 RCX: 00007f07839f53dd [ 229.044833] RDX: 0000000000000000 RSI: 00005574ab372c5a RDI: 000000000000000e [ 229.046002] RBP: 00005574ab372c5a R08: 0000000000000000 R09: 00005574ab37baa0 [ 229.047195] R10: 00005574ab37f850 R11: 0000000000000246 R12: 0000000000040000 [ 229.048275] R13: 0000000000000000 R14: 00005574ab3841b0 R15: 00005574ab37b480 [ 229.049320] </TASK> [ 229.049767] [ 229.050124] The buggy address belongs to the variable: [ 229.050961] __func__.1+0x288/0xffffffffffeeafa0 [btrfs] [ 229.051928] [ 229.052205] Memory state around the buggy address: [ 229.052971] ffffffffc07f3180: f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9 00 00 00 00 [ 229.054075] ffffffffc07f3200: 00 00 00 00 03 f9 f9 f9 f9 f9 f9 f9 00 00 00 03 [ 229.055173] >ffffffffc07f3280: f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9 00 07 f9 f9 [ 229.056210] ^ [ 229.057066] ffffffffc07f3300: f9 f9 f9 f9 00 00 00 00 04 f9 f9 f9 f9 f9 f9 f9 [ 229.058152] ffffffffc07f3380: 00 00 00 02 f9 f9 f9 f9 00 00 03 f9 f9 f9 f9 f9 [ 229.059119] ================================================================== [ 229.060341] Disabling lock debugging due to kernel taint [ 229.061254] BUG: unable to handle page fault for address: 00006b636f6c5f7a [ 229.062383] #PF: supervisor read access in kernel mode [ 229.063232] #PF: error_code(0x0000) - not-present page [ 229.064079] PGD 0 P4D 0 [ 229.064544] Oops: 0000 [#1] PREEMPT SMP KASAN [ 229.065296] CPU: 2 PID: 13543 Comm: modprobe Tainted: G B O 6.7.0-rc4-default+ #2250 [ 229.066783] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 [ 229.068574] RIP: 0010:folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.072394] RSP: 0018:ffff88800294f840 EFLAGS: 00010282 [ 229.073281] RAX: 0000000000000000 RBX: 00006b636f6c5f72 RCX: ffffffffc05c5c12 [ 229.074409] RDX: 0000000000000000 RSI: 0000000000000008 RDI: 00006b636f6c5f7a [ 229.075488] RBP: 00006b636f6c5f72 R08: 0000000000000001 R09: fffffbfff37183f8 [ 229.076600] R10: ffffffff9b8c1fc7 R11: 0000000000000001 R12: 0000000000000000 [ 229.077723] R13: ffff88801d1e4008 R14: 0000000000001000 R15: ffffffffc08b0228 [ 229.078905] FS: 00007f07838e5740(0000) GS:ffff88806ce00000(0000) knlGS:0000000000000000 [ 229.080262] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 229.081228] CR2: 00006b636f6c5f7a CR3: 000000000598a000 CR4: 00000000000006b0 [ 229.082417] Call Trace: [ 229.082849] <TASK> [ 229.083289] ? __die+0x1f/0x60 [ 229.083896] ? page_fault_oops+0x71/0xa0 [ 229.084629] ? exc_page_fault+0x69/0xd0 [ 229.085354] ? asm_exc_page_fault+0x22/0x30 [ 229.086130] ? folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.087170] ? folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.088173] __alloc_dummy_extent_buffer+0x5b/0x2b0 [btrfs] [ 229.089206] test_btrfs_split_item+0xcf/0x7d0 [btrfs] [ 229.090139] ? btrfs_test_free_space_cache+0x1e0/0x1e0 [btrfs] [ 229.091192] ? info_print_prefix+0x100/0x100 [ 229.091900] ? btrfs_test_free_space_cache+0xda/0x1e0 [btrfs] [ 229.092924] ? __kmem_cache_free+0xfa/0x200 [ 229.093604] btrfs_run_sanity_tests+0x78/0x140 [btrfs] [ 229.094544] init_btrfs_fs+0x38/0x220 [btrfs] [ 229.095401] ? btrfs_interface_init+0x20/0x20 [btrfs] [ 229.096325] do_one_initcall+0xc3/0x3b0 [ 229.096948] ? trace_event_raw_event_initcall_level+0x150/0x150 [ 229.097765] ? __kmem_cache_alloc_node+0x1b5/0x2e0 [ 229.098594] ? do_init_module+0x38/0x3b0 [ 229.099189] ? kasan_unpoison+0x40/0x60 [ 229.099794] do_init_module+0x135/0x3b0 [ 229.100479] load_module+0x11c1/0x13c0 [ 229.101095] ? layout_and_allocate.isra.0+0x280/0x280 [ 229.101874] ? kernel_read_file+0x252/0x3f0 [ 229.102481] ? __ia32_sys_fsconfig+0x70/0x70 [ 229.103189] ? init_module_from_file+0xd1/0x130 [ 229.103918] init_module_from_file+0xd1/0x130 [ 229.104615] ? __do_sys_init_module+0x1a0/0x1a0 [ 229.105352] ? idempotent_init_module+0x3b9/0x3d0 [ 229.106118] ? do_raw_spin_unlock+0x84/0xf0 [ 229.106787] idempotent_init_module+0x1ac/0x3d0 [ 229.107592] ? init_module_from_file+0x130/0x130 [ 229.108413] ? __fget_files+0xfd/0x1e0 [ 229.108979] __x64_sys_finit_module+0x72/0xb0 [ 229.109686] do_syscall_64+0x41/0xe0 [ 229.110286] entry_SYSCALL_64_after_hwframe+0x46/0x4e [ 229.111074] RIP: 0033:0x7f07839f53dd [ 229.114183] RSP: 002b:00007fff7eb94c18 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [ 229.115057] RAX: ffffffffffffffda RBX: 00005574ab37ba20 RCX: 00007f07839f53dd [ 229.116099] RDX: 0000000000000000 RSI: 00005574ab372c5a RDI: 000000000000000e [ 229.117162] RBP: 00005574ab372c5a R08: 0000000000000000 R09: 00005574ab37baa0 [ 229.118178] R10: 00005574ab37f850 R11: 0000000000000246 R12: 0000000000040000 [ 229.119254] R13: 0000000000000000 R14: 00005574ab3841b0 R15: 00005574ab37b480 [ 229.120183] </TASK> [ 229.120582] Modules linked in: btrfs(O+) blake2b_generic libcrc32c xor lzo_compress lzo_decompress raid6_pq zstd_decompress zstd_compress xxhash zstd_common loop [ 229.122735] CR2: 00006b636f6c5f7a [ 229.123266] ---[ end trace 0000000000000000 ]--- [ 229.123916] RIP: 0010:folio_flags.constprop.0+0x12/0x30 [btrfs] [ 229.127469] RSP: 0018:ffff88800294f840 EFLAGS: 00010282 [ 229.128273] RAX: 0000000000000000 RBX: 00006b636f6c5f72 RCX: ffffffffc05c5c12 [ 229.129305] RDX: 0000000000000000 RSI: 0000000000000008 RDI: 00006b636f6c5f7a [ 229.130327] RBP: 00006b636f6c5f72 R08: 0000000000000001 R09: fffffbfff37183f8 [ 229.131362] R10: ffffffff9b8c1fc7 R11: 0000000000000001 R12: 0000000000000000 [ 229.132442] R13: ffff88801d1e4008 R14: 0000000000001000 R15: ffffffffc08b0228 [ 229.133657] FS: 00007f07838e5740(0000) GS:ffff88806ce00000(0000) knlGS:0000000000000000 [ 229.134887] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 229.135776] CR2: 00006b636f6c5f7a CR3: 000000000598a000 CR4: 00000000000006b0
Quoted 32 lines · Qu Wenruo
[CHANGELOG]
v2:
- Adda new patch to do more cleanups for metadata page pointers usageThis patchset would migrate extent_buffer::pages[] to folios[], then cleanup the existing metadata page pointer usage to proper folios ones.
This cleanup would help future higher order folios usage for metadata in the following aspects:
- No more need to iterate through the remaining pages for page flags We just call folio_set/mark/start_*() helpers, for the single folio. The helper would only set the flag (mostly for the leading page).
- Single
bio_add_folio()call for the whole eb- Better filio helpers naming
PageUptodate()compared tofolio_test_uptodate().The first patch would do a very simple conversion, then the 2nd patch do the prepartion for the higher order folio situation.
There are two locations which won't be converted to folios yet:
- Subpage code
There is no meaning to support higher order folio for subpage. The two conditions are just conflicting with each other.- Data page pointers
That would be more useful in the future, before we going to support multi-page sectorsize.
Quoted 7 lines
However the 2nd one would also add a new corner case:
- Order mismatch in filemap and eb folios
Unforatunately I don't have a better plan other than re-allocate the folios to the same order.
Maybe in the future we would have better ways to handle it? Like migrating the pages to the higher order one?
As long as it's a no-op for now this is OK, we can do the higher order allocation for eb pages afterwards.
Quoted 35 lines · David Sterba
Quoted 34 lines · Qu Wenruo
[CHANGELOG]
v2:
- Adda new patch to do more cleanups for metadata page pointers usageThis patchset would migrate extent_buffer::pages[] to folios[], then cleanup the existing metadata page pointer usage to proper folios ones.
This cleanup would help future higher order folios usage for metadata in the following aspects:
- No more need to iterate through the remaining pages for page flags We just call folio_set/mark/start_*() helpers, for the single folio. The helper would only set the flag (mostly for the leading page).
- Single
bio_add_folio()call for the whole eb- Better filio helpers naming
PageUptodate()compared tofolio_test_uptodate().The first patch would do a very simple conversion, then the 2nd patch do the prepartion for the higher order folio situation.
There are two locations which won't be converted to folios yet:
- Subpage code
There is no meaning to support higher order folio for subpage. The two conditions are just conflicting with each other.- Data page pointers
That would be more useful in the future, before we going to support multi-page sectorsize.However the 2nd one would also add a new corner case:
Quoted 9 lines
Quoted 5 lines
- Order mismatch in filemap and eb folios
Unforatunately I don't have a better plan other than re-allocate the folios to the same order.
Maybe in the future we would have better ways to handle it? Like migrating the pages to the higher order one?As long as it's a no-op for now this is OK, we can do the higher order allocation for eb pages afterwards.
Yep, it won't cause any problem for now.
Although this corner case is making me wondering if the new alloc-then-attach is really any better than the original alloc-and-attach solution.
If the mm (filemap) layer can allow us to allocate larger folios, it may be much simpler.
The current code only needs to setlarge folio support for the mapping, then go with high order fpg_flags.
The filemap code is already doing the retry and unalignment check.
But the existing filemap code would also try to reduce the order, which can lead to other problems, like one extent buffer with multiple different order folios.
Meanwhile alloc-and-attach gives us full control on the order, thus allowing all-or-none (one single large folio, or all single page ones) solution required by the 2nd patch.
Anyway, I would continue with the current alloc-then-attach method to experiment the higher order folios allocation first to find out all the pitfalls first.
Thanks,
Qu
Quoted 64 lines · Qu Wenruo
Quoted 35 lines · David Sterba
Quoted 34 lines · Qu Wenruo
[CHANGELOG]
v2:
- Adda new patch to do more cleanups for metadata page pointers usageThis patchset would migrate extent_buffer::pages[] to folios[], then cleanup the existing metadata page pointer usage to proper folios ones.
This cleanup would help future higher order folios usage for metadata in the following aspects:
- No more need to iterate through the remaining pages for page flags We just call folio_set/mark/start_*() helpers, for the single folio. The helper would only set the flag (mostly for the leading page).
- Single
bio_add_folio()call for the whole eb- Better filio helpers naming
PageUptodate()compared tofolio_test_uptodate().The first patch would do a very simple conversion, then the 2nd patch do the prepartion for the higher order folio situation.
There are two locations which won't be converted to folios yet:
- Subpage code
There is no meaning to support higher order folio for subpage. The two conditions are just conflicting with each other.- Data page pointers
That would be more useful in the future, before we going to support multi-page sectorsize.However the 2nd one would also add a new corner case:
Quoted 9 lines
Quoted 5 lines
- Order mismatch in filemap and eb folios
Unforatunately I don't have a better plan other than re-allocate the folios to the same order.
Maybe in the future we would have better ways to handle it? Like migrating the pages to the higher order one?As long as it's a no-op for now this is OK, we can do the higher order allocation for eb pages afterwards.
Yep, it won't cause any problem for now.
Although this corner case is making me wondering if the new alloc-then-attach is really any better than the original alloc-and-attach solution.
If the mm (filemap) layer can allow us to allocate larger folios, it may be much simpler.
The current code only needs to setlarge folio support for the mapping, then go with high orderfpg_flags.
The filemap code is already doing the retry and unalignment check.But the existing filemap code would also try to reduce the order, which can lead to other problems, like one extent buffer with multiple different order folios.
Meanwhile alloc-and-attach gives us full control on the order, thus allowing all-or-none (one single large folio, or all single page ones) solution required by the 2nd patch.
Quoted 3 lines
Anyway, I would continue with the current alloc-then-attach method to experiment the higher order folios allocation first to find out all the pitfalls first.
Agreed, we'll eventually converge to the full folio API but what you found so far seems that we can expect surprises.