From: Darrick J. Wong Date: Thu, 24 Apr 2025 21:45:43 +0000 (-0700) Subject: fuse2fs: report cache hits and misses at unmount time X-Git-Tag: v1.47.3-rc1~81 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fc31e7f7678f611f69a4741a1cf11fa717bd362;p=thirdparty%2Fe2fsprogs.git fuse2fs: report cache hits and misses at unmount time Log the IO cache's hit and miss quantities at unmount time. Signed-off-by: Darrick J. Wong Link: https://lore.kernel.org/r/174553065528.1161238.4178228996070898927.stgit@frogsfrogsfrogs Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h index 27eaaf1b..39a4e8fc 100644 --- a/lib/ext2fs/ext2_io.h +++ b/lib/ext2fs/ext2_io.h @@ -71,6 +71,8 @@ struct struct_io_stats { int reserved; unsigned long long bytes_read; unsigned long long bytes_written; + unsigned long long cache_hits; + unsigned long long cache_misses; }; struct struct_io_manager { diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 4b4f25a4..207a8e63 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -536,6 +536,7 @@ static struct unix_cache *find_cached_block(struct unix_private_data *data, } if (cache->block == block) { cache->access_time = ++data->access_time; + data->io_stats.cache_hits++; return cache; } if (!oldest_cache || @@ -544,6 +545,7 @@ static struct unix_cache *find_cached_block(struct unix_private_data *data, } if (eldest) *eldest = (unused_cache) ? unused_cache : oldest_cache; + data->io_stats.cache_misses++; return 0; } @@ -737,7 +739,7 @@ static errcode_t unix_open_channel(const char *name, int fd, memset(data, 0, sizeof(struct unix_private_data)); data->magic = EXT2_ET_MAGIC_UNIX_IO_CHANNEL; - data->io_stats.num_fields = 2; + data->io_stats.num_fields = 4; data->flags = flags; data->dev = fd; diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index eac52d66..efe8614f 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -604,6 +604,19 @@ static void op_destroy(void *p EXT2FS_ATTR((unused))) translate_error(fs, 0, err); } + if (ff->debug && fs->io->manager->get_stats) { + io_stats stats = NULL; + + fs->io->manager->get_stats(fs->io, &stats); + dbg_printf(ff, "read: %lluk\n", stats->bytes_read >> 10); + dbg_printf(ff, "write: %lluk\n", stats->bytes_written >> 10); + dbg_printf(ff, "hits: %llu\n", stats->cache_hits); + dbg_printf(ff, "misses: %llu\n", stats->cache_misses); + dbg_printf(ff, "hit_ratio: %.1f%%\n", + (100.0 * stats->cache_hits) / + (stats->cache_hits + stats->cache_misses)); + } + if (ff->kernel) { char uuid[UUID_STR_SIZE];