Commit b368cc5e authored by Fengnan Chang's avatar Fengnan Chang Committed by Jaegeuk Kim

f2fs: compress: fix overwrite may reduce compress ratio unproperly

when overwrite only first block of cluster, since cluster is not full, it
will call f2fs_write_raw_pages when f2fs_write_multi_pages, and cause the
whole cluster become uncompressed eventhough data can be compressed.
this may will make random write bench score reduce a lot.

root# dd if=/dev/zero of=./fio-test bs=1M count=1

root# sync

root# echo 3 > /proc/sys/vm/drop_caches

root# f2fs_io get_cblocks ./fio-test

root# dd if=/dev/zero of=./fio-test bs=4K count=1 oflag=direct conv=notrunc

w/o patch:
root# f2fs_io get_cblocks ./fio-test
189

w/ patch:
root# f2fs_io get_cblocks ./fio-test
192
Signed-off-by: default avatarFengnan Chang <changfengnan@vivo.com>
Signed-off-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 71f2c820
...@@ -881,6 +881,25 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index) ...@@ -881,6 +881,25 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index)
return is_page_in_cluster(cc, index); return is_page_in_cluster(cc, index);
} }
bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
int index, int nr_pages)
{
unsigned long pgidx;
int i;
if (nr_pages - index < cc->cluster_size)
return false;
pgidx = pvec->pages[index]->index;
for (i = 1; i < cc->cluster_size; i++) {
if (pvec->pages[index + i]->index != pgidx + i)
return false;
}
return true;
}
static bool cluster_has_invalid_data(struct compress_ctx *cc) static bool cluster_has_invalid_data(struct compress_ctx *cc)
{ {
loff_t i_size = i_size_read(cc->inode); loff_t i_size = i_size_read(cc->inode);
......
...@@ -3040,6 +3040,10 @@ static int f2fs_write_cache_pages(struct address_space *mapping, ...@@ -3040,6 +3040,10 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
need_readd = false; need_readd = false;
#ifdef CONFIG_F2FS_FS_COMPRESSION #ifdef CONFIG_F2FS_FS_COMPRESSION
if (f2fs_compressed_file(inode)) { if (f2fs_compressed_file(inode)) {
void *fsdata = NULL;
struct page *pagep;
int ret2;
ret = f2fs_init_compress_ctx(&cc); ret = f2fs_init_compress_ctx(&cc);
if (ret) { if (ret) {
done = 1; done = 1;
...@@ -3058,27 +3062,23 @@ static int f2fs_write_cache_pages(struct address_space *mapping, ...@@ -3058,27 +3062,23 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
if (unlikely(f2fs_cp_error(sbi))) if (unlikely(f2fs_cp_error(sbi)))
goto lock_page; goto lock_page;
if (f2fs_cluster_is_empty(&cc)) { if (!f2fs_cluster_is_empty(&cc))
void *fsdata = NULL; goto lock_page;
struct page *pagep;
int ret2;
ret2 = f2fs_prepare_compress_overwrite( ret2 = f2fs_prepare_compress_overwrite(
inode, &pagep, inode, &pagep,
page->index, &fsdata); page->index, &fsdata);
if (ret2 < 0) { if (ret2 < 0) {
ret = ret2; ret = ret2;
done = 1; done = 1;
break; break;
} else if (ret2 && } else if (ret2 &&
!f2fs_compress_write_end(inode, (!f2fs_compress_write_end(inode,
fsdata, page->index, fsdata, page->index, 1) ||
1)) { !f2fs_all_cluster_page_loaded(&cc,
retry = 1; &pvec, i, nr_pages))) {
break; retry = 1;
} break;
} else {
goto lock_page;
} }
} }
#endif #endif
......
...@@ -4052,6 +4052,8 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed, ...@@ -4052,6 +4052,8 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed,
block_t blkaddr); block_t blkaddr);
bool f2fs_cluster_is_empty(struct compress_ctx *cc); bool f2fs_cluster_is_empty(struct compress_ctx *cc);
bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 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,
int index, int nr_pages);
bool f2fs_sanity_check_cluster(struct dnode_of_data *dn); bool f2fs_sanity_check_cluster(struct dnode_of_data *dn);
void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
int f2fs_write_multi_pages(struct compress_ctx *cc, int f2fs_write_multi_pages(struct compress_ctx *cc,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment