Skip to content

Commit b368cc5

Browse files
Fengnan ChangJaegeuk Kim
authored andcommitted
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: Fengnan Chang <[email protected]> Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 71f2c82 commit b368cc5

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

fs/f2fs/compress.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,25 @@ bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index)
881881
return is_page_in_cluster(cc, index);
882882
}
883883

884+
bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
885+
int index, int nr_pages)
886+
{
887+
unsigned long pgidx;
888+
int i;
889+
890+
if (nr_pages - index < cc->cluster_size)
891+
return false;
892+
893+
pgidx = pvec->pages[index]->index;
894+
895+
for (i = 1; i < cc->cluster_size; i++) {
896+
if (pvec->pages[index + i]->index != pgidx + i)
897+
return false;
898+
}
899+
900+
return true;
901+
}
902+
884903
static bool cluster_has_invalid_data(struct compress_ctx *cc)
885904
{
886905
loff_t i_size = i_size_read(cc->inode);

fs/f2fs/data.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,10 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
30403040
need_readd = false;
30413041
#ifdef CONFIG_F2FS_FS_COMPRESSION
30423042
if (f2fs_compressed_file(inode)) {
3043+
void *fsdata = NULL;
3044+
struct page *pagep;
3045+
int ret2;
3046+
30433047
ret = f2fs_init_compress_ctx(&cc);
30443048
if (ret) {
30453049
done = 1;
@@ -3058,27 +3062,23 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
30583062
if (unlikely(f2fs_cp_error(sbi)))
30593063
goto lock_page;
30603064

3061-
if (f2fs_cluster_is_empty(&cc)) {
3062-
void *fsdata = NULL;
3063-
struct page *pagep;
3064-
int ret2;
3065+
if (!f2fs_cluster_is_empty(&cc))
3066+
goto lock_page;
30653067

3066-
ret2 = f2fs_prepare_compress_overwrite(
3068+
ret2 = f2fs_prepare_compress_overwrite(
30673069
inode, &pagep,
30683070
page->index, &fsdata);
3069-
if (ret2 < 0) {
3070-
ret = ret2;
3071-
done = 1;
3072-
break;
3073-
} else if (ret2 &&
3074-
!f2fs_compress_write_end(inode,
3075-
fsdata, page->index,
3076-
1)) {
3077-
retry = 1;
3078-
break;
3079-
}
3080-
} else {
3081-
goto lock_page;
3071+
if (ret2 < 0) {
3072+
ret = ret2;
3073+
done = 1;
3074+
break;
3075+
} else if (ret2 &&
3076+
(!f2fs_compress_write_end(inode,
3077+
fsdata, page->index, 1) ||
3078+
!f2fs_all_cluster_page_loaded(&cc,
3079+
&pvec, i, nr_pages))) {
3080+
retry = 1;
3081+
break;
30823082
}
30833083
}
30843084
#endif

fs/f2fs/f2fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,6 +4052,8 @@ void f2fs_end_read_compressed_page(struct page *page, bool failed,
40524052
block_t blkaddr);
40534053
bool f2fs_cluster_is_empty(struct compress_ctx *cc);
40544054
bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
4055+
bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec,
4056+
int index, int nr_pages);
40554057
bool f2fs_sanity_check_cluster(struct dnode_of_data *dn);
40564058
void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
40574059
int f2fs_write_multi_pages(struct compress_ctx *cc,

0 commit comments

Comments
 (0)