]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: report cache hits and misses at unmount time
authorDarrick J. Wong <djwong@kernel.org>
Thu, 24 Apr 2025 21:45:43 +0000 (14:45 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2025 14:29:30 +0000 (10:29 -0400)
Log the IO cache's hit and miss quantities at unmount time.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/174553065528.1161238.4178228996070898927.stgit@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/ext2_io.h
lib/ext2fs/unix_io.c
misc/fuse2fs.c

index 27eaaf1be35442660a9ac6c23b4b554b2c2f693d..39a4e8fcf6b5159b6a1950f12f7f962736bf02c1 100644 (file)
@@ -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 {
index 4b4f25a494f8c64798b732b2700ba2f62359ee60..207a8e63b77fd45a449052739e8ddcc08f8e94a5 100644 (file)
@@ -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;
 
index eac52d66b21a38055e85bacdf2ec38aea18dee9e..efe8614f69be9efce5a3802f8d90ff169d4f6263 100644 (file)
@@ -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];