f2fs: cache: show per-cache usage in debugfs

This patch exposes per-cache memory usage (entry struct memory vs.
cached block buffer memory) for meta, node, and compress caches under
the memory section in debugfs:
  - meta entry: xxx KB, meta cache: xxx KB
  - node entry: xxx KB, node cache: xxx KB
  - compress entry: xxx KB, compress cache: xxx KB

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:43 +08:00 committed by Jaegeuk Kim
parent cc46c2e933
commit f17987c621
3 changed files with 42 additions and 8 deletions

View File

@ -38,6 +38,7 @@ enum f2fs_cache_type {
F2FS_META_CACHE,
F2FS_NODE_CACHE,
F2FS_COMPRESS_CACHE,
NR_CACHE_TYPES,
};
/* Main cache control structure (per sb_info) */

View File

@ -380,17 +380,36 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
si->cache_mem += si->ext_mem[i];
}
si->page_mem = 0;
si->page_mem += (unsigned long long)META_CACHE(sbi)->num_entries << PAGE_SHIFT;
si->cache_mem += META_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
si->page_mem += (unsigned long long)NODE_CACHE(sbi)->num_entries << PAGE_SHIFT;
si->cache_mem += NODE_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
si->cache_entry_mem[F2FS_META_CACHE] =
(unsigned long long)META_CACHE(sbi)->num_entries *
sizeof(struct f2fs_cached_block);
si->cache_data_mem[F2FS_META_CACHE] =
(unsigned long long)META_CACHE(sbi)->num_entries * sbi->blocksize;
si->cache_entry_mem[F2FS_NODE_CACHE] =
(unsigned long long)NODE_CACHE(sbi)->num_entries *
sizeof(struct f2fs_cached_block);
si->cache_data_mem[F2FS_NODE_CACHE] =
(unsigned long long)NODE_CACHE(sbi)->num_entries * sbi->blocksize;
si->cache_mem += si->cache_entry_mem[F2FS_META_CACHE] +
si->cache_entry_mem[F2FS_NODE_CACHE];
si->page_mem = si->cache_data_mem[F2FS_META_CACHE] +
si->cache_data_mem[F2FS_NODE_CACHE];
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (test_opt(sbi, COMPRESS_CACHE)) {
unsigned long npages = COMPRESS_CACHE(sbi)->num_entries;
si->cache_entry_mem[F2FS_COMPRESS_CACHE] =
(unsigned long long)COMPRESS_CACHE(sbi)->num_entries *
sizeof(struct f2fs_cached_block);
si->cache_data_mem[F2FS_COMPRESS_CACHE] =
(unsigned long long)COMPRESS_CACHE(sbi)->num_entries *
sbi->blocksize;
si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
si->cache_mem += npages * sizeof(struct f2fs_cached_block);
si->cache_mem += si->cache_entry_mem[F2FS_COMPRESS_CACHE];
si->page_mem += si->cache_data_mem[F2FS_COMPRESS_CACHE];
} else {
si->cache_entry_mem[F2FS_COMPRESS_CACHE] = 0;
si->cache_data_mem[F2FS_COMPRESS_CACHE] = 0;
}
#endif
}
@ -749,6 +768,18 @@ static int stat_show(struct seq_file *s, void *v)
si->ext_mem[EX_READ] >> 10);
seq_printf(s, " - block age extent cache: %llu KB\n",
si->ext_mem[EX_BLOCK_AGE] >> 10);
seq_printf(s, " - meta entry: %llu KB, meta cache: %llu KB\n",
si->cache_entry_mem[F2FS_META_CACHE] >> 10,
si->cache_data_mem[F2FS_META_CACHE] >> 10);
seq_printf(s, " - node entry: %llu KB, node cache: %llu KB\n",
si->cache_entry_mem[F2FS_NODE_CACHE] >> 10,
si->cache_data_mem[F2FS_NODE_CACHE] >> 10);
#ifdef CONFIG_F2FS_FS_COMPRESSION
if (test_opt(sbi, COMPRESS_CACHE))
seq_printf(s, " - compress entry: %llu KB, compress cache: %llu KB\n",
si->cache_entry_mem[F2FS_COMPRESS_CACHE] >> 10,
si->cache_data_mem[F2FS_COMPRESS_CACHE] >> 10);
#endif
seq_printf(s, " - paged : %llu KB\n",
si->page_mem >> 10);
}

View File

@ -4525,6 +4525,8 @@ struct f2fs_stat_info {
unsigned int block_count[2];
unsigned int inplace_count;
unsigned long long base_mem, cache_mem, page_mem;
unsigned long long cache_entry_mem[NR_CACHE_TYPES];
unsigned long long cache_data_mem[NR_CACHE_TYPES];
struct f2fs_dev_stats *dev_stats;
};