ceph: add min/max latency support for read/write/metadata metrics
PATCH 1/1 ceph: add min/max latency support for read/write/metadata metrics
From: Xiubo Li <[email protected]>
These will be very useful help diagnose problems.
URL: https://tracker.ceph.com/issues/44533
---
The output will be like:
# cat /sys/kernel/debug/ceph/19e31430-fc65-4aa1-99cf-2c8eaaafd451.client4347/metrics item total sum_lat(us) avg_lat(us) min_lat(us) max_lat(us) ------------------------------------------------------------------------------------- read 27 297000 11000 2000 27000 write 16 3860000 241250 175000 263000 metadata 3 30000 10000 2000 16000
item total miss hit
-------------------------------------------------
d_lease 2 0 1 caps 2 0 3078
fs/ceph/debugfs.c | 27 ++++++++++++++++++++------ fs/ceph/mds_client.c | 12 ++++++++++++ fs/ceph/metric.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 7 deletions(-)
fs/ceph/debugfs.c +21 -6
@@ -129,28 +129,43 @@ static int metric_show(struct seq_file *s, void *p)struct ceph_fs_client *fsc = s->private;struct ceph_mds_client *mdsc = fsc->mdsc;int i, nr_caps =0 ; -s64 total, sum, avg =0 ; +s64 total, sum, avg =0 , min, max; -seq_printf (s,"item total sum_lat(us) avg_lat(us)\n" ); -seq_printf (s,"-----------------------------------------------------\n" ); +seq_printf (s,"item total sum_lat(us) avg_lat(us) min_lat(us) max_lat(us)\n" ); +seq_printf (s,"-------------------------------------------------------------------------------------\n" ); total =percpu_counter_sum (&mdsc->metric.total_reads); sum =percpu_counter_sum (&mdsc->metric.read_latency_sum); sum =jiffies_to_usecs (sum); avg = total ? sum / total :0 ; -seq_printf (s,"%-14s%-12lld%-16lld%lld\n" ,"read" , total, sum, avg); + min =atomic64_read (&mdsc->metric.read_latency_min); + min =jiffies_to_usecs (min ==S64_MAX ?0 : min); + max =atomic64_read (&mdsc->metric.read_latency_max); + max =jiffies_to_usecs (max); +seq_printf (s,"%-14s%-12lld%-16lld%-16lld%-16lld%lld\n" ,"read" , + total, sum, avg, min, max); total =percpu_counter_sum (&mdsc->metric.total_writes); sum =percpu_counter_sum (&mdsc->metric.write_latency_sum); sum =jiffies_to_usecs (sum); avg = total ? sum / total :0 ; -seq_printf (s,"%-14s%-12lld%-16lld%lld\n" ,"write" , total, sum, avg); + min =atomic64_read (&mdsc->metric.write_latency_min); + min =jiffies_to_usecs (min ==S64_MAX ?0 : min); + max =atomic64_read (&mdsc->metric.write_latency_max); + max =jiffies_to_usecs (max); +seq_printf (s,"%-14s%-12lld%-16lld%-16lld%-16lld%lld\n" ,"write" , + total, sum, avg, min, max); total =percpu_counter_sum (&mdsc->metric.total_metadatas); sum =percpu_counter_sum (&mdsc->metric.metadata_latency_sum); sum =jiffies_to_usecs (sum); avg = total ? sum / total :0 ; -seq_printf (s,"%-14s%-12lld%-16lld%lld\n" ,"metadata" , total, sum, avg); + min =atomic64_read (&mdsc->metric.metadata_latency_min); + min =jiffies_to_usecs (min ==S64_MAX ?0 : min); + max =atomic64_read (&mdsc->metric.metadata_latency_max); + max =jiffies_to_usecs (max); +seq_printf (s,"%-14s%-12lld%-16lld%-16lld%-16lld%lld\n" ,"metadata" , + total, sum, avg, min, max);seq_printf (s,"\n" );seq_printf (s,"item total miss hit\n" );
fs/ceph/mds_client.c +12 -0
@@ -4358,6 +4358,10 @@ static int ceph_mdsc_metric_init(struct ceph_client_metric *metric)if (ret) goto err_read_latency_sum; +spin_lock_init (&metric->read_latency_lock); +atomic64_set (&metric->read_latency_min,S64_MAX ); +atomic64_set (&metric->read_latency_max,0 ); + ret =percpu_counter_init (&metric->total_writes,0 ,GFP_KERNEL );if (ret) goto err_total_writes;
@@ -4366,6 +4370,10 @@ static int ceph_mdsc_metric_init(struct ceph_client_metric *metric)if (ret) goto err_write_latency_sum; +spin_lock_init (&metric->write_latency_lock); +atomic64_set (&metric->write_latency_min,S64_MAX ); +atomic64_set (&metric->write_latency_max,0 ); + ret =percpu_counter_init (&metric->total_metadatas,0 ,GFP_KERNEL );if (ret) goto err_total_metadatas;
@@ -4374,6 +4382,10 @@ static int ceph_mdsc_metric_init(struct ceph_client_metric *metric)if (ret) goto err_metadata_latency_sum; +spin_lock_init (&metric->metadata_latency_lock); +atomic64_set (&metric->metadata_latency_min,S64_MAX ); +atomic64_set (&metric->metadata_latency_max,0 ); +return 0 ; err_metadata_latency_sum:
fs/ceph/metric.h +53 -1
103 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 82 lines · On Mon, 2020-03-09 at 22:36 -0400, [email protected] wrote:
From: Xiubo Li <[email protected]>
These will be very useful help diagnose problems.
URL: https://tracker.ceph.com/issues/44533
Signed-off-by Xiubo Li <[email protected]>---
The output will be like:
# cat /sys/kernel/debug/ceph/19e31430-fc65-4aa1-99cf-2c8eaaafd451.client4347/metrics item total sum_lat(us) avg_lat(us) min_lat(us) max_lat(us) ------------------------------------------------------------------------------------- read 27 297000 11000 2000 27000 write 16 3860000 241250 175000 263000 metadata 3 30000 10000 2000 16000item total miss hit
-------------------------------------------------d_lease 2 0 1 caps 2 0 3078fs/ceph/debugfs.c | 27 ++++++++++++++++++++------ fs/ceph/mds_client.c | 12 ++++++++++++ fs/ceph/metric.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 7 deletions(-)fs/ceph/metric.h +19
-1@@ -2,6 +2,10 @@ #ifndef _FS_CEPH_MDS_METRIC_H #define _FS_CEPH_MDS_METRIC_H +#include <linux/atomic.h> +#include <linux/percpu.h> +#include <linux/spinlock.h> + /* This is the global metrics */ struct ceph_client_metric { atomic64_t total_dentries;@@ -13,12 +17,21 @@ struct ceph_client_metric {struct percpu_counter total_reads;struct percpu_counter read_latency_sum; +spinlock_t read_latency_lock; +atomic64_t read_latency_min; +atomic64_t read_latency_max;struct percpu_counter total_writes;struct percpu_counter write_latency_sum; +spinlock_t write_latency_lock; +atomic64_t write_latency_min; +atomic64_t write_latency_max;struct percpu_counter total_metadatas;struct percpu_counter metadata_latency_sum; +spinlock_t metadata_latency_lock; +atomic64_t metadata_latency_min; +atomic64_t metadata_latency_max; };static inline void ceph_update_cap_hit (struct ceph_client_metric *m)@@ -36,11 +49,24 @@ static inline void ceph_update_read_latency(struct ceph_client_metric *m, unsigned long r_end, int rc) { +unsigned long lat = r_end - r_start; +if (rc <0 && rc != -ENOENT && rc != -ETIMEDOUT )return ;percpu_counter_inc (&m->total_reads); -percpu_counter_add (&m->read_latency_sum, r_end - r_start); +percpu_counter_add (&m->read_latency_sum, lat); + +if (lat >=atomic64_read (&m->read_latency_min) && + lat <=atomic64_read (&m->read_latency_max))
fs/ceph/metric.h static inline void ceph_update_read_latency(struct ceph_client_metric *m, · line 71
Quoted 10 lines
fs/ceph/metric.h +8
-0+return ; + +spin_lock (&m->read_latency_lock); +if (lat <atomic64_read (&m->read_latency_min)) +atomic64_set (&m->read_latency_min, lat); +if (lat >atomic64_read (&m->read_latency_max)) +atomic64_set (&m->read_latency_max, lat); +spin_unlock (&m->read_latency_lock); }
Looks reasonable overall. I do sort of wonder if we really need spinlocks for these though. Might it be more efficient to use cmpxchg instead? i.e.:
cur = atomic64_read(&m->read_latency_min);
do {
old = cur;
if (likely(lat >= old))
break;
} while ((cur = atomic_long_cmpxchg(&m->read_latency_min, old, lat)) != old);...another idea might be to use a seqlock and non-atomic vars.
Mostly this shouldn't matter much though as we'll almost always be hitting the non-locking fastpath. I'll plan to merge this as-is unless you want to rework it.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 97 lines · Jeff Layton
Quoted 82 lines · On Mon, 2020-03-09 at 22:36 -0400, [email protected] wrote:
From: Xiubo Li <[email protected]>
These will be very useful help diagnose problems.
URL: https://tracker.ceph.com/issues/44533
Signed-off-by Xiubo Li <[email protected]>---
The output will be like:
# cat /sys/kernel/debug/ceph/19e31430-fc65-4aa1-99cf-2c8eaaafd451.client4347/metrics item total sum_lat(us) avg_lat(us) min_lat(us) max_lat(us) ------------------------------------------------------------------------------------- read 27 297000 11000 2000 27000 write 16 3860000 241250 175000 263000 metadata 3 30000 10000 2000 16000item total miss hit
-------------------------------------------------d_lease 2 0 1 caps 2 0 3078fs/ceph/debugfs.c | 27 ++++++++++++++++++++------ fs/ceph/mds_client.c | 12 ++++++++++++ fs/ceph/metric.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 7 deletions(-)fs/ceph/metric.h +19
-1@@ -2,6 +2,10 @@ #ifndef _FS_CEPH_MDS_METRIC_H #define _FS_CEPH_MDS_METRIC_H +#include <linux/atomic.h> +#include <linux/percpu.h> +#include <linux/spinlock.h> + /* This is the global metrics */ struct ceph_client_metric { atomic64_t total_dentries;@@ -13,12 +17,21 @@ struct ceph_client_metric {struct percpu_counter total_reads;struct percpu_counter read_latency_sum; +spinlock_t read_latency_lock; +atomic64_t read_latency_min; +atomic64_t read_latency_max;struct percpu_counter total_writes;struct percpu_counter write_latency_sum; +spinlock_t write_latency_lock; +atomic64_t write_latency_min; +atomic64_t write_latency_max;struct percpu_counter total_metadatas;struct percpu_counter metadata_latency_sum; +spinlock_t metadata_latency_lock; +atomic64_t metadata_latency_min; +atomic64_t metadata_latency_max; };static inline void ceph_update_cap_hit (struct ceph_client_metric *m)@@ -36,11 +49,24 @@ static inline void ceph_update_read_latency(struct ceph_client_metric *m, unsigned long r_end, int rc) { +unsigned long lat = r_end - r_start; +if (rc <0 && rc != -ENOENT && rc != -ETIMEDOUT )return ;percpu_counter_inc (&m->total_reads); -percpu_counter_add (&m->read_latency_sum, r_end - r_start); +percpu_counter_add (&m->read_latency_sum, lat); + +if (lat >=atomic64_read (&m->read_latency_min) && + lat <=atomic64_read (&m->read_latency_max))fs/ceph/metric.h static inline void ceph_update_read_latency(struct ceph_client_metric *m, · line 71
Quoted 10 lines
fs/ceph/metric.h +8
-0+return ; + +spin_lock (&m->read_latency_lock); +if (lat <atomic64_read (&m->read_latency_min)) +atomic64_set (&m->read_latency_min, lat); +if (lat >atomic64_read (&m->read_latency_max)) +atomic64_set (&m->read_latency_max, lat); +spin_unlock (&m->read_latency_lock); }Looks reasonable overall. I do sort of wonder if we really need spinlocks for these though. Might it be more efficient to use cmpxchg instead? i.e.:
Quoted 6 lines
cur =
atomic64_read(&m->read_latency_min);do { old = cur; if (likely(lat >= old)) break; } while ((cur = atomic_long_cmpxchg(&m->read_latency_min, old, lat)) != old);
IMO the above case should be more efficient here.
Let me post the V2 to fix it.
BRs
Quoted 5 lines
...another idea might be to use a seqlock and non-atomic vars.
Mostly this shouldn't matter much though as we'll almost always be hitting the non-locking fastpath. I'll plan to merge this as-is unless you want to rework it.