Skip to content

Commit a9419b6

Browse files
author
Jaegeuk Kim
committed
f2fs: do not bother checkpoint by f2fs_get_node_info
This patch tries to mitigate lock contention between f2fs_write_checkpoint and f2fs_get_node_info along with nat_tree_lock. The idea is, if checkpoint is currently running, other threads that try to grab nat_tree_lock would be better to wait for checkpoint. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 0df035c commit a9419b6

File tree

11 files changed

+26
-25
lines changed

11 files changed

+26
-25
lines changed

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
664664
/* truncate all the data during iput */
665665
iput(inode);
666666

667-
err = f2fs_get_node_info(sbi, ino, &ni);
667+
err = f2fs_get_node_info(sbi, ino, &ni, false);
668668
if (err)
669669
goto err_out;
670670

fs/f2fs/compress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
12861286

12871287
psize = (loff_t)(cc->rpages[last_index]->index + 1) << PAGE_SHIFT;
12881288

1289-
err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
1289+
err = f2fs_get_node_info(fio.sbi, dn.nid, &ni, false);
12901290
if (err)
12911291
goto out_put_dnode;
12921292

fs/f2fs/data.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
13551355
if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC)))
13561356
return -EPERM;
13571357

1358-
err = f2fs_get_node_info(sbi, dn->nid, &ni);
1358+
err = f2fs_get_node_info(sbi, dn->nid, &ni, false);
13591359
if (err)
13601360
return err;
13611361

@@ -1757,7 +1757,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,
17571757
if (!page)
17581758
return -ENOMEM;
17591759

1760-
err = f2fs_get_node_info(sbi, inode->i_ino, &ni);
1760+
err = f2fs_get_node_info(sbi, inode->i_ino, &ni, false);
17611761
if (err) {
17621762
f2fs_put_page(page, 1);
17631763
return err;
@@ -1789,7 +1789,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,
17891789
if (!page)
17901790
return -ENOMEM;
17911791

1792-
err = f2fs_get_node_info(sbi, xnid, &ni);
1792+
err = f2fs_get_node_info(sbi, xnid, &ni, false);
17931793
if (err) {
17941794
f2fs_put_page(page, 1);
17951795
return err;
@@ -2649,7 +2649,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
26492649
fio->need_lock = LOCK_REQ;
26502650
}
26512651

2652-
err = f2fs_get_node_info(fio->sbi, dn.nid, &ni);
2652+
err = f2fs_get_node_info(fio->sbi, dn.nid, &ni, false);
26532653
if (err)
26542654
goto out_writepage;
26552655

fs/f2fs/f2fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,7 @@ int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
34123412
bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
34133413
bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
34143414
int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
3415-
struct node_info *ni);
3415+
struct node_info *ni, bool checkpoint_context);
34163416
pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
34173417
int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
34183418
int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);

fs/f2fs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
12331233
if (ret)
12341234
return ret;
12351235

1236-
ret = f2fs_get_node_info(sbi, dn.nid, &ni);
1236+
ret = f2fs_get_node_info(sbi, dn.nid, &ni, false);
12371237
if (ret) {
12381238
f2fs_put_dnode(&dn);
12391239
return ret;

fs/f2fs/gc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,
959959
continue;
960960
}
961961

