From b9167201a00e38ce8f63d3013ab89571c3492f52 Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Tue, 25 Jan 2022 21:50:37 -0500 Subject: [PATCH] LU-14139 statahead: add total hit/miss count stats In this patch, it adds total hit/miss count stats for statahead. These statistics are updated when the statahead thread terminated. This patch also adds support to clear all statahead stats: $LCTL set_param llite.*.statahead_stats=0 Signed-off-by: Qian Yingjin Change-Id: I8b11d26385234305631c232a15711224dcfb0668 Reviewed-on: https://review.whamcloud.com/46309 Reviewed-by: Andreas Dilger Reviewed-by: Lai Siyao Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/llite/llite_internal.h | 2 ++ lustre/llite/llite_lib.c | 2 ++ lustre/llite/lproc_llite.c | 26 +++++++++++++++++++++++--- lustre/llite/statahead.c | 3 +++ lustre/tests/sanity.sh | 24 ++++++++++++++---------- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index c585a68..21a3ded 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -758,6 +758,8 @@ struct ll_sb_info { atomic_t ll_sa_running; /* running statahead thread * count */ atomic_t ll_agl_total; /* AGL thread started count */ + atomic_t ll_sa_hit_total; /* total hit count */ + atomic_t ll_sa_miss_total; /* total miss count */ dev_t ll_sdev_orig; /* save s_dev before assign for * clustred nfs */ diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 03e9e39..070c225 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -178,6 +178,8 @@ static struct ll_sb_info *ll_init_sbi(void) atomic_set(&sbi->ll_sa_wrong, 0); atomic_set(&sbi->ll_sa_running, 0); atomic_set(&sbi->ll_agl_total, 0); + atomic_set(&sbi->ll_sa_hit_total, 0); + atomic_set(&sbi->ll_sa_miss_total, 0); set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags); set_bit(LL_SBI_FAST_READ, sbi->ll_flags); set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags); diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c index 31ed585..50fd29d 100644 --- a/lustre/llite/lproc_llite.c +++ b/lustre/llite/lproc_llite.c @@ -833,14 +833,34 @@ static int ll_statahead_stats_seq_show(struct seq_file *m, void *v) seq_printf(m, "statahead total: %u\n" "statahead wrong: %u\n" - "agl total: %u\n", + "agl total: %u\n" + "hit_total: %u\n" + "miss_total: %u\n", atomic_read(&sbi->ll_sa_total), atomic_read(&sbi->ll_sa_wrong), - atomic_read(&sbi->ll_agl_total)); + atomic_read(&sbi->ll_agl_total), + atomic_read(&sbi->ll_sa_hit_total), + atomic_read(&sbi->ll_sa_miss_total)); return 0; } -LDEBUGFS_SEQ_FOPS_RO(ll_statahead_stats); +static ssize_t ll_statahead_stats_seq_write(struct file *file, + const char __user *buffer, + size_t count, loff_t *off) +{ + struct seq_file *m = file->private_data; + struct super_block *sb = m->private; + struct ll_sb_info *sbi = ll_s2sbi(sb); + + atomic_set(&sbi->ll_sa_total, 0); + atomic_set(&sbi->ll_sa_wrong, 0); + atomic_set(&sbi->ll_agl_total, 0); + atomic_set(&sbi->ll_sa_hit_total, 0); + atomic_set(&sbi->ll_sa_miss_total, 0); + + return count; +} +LDEBUGFS_SEQ_FOPS(ll_statahead_stats); static ssize_t lazystatfs_show(struct kobject *kobj, struct attribute *attr, diff --git a/lustre/llite/statahead.c b/lustre/llite/statahead.c index ad31e6e..597405f 100644 --- a/lustre/llite/statahead.c +++ b/lustre/llite/statahead.c @@ -1247,6 +1247,9 @@ out: spin_unlock(&lli->lli_sa_lock); wake_up(&sai->sai_waitq); + atomic_add(sai->sai_hit, &sbi->ll_sa_hit_total); + atomic_add(sai->sai_miss, &sbi->ll_sa_miss_total); + ll_sai_put(sai); return rc; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 4a6cbe4..c78d2b0 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -13037,7 +13037,7 @@ test_123a_base() { # was test 123, statahead(bug 11401) lctl set_param llite.*.statahead_max=$max swrong=$(lctl get_param -n llite.*.statahead_stats | - grep "statahead wrong:" | awk '{print $3}') + awk '/statahead.wrong:/ { print $NF }') lctl get_param -n llite.*.statahead_max | grep '[0-9]' cancel_lru_locks mdc cancel_lru_locks osc @@ -13048,13 +13048,13 @@ test_123a_base() { # was test 123, statahead(bug 11401) log "$lsx $i files with statahead: $delta_sa sec" lctl get_param -n llite.*.statahead_stats ewrong=$(lctl get_param -n llite.*.statahead_stats | - grep "statahead wrong:" | awk '{print $3}') + awk '/statahead.wrong:/ { print $NF }') [[ $swrong -lt $ewrong ]] && log "statahead was stopped, maybe too many locks held!" [[ $delta -eq 0 || $delta_sa -eq 0 ]] && continue - if [ $((delta_sa * 100)) -gt $((delta * 105)) -a $delta_sa -gt $((delta + 2)) ]; then + if (( $delta_sa*100 > $delta*105 && $delta_sa > $delta+2)); then max=$(lctl get_param -n llite.*.statahead_max | head -n 1) lctl set_param -n llite.*.statahead_max 0 @@ -13067,8 +13067,8 @@ test_123a_base() { # was test 123, statahead(bug 11401) delta=$((etime - stime)) log "$lsx $i files again without statahead: $delta sec" lctl set_param llite.*.statahead_max=$max - if [ $((delta_sa * 100 > delta * 105 && delta_sa > delta + 2)) ]; then - if [ $SLOWOK -eq 0 ]; then + if (( $delta_sa*100 > delta*105 && delta_sa > delta+2 )); then + if [ $SLOWOK -eq 0 ]; then error "$lsx $i files is slower with statahead!" else log "$lsx $i files is slower with statahead!" @@ -13122,11 +13122,11 @@ test_123ac() { cancel_lru_locks $OSC rpcs_before=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue) agl_before=$($LCTL get_param -n llite.*.statahead_stats | - awk '/agl.total:/ {print $3}') + awk '/agl.total:/ { print $NF }') test_123a_base "$STATX -c \"%n %i %A %h %u %g %W %X %Z\" -D" test_123a_base "$STATX --cached=always -D" agl_after=$($LCTL get_param -n llite.*.statahead_stats | - awk '/agl.total:/ {print $3}') + awk '/agl.total:/ { print $NF }') [ $agl_before -eq $agl_after ] || error "Should not trigger AGL thread - $agl_before:$agl_after" rpcs_after=$(calc_stats $OSC.*$OSC*.stats ldlm_glimpse_enqueue) @@ -13188,13 +13188,17 @@ test_123d() { createmany -d $DIR/$tdir/$tfile $num || error "createmany $num failed" remount_client $MOUNT $LCTL get_param llite.*.statahead_max + $LCTL set_param llite.*.statahead_stats=0 || + error "clear statahead_stats failed" swrong=$(lctl get_param -n llite.*.statahead_stats | - grep "statahead wrong:" | awk '{print $3}') + awk '/statahead.wrong:/ { print $NF }') ls -l $DIR/$tdir || error "ls -l $DIR/$tdir failed" + # wait for statahead thread finished to update hit/miss stats. + sleep 1 $LCTL get_param -n llite.*.statahead_stats ewrong=$(lctl get_param -n llite.*.statahead_stats | - grep "statahead wrong:" | awk '{print $3}') - [[ $swrong -eq $ewrong ]] || + awk '/statahead.wrong:/ { print $NF }') + (( $swrong == $ewrong )) || log "statahead was stopped, maybe too many locks held!" } run_test 123d "Statahead on striped directories works correctly" -- 1.8.3.1