Skip to content

Commit 66e9e0d

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: trace elapsed time for cp_rwsem lock
Use f2fs_{down,up}_read_trace for cp_rwsem to trace lock elapsed time. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent e4b7562 commit 66e9e0d

13 files changed

Lines changed: 173 additions & 126 deletions

File tree

fs/f2fs/checkpoint.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ void f2fs_up_write_trace(struct f2fs_rwsem *sem, struct f2fs_lock_context *lc)
127127
trace_lock_elapsed_time_end(sem, lc, true);
128128
}
129129

130+
void f2fs_lock_op(struct f2fs_sb_info *sbi, struct f2fs_lock_context *lc)
131+
{
132+
f2fs_down_read_trace(&sbi->cp_rwsem, lc);
133+
}
134+
135+
int f2fs_trylock_op(struct f2fs_sb_info *sbi, struct f2fs_lock_context *lc)
136+
{
137+
if (time_to_inject(sbi, FAULT_LOCK_OP))
138+
return 0;
139+
140+
return f2fs_down_read_trylock_trace(&sbi->cp_rwsem, lc);
141+
}
142+
143+
void f2fs_unlock_op(struct f2fs_sb_info *sbi, struct f2fs_lock_context *lc)
144+
{
145+
f2fs_up_read_trace(&sbi->cp_rwsem, lc);
146+
}
147+
148+
static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
149+
{
150+
f2fs_down_write(&sbi->cp_rwsem);
151+
}
152+
153+
static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
154+
{
155+
f2fs_up_write(&sbi->cp_rwsem);
156+
}
157+
130158
#define DEFAULT_CHECKPOINT_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_RT, 3))
131159

132160
static struct kmem_cache *ino_entry_slab;

fs/f2fs/compress.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
12901290
struct dnode_of_data dn;
12911291
struct node_info ni;
12921292
struct compress_io_ctx *cic;
1293+
struct f2fs_lock_context lc;
12931294
pgoff_t start_idx = start_idx_of_cluster(cc);
12941295
unsigned int last_index = cc->cluster_size - 1;
12951296
loff_t psize;
@@ -1309,7 +1310,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
13091310
* the below discard race condition.
13101311
*/
13111312
f2fs_down_read(&sbi->node_write);
1312-
} else if (!f2fs_trylock_op(sbi)) {
1313+
} else if (!f2fs_trylock_op(sbi, &lc)) {
13131314
goto out_free;
13141315
}
13151316

@@ -1435,7 +1436,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
14351436
if (quota_inode)
14361437
f2fs_up_read(&sbi->node_write);
14371438
else
1438-
f2fs_unlock_op(sbi);
1439+
f2fs_unlock_op(sbi, &lc);
14391440

