From a20f25d24b5f0ce7b5e77f7c596bffd0450cbdae Mon Sep 17 00:00:00 2001 From: Qian Yingjin Date: Fri, 11 Dec 2020 11:20:38 +0800 Subject: [PATCH] LU-14139 statahead: add stats for batch RPC requests This patch adds stats for batch PtlRPC request. It can show the statistical information such as how many subreqs in a batch RPC. Signed-off-by: Qian Yingjin Change-Id: I2f71ff5d01ab1070bd8d771a72edd786ad27f03c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/40943 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Mikhail Pershin Reviewed-by: Oleg Drokin --- lustre/include/obd.h | 2 ++ lustre/ldlm/ldlm_lib.c | 1 + lustre/mdc/lproc_mdc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lustre/ptlrpc/batch.c | 7 ++++++- lustre/tests/sanity.sh | 3 +++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index e0fa3ce..1017c91 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -281,6 +281,8 @@ struct client_obd { struct obd_histogram cl_write_page_hist; struct obd_histogram cl_read_offset_hist; struct obd_histogram cl_write_offset_hist; + ktime_t cl_batch_stats_init; + struct obd_histogram cl_batch_rpc_hist; /** LRU for osc caching pages */ struct cl_client_cache *cl_cache; diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 41b6b95..2ef3add 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -421,6 +421,7 @@ int client_obd_setup(struct obd_device *obd, struct lustre_cfg *lcfg) spin_lock_init(&cli->cl_write_page_hist.oh_lock); spin_lock_init(&cli->cl_read_offset_hist.oh_lock); spin_lock_init(&cli->cl_write_offset_hist.oh_lock); + spin_lock_init(&cli->cl_batch_rpc_hist.oh_lock); /* lru for osc. */ INIT_LIST_HEAD(&cli->cl_lru_osc); diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index f932dfc..1dc5803 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -514,6 +514,48 @@ static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v) } LPROC_SEQ_FOPS(mdc_rpc_stats); +static ssize_t mdc_batch_stats_seq_write(struct file *file, + const char __user *buf, + size_t len, loff_t *off) +{ + struct seq_file *seq = file->private_data; + struct obd_device *obd = seq->private; + struct client_obd *cli = &obd->u.cli; + + lprocfs_oh_clear(&cli->cl_batch_rpc_hist); + cli->cl_batch_stats_init = ktime_get_real(); + + return len; +} + +static int mdc_batch_stats_seq_show(struct seq_file *seq, void *v) +{ + struct obd_device *obd = seq->private; + struct client_obd *cli = &obd->u.cli; + unsigned long tot; + unsigned long cum; + int i; + + lprocfs_stats_header(seq, ktime_get_real(), cli->cl_batch_stats_init, + 25, ":", true, ""); + seq_printf(seq, "subreqs per batch batches %% cum %%\n"); + tot = lprocfs_oh_sum(&cli->cl_batch_rpc_hist); + cum = 0; + + for (i = 0; i < OBD_HIST_MAX; i++) { + unsigned long cnt = cli->cl_batch_rpc_hist.oh_buckets[i]; + + cum += cnt; + seq_printf(seq, "%d:\t\t%10lu %3u %3u\n", + 1 << i, cnt, pct(cnt, tot), pct(cum, tot)); + if (cum == tot) + break; + } + + return 0; +} +LPROC_SEQ_FOPS(mdc_batch_stats); + static int mdc_stats_seq_show(struct seq_file *seq, void *v) { struct obd_device *obd = seq->private; @@ -632,6 +674,8 @@ struct lprocfs_vars lprocfs_mdc_obd_vars[] = { .fops = &mdc_pinger_recov_fops }, { .name = "rpc_stats", .fops = &mdc_rpc_stats_fops }, + { .name = "batch_stats", + .fops = &mdc_batch_stats_fops }, { .name = "unstable_stats", .fops = &mdc_unstable_stats_fops }, { .name = "mdc_stats", diff --git a/lustre/ptlrpc/batch.c b/lustre/ptlrpc/batch.c index 0cc8f88..d678211 100644 --- a/lustre/ptlrpc/batch.c +++ b/lustre/ptlrpc/batch.c @@ -36,6 +36,7 @@ #define DEBUG_SUBSYSTEM S_MDC #include +#include #include #ifdef HAVE_SERVER_SUPPORT #include @@ -410,9 +411,10 @@ static int batch_update_interpret(const struct lu_env *env, static int batch_send_update_req(const struct lu_env *env, struct batch_update_head *head) { - struct lu_batch *bh; + struct obd_device *obd; struct ptlrpc_request *req = NULL; struct batch_update_args *aa; + struct lu_batch *bh; int rc; ENTRY; @@ -420,6 +422,7 @@ static int batch_send_update_req(const struct lu_env *env, if (head == NULL) RETURN(0); + obd = class_exp2obd(head->buh_exp); bh = head->buh_batch; rc = batch_prep_update_req(head, &req); if (rc) { @@ -456,6 +459,8 @@ static int batch_send_update_req(const struct lu_env *env, if (req != NULL) ptlrpc_req_finished(req); + lprocfs_oh_tally_log2(&obd->u.cli.cl_batch_rpc_hist, + head->buh_update_count); RETURN(rc); } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 77b706a..0d23256 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -13575,6 +13575,8 @@ test_123a_base() { # was test 123, statahead(bug 11401) fi running_in_vm && SLOWOK=1 + $LCTL set_param mdc.*.batch_stats=0 + rm -rf $DIR/$tdir test_mkdir $DIR/$tdir NUMFREE=$(df -i -P $DIR | tail -n 1 | awk '{ print $4 }') @@ -13650,6 +13652,7 @@ test_123a_base() { # was test 123, statahead(bug 11401) log "rm -r $DIR/$tdir/: $delta seconds" log "rm done" lctl get_param -n llite.*.statahead_stats + $LCTL get_param mdc.*.batch_stats } test_123aa() { -- 1.8.3.1