Skip to content

Commit f433fbd

Browse files
adam900710kdave
authored andcommitted
btrfs: refresh add_ra_bio_pages() to indicate it's using folios
The function add_ra_bio_folios() has been utilizing folio interfaces since c808c1d ("btrfs: convert add_ra_bio_pages() to use only folios"), but we are still referring to "pages" inside the function name and all comments. Furthermore, such folio/page mixing can even be confusing, e.g. the variable @page_end is very confusing as we're not really referring to the end of the page, but the end of the folio, especially when we already have large folio support. Enhance that function by: - Rename "page" to "folio" to avoid confusion - Skip to the folio end if there is already a folio in the page cache The existing skip is: cur += folio_size(folio); This is incorrect if @Cur is not folio size aligned, and can be common with large folio support. Thankfully this is not going to cause any real bugs, but at most will skip some blocks that can be added to readahead. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3d2e23a commit f433fbd

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

fs/btrfs/compression.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,16 @@ struct compressed_bio *btrfs_alloc_compressed_write(struct btrfs_inode *inode,
355355
}
356356

357357
/*
358-
* Add extra pages in the same compressed file extent so that we don't need to
358+
* Add extra folios in the same compressed file extent so that we don't need to
359359
* re-read the same extent again and again.
360360
*
361-
* If in the same page, we have several non-contiguous blocks which are pointing
361+
* If in the same folio, we have several non-contiguous blocks which are pointing
362362
* to the same on-disk compressed data, we will re-read the same extent many
363-
* times, as this function can only help cross page situations.
363+
* times, as this function can only help cross folio situations.
364364
*/
365-
static noinline int add_ra_bio_pages(struct inode *inode,
366-
u64 compressed_end,
367-
struct compressed_bio *cb,
368-
int *memstall, unsigned long *pflags,
369-
bool direct_reclaim)
365+
static noinline int add_ra_bio_folios(struct inode *inode, u64 compressed_end,
366+
struct compressed_bio *cb, int *memstall,
367+
unsigned long *pflags, bool direct_reclaim)
370368
{
371369
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
372370
pgoff_t end_index;
@@ -396,7 +394,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
396394

397395
/*
398396
* Avoid direct reclaim when the caller does not allow it. Since
399-
* add_ra_bio_pages() is always speculative, suppress allocation warnings
397+
* add_ra_bio_folios() is always speculative, suppress allocation warnings
400398
* in either case.
401399
*/
402400
if (!direct_reclaim) {
@@ -408,7 +406,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
408406
}
409407

410408
while (cur < compressed_end) {
411-
pgoff_t page_end;
409+
u64 folio_end;
412410
pgoff_t pg_index = cur >> PAGE_SHIFT;
413411
u32 add_size;
414412

@@ -442,8 +440,8 @@ static noinline int add_ra_bio_pages(struct inode *inode,
442440
break;
443441

444442
if (filemap_add_folio(mapping, folio, pg_index, cache_gfp)) {
445-
/* There is already a folio, skip to folio end. */
446-
cur += folio_size(folio);
443+
/* There is already a folio, skip to the folio end. */
444+
cur += folio_size(folio) - offset_in_folio(folio, cur);
447445
folio_put(folio);
448446
continue;
449447
}
@@ -460,10 +458,10 @@ static noinline int add_ra_bio_pages(struct inode *inode,
460458
break;
461459
}
462460

463-
page_end = (pg_index << PAGE_SHIFT) + folio_size(folio) - 1;
464-
btrfs_lock_extent(tree, cur, page_end, NULL);
461+
folio_end = folio_next_pos(folio) - 1;
462+
btrfs_lock_extent(tree, cur, folio_end, NULL);
465463
read_lock(&em_tree->lock);
466-
em = btrfs_lookup_extent_mapping(em_tree, cur, page_end + 1 - cur);
464+
em = btrfs_lookup_extent_mapping(em_tree, cur, folio_end + 1 - cur);
467465
read_unlock(&em_tree->lock);
468466

469467
/*
@@ -476,14 +474,14 @@ static noinline int add_ra_bio_pages(struct inode *inode,
476474
(btrfs_extent_map_block_start(em) >> SECTOR_SHIFT) !=
477475
orig_bio->bi_iter.bi_sector) {
478476
btrfs_free_extent_map(em);
479-
btrfs_unlock_extent(tree, cur, page_end, NULL);
477+
btrfs_unlock_extent(tree, cur, folio_end, NULL);
480478
folio_unlock(folio);
481479
folio_put(folio);
482480
break;
483481
}
484-
add_size = min(btrfs_extent_map_end(em), page_end + 1) - cur;
482+
add_size = min(btrfs_extent_map_end(em), folio_end + 1) - cur;
485483
btrfs_free_extent_map(em);
486-
btrfs_unlock_extent(tree, cur, page_end, NULL);
484+
btrfs_unlock_extent(tree, cur, folio_end, NULL);
487485

488486
if (folio_contains(folio, end_index)) {
489487
size_t zero_offset = offset_in_folio(folio, isize);
@@ -592,8 +590,8 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio)
592590
}
593591
ASSERT(cb->bbio.bio.bi_iter.bi_size == compressed_len);
594592

595-
add_ra_bio_pages(&inode->vfs_inode, em_start + em_len, cb, &memstall,
596-
&pflags, !(bbio->bio.bi_opf & REQ_RAHEAD));
593+
add_ra_bio_folios(&inode->vfs_inode, em_start + em_len, cb, &memstall,
594+
&pflags, !(bbio->bio.bi_opf & REQ_RAHEAD));
597595

598596
cb->len = bbio->bio.bi_iter.bi_size;
599597
cb->bbio.bio.bi_iter.bi_sector = bbio->bio.bi_iter.bi_sector;

0 commit comments

Comments
 (0)