From cdcf97e17e73dfdd65c4e46bb30c4a07f5e710cf Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Wed, 23 Nov 2022 04:42:53 -0500 Subject: [PATCH] LU-16338 readahead: add stats for read-ahead page count This patch adds the stats for read-ahead page count: lctl get_param llite.*.read_ahead_stats llite.lustre-ffff938b7849d000.read_ahead_stats= snapshot_time 4011.320890492 secs.nsecs start_time 0.000000000 secs.nsecs elapsed_time 4011.320890492 secs.nsecs hits 4 samples [pages] misses 1 samples [pages] zero_size_window 4 samples [pages] failed_to_reach_end 1 samples [pages] failed_to_fast_read 1 samples [pages] readahead_pages 1 samples [pages] 255 255 255 Signed-off-by: Qian Yingjin Change-Id: Iada06eb7d78ab28cfcc7167e49d25da252da4009 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49224 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Patrick Farrell Reviewed-by: Oleg Drokin --- lustre/llite/llite_internal.h | 1 + lustre/llite/lproc_llite.c | 15 ++++++++++++--- lustre/llite/rw.c | 13 +++++++++++++ lustre/tests/sanity.sh | 14 ++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index bdbfbb0..87de8fd 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -593,6 +593,7 @@ enum ra_stat { RA_STAT_ASYNC, RA_STAT_FAILED_FAST_READ, RA_STAT_MMAP_RANGE_READ, + RA_STAT_READAHEAD_PAGES, _NR_RA_STAT, }; diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 7776381..b729bc6 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -1898,6 +1898,7 @@ static const char *const ra_stat_string[] = { [RA_STAT_ASYNC] = "async_readahead", [RA_STAT_FAILED_FAST_READ] = "failed_to_fast_read", [RA_STAT_MMAP_RANGE_READ] = "mmap_range_read", + [RA_STAT_READAHEAD_PAGES] = "readahead_pages" }; int ll_debugfs_register_super(struct super_block *sb, const char *name) @@ -1949,9 +1950,17 @@ int ll_debugfs_register_super(struct super_block *sb, const char *name) if (sbi->ll_ra_stats == NULL) GOTO(out_stats, err = -ENOMEM); - for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++) - lprocfs_counter_init(sbi->ll_ra_stats, id, LPROCFS_TYPE_PAGES, - ra_stat_string[id]); + for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++) { + if (id == RA_STAT_READAHEAD_PAGES) + lprocfs_counter_init(sbi->ll_ra_stats, id, + LPROCFS_TYPE_PAGES | + LPROCFS_CNTR_AVGMINMAX, + ra_stat_string[id]); + else + lprocfs_counter_init(sbi->ll_ra_stats, id, + LPROCFS_TYPE_PAGES, + ra_stat_string[id]); + } debugfs_create_file("read_ahead_stats", 0644, sbi->ll_debugfs_entry, sbi->ll_ra_stats, &ldebugfs_stats_seq_fops); diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index 66496e6..49f174f 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -148,9 +148,18 @@ static inline bool ll_readahead_enabled(struct ll_sb_info *sbi) void ll_ra_stats_inc(struct inode *inode, enum ra_stat which) { struct ll_sb_info *sbi = ll_i2sbi(inode); + ll_ra_stats_inc_sbi(sbi, which); } +void ll_ra_stats_add(struct inode *inode, enum ra_stat which, long count) +{ + struct ll_sb_info *sbi = ll_i2sbi(inode); + + LASSERTF(which < _NR_RA_STAT, "which: %u\n", which); + lprocfs_counter_add(sbi->ll_ra_stats, which, count); +} + #define RAS_CDEBUG(ras) \ CDEBUG(D_READA, \ "lre %llu cr %lu cb %llu wsi %lu wp %lu nra %lu rpc %lu " \ @@ -524,6 +533,10 @@ ll_read_ahead_pages(const struct lu_env *env, struct cl_io *io, cl_read_ahead_release(env, &ra); + if (count) + ll_ra_stats_add(vvp_object_inode(io->ci_obj), + RA_STAT_READAHEAD_PAGES, count); + return count; } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 44c02a3..d94511a 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -11152,6 +11152,20 @@ test_101j() { } run_test 101j "A complete read block should be submitted when no RA" +test_101k() +{ + local file=$DIR/$tfile + + check_set_fallocate_or_skip + + $LCTL set_param -n llite.*.read_ahead_stats=0 + fallocate -l 16K $file || error "failed to fallocate $file" + cancel_lru_locks osc + $MULTIOP $file or1048576c + $LCTL get_param llite.*.read_ahead_stats +} +run_test 101k "read ahead for small file" + setup_test102() { test_mkdir $DIR/$tdir chown $RUNAS_ID $DIR/$tdir -- 1.8.3.1