summaryrefslogtreecommitdiff
path: root/fs/f2fs/data.c
diff options
context:
space:
mode:
authorChao Yu <chao@kernel.org>2026-01-04 10:07:18 +0800
committerJaegeuk Kim <jaegeuk@kernel.org>2026-01-07 03:17:06 +0000
commit66e9e0d55d117a7de2c00a9a06fb943ead56e1c2 (patch)
tree993b20be1ad7d41ff6df779f1e8b6236b1348fb1 /fs/f2fs/data.c
parente4b75621fc439399b94c4265cb54d2bda1177397 (diff)
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>
Diffstat (limited to 'fs/f2fs/data.c')
-rw-r--r--fs/f2fs/data.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 471e52c6c1e0..73fcafbc8191 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1466,34 +1466,39 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
return 0;
}
-static void f2fs_map_lock(struct f2fs_sb_info *sbi, int flag)
+static void f2fs_map_lock(struct f2fs_sb_info *sbi,
+ struct f2fs_lock_context *lc,
+ int flag)
{
f2fs_down_read(&sbi->cp_enable_rwsem);
if (flag == F2FS_GET_BLOCK_PRE_AIO)
f2fs_down_read(&sbi->node_change);
else
- f2fs_lock_op(sbi);
+ f2fs_lock_op(sbi, lc);
}
-static void f2fs_map_unlock(struct f2fs_sb_info *sbi, int flag)
+static void f2fs_map_unlock(struct f2fs_sb_info *sbi,
+ struct f2fs_lock_context *lc,
+ int flag)
{
if (flag == F2FS_GET_BLOCK_PRE_AIO)
f2fs_up_read(&sbi->node_change);
else
- f2fs_unlock_op(sbi);
+ f2fs_unlock_op(sbi, lc);
f2fs_up_read(&sbi->cp_enable_rwsem);
}
int f2fs_get_block_locked(struct dnode_of_data *dn, pgoff_t index)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
+ struct f2fs_lock_context lc;
int err = 0;
- f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
+ f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
if (!f2fs_lookup_read_extent_cache_block(dn->inode, index,
&dn->data_blkaddr))
err = f2fs_reserve_block(dn, index);
- f2fs_map_unlock(sbi, F2FS_GET_BLOCK_PRE_AIO);
+ f2fs_map_unlock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
return err;
}
@@ -1584,6 +1589,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
unsigned int maxblocks = map->m_len;
struct dnode_of_data dn;
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
+ struct f2fs_lock_context lc;
int mode = map->m_may_create ? ALLOC_NODE : LOOKUP_NODE;
pgoff_t pgofs, end_offset, end;
int err = 0, ofs = 1;
@@ -1622,7 +1628,7 @@ next_dnode:
if (map->m_may_create) {
if (f2fs_lfs_mode(sbi))
f2fs_balance_fs(sbi, true);
- f2fs_map_lock(sbi, flag);
+ f2fs_map_lock(sbi, &lc, flag);
}
/* When reading holes, we need its node page */
@@ -1788,7 +1794,7 @@ skip:
f2fs_put_dnode(&dn);
if (map->m_may_create) {
- f2fs_map_unlock(sbi, flag);
+ f2fs_map_unlock(sbi, &lc, flag);
f2fs_balance_fs(sbi, dn.node_changed);
}
goto next_dnode;
@@ -1835,7 +1841,7 @@ sync_out:
f2fs_put_dnode(&dn);
unlock_out:
if (map->m_may_create) {
- f2fs_map_unlock(sbi, flag);
+ f2fs_map_unlock(sbi, &lc, flag);
f2fs_balance_fs(sbi, dn.node_changed);
}
out:
@@ -2865,6 +2871,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
struct inode *inode = folio->mapping->host;
struct dnode_of_data dn;
struct node_info ni;
+ struct f2fs_lock_context lc;
bool ipu_force = false;
bool atomic_commit;
int err = 0;
@@ -2890,7 +2897,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
}
/* Deadlock due to between page->lock and f2fs_lock_op */
- if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi))
+ if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi, &lc))
return -EAGAIN;
err = f2fs_get_dnode_of_data(&dn, folio->index, LOOKUP_NODE);
@@ -2931,7 +2938,7 @@ got_it:
folio_start_writeback(folio);
f2fs_put_dnode(&dn);
if (fio->need_lock == LOCK_REQ)
- f2fs_unlock_op(fio->sbi);
+ f2fs_unlock_op(fio->sbi, &lc);
err = f2fs_inplace_write_data(fio);
if (err) {
if (fscrypt_inode_uses_fs_layer_crypto(inode))
@@ -2945,7 +2952,7 @@ got_it:
}
if (fio->need_lock == LOCK_RETRY) {
- if (!f2fs_trylock_op(fio->sbi)) {
+ if (!f2fs_trylock_op(fio->sbi, &lc)) {
err = -EAGAIN;
goto out_writepage;
}
@@ -2977,7 +2984,7 @@ out_writepage:
f2fs_put_dnode(&dn);
out:
if (fio->need_lock == LOCK_REQ)
- f2fs_unlock_op(fio->sbi);
+ f2fs_unlock_op(fio->sbi, &lc);
return err;
}
@@ -3570,6 +3577,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
struct inode *inode = folio->mapping->host;
pgoff_t index = folio->index;
struct dnode_of_data dn;
+ struct f2fs_lock_context lc;
struct folio *ifolio;
bool locked = false;
int flag = F2FS_GET_BLOCK_PRE_AIO;
@@ -3586,10 +3594,10 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
if (f2fs_has_inline_data(inode)) {
if (pos + len > MAX_INLINE_DATA(inode))
flag = F2FS_GET_BLOCK_DEFAULT;
- f2fs_map_lock(sbi, flag);
+ f2fs_map_lock(sbi, &lc, flag);
locked = true;
} else if ((pos & PAGE_MASK) >= i_size_read(inode)) {
- f2fs_map_lock(sbi, flag);
+ f2fs_map_lock(sbi, &lc, flag);
locked = true;
}
@@ -3633,7 +3641,7 @@ restart:
if (!err && dn.data_blkaddr != NULL_ADDR)
goto out;
f2fs_put_dnode(&dn);
- f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
+ f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO);
locked = true;
goto restart;
@@ -3647,7 +3655,7 @@ out:
f2fs_put_dnode(&dn);
unlock_out:
if (locked)
- f2fs_map_unlock(sbi, flag);
+ f2fs_map_unlock(sbi, &lc, flag);
return err;
}
@@ -3683,10 +3691,11 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct dnode_of_data dn;
+ struct f2fs_lock_context lc;
struct folio *ifolio;
int err = 0;
- f2fs_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO);
+ f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
if (IS_ERR(ifolio)) {
@@ -3704,7 +3713,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
f2fs_put_dnode(&dn);
unlock_out:
- f2fs_map_unlock(sbi, F2FS_GET_BLOCK_PRE_AIO);
+ f2fs_map_unlock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
return err;
}