From e1b63fd21177b40d5c23cedd9e5d81b461db53c3 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 26 Dec 2018 03:45:52 -0700 Subject: [PATCH] LU-10171 lmv: avoid gratuitous 64-bit modulus Fix the pct() calculation to use unsigned long arguments, since this is what callers use. Remove duplicate pct() definition in lproc_mdc. Don't do a 64-bit modulus of the LNet NID to find the starting MDT index when this isn't really needed. Similarly, don't compute the FLD cache usage percentage for a debug message that is never used. Fixes: 9b924e86b27d ("LU-10171 headers: define pct(a,b) once") Signed-off-by: Andreas Dilger Change-Id: I34cefd269cb83f563d2f08c32dc3fa1ed5c5a5b1 Reviewed-on: https://review.whamcloud.com/33922 Reviewed-by: Ben Evans Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/fld/fld_cache.c | 16 +++++----------- lustre/include/lprocfs_status.h | 2 +- lustre/include/obd.h | 5 ++--- lustre/lmv/lmv_obd.c | 5 ++++- lustre/mdc/lproc_mdc.c | 8 +++----- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lustre/fld/fld_cache.c b/lustre/fld/fld_cache.c index bb3dfe0..f638e0d 100644 --- a/lustre/fld/fld_cache.c +++ b/lustre/fld/fld_cache.c @@ -88,20 +88,14 @@ struct fld_cache *fld_cache_init(const char *name, */ void fld_cache_fini(struct fld_cache *cache) { - ENTRY; - - LASSERT(cache != NULL); - fld_cache_flush(cache); + LASSERT(cache != NULL); + fld_cache_flush(cache); - CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name); - CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count); + CDEBUG(D_INFO, "FLD cache statistics (%s):\n", cache->fci_name); CDEBUG(D_INFO, " Cache reqs: %llu\n", cache->fci_stat.fst_cache); - CDEBUG(D_INFO, " Cache hits: %u%%\n", - pct(cache->fci_stat.fst_cache, cache->fci_stat.fst_count)); - - OBD_FREE_PTR(cache); + CDEBUG(D_INFO, " Total reqs: %llu\n", cache->fci_stat.fst_count); - EXIT; + OBD_FREE_PTR(cache); } /** diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index acf1bc0..3da912c 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -58,7 +58,7 @@ struct lprocfs_vars { mode_t proc_mode; }; -static inline u32 pct(s64 a, s64 b) +static inline unsigned int pct(unsigned long a, unsigned long b) { return b ? a * 100 / b : 0; } diff --git a/lustre/include/obd.h b/lustre/include/obd.h index 200a0f3..f651de9 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -441,11 +441,10 @@ struct lmv_obd { int connected; int max_easize; int max_def_easize; + u32 lmv_statfs_start; - __u32 tgts_size; /* size of tgts array */ + u32 tgts_size; /* size of tgts array */ struct lmv_tgt_desc **tgts; - int lmv_statfs_start; - struct obd_connect_data conn_data; struct kobject *lmv_tgts_kobj; diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 5a7945b..19bfed4 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -1373,8 +1373,11 @@ static int lmv_select_statfs_mdt(struct lmv_obd *lmv, __u32 flags) break; if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) { + /* We dont need a full 64-bit modulus, just enough + * to distribute the requests across MDTs evenly. + */ lmv->lmv_statfs_start = - lnet_id.nid % lmv->desc.ld_tgt_count; + (u32)lnet_id.nid % lmv->desc.ld_tgt_count; break; } } diff --git a/lustre/mdc/lproc_mdc.c b/lustre/mdc/lproc_mdc.c index c912232..1530dd1 100644 --- a/lustre/mdc/lproc_mdc.c +++ b/lustre/mdc/lproc_mdc.c @@ -326,7 +326,6 @@ static ssize_t mdc_rpc_stats_seq_write(struct file *file, return len; } -#define pct(a, b) (b ? a * 100 / b : 0) static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v) { struct obd_device *dev = seq->private; @@ -362,7 +361,7 @@ static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v) read_cum += r; write_cum += w; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", + seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n", 1 << i, r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), @@ -386,7 +385,7 @@ static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v) read_cum += r; write_cum += w; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", + seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n", i, r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); if (read_cum == read_tot && write_cum == write_tot) @@ -408,7 +407,7 @@ static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v) read_cum += r; write_cum += w; - seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n", + seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n", (i == 0) ? 0 : 1 << (i - 1), r, pct(r, read_tot), pct(read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); @@ -419,7 +418,6 @@ static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v) return 0; } -#undef pct LPROC_SEQ_FOPS(mdc_rpc_stats); static int mdc_stats_seq_show(struct seq_file *seq, void *v) -- 1.8.3.1