14401441
spin_lock(&fi->i_size_lock);
14411442
if (fi->last_disk_size < psize)
@@ -1464,7 +1465,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
14641465
if (quota_inode)
14651466
f2fs_up_read(&sbi->node_write);
14661467
else
1467-
f2fs_unlock_op(sbi);
1468+
f2fs_unlock_op(sbi, &lc);
14681469
out_free:
14691470
for (i = 0; i < cc->valid_nr_cpages; i++) {
14701471
f2fs_compress_free_page(cc->cpages[i]);
@@ -1511,6 +1512,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
15111512
{
15121513
struct address_space *mapping = cc->inode->i_mapping;
15131514
struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
1515+
struct f2fs_lock_context lc;
15141516
int submitted, compr_blocks, i;
15151517
int ret = 0;
15161518

@@ -1529,7 +1531,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
15291531

15301532
/* overwrite compressed cluster w/ normal cluster */
15311533
if (compr_blocks > 0)
1532-
f2fs_lock_op(sbi);
1534+
f2fs_lock_op(sbi, &lc);
15331535

15341536
for (i = 0; i < cc->cluster_size; i++) {
15351537
struct folio *folio;
@@ -1585,7 +1587,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
15851587

15861588
out:
15871589
if (compr_blocks > 0)
1588-
f2fs_unlock_op(sbi);
1590+
f2fs_unlock_op(sbi, &lc);
15891591

15901592
f2fs_balance_fs(sbi, true);
15911593
return ret;

fs/f2fs/data.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,34 +1466,39 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
14661466
return 0;
14671467
}
14681468

1469-
static void f2fs_map_lock(struct f2fs_sb_info *sbi, int flag)
1469+
static void f2fs_map_lock(struct f2fs_sb_info *sbi,
1470+
struct f2fs_lock_context *lc,
1471+
int flag)
14701472
{
14711473
f2fs_down_read(&sbi->cp_enable_rwsem);
14721474
if (flag == F2FS_GET_BLOCK_PRE_AIO)
14731475
f2fs_down_read(&sbi->node_change);
14741476
else
1475-
f2fs_lock_op(sbi);
1477+
f2fs_lock_op(sbi, lc);
14761478
}
14771479

1478-
static void f2fs_map_unlock(struct f2fs_sb_info *sbi, int flag)
1480+
static void f2fs_map_unlock(struct f2fs_sb_info *sbi,
1481+
struct f2fs_lock_context *lc,
1482+
int flag)
14791483
{
14801484
if (flag == F2FS_GET_BLOCK_PRE_AIO)
14811485
f2fs_up_read(&sbi->node_change);
14821486
else
1483-
f2fs_unlock_op(sbi);
1487+
f2fs_unlock_op(sbi, lc);
14841488
f2fs_up_read(&sbi->cp_enable_rwsem);
14851489
}
14861490

14871491
int f2fs_get_block_locked(struct dnode_of_data *dn, pgoff_t index)
14881492
{
14891493
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
1494+
struct f2fs_lock_context lc;
14901495
int err = 0;
14911496

1492-
f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
1497+
f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
14931498
if (!f2fs_lookup_read_extent_cache_block(dn->inode, index,
14941499
&dn->data_blkaddr))
14951500
err = f2fs_reserve_block(dn, index);
1496-
f2fs_map_unlock(sbi, F2FS_GET_BLOCK_PRE_AIO);
1501+
f2fs_map_unlock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
14971502

14981503
return err;
14991504
}
@@ -1584,6 +1589,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
15841589
unsigned int maxblocks = map->m_len;
15851590
struct dnode_of_data dn;
15861591
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1592+
struct f2fs_lock_context lc;
15871593
int mode = map->m_may_create ? ALLOC_NODE : LOOKUP_NODE;
15881594
pgoff_t pgofs, end_offset, end;
15891595
int err = 0, ofs = 1;
@@ -1622,7 +1628,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
16221628
if (map->m_may_create) {
16231629
if (f2fs_lfs_mode(sbi))
16241630
f2fs_balance_fs(sbi, true);
1625-
f2fs_map_lock(sbi, flag);
1631+
f2fs_map_lock(sbi, &lc, flag);
16261632
}
16271633

16281634
/* When reading holes, we need its node page */
@@ -1788,7 +1794,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
17881794
f2fs_put_dnode(&dn);
17891795

17901796
if (map->m_may_create) {
1791-
f2fs_map_unlock(sbi, flag);
1797+
f2fs_map_unlock(sbi, &lc, flag);
17921798
f2fs_balance_fs(sbi, dn.node_changed);
17931799
}
17941800
goto next_dnode;
@@ -1835,7 +1841,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
18351841
f2fs_put_dnode(&dn);
18361842
unlock_out:
18371843
if (map->m_may_create) {
1838-
f2fs_map_unlock(sbi, flag);
1844+
f2fs_map_unlock(sbi, &lc, flag);
18391845
f2fs_balance_fs(sbi, dn.node_changed);
18401846
}
18411847
out:
@@ -2865,6 +2871,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
28652871
struct inode *inode = folio->mapping->host;
28662872
struct dnode_of_data dn;
28672873
struct node_info ni;
2874+
struct f2fs_lock_context lc;
28682875
bool ipu_force = false;
28692876
bool atomic_commit;
28702877
int err = 0;
@@ -2890,7 +2897,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
28902897
}
28912898

28922899
/* Deadlock due to between page->lock and f2fs_lock_op */
2893-
if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi))
2900+
if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi, &lc))
28942901
return -EAGAIN;
28952902

28962903
err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
@@ -2931,7 +2938,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
29312938
folio_start_writeback(folio);
29322939
f2fs_put_dnode(&dn);
29332940
if (fio->need_lock == LOCK_REQ)
2934-
f2fs_unlock_op(fio->sbi);
2941+
f2fs_unlock_op(fio->sbi, &lc);
29352942
err = f2fs_inplace_write_data(fio);
29362943
if (err) {
29372944
if (fscrypt_inode_uses_fs_layer_crypto(inode))
@@ -2945,7 +2952,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
29452952
}
29462953

