Skip to content

Commit 70ef8f0

Browse files
committed
Merge tag 'for-f2fs-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "In this round, we've focused on enhancing performance with regards to block allocation, GC, and discard/in-place-update IO controls. There are a bunch of clean-ups as well as minor bug fixes. Enhancements: - disable heap-based allocation by default - issue small-sized discard commands by default - change the policy of data hotness for logging - distinguish IOs in terms of size and wbc type - start SSR earlier to avoid foreground GC - enhance data structures managing discard commands - enhance in-place update flow - add some more fault injection routines - secure one more xattr entry Bug fixes: - calculate victim cost for GC correctly - remain correct victim segment number for GC - race condition in nid allocator and initializer - stale pointer produced by atomic_writes - fix missing REQ_SYNC for flush commands - handle missing errors in more corner cases" * tag 'for-f2fs-4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (111 commits) f2fs: fix a mount fail for wrong next_scan_nid f2fs: enhance scalability of trace macro f2fs: relocate inode_{,un}lock in F2FS_IOC_SETFLAGS f2fs: Make flush bios explicitely sync f2fs: show available_nids in f2fs/status f2fs: flush dirty nats periodically f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard f2fs: allow cpc->reason to indicate more than one reason f2fs: release cp and dnode lock before IPU f2fs: shrink size of struct discard_cmd f2fs: don't hold cmd_lock during waiting discard command f2fs: nullify fio->encrypted_page for each writes f2fs: sanity check segment count f2fs: introduce valid_ipu_blkaddr to clean up f2fs: lookup extent cache first under IPU scenario f2fs: reconstruct code to write a data page f2fs: introduce __wait_discard_cmd f2fs: introduce __issue_discard_cmd f2fs: enable small discard by default f2fs: delay awaking discard thread ...
2 parents 677375c + e9cdd30 commit 70ef8f0

22 files changed

Lines changed: 1747 additions & 928 deletions

File tree

‎fs/f2fs/checkpoint.c‎

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
275275
get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META))
276276
goto skip_write;
277277

278-
trace_f2fs_writepages(mapping->host, wbc, META);
278+
/* if locked failed, cp will flush dirty pages instead */
279+
if (!mutex_trylock(&sbi->cp_mutex))
280+
goto skip_write;
279281

280-
/* if mounting is failed, skip writing node pages */
281-
mutex_lock(&sbi->cp_mutex);
282+
trace_f2fs_writepages(mapping->host, wbc, META);
282283
diff = nr_pages_to_write(sbi, META, wbc);
283284
written = sync_meta_pages(sbi, META, wbc->nr_to_write);
284285
mutex_unlock(&sbi->cp_mutex);
@@ -567,7 +568,7 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
567568
if (ni.blk_addr != NULL_ADDR) {
568569
set_sbi_flag(sbi, SBI_NEED_FSCK);
569570
f2fs_msg(sbi->sb, KERN_WARNING,
570-
"%s: orphan failed (ino=%x), run fsck to fix.",
571+
"%s: orphan failed (ino=%x) by kernel, retry mount.",
571572
__func__, ino);
572573
return -EIO;
573574
}
@@ -677,7 +678,7 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
677678
*cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
678679

679680
crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
680-
if (crc_offset >= blk_size) {
681+
if (crc_offset > (blk_size - sizeof(__le32))) {
681682
f2fs_msg(sbi->sb, KERN_WARNING,
682683
"invalid crc_offset: %zu", crc_offset);
683684
return -EINVAL;
@@ -816,7 +817,9 @@ static void __add_dirty_inode(struct inode *inode, enum inode_type type)
816817
return;
817818

818819
set_inode_flag(inode, flag);
819-
list_add_tail(&F2FS_I(inode)->dirty_list, &sbi->inode_list[type]);
820+
if (!f2fs_is_volatile_file(inode))
821+
list_add_tail(&F2FS_I(inode)->dirty_list,
822+
&sbi->inode_list[type]);
820823
stat_inc_dirty_inode(sbi, type);
821824
}
822825

@@ -941,6 +944,19 @@ int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
941944
return 0;
942945
}
943946

947+
static void __prepare_cp_block(struct f2fs_sb_info *sbi)
948+
{
949+
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
950+
struct f2fs_nm_info *nm_i = NM_I(sbi);
951+
nid_t last_nid = nm_i->next_scan_nid;
952+
953+
next_free_nid(sbi, &last_nid);
954+
ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
955+
ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
956+
ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
957+
ckpt->next_free_nid = cpu_to_le32(last_nid);
958+
}
959+
944960
/*
945961
* Freeze all the FS-operations for checkpoint.
946962
*/
@@ -964,33 +980,47 @@ static int block_operations(struct f2fs_sb_info *sbi)
964980
err = sync_dirty_inodes(sbi, DIR_INODE);
965981
if (err)
966982
goto out;
983+
cond_resched();
967984
goto retry_flush_dents;
968985
}
969986

