Skip to content

Commit 086ba2e

Browse files
committed
Merge tag 'f2fs-for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "In this round, we've added two small interfaces: (a) GC_URGENT_LOW mode for performance and (b) F2FS_IOC_SEC_TRIM_FILE ioctl for security. The new GC mode allows Android to run some lower priority GCs in background, while new ioctl discards user information without race condition when the account is removed. In addition, some patches were merged to address latency-related issues. We've fixed some compression-related bug fixes as well as edge race conditions. Enhancements: - add GC_URGENT_LOW mode in gc_urgent - introduce F2FS_IOC_SEC_TRIM_FILE ioctl - bypass racy readahead to improve read latencies - shrink node_write lock coverage to avoid long latency Bug fixes: - fix missing compression flag control, i_size, and mount option - fix deadlock between quota writes and checkpoint - remove inode eviction path in synchronous path to avoid deadlock - fix to wait GCed compressed page writeback - fix a kernel panic in f2fs_is_compressed_page - check page dirty status before writeback - wait page writeback before update in node page write flow - fix a race condition between f2fs_write_end_io and f2fs_del_fsync_node_entry We've added some minor sanity checks and refactored trivial code blocks for better readability and debugging information" * tag 'f2fs-for-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (52 commits) f2fs: prepare a waiter before entering io_schedule f2fs: update_sit_entry: Make the judgment condition of f2fs_bug_on more intuitive f2fs: replace test_and_set/clear_bit() with set/clear_bit() f2fs: make file immutable even if releasing zero compression block f2fs: compress: disable compression mount option if compression is off f2fs: compress: add sanity check during compressed cluster read f2fs: use macro instead of f2fs verity version f2fs: fix deadlock between quota writes and checkpoint f2fs: correct comment of f2fs_exist_written_data f2fs: compress: delay temp page allocation f2fs: compress: fix to update isize when overwriting compressed file f2fs: space related cleanup f2fs: fix use-after-free issue f2fs: Change the type of f2fs_flush_inline_data() to void f2fs: add F2FS_IOC_SEC_TRIM_FILE ioctl f2fs: should avoid inode eviction in synchronous path f2fs: segment.h: delete a duplicated word f2fs: compress: fix to avoid memory leak on cc->cpages f2fs: use generic names for generic ioctls f2fs: don't keep meta inode pages used for compressed block migration ...
2 parents 8c2618a + 828add7 commit 086ba2e

File tree

23 files changed

+815
-292
lines changed

23 files changed

+815
-292
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ Date: August 2017
229229
Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
230230
Description: Do background GC agressively when set. When gc_urgent = 1,
231231
background thread starts to do GC by given gc_urgent_sleep_time
232-
interval. It is set to 0 by default.
232+
interval. When gc_urgent = 2, F2FS will lower the bar of
233+
checking idle in order to process outstanding discard commands
234+
and GC a little bit aggressively. It is set to 0 by default.
233235

234236
What: /sys/fs/f2fs/<disk>/gc_urgent_sleep_time
235237
Date: August 2017

Documentation/filesystems/f2fs.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ compress_extension=%s Support adding specified extension, so that f2fs can enab
258258
on compression extension list and enable compression on
259259
these file by default rather than to enable it via ioctl.
260260
For other files, we can still enable compression via ioctl.
261+
Note that, there is one reserved special extension '*', it
262+
can be set to enable compression for all files.
261263
inlinecrypt When possible, encrypt/decrypt the contents of encrypted
262264
files using the blk-crypto framework rather than
263265
filesystem-layer encryption. This allows the use of
@@ -743,8 +745,8 @@ Compression implementation
743745

744746
- In order to eliminate write amplification during overwrite, F2FS only
745747
support compression on write-once file, data can be compressed only when
746-
all logical blocks in file are valid and cluster compress ratio is lower
747-
than specified threshold.
748+
all logical blocks in cluster contain valid data and compress ratio of
749+
cluster data is lower than specified threshold.
748750

749751
- To enable compression on regular inode, there are three ways:
750752

fs/f2fs/checkpoint.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
523523
__remove_ino_entry(sbi, ino, type);
524524
}
525525