29472954
if (fio->need_lock == LOCK_RETRY) {
2948-
if (!f2fs_trylock_op(fio->sbi)) {
2955+
if (!f2fs_trylock_op(fio->sbi, &lc)) {
29492956
err = -EAGAIN;
29502957
goto out_writepage;
29512958
}
@@ -2977,7 +2984,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
29772984
f2fs_put_dnode(&dn);
29782985
out:
29792986
if (fio->need_lock == LOCK_REQ)
2980-
f2fs_unlock_op(fio->sbi);
2987+
f2fs_unlock_op(fio->sbi, &lc);
29812988
return err;
29822989
}
29832990

@@ -3570,6 +3577,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
35703577
struct inode *inode = folio->mapping->host;
35713578
pgoff_t index = folio->index;
35723579
struct dnode_of_data dn;
3580+
struct f2fs_lock_context lc;
35733581
struct folio *ifolio;
35743582
bool locked = false;
35753583
int flag = F2FS_GET_BLOCK_PRE_AIO;
@@ -3586,10 +3594,10 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
35863594
if (f2fs_has_inline_data(inode)) {
35873595
if (pos + len > MAX_INLINE_DATA(inode))
35883596
flag = F2FS_GET_BLOCK_DEFAULT;
3589-
f2fs_map_lock(sbi, flag);
3597+
f2fs_map_lock(sbi, &lc, flag);
35903598
locked = true;
35913599
} else if ((pos & PAGE_MASK) >= i_size_read(inode)) {
3592-
f2fs_map_lock(sbi, flag);
3600+
f2fs_map_lock(sbi, &lc, flag);
35933601
locked = true;
35943602
}
35953603

@@ -3633,7 +3641,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
36333641
if (!err && dn.data_blkaddr != NULL_ADDR)
36343642
goto out;
36353643
f2fs_put_dnode(&dn);
3636-
f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
3644+
f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
36373645
WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO);
36383646
locked = true;
36393647
goto restart;
@@ -3647,7 +3655,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
36473655
f2fs_put_dnode(&dn);
36483656
unlock_out:
36493657
if (locked)
3650-
f2fs_map_unlock(sbi, flag);
3658+
f2fs_map_unlock(sbi, &lc, flag);
36513659
return err;
36523660
}
36533661

@@ -3683,10 +3691,11 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
36833691
{
36843692
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
36853693
struct dnode_of_data dn;
3694+
struct f2fs_lock_context lc;
36863695
struct folio *ifolio;
36873696
int err = 0;
36883697

3689-
f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
3698+
f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
36903699

36913700
ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
36923701
if (IS_ERR(ifolio)) {
@@ -3704,7 +3713,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
37043713
f2fs_put_dnode(&dn);
37053714

37063715
unlock_out:
3707-
f2fs_map_unlock(sbi, F2FS_GET_BLOCK_PRE_AIO);
3716+
f2fs_map_unlock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
37083717
return err;
37093718
}
37103719

fs/f2fs/f2fs.h

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ enum device_allocation_policy {
175175

176176
enum f2fs_lock_name {
177177
LOCK_NAME_NONE,
178+
LOCK_NAME_CP_RWSEM,
178179
};
179180

180181
/*
@@ -2417,33 +2418,6 @@ static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
24172418
return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
24182419
}
24192420

2420-
static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
2421-
{
2422-
f2fs_down_read(&sbi->cp_rwsem);
2423-
}
2424-
2425-
static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
2426-
{
2427-
if (time_to_inject(sbi, FAULT_LOCK_OP))
2428-
return 0;
2429-
return f2fs_down_read_trylock(&sbi->cp_rwsem);
2430-
}
2431-
2432-
static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
2433-
{
2434-
f2fs_up_read(&sbi->cp_rwsem);
2435-
}
2436-
2437-
static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
2438-
{
2439-
f2fs_down_write(&sbi->cp_rwsem);
2440-
}
2441-
2442-
static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
2443-
{
2444-
f2fs_up_write(&sbi->cp_rwsem);
2445-
}
2446-
24472421
static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
24482422
{
24492423
int reason = CP_SYNC;
@@ -3770,7 +3744,7 @@ void f2fs_update_inode_page(struct inode *inode);
37703744
int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
37713745
void f2fs_remove_donate_inode(struct inode *inode);
37723746
void f2fs_evict_inode(struct inode *inode);
3773-
void f2fs_handle_failed_inode(struct inode *inode);
3747+
void f2fs_handle_failed_inode(struct inode *inode, struct f2fs_lock_context *lc);
37743748

37753749
/*
37763750
* namei.c
@@ -4037,6 +4011,9 @@ static inline bool f2fs_need_rand_seg(struct f2fs_sb_info *sbi)
40374011
/*
40384012
* checkpoint.c
40394013
*/
4014+
void f2fs_lock_op(struct f2fs_sb_info *sbi, struct f2fs_lock_context *lc);
4015+
int f2fs_trylock_op(struct f2fs_sb_info *sbi, struct f2fs_lock_context *lc);
4016+
void f2fs_unlock_op(struct f2fs_sb_info *sbi, struct f2fs_lock_context *lc);
40404017
void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io,
40414018
unsigned char reason);
40424019
void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi);

0 commit comments

Comments
 (0)