Since pvec have 15 pages, it not a multiple of 4, when write compressed pages, write in 64K as a unit, it will call pagevec_lookup_range_tag agagin, sometimes this will take a lot of time. Use onstack pages instead of pvec to mitigate this problem.
Signed-off-by: Fengnan Chang <[email protected]> --- fs/f2fs/compress.c | 14 +++++++------- fs/f2fs/data.c | 16 +++++++--------- fs/f2fs/f2fs.h | 5 +++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 11499fd3dd6b..bebaae51863a 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -871,13 +871,13 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index) return is_page_in_cluster(cc, index); } -bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec, +bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct page **pages, int index, int nr_pages) { unsigned long pgidx; int i; - pgidx = pvec->pages[index]->index; + pgidx = pages[index]->index; if (pgidx % cc->cluster_size) return false; @@ -885,15 +885,15 @@ bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pve return false; for (i = 0; i < cc->cluster_size; i++) { - if (pvec->pages[index + i]->index != pgidx + i) + if (pages[index + i]->index != pgidx + i) return false; - if (!PageUptodate(pvec->pages[index + i])) + if (!PageUptodate(pages[index + i])) return false; } return true; } -bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec, +bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct page **pages, int index, int nr_pages) { unsigned long pgidx; @@ -902,9 +902,9 @@ bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec, if (nr_pages - index < cc->cluster_size) return false; - pgidx = pvec->pages[index]->index; + pgidx = pages[index]->index; for (i = 1; i < cc->cluster_size; i++) { - if (pvec->pages[index + i]->index != pgidx + i) + if (pages[index + i]->index != pgidx + i) return false; } diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b8204d91fed4..dd9a97f6900c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2872,7 +2872,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping, { int ret = 0; int done = 0, retry = 0; - struct pagevec pvec; + struct page *pages[F2FS_ONSTACK_PAGES]; struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); struct bio *bio = NULL; sector_t last_block; @@ -2903,8 +2903,6 @@ static int f2fs_write_cache_pages(struct address_space *mapping, int submitted = 0; int i; - pagevec_init(&pvec); - if (get_dirty_pages(mapping->host) <= SM_I(F2FS_M_SB(mapping))->min_hot_blocks) set_inode_flag(mapping->host, FI_HOT_DATA); @@ -2930,13 +2928,13 @@ static int f2fs_write_cache_pages(struct address_space *mapping, tag_pages_for_writeback(mapping, index, end); done_index = index; while (!done && !retry && (index <= end)) { - nr_pages = pagevec_lookup_range_tag(&pvec, mapping, &index, end, - tag); + nr_pages = find_get_pages_range_tag(mapping, &index, end, + tag, F2FS_ONSTACK_PAGES, pages); if (nr_pages == 0) break; for (i = 0; i < nr_pages; i++) { - struct page *page = pvec.pages[i]; + struct page *page = pages[i]; bool need_readd; readd: need_readd = false; @@ -2968,7 +2966,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping, goto lock_page; if (f2fs_all_cluster_page_uptodate(&cc, - &pvec, i, nr_pages)) { + pages, i, nr_pages)) { goto lock_page; } @@ -2983,7 +2981,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping, (!f2fs_compress_write_end(inode, fsdata, page->index, 1) || !f2fs_all_cluster_page_loaded(&cc, - &pvec, i, nr_pages))) { + pages, i, nr_pages))) { retry = 1; break; } @@ -3073,7 +3071,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping, if (need_readd) goto readd; } - pagevec_release(&pvec); + release_pages(pages, nr_pages); cond_resched(); } #ifdef CONFIG_F2FS_FS_COMPRESSION diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index b4bed1e983bb..4b005d7f326a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -597,6 +597,7 @@ enum { #define RECOVERY_MAX_RA_BLOCKS BIO_MAX_VECS #define RECOVERY_MIN_RA_BLOCKS 1 +#define F2FS_ONSTACK_PAGES 16 /* nr of onstack pages */ struct rb_entry { struct rb_node rb_node; /* rb node located in rb-tree */ union { @@ -4177,10 +4178,10 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed, block_t blkaddr); bool f2fs_cluster_is_empty(struct compress_ctx *cc); bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); -bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec, +bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct page **pages, int index, int nr_pages); bool f2fs_sanity_check_cluster(struct dnode_of_data *dn); -bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct pagevec *pvec, +bool f2fs_all_cluster_page_uptodate(struct compress_ctx *cc, struct page **pages, int index, int nr_pages); void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); int f2fs_write_multi_pages(struct compress_ctx *cc, -- 2.32.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