526-
/* mode should be APPEND_INO or UPDATE_INO */
526+
/* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */
527527
bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
528528
{
529529
struct inode_management *im = &sbi->im[mode];
@@ -1258,8 +1258,6 @@ void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
12581258
DEFINE_WAIT(wait);
12591259

12601260
for (;;) {
1261-
prepare_to_wait(&sbi->cp_wait, &wait, TASK_UNINTERRUPTIBLE);
1262-
12631261
if (!get_pages(sbi, type))
12641262
break;
12651263

@@ -1269,6 +1267,10 @@ void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
12691267
if (type == F2FS_DIRTY_META)
12701268
f2fs_sync_meta_pages(sbi, META, LONG_MAX,
12711269
FS_CP_META_IO);
1270+
else if (type == F2FS_WB_CP_DATA)
1271+
f2fs_submit_merged_write(sbi, DATA);
1272+
1273+
prepare_to_wait(&sbi->cp_wait, &wait, TASK_UNINTERRUPTIBLE);
12721274
io_schedule_timeout(DEFAULT_IO_TIMEOUT);
12731275
}
12741276
finish_wait(&sbi->cp_wait, &wait);
@@ -1415,7 +1417,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
14151417
curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
14161418
}
14171419

1418-
/* 2 cp + n data seg summary + orphan inode blocks */
1420+
/* 2 cp + n data seg summary + orphan inode blocks */
14191421
data_sum_blocks = f2fs_npages_for_summary_flush(sbi, false);
14201422
spin_lock_irqsave(&sbi->cp_lock, flags);
14211423
if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
@@ -1515,9 +1517,10 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
15151517

15161518
/*
15171519
* invalidate intermediate page cache borrowed from meta inode which are
1518-
* used for migration of encrypted or verity inode's blocks.
1520+
* used for migration of encrypted, verity or compressed inode's blocks.
15191521
*/
1520-
if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi))
1522+
if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi) ||
1523+
f2fs_sb_has_compression(sbi))
15211524
invalidate_mapping_pages(META_MAPPING(sbi),
15221525
MAIN_BLKADDR(sbi), MAX_BLKADDR(sbi) - 1);
15231526

fs/f2fs/compress.c

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ bool f2fs_is_compressed_page(struct page *page)
4949
return false;
5050
if (IS_ATOMIC_WRITTEN_PAGE(page) || IS_DUMMY_WRITTEN_PAGE(page))
5151
return false;
52+
/*
53+
* page->private may be set with pid.
54+
* pid_max is enough to check if it is traced.
55+
*/
56+
if (IS_IO_TRACED_PAGE(page))
57+
return false;
58+
5259
f2fs_bug_on(F2FS_M_SB(page->mapping),
5360
*((u32 *)page_private(page)) != F2FS_COMPRESSED_PAGE_MAGIC);
5461
return true;
@@ -506,7 +513,7 @@ bool f2fs_is_compress_backend_ready(struct inode *inode)
506513
return f2fs_cops[F2FS_I(inode)->i_compress_algorithm];
507514
}
508515

509-
static mempool_t *compress_page_pool = NULL;
516+
static mempool_t *compress_page_pool;
510517
static int num_compress_pages = 512;
511518
module_param(num_compress_pages, uint, 0444);
512519
MODULE_PARM_DESC(num_compress_pages,
@@ -663,6 +670,7 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity)
663670
const struct f2fs_compress_ops *cops =
664671
f2fs_cops[fi->i_compress_algorithm];
665672
int ret;
673+
int i;
666674

667675
dec_page_count(sbi, F2FS_RD_DATA);
668676

@@ -681,6 +689,26 @@ void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity)
681689
goto out_free_dic;
682690
}
683691

692+
dic->tpages = f2fs_kzalloc(sbi, sizeof(struct page *) *
693+
dic->cluster_size, GFP_NOFS);
694+
if (!dic->tpages) {
695+
ret = -ENOMEM;
696+
goto out_free_dic;
697+
}
698+
699+
for (i = 0; i < dic->cluster_size; i++) {
700+
if (dic->rpages[i]) {
701+
dic->tpages[i] = dic->rpages[i];
702+
continue;
703+
}
704+
705+
dic->tpages[i] = f2fs_compress_alloc_page();
706+
if (!dic->tpages[i]) {
707+
ret = -ENOMEM;
708+
goto out_free_dic;
709+
}
710+
}
711+
684712
if (cops->init_decompress_ctx) {
685713
ret = cops->init_decompress_ctx(dic);
686714
if (ret)
@@ -821,7 +849,7 @@ static int f2fs_compressed_blocks(struct compress_ctx *cc)
821849
}
822850

823851
/* return # of valid blocks in compressed cluster */
824-
static int f2fs_cluster_blocks(struct compress_ctx *cc, bool compr)
852+
static int f2fs_cluster_blocks(struct compress_ctx *cc)
825853
{
826854
return __f2fs_cluster_blocks(cc, false);
827855
}
@@ -835,7 +863,7 @@ int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index)
835863
.cluster_idx = index >> F2FS_I(inode)->i_log_cluster_size,
836864
};
837865

838-
return f2fs_cluster_blocks(&cc, false);
866+
return f2fs_cluster_blocks(&cc);
839867
}
840868

