Use f2fs_{down,up}_write_trace for cp_global_sem to trace lock elapsed time.

Signed-off-by: Chao Yu <[email protected]>
---
 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to