From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 07/14] f2fs: trace elapsed time for cp_global_sem lock
Date: Sun, 4 Jan 2026 10:07:22 +0800 [thread overview]
Message-ID: <20260104020729.1064529-7-chao@kernel.org> (raw)
In-Reply-To: <20260104020729.1064529-1-chao@kernel.org>
Use f2fs_{down,up}_write_trace for cp_global_sem to trace lock elapsed time.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/checkpoint.c | 10 ++++++----
fs/f2fs/f2fs.h | 1 +
fs/f2fs/gc.c | 5 +++--
fs/f2fs/recovery.c | 5 +++--
fs/f2fs/super.c | 2 +-
include/trace/events/f2fs.h | 3 ++-
6 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index da7bcfa2a178..86656231ce83 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -513,6 +513,7 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
struct writeback_control *wbc)
{
struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
+ struct f2fs_lock_context lc;
long diff, written;
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
@@ -525,13 +526,13 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
goto skip_write;
/* if locked failed, cp will flush dirty pages instead */
- if (!f2fs_down_write_trylock(&sbi->cp_global_sem))
+ if (!f2fs_down_write_trylock_trace(&sbi->cp_global_sem, &lc))
goto skip_write;
trace_f2fs_writepages(mapping->host, wbc, META);
diff = nr_pages_to_write(sbi, META, wbc);
written = f2fs_sync_meta_pages(sbi, META, wbc->nr_to_write, FS_META_IO);
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &lc);
wbc->nr_to_write = max((long)0, wbc->nr_to_write - written - diff);
return 0;
@@ -1780,6 +1781,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
{
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
+ struct f2fs_lock_context lc;
unsigned long long ckpt_ver;
int err = 0;
@@ -1794,7 +1796,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
f2fs_warn(sbi, "Start checkpoint disabled!");
}
if (cpc->reason != CP_RESIZE)
- f2fs_down_write(&sbi->cp_global_sem);
+ f2fs_down_write_trace(&sbi->cp_global_sem, &lc);
stat_cp_time(cpc, CP_TIME_LOCK);
@@ -1884,7 +1886,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, CP_PHASE_FINISH_CHECKPOINT);
out:
if (cpc->reason != CP_RESIZE)
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &lc);
return err;
}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 5b6e632b37a9..baaae854c74f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -179,6 +179,7 @@ enum f2fs_lock_name {
LOCK_NAME_NODE_CHANGE,
LOCK_NAME_NODE_WRITE,
LOCK_NAME_GC_LOCK,
+ LOCK_NAME_CP_GLOBAL,
};
/*
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 391e66064c7e..1538f5b0a644 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -2267,6 +2267,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
struct cp_control cpc = { CP_RESIZE, 0, 0, 0 };
struct f2fs_lock_context lc;
struct f2fs_lock_context glc;
+ struct f2fs_lock_context clc;
unsigned int secs;
int err = 0;
__u32 rem;
@@ -2350,7 +2351,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
}
f2fs_down_write_trace(&sbi->gc_lock, &glc);
- f2fs_down_write(&sbi->cp_global_sem);
+ f2fs_down_write_trace(&sbi->cp_global_sem, &clc);
spin_lock(&sbi->stat_lock);
if (shrunk_blocks + valid_user_blocks(sbi) +
@@ -2398,7 +2399,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
spin_unlock(&sbi->stat_lock);
}
out_err:
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &clc);
f2fs_up_write_trace(&sbi->gc_lock, &glc);
thaw_super(sbi->sb, FREEZE_HOLDER_KERNEL, NULL);
return err;
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index c3415ebb9f50..39f6e9830a9c 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -875,6 +875,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
LIST_HEAD(inode_list);
LIST_HEAD(tmp_inode_list);
LIST_HEAD(dir_list);
+ struct f2fs_lock_context lc;
int err;
int ret = 0;
unsigned long s_flags = sbi->sb->s_flags;
@@ -888,7 +889,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
f2fs_info(sbi, "recover fsync data on readonly fs");
/* prevent checkpoint */
- f2fs_down_write(&sbi->cp_global_sem);
+ f2fs_down_write_trace(&sbi->cp_global_sem, &lc);
/* step #1: find fsynced inode numbers */
err = find_fsync_dnodes(sbi, &inode_list, check_only, &new_inode);
@@ -932,7 +933,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
if (!err)
clear_sbi_flag(sbi, SBI_POR_DOING);
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &lc);
/* let's drop all the directory inodes for clean checkpoint */
destroy_fsync_dnodes(&dir_list, err);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index abb468eb4394..3583a640e614 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4898,7 +4898,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
/* initialize locks within allocated memory */
init_f2fs_rwsem_trace(&sbi->gc_lock, sbi, LOCK_NAME_GC_LOCK);
mutex_init(&sbi->writepages);
- init_f2fs_rwsem(&sbi->cp_global_sem);
+ init_f2fs_rwsem_trace(&sbi->cp_global_sem, sbi, LOCK_NAME_CP_GLOBAL);
init_f2fs_rwsem_trace(&sbi->node_write, sbi, LOCK_NAME_NODE_WRITE);
init_f2fs_rwsem_trace(&sbi->node_change, sbi, LOCK_NAME_NODE_CHANGE);
spin_lock_init(&sbi->stat_lock);
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index bf353e7e024d..859de7c8d1c7 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -189,7 +189,8 @@ TRACE_DEFINE_ENUM(CP_PHASE_FINISH_CHECKPOINT);
{ LOCK_NAME_CP_RWSEM, "cp_rwsem" }, \
{ LOCK_NAME_NODE_CHANGE, "node_change" }, \
{ LOCK_NAME_NODE_WRITE, "node_write" }, \
- { LOCK_NAME_GC_LOCK, "gc_lock" })
+ { LOCK_NAME_GC_LOCK, "gc_lock" }, \
+ { LOCK_NAME_CP_GLOBAL, "cp_global" })
struct f2fs_sb_info;
struct f2fs_io_info;
--
2.49.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Chao Yu <chao@kernel.org>
Subject: [PATCH 07/14] f2fs: trace elapsed time for cp_global_sem lock
Date: Sun, 4 Jan 2026 10:07:22 +0800 [thread overview]
Message-ID: <20260104020729.1064529-7-chao@kernel.org> (raw)
In-Reply-To: <20260104020729.1064529-1-chao@kernel.org>
Use f2fs_{down,up}_write_trace for cp_global_sem to trace lock elapsed time.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/f2fs/checkpoint.c | 10 ++++++----
fs/f2fs/f2fs.h | 1 +
fs/f2fs/gc.c | 5 +++--
fs/f2fs/recovery.c | 5 +++--
fs/f2fs/super.c | 2 +-
include/trace/events/f2fs.h | 3 ++-
6 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index da7bcfa2a178..86656231ce83 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -513,6 +513,7 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
struct writeback_control *wbc)
{
struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
+ struct f2fs_lock_context lc;
long diff, written;
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
@@ -525,13 +526,13 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
goto skip_write;
/* if locked failed, cp will flush dirty pages instead */
- if (!f2fs_down_write_trylock(&sbi->cp_global_sem))
+ if (!f2fs_down_write_trylock_trace(&sbi->cp_global_sem, &lc))
goto skip_write;
trace_f2fs_writepages(mapping->host, wbc, META);
diff = nr_pages_to_write(sbi, META, wbc);
written = f2fs_sync_meta_pages(sbi, META, wbc->nr_to_write, FS_META_IO);
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &lc);
wbc->nr_to_write = max((long)0, wbc->nr_to_write - written - diff);
return 0;
@@ -1780,6 +1781,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
{
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
+ struct f2fs_lock_context lc;
unsigned long long ckpt_ver;
int err = 0;
@@ -1794,7 +1796,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
f2fs_warn(sbi, "Start checkpoint disabled!");
}
if (cpc->reason != CP_RESIZE)
- f2fs_down_write(&sbi->cp_global_sem);
+ f2fs_down_write_trace(&sbi->cp_global_sem, &lc);
stat_cp_time(cpc, CP_TIME_LOCK);
@@ -1884,7 +1886,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, CP_PHASE_FINISH_CHECKPOINT);
out:
if (cpc->reason != CP_RESIZE)
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &lc);
return err;
}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 5b6e632b37a9..baaae854c74f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -179,6 +179,7 @@ enum f2fs_lock_name {
LOCK_NAME_NODE_CHANGE,
LOCK_NAME_NODE_WRITE,
LOCK_NAME_GC_LOCK,
+ LOCK_NAME_CP_GLOBAL,
};
/*
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 391e66064c7e..1538f5b0a644 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -2267,6 +2267,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
struct cp_control cpc = { CP_RESIZE, 0, 0, 0 };
struct f2fs_lock_context lc;
struct f2fs_lock_context glc;
+ struct f2fs_lock_context clc;
unsigned int secs;
int err = 0;
__u32 rem;
@@ -2350,7 +2351,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
}
f2fs_down_write_trace(&sbi->gc_lock, &glc);
- f2fs_down_write(&sbi->cp_global_sem);
+ f2fs_down_write_trace(&sbi->cp_global_sem, &clc);
spin_lock(&sbi->stat_lock);
if (shrunk_blocks + valid_user_blocks(sbi) +
@@ -2398,7 +2399,7 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
spin_unlock(&sbi->stat_lock);
}
out_err:
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &clc);
f2fs_up_write_trace(&sbi->gc_lock, &glc);
thaw_super(sbi->sb, FREEZE_HOLDER_KERNEL, NULL);
return err;
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index c3415ebb9f50..39f6e9830a9c 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -875,6 +875,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
LIST_HEAD(inode_list);
LIST_HEAD(tmp_inode_list);
LIST_HEAD(dir_list);
+ struct f2fs_lock_context lc;
int err;
int ret = 0;
unsigned long s_flags = sbi->sb->s_flags;
@@ -888,7 +889,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
f2fs_info(sbi, "recover fsync data on readonly fs");
/* prevent checkpoint */
- f2fs_down_write(&sbi->cp_global_sem);
+ f2fs_down_write_trace(&sbi->cp_global_sem, &lc);
/* step #1: find fsynced inode numbers */
err = find_fsync_dnodes(sbi, &inode_list, check_only, &new_inode);
@@ -932,7 +933,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
if (!err)
clear_sbi_flag(sbi, SBI_POR_DOING);
- f2fs_up_write(&sbi->cp_global_sem);
+ f2fs_up_write_trace(&sbi->cp_global_sem, &lc);
/* let's drop all the directory inodes for clean checkpoint */
destroy_fsync_dnodes(&dir_list, err);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index abb468eb4394..3583a640e614 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -4898,7 +4898,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
/* initialize locks within allocated memory */
init_f2fs_rwsem_trace(&sbi->gc_lock, sbi, LOCK_NAME_GC_LOCK);
mutex_init(&sbi->writepages);
- init_f2fs_rwsem(&sbi->cp_global_sem);
+ init_f2fs_rwsem_trace(&sbi->cp_global_sem, sbi, LOCK_NAME_CP_GLOBAL);
init_f2fs_rwsem_trace(&sbi->node_write, sbi, LOCK_NAME_NODE_WRITE);
init_f2fs_rwsem_trace(&sbi->node_change, sbi, LOCK_NAME_NODE_CHANGE);
spin_lock_init(&sbi->stat_lock);
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index bf353e7e024d..859de7c8d1c7 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -189,7 +189,8 @@ TRACE_DEFINE_ENUM(CP_PHASE_FINISH_CHECKPOINT);
{ LOCK_NAME_CP_RWSEM, "cp_rwsem" }, \
{ LOCK_NAME_NODE_CHANGE, "node_change" }, \
{ LOCK_NAME_NODE_WRITE, "node_write" }, \
- { LOCK_NAME_GC_LOCK, "gc_lock" })
+ { LOCK_NAME_GC_LOCK, "gc_lock" }, \
+ { LOCK_NAME_CP_GLOBAL, "cp_global" })
struct f2fs_sb_info;
struct f2fs_io_info;
--
2.49.0
next prev parent reply other threads:[~2026-01-04 2:08 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-04 2:07 [f2fs-dev] [PATCH 01/14] f2fs: add lock elapsed time trace facility for f2fs rwsemphore Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 02/14] f2fs: sysfs: introduce max_lock_elapsed_time Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 03/14] f2fs: trace elapsed time for cp_rwsem lock Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 04/14] f2fs: trace elapsed time for node_change lock Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 05/14] f2fs: trace elapsed time for node_write lock Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 06/14] f2fs: trace elapsed time for gc_lock lock Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 5:35 ` [f2fs-dev] " Jaegeuk Kim via Linux-f2fs-devel
2026-01-04 5:35 ` Jaegeuk Kim
2026-01-04 5:42 ` [f2fs-dev] " Jaegeuk Kim via Linux-f2fs-devel
2026-01-04 5:42 ` Jaegeuk Kim
2026-01-04 6:27 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2026-01-04 6:27 ` Chao Yu
2026-01-04 2:07 ` Chao Yu via Linux-f2fs-devel [this message]
2026-01-04 2:07 ` [PATCH 07/14] f2fs: trace elapsed time for cp_global_sem lock Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 08/14] f2fs: trace elapsed time for io_rwsem lock Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 09/14] f2fs: clean up w/ __f2fs_schedule_timeout() Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 10/14] f2fs: fix to use jiffies based precision for DEFAULT_SCHEDULE_TIMEOUT Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 11/14] f2fs: fix timeout precision of f2fs_io_schedule_timeout_killable() Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 12/14] f2fs: rename FAULT_TIMEOUT to FAULT_ATOMIC_TIMEOUT Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 13/14] f2fs: introduce FAULT_LOCK_TIMEOUT Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 2:07 ` [f2fs-dev] [PATCH 14/14] f2fs: sysfs: introduce inject_lock_timeout Chao Yu via Linux-f2fs-devel
2026-01-04 2:07 ` Chao Yu
2026-01-04 5:28 ` [f2fs-dev] [PATCH 01/14] f2fs: add lock elapsed time trace facility for f2fs rwsemphore Jaegeuk Kim via Linux-f2fs-devel
2026-01-04 5:28 ` Jaegeuk Kim
2026-01-07 3:30 ` [f2fs-dev] " patchwork-bot+f2fs--- via Linux-f2fs-devel
2026-01-07 3:30 ` patchwork-bot+f2fs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260104020729.1064529-7-chao@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.