841869
static bool cluster_may_compress(struct compress_ctx *cc)
@@ -886,7 +914,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
886914
bool prealloc;
887915

888916
retry:
889-
ret = f2fs_cluster_blocks(cc, false);
917+
ret = f2fs_cluster_blocks(cc);
890918
if (ret <= 0)
891919
return ret;
892920

@@ -949,7 +977,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
949977
}
950978

951979
if (prealloc) {
952-
__do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true);
980+
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true);
953981

954982
set_new_dnode(&dn, cc->inode, NULL, NULL, 0);
955983

@@ -964,7 +992,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
964992
break;
965993
}
966994

967-
__do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false);
995+
f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false);
968996
}
969997

970998
if (likely(!ret)) {
@@ -1096,8 +1124,16 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
10961124
loff_t psize;
10971125
int i, err;
10981126

1099-
if (!IS_NOQUOTA(inode) && !f2fs_trylock_op(sbi))
1127+
if (IS_NOQUOTA(inode)) {
1128+
/*
1129+
* We need to wait for node_write to avoid block allocation during
1130+
* checkpoint. This can only happen to quota writes which can cause
1131+
* the below discard race condition.
1132+
*/
1133+
down_read(&sbi->node_write);
1134+
} else if (!f2fs_trylock_op(sbi)) {
11001135
return -EAGAIN;
1136+
}
11011137

11021138
set_new_dnode(&dn, cc->inode, NULL, NULL, 0);
11031139

@@ -1137,6 +1173,13 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
11371173
f2fs_set_compressed_page(cc->cpages[i], inode,
11381174
cc->rpages[i + 1]->index, cic);
11391175
fio.compressed_page = cc->cpages[i];
1176+
1177+
fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_page,
1178+
dn.ofs_in_node + i + 1);
1179+
1180+
/* wait for GCed page writeback via META_MAPPING */
1181+
f2fs_wait_on_block_writeback(inode, fio.old_blkaddr);
1182+
11401183
if (fio.encrypted) {
11411184
fio.page = cc->rpages[i + 1];
11421185
err = f2fs_encrypt_one_page(&fio);
@@ -1203,7 +1246,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
12031246
set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN);
12041247

12051248
f2fs_put_dnode(&dn);
1206-
if (!IS_NOQUOTA(inode))
1249+
if (IS_NOQUOTA(inode))
1250+
up_read(&sbi->node_write);
1251+
else
12071252
f2fs_unlock_op(sbi);
12081253

12091254
spin_lock(&fi->i_size_lock);
@@ -1230,7 +1275,9 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
12301275
out_put_dnode:
12311276
f2fs_put_dnode(&dn);
12321277
out_unlock_op:
1233-
if (!IS_NOQUOTA(inode))
1278+
if (IS_NOQUOTA(inode))
1279+
up_read(&sbi->node_write);
1280+
else
12341281
f2fs_unlock_op(sbi);
12351282
return -EAGAIN;
12361283
}
@@ -1310,6 +1357,12 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
13101357
congestion_wait(BLK_RW_ASYNC,
13111358
DEFAULT_IO_TIMEOUT);
13121359
lock_page(cc->rpages[i]);
1360+
1361+
if (!PageDirty(cc->rpages[i])) {
1362+
unlock_page(cc->rpages[i]);
1363+
continue;
1364+
}
1365+
13131366
clear_page_dirty_for_io(cc->rpages[i]);
13141367
goto retry_write;
13151368
}
@@ -1353,6 +1406,8 @@ int f2fs_write_multi_pages(struct compress_ctx *cc,
13531406
err = f2fs_write_compressed_pages(cc, submitted,
13541407
wbc, io_type);
13551408
cops->destroy_compress_ctx(cc);
1409+
kfree(cc->cpages);
1410+
cc->cpages = NULL;
13561411
if (!err)
13571412
return 0;
13581413
f2fs_bug_on(F2FS_I_SB(cc->inode), err != -EAGAIN);
@@ -1415,22 +1470,6 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc)
14151470
dic->cpages[i] = page;
14161471
}
14171472

1418-
dic->tpages = f2fs_kzalloc(sbi, sizeof(struct page *) *
1419-
dic->cluster_size, GFP_NOFS);
1420-
if (!dic->tpages)
1421-
goto out_free;
1422-
1423-
for (i = 0; i < dic->cluster_size; i++) {
1424-
if (cc->rpages[i]) {
1425-
dic->tpages[i] = cc->rpages[i];
1426-
continue;
1427-
}
1428-
1429-
dic->tpages[i] = f2fs_compress_alloc_page();
1430-
if (!dic->tpages[i])
1431-
goto out_free;
1432-
}
1433-
14341473
return dic;
14351474

14361475
out_free:

0 commit comments

Comments
 (0)