Skip to content

Commit fe2961f

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: avoid f2fs_map_blocks() for consecutive holes in readpages
For consecutive large hole mapping across {d,id,did}nodes , we don't need to call f2fs_map_blocks() to check one hole block per one time, instead, we can use map.m_next_pgofs as a hint of next potential valid block, so that we can skip calling f2fs_map_blocks the range of [cur_pgofs + 1, .m_next_pgofs). 1) regular case touch /mnt/f2fs/file truncate -s $((1024*1024*1024)) /mnt/f2fs/file time dd if=/mnt/f2fs/file of=/dev/null bs=1M count=1024 Before: real 0m0.706s user 0m0.000s sys 0m0.706s After: real 0m0.620s user 0m0.008s sys 0m0.611s 2) large folio case touch /mnt/f2fs/file truncate -s $((1024*1024*1024)) /mnt/f2fs/file f2fs_io setflags immutable /mnt/f2fs/file sync echo 3 > /proc/sys/vm/drop_caches time dd if=/mnt/f2fs/file of=/dev/null bs=1M count=1024 Before: real 0m0.438s user 0m0.004s sys 0m0.433s After: real 0m0.368s user 0m0.004s sys 0m0.364s Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent d194f11 commit fe2961f

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

fs/f2fs/data.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,10 +2164,13 @@ static int f2fs_read_single_page(struct inode *inode, struct folio *folio,
21642164
/*
21652165
* Map blocks using the previous result first.
21662166
*/
2167-
if ((map->m_flags & F2FS_MAP_MAPPED) &&
2168-
block_in_file > map->m_lblk &&
2167+
if (map->m_flags & F2FS_MAP_MAPPED) {
2168+
if (block_in_file > map->m_lblk &&
21692169
block_in_file < (map->m_lblk + map->m_len))
2170+
goto got_it;
2171+
} else if (block_in_file < *map->m_next_pgofs) {
21702172
goto got_it;
2173+
}
21712174

21722175
/*
21732176
* Then do more f2fs_map_blocks() calls until we are
@@ -2442,7 +2445,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
24422445
struct bio *bio = NULL;
24432446
sector_t last_block_in_bio = 0;
24442447
struct f2fs_map_blocks map = {0, };
2445-
pgoff_t index, offset;
2448+
pgoff_t index, offset, next_pgofs = 0;
24462449
unsigned max_nr_pages = rac ? readahead_count(rac) :
24472450
folio_nr_pages(folio);
24482451
unsigned nrpages;
@@ -2475,16 +2478,21 @@ static int f2fs_read_data_large_folio(struct inode *inode,
24752478
/*
24762479
* Map blocks using the previous result first.
24772480
*/
2478-
if ((map.m_flags & F2FS_MAP_MAPPED) &&
2479-
index > map.m_lblk &&
2481+
if (map.m_flags & F2FS_MAP_MAPPED) {
2482+
if (index > map.m_lblk &&
24802483
index < (map.m_lblk + map.m_len))
2484+
goto got_it;
2485+
} else if (index < next_pgofs) {
2486+
/* hole case */
24812487
goto got_it;
2488+
}
24822489

24832490
/*
24842491
* Then do more f2fs_map_blocks() calls until we are
24852492
* done with this page.
24862493
*/
24872494
memset(&map, 0, sizeof(map));
2495+
map.m_next_pgofs = &next_pgofs;
24882496
map.m_seg_type = NO_CHECK_TYPE;
24892497
map.m_lblk = index;
24902498
map.m_len = max_nr_pages;
@@ -2611,6 +2619,7 @@ static int f2fs_mpage_readpages(struct inode *inode,
26112619
pgoff_t nc_cluster_idx = NULL_CLUSTER;
26122620
pgoff_t index;
26132621
#endif
2622+
pgoff_t next_pgofs = 0;
26142623
unsigned nr_pages = rac ? readahead_count(rac) : 1;
26152624
struct address_space *mapping = rac ? rac->mapping : folio->mapping;
26162625
unsigned max_nr_pages = nr_pages;
@@ -2631,7 +2640,7 @@ static int f2fs_mpage_readpages(struct inode *inode,
26312640
map.m_lblk = 0;
26322641
map.m_len = 0;
26332642
map.m_flags = 0;
2634-
map.m_next_pgofs = NULL;
2643+
map.m_next_pgofs = &next_pgofs;
26352644
map.m_next_extent = NULL;
26362645
map.m_seg_type = NO_CHECK_TYPE;
26372646
map.m_may_create = false;

0 commit comments

Comments
 (0)