f2fs: cache: introduce tracepoints

This patch introduces ftrace tracepoints to observe and profile metadata
cache operations:
- trace_f2fs_cache_set_dirty to trace marking a cached block dirty
- trace_f2fs_write_cache to trace single block writeback submission
- trace_f2fs_write_caches to tracesbatch writeback and sync sessions

Reviewed-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2026-09-17 15:33:42 +08:00 committed by Jaegeuk Kim
parent 4f9ad04b59
commit cc46c2e933
5 changed files with 87 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "f2fs.h"
#include "cache.h"
#include "node.h"
#include <trace/events/f2fs.h>
#include "segment.h"
void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
@ -73,6 +74,8 @@ bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry)
enum count_type type = IS_META_CACHE(cache) ?
F2FS_DIRTY_META : F2FS_DIRTY_NODES;
trace_f2fs_cache_set_dirty(entry,
IS_META_CACHE(cache) ? META : NODE);
f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_NONE,
F2FS_CACHE_TAG_DIRTY);
inc_page_count(cache->sbi, type);

View File

@ -550,6 +550,8 @@ static bool __f2fs_write_meta_cache(struct f2fs_cached_block *entry,
{
struct f2fs_sb_info *sbi = entry->cache->sbi;
trace_f2fs_write_cache(entry, META);
if (unlikely(f2fs_cp_error(sbi))) {
if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) {
f2fs_cache_clear_uptodate(entry);
@ -611,6 +613,8 @@ long f2fs_sync_meta_caches(struct f2fs_sb_info *sbi, long nr_to_write,
struct blk_plug plug;
bool background = nr_to_write != LONG_MAX;
trace_f2fs_write_caches(sbi, nr_to_write, 0, META);
blk_start_plug(&plug);
while ((nr = f2fs_cache_gang_lookup_tag(META_CACHE(sbi), entries,
@ -666,6 +670,8 @@ long f2fs_sync_meta_caches(struct f2fs_sb_info *sbi, long nr_to_write,
blk_finish_plug(&plug);
trace_f2fs_write_caches(sbi, nr_to_write, nwritten, META);
return nwritten;
}

View File

@ -2110,6 +2110,8 @@ int f2fs_writeback_node_caches(struct f2fs_sb_info *sbi, long nr_to_write,
int ret = 0;
int nr, done = 0;
trace_f2fs_write_caches(sbi, nr_to_write, 0, NODE);
next_step:
index = 0;
@ -2217,6 +2219,8 @@ int f2fs_writeback_node_caches(struct f2fs_sb_info *sbi, long nr_to_write,
if (nwritten)
f2fs_submit_merged_write(sbi, NODE);
trace_f2fs_write_caches(sbi, nr_to_write, nwritten, NODE);
if (unlikely(f2fs_cp_error(sbi)))
return -EIO;
return ret;

View File

@ -4226,6 +4226,9 @@ void f2fs_do_write_node_cache(unsigned int nid, struct f2fs_io_info *fio)
{
struct f2fs_summary sum;
if (fio->is_cache)
trace_f2fs_write_cache(fio->cache_entry, NODE);
set_summary(&sum, nid, 0, 0);
do_write_block(&sum, fio);

View File

@ -1430,6 +1430,50 @@ DEFINE_EVENT(f2fs__folio, f2fs_set_page_dirty,
TP_ARGS(folio, type)
);
DECLARE_EVENT_CLASS(f2fs__cached_block,
TP_PROTO(struct f2fs_cached_block *block, int type),
TP_ARGS(block, type),
TP_STRUCT__entry(
__field(dev_t, dev)
__field(pgoff_t, index)
__field(int, type)
__field(int, dirty)
__field(int, uptodate)
),
TP_fast_assign(
__entry->dev = block->cache->sbi->sb->s_dev;
__entry->index = block->index;
__entry->type = type;
__entry->dirty = f2fs_cache_test_dirty(block);
__entry->uptodate = f2fs_cache_test_uptodate(block);
),
TP_printk("dev = (%d,%d), %s, index = %lu, dirty = %d, uptodate = %d",
show_dev(__entry->dev),
show_block_type(__entry->type),
(unsigned long)__entry->index,
__entry->dirty,
__entry->uptodate)
);
DEFINE_EVENT(f2fs__cached_block, f2fs_write_cache,
TP_PROTO(struct f2fs_cached_block *block, int type),
TP_ARGS(block, type)
);
DEFINE_EVENT(f2fs__cached_block, f2fs_cache_set_dirty,
TP_PROTO(struct f2fs_cached_block *block, int type),
TP_ARGS(block, type)
);
TRACE_EVENT(f2fs_replace_atomic_write_block,
TP_PROTO(struct inode *inode, struct inode *cow_inode, pgoff_t index,
@ -1574,6 +1618,33 @@ TRACE_EVENT(f2fs_writepages,
__entry->for_sync)
);
TRACE_EVENT(f2fs_write_caches,
TP_PROTO(struct f2fs_sb_info *sbi, long nr_to_write, long nwritten, int type),
TP_ARGS(sbi, nr_to_write, nwritten, type),
TP_STRUCT__entry(
__field(dev_t, dev)
__field(long, nr_to_write)
__field(long, nwritten)
__field(int, type)
),
TP_fast_assign(
__entry->dev = sbi->sb->s_dev;
__entry->nr_to_write = nr_to_write;
__entry->nwritten = nwritten;
__entry->type = type;
),
TP_printk("dev = (%d,%d), %s, nr_to_write = %ld, nwritten = %ld",
show_dev(__entry->dev),
show_block_type(__entry->type),
__entry->nr_to_write,
__entry->nwritten)
);
TRACE_EVENT(f2fs_readpages,
TP_PROTO(struct inode *inode, pgoff_t start, unsigned int nrpage),