987+
/*
988+
* POR: we should ensure that there are no dirty node pages
989+
* until finishing nat/sit flush. inode->i_blocks can be updated.
990+
*/
991+
down_write(&sbi->node_change);
992+
970993
if (get_pages(sbi, F2FS_DIRTY_IMETA)) {
994+
up_write(&sbi->node_change);
971995
f2fs_unlock_all(sbi);
972996
err = f2fs_sync_inode_meta(sbi);
973997
if (err)
974998
goto out;
999+
cond_resched();
9751000
goto retry_flush_dents;
9761001
}
9771002

978-
/*
979-
* POR: we should ensure that there are no dirty node pages
980-
* until finishing nat/sit flush.
981-
*/
9821003
retry_flush_nodes:
9831004
down_write(&sbi->node_write);
9841005

9851006
if (get_pages(sbi, F2FS_DIRTY_NODES)) {
9861007
up_write(&sbi->node_write);
9871008
err = sync_node_pages(sbi, &wbc);
9881009
if (err) {
1010+
up_write(&sbi->node_change);
9891011
f2fs_unlock_all(sbi);
9901012
goto out;
9911013
}
1014+
cond_resched();
9921015
goto retry_flush_nodes;
9931016
}
1017+
1018+
/*
1019+
* sbi->node_change is used only for AIO write_begin path which produces
1020+
* dirty node blocks and some checkpoint values by block allocation.
1021+
*/
1022+
__prepare_cp_block(sbi);
1023+
up_write(&sbi->node_change);
9941024
out:
9951025
blk_finish_plug(&plug);
9961026
return err;
@@ -1024,16 +1054,20 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
10241054

10251055
spin_lock(&sbi->cp_lock);
10261056

1027-
if (cpc->reason == CP_UMOUNT && ckpt->cp_pack_total_block_count >
1057+
if ((cpc->reason & CP_UMOUNT) &&
1058+
le32_to_cpu(ckpt->cp_pack_total_block_count) >
10281059
sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
10291060
disable_nat_bits(sbi, false);
10301061

1031-
if (cpc->reason == CP_UMOUNT)
1062+
if (cpc->reason & CP_TRIMMED)
1063+
__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
1064+
1065+
if (cpc->reason & CP_UMOUNT)
10321066
__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
10331067
else
10341068
__clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
10351069

1036-
if (cpc->reason == CP_FASTBOOT)
1070+
if (cpc->reason & CP_FASTBOOT)
10371071
__set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
10381072
else
10391073
__clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
@@ -1057,7 +1091,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
10571091
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
10581092
struct f2fs_nm_info *nm_i = NM_I(sbi);
10591093
unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num;
1060-
nid_t last_nid = nm_i->next_scan_nid;
10611094
block_t start_blk;
10621095
unsigned int data_sum_blocks, orphan_blocks;
10631096
__u32 crc32 = 0;
@@ -1074,14 +1107,11 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
10741107
return -EIO;
10751108
}
10761109

1077-
next_free_nid(sbi, &last_nid);
1078-
10791110
/*
10801111
* modify checkpoint
10811112
* version number is already updated
10821113
*/
10831114
ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi));
1084-
ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
10851115
ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
10861116
for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
10871117
ckpt->cur_node_segno[i] =
@@ -1100,10 +1130,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
11001130
curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
11011131
}
11021132

1103-
ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
1104-
ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
1105-
ckpt->next_free_nid = cpu_to_le32(last_nid);
1106-
11071133
/* 2 cp + n data seg summary + orphan inode blocks */
11081134
data_sum_blocks = npages_for_summary_flush(sbi, false);
11091135
spin_lock(&sbi->cp_lock);
@@ -1143,7 +1169,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
11431169
/* write nat bits */
11441170
if (enabled_nat_bits(sbi, cpc)) {
11451171
__u64 cp_ver = cur_cp_version(ckpt);
1146-
unsigned int i;
11471172
block_t blk;
11481173

11491174
cp_ver |= ((__u64)crc32 << 32);
@@ -1250,8 +1275,8 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
12501275
mutex_lock(&sbi->cp_mutex);
12511276

12521277
if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
1253-
(cpc->reason == CP_FASTBOOT || cpc->reason == CP_SYNC ||
1254-
(cpc->reason == CP_DISCARD && !sbi->discard_blks)))
1278+
((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
1279+
((cpc->reason & CP_DISCARD) && !sbi->discard_blks)))
12551280
goto out;
12561281
if (unlikely(f2fs_cp_error(sbi))) {
12571282
err = -EIO;
@@ -1273,7 +1298,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
12731298
f2fs_flush_merged_bios(sbi);
12741299

12751300
/* this is the case of multiple fstrims without any changes */
1276-
if (cpc->reason == CP_DISCARD) {
1301+
if (cpc->reason & CP_DISCARD) {
12771302
if (!exist_trim_candidates(sbi, cpc)) {
12781303
unblock_operations(sbi);
12791304
goto out;
@@ -1311,7 +1336,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
13111336
unblock_operations(sbi);
13121337
stat_inc_cp_count(sbi->stat_info);
13131338

1314-
if (cpc->reason == CP_RECOVERY)
1339+
if (cpc->reason & CP_RECOVERY)
13151340
f2fs_msg(sbi->sb, KERN_NOTICE,
13161341
"checkpoint: version = %llx", ckpt_ver);
13171342

0 commit comments

Comments
 (0)