962-
if (f2fs_get_node_info(sbi, nid, &ni)) {
962+
if (f2fs_get_node_info(sbi, nid, &ni, false)) {
963963
f2fs_put_page(node_page, 1);
964964
continue;
965965
}
@@ -1027,7 +1027,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
10271027
if (IS_ERR(node_page))
10281028
return false;
10291029

1030-
if (f2fs_get_node_info(sbi, nid, dni)) {
1030+
if (f2fs_get_node_info(sbi, nid, dni, false)) {
10311031
f2fs_put_page(node_page, 1);
10321032
return false;
10331033
}
@@ -1221,7 +1221,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
12211221

12221222
f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
12231223

1224-
err = f2fs_get_node_info(fio.sbi, dn.nid, &ni);
1224+
err = f2fs_get_node_info(fio.sbi, dn.nid, &ni, false);
12251225
if (err)
12261226
goto put_out;
12271227

fs/f2fs/inline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
131131
if (err)
132132
return err;
133133

134-
err = f2fs_get_node_info(fio.sbi, dn->nid, &ni);
134+
err = f2fs_get_node_info(fio.sbi, dn->nid, &ni, false);
135135
if (err) {
136136
f2fs_truncate_data_blocks_range(dn, 1);
137137
f2fs_put_dnode(dn);
@@ -786,7 +786,7 @@ int f2fs_inline_data_fiemap(struct inode *inode,
786786
ilen = start + len;
787787
ilen -= start;
788788

789-
err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni);
789+
err = f2fs_get_node_info(F2FS_I_SB(inode), inode->i_ino, &ni, false);
790790
if (err)
791791
goto out;
792792

fs/f2fs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ void f2fs_handle_failed_inode(struct inode *inode)
881881
* so we can prevent losing this orphan when encoutering checkpoint
882882
* and following suddenly power-off.
883883
*/
884-
err = f2fs_get_node_info(sbi, inode->i_ino, &ni);
884+
err = f2fs_get_node_info(sbi, inode->i_ino, &ni, false);
885885
if (err) {
886886
set_sbi_flag(sbi, SBI_NEED_FSCK);
887887
f2fs_warn(sbi, "May loss orphan inode, run fsck to fix.");

fs/f2fs/node.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
543543
}
544544

545545
int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
546-
struct node_info *ni)
546+
struct node_info *ni, bool checkpoint_context)
547547
{
548548
struct f2fs_nm_info *nm_i = NM_I(sbi);
549549
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
@@ -576,9 +576,10 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
576576
* nat_tree_lock. Therefore, we should retry, if we failed to grab here
577577
* while not bothering checkpoint.
578578
*/
579-
if (!rwsem_is_locked(&sbi->cp_global_sem)) {
579+
if (!rwsem_is_locked(&sbi->cp_global_sem) || checkpoint_context) {
580580
down_read(&curseg->journal_rwsem);
581-
} else if (!down_read_trylock(&curseg->journal_rwsem)) {
581+
} else if (rwsem_is_contended(&nm_i->nat_tree_lock) ||
582+
!down_read_trylock(&curseg->journal_rwsem)) {
582583
up_read(&nm_i->nat_tree_lock);
583584
goto retry;
584585
}
@@ -891,7 +892,7 @@ static int truncate_node(struct dnode_of_data *dn)
891892
int err;
892893
pgoff_t index;
893894

894-
err = f2fs_get_node_info(sbi, dn->nid, &ni);
895+
err = f2fs_get_node_info(sbi, dn->nid, &ni, false);
895896
if (err)
896897
return err;
897898

@@ -1290,7 +1291,7 @@ struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs)
12901291
goto fail;
12911292

12921293
#ifdef CONFIG_F2FS_CHECK_FS
1293-
err = f2fs_get_node_info(sbi, dn->nid, &new_ni);
1294+
err = f2fs_get_node_info(sbi, dn->nid, &new_ni, false);
12941295
if (err) {
12951296
dec_valid_node_count(sbi, dn->inode, !ofs);
12961297
goto fail;
@@ -1352,7 +1353,7 @@ static int read_node_page(struct page *page, int op_flags)
13521353
return LOCKED_PAGE;
13531354
}
13541355

1355-
err = f2fs_get_node_info(sbi, page->index, &ni);
1356+
err = f2fs_get_node_info(sbi, page->index, &ni, false);
13561357
if (err)
13571358
return err;
13581359

@@ -1604,7 +1605,7 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted,
16041605
nid = nid_of_node(page);
16051606
f2fs_bug_on(sbi, page->index != nid);
16061607

1607-
if (f2fs_get_node_info(sbi, nid, &ni))
1608+
if (f2fs_get_node_info(sbi, nid, &ni, !do_balance))
16081609
goto redirty_out;
16091610

16101611
if (wbc->for_reclaim) {
@@ -2705,7 +2706,7 @@ int f2fs_recover_xattr_data(struct inode *inode, struct page *page)
27052706
goto recover_xnid;
27062707

27072708
/* 1: invalidate the previous xattr nid */
2708-
err = f2fs_get_node_info(sbi, prev_xnid, &ni);
2709+
err = f2fs_get_node_info(sbi, prev_xnid, &ni, false);
27092710
if (err)
27102711
return err;
27112712

@@ -2745,7 +2746,7 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
27452746
struct page *ipage;
27462747
int err;
27472748

2748-
err = f2fs_get_node_info(sbi, ino, &old_ni);
2749+
err = f2fs_get_node_info(sbi, ino, &old_ni, false);
27492750
if (err)
27502751
return err;
27512752

fs/f2fs/recovery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
595595

596596
f2fs_wait_on_page_writeback(dn.node_page, NODE, true, true);
597597

598-
err = f2fs_get_node_info(sbi, dn.nid, &ni);
598+
err = f2fs_get_node_info(sbi, dn.nid, &ni, false);
599599
if (err)
600600
goto err;
601601

0 commit comments

Comments
 (0)