Skip to contentSkip to conversation

ceph: forward average read/write/metadata latency

PATCH Superseded Venky Shankar 3 participants 9 messages Sep 13, 2021 – Sep 14, 2021 Ceph client

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ceph: forward average read/write/metadata latency

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

The math involved in keeping track of the average latency and stdev seems incorrect, so, this series fixes that up too (closely mimics how its done in userspace with some restrictions obviously) as per::

NEW_AVG = OLD_AVG + ((latency - OLD_AVG) / total_ops)
NEW_STDEV = SQRT(((OLD_STDEV + (latency - OLD_AVG)*(latency - NEW_AVG)) / (total_ops - 1)))

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Venky Shankar (4):
ceph: use "struct ceph_timespec" for r/w/m latencies
ceph: track average/stdev r/w/m latency
ceph: include average/stddev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

 fs/ceph/debugfs.c | 12 +++----
 fs/ceph/metric.c  | 81 +++++++++++++++++++++++++----------------------
 fs/ceph/metric.h  | 64 +++++++++++++++++++++++--------------
 3 files changed, 90 insertions(+), 67 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/4 ceph: use "struct ceph_timespec" for r/w/m latencies

---
 fs/ceph/metric.c | 12 ++++++------
 fs/ceph/metric.h | 17 +++++++----------
 2 files changed, 13 insertions(+), 16 deletions(-)
fs/ceph/metric.c +6 -6
index 5ec94bd4c1de..19bca20cf7e1 100644
@@ -56,8 +56,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	read->data_len = cpu_to_le32(sizeof(*read) - 10);
 	sum = m->read_latency_sum;
 	jiffies_to_timespec64(sum, &ts);
-	read->sec = cpu_to_le32(ts.tv_sec);
-	read->nsec = cpu_to_le32(ts.tv_nsec);
+	read->lat.tv_sec = cpu_to_le32(ts.tv_sec);
+	read->lat.tv_nsec = cpu_to_le32(ts.tv_nsec);
 	items++;
 
 	/* encode the write latency metric */
@@ -68,8 +68,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	write->data_len = cpu_to_le32(sizeof(*write) - 10);
 	sum = m->write_latency_sum;
 	jiffies_to_timespec64(sum, &ts);
-	write->sec = cpu_to_le32(ts.tv_sec);
-	write->nsec = cpu_to_le32(ts.tv_nsec);
+	write->lat.tv_sec = cpu_to_le32(ts.tv_sec);
+	write->lat.tv_nsec = cpu_to_le32(ts.tv_nsec);
 	items++;
 
 	/* encode the metadata latency metric */
@@ -80,8 +80,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	meta->data_len = cpu_to_le32(sizeof(*meta) - 10);
 	sum = m->metadata_latency_sum;
 	jiffies_to_timespec64(sum, &ts);
-	meta->sec = cpu_to_le32(ts.tv_sec);
-	meta->nsec = cpu_to_le32(ts.tv_nsec);
+	meta->lat.tv_sec = cpu_to_le32(ts.tv_sec);
+	meta->lat.tv_nsec = cpu_to_le32(ts.tv_nsec);
 	items++;
 
 	/* encode the dentry lease metric */
fs/ceph/metric.h +7 -10
index af6038ff39d4..1151d64dbcbc 100644
@@ -2,7 +2,7 @@
 #ifndef _FS_CEPH_MDS_METRIC_H
 #define _FS_CEPH_MDS_METRIC_H
 
-#include <linux/types.h>
+#include <linux/ceph/types.h>
 #include <linux/percpu_counter.h>
 #include <linux/ktime.h>
 
@@ -52,9 +52,8 @@ struct ceph_metric_read_latency {
 	__u8  ver;
 	__u8  compat;
 
-	__le32 data_len; /* length of sizeof(sec + nsec) */
-	__le32 sec;
-	__le32 nsec;
+	__le32 data_len; /* length of sizeof(lat) */
+	struct ceph_timespec lat;
 } __packed;
 
 /* metric write latency header */
@@ -64,9 +63,8 @@ struct ceph_metric_write_latency {
 	__u8  ver;
 	__u8  compat;
 
-	__le32 data_len; /* length of sizeof(sec + nsec) */
-	__le32 sec;
-	__le32 nsec;
+	__le32 data_len; /* length of sizeof(lat) */
+	struct ceph_timespec lat;
 } __packed;
 
 /* metric metadata latency header */
@@ -76,9 +74,8 @@ struct ceph_metric_metadata_latency {
 	__u8  ver;
 	__u8  compat;
 
-	__le32 data_len; /* length of sizeof(sec + nsec) */
-	__le32 sec;
-	__le32 nsec;
+	__le32 data_len; /* length of sizeof(lat) */
+	struct ceph_timespec lat;
 } __packed;
 
 /* metric dentry lease header */
Signature · 1 line
2.27.0
#2 lore raw

PATCH 2/4 ceph: track average/stdev r/w/m latency

In reply to Venky Shankar

The math involved in tracking average and standard deviation for r/w/m latencies looks incorrect. Fix that up. Also, change the variable name that tracks standard deviation (*_sq_sum) to *_stdev.

---
 fs/ceph/debugfs.c |  6 +++---
 fs/ceph/metric.c  | 45 ++++++++++++++++++++++++---------------------
 fs/ceph/metric.h  |  9 ++++++---
 3 files changed, 33 insertions(+), 27 deletions(-)
fs/ceph/debugfs.c +3 -3
index f9ff70704423..9153bc233e08 100644
@@ -176,7 +176,7 @@ static int metric_show(struct seq_file *s, void *p)
 	avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
 	min = m->read_latency_min;
 	max = m->read_latency_max;
-	sq = m->read_latency_sq_sum;
+	sq = m->read_latency_stdev;
 	spin_unlock(&m->read_latency_lock);
 	CEPH_METRIC_SHOW("read", total, avg, min, max, sq);
 
@@ -186,7 +186,7 @@ static int metric_show(struct seq_file *s, void *p)
 	avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
 	min = m->write_latency_min;
 	max = m->write_latency_max;
-	sq = m->write_latency_sq_sum;
+	sq = m->write_latency_stdev;
 	spin_unlock(&m->write_latency_lock);
 	CEPH_METRIC_SHOW("write", total, avg, min, max, sq);
 
@@ -196,7 +196,7 @@ static int metric_show(struct seq_file *s, void *p)
 	avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
 	min = m->metadata_latency_min;
 	max = m->metadata_latency_max;
-	sq = m->metadata_latency_sq_sum;
+	sq = m->metadata_latency_stdev;
 	spin_unlock(&m->metadata_latency_lock);
 	CEPH_METRIC_SHOW("metadata", total, avg, min, max, sq);
 
fs/ceph/metric.c +24 -21

93 lines not on this page · raw message

fs/ceph/metric.h +6 -3
index 1151d64dbcbc..136689fa0aec 100644
@@ -108,21 +108,24 @@ struct ceph_client_metric {
 	spinlock_t read_latency_lock;
 	u64 total_reads;
 	ktime_t read_latency_sum;
-	ktime_t read_latency_sq_sum;
+	ktime_t avg_read_latency;
+	ktime_t read_latency_stdev;
 	ktime_t read_latency_min;
 	ktime_t read_latency_max;
 
 	spinlock_t write_latency_lock;
 	u64 total_writes;
 	ktime_t write_latency_sum;
-	ktime_t write_latency_sq_sum;
+	ktime_t avg_write_latency;
+	ktime_t write_latency_stdev;
 	ktime_t write_latency_min;
 	ktime_t write_latency_max;
 
 	spinlock_t metadata_latency_lock;
 	u64 total_metadatas;
 	ktime_t metadata_latency_sum;
-	ktime_t metadata_latency_sq_sum;
+	ktime_t avg_metadata_latency;
+	ktime_t metadata_latency_stdev;
 	ktime_t metadata_latency_min;
 	ktime_t metadata_latency_max;
 
Signature · 1 line
2.27.0
#3 lore raw

PATCH 3/4 ceph: include average/stddev r/w/m latency in mds metrics

In reply to Venky Shankar

The use of jiffies_to_timespec64() seems incorrect too, switch that to ktime_to_timespec64().

---
 fs/ceph/metric.c | 36 +++++++++++++++++++-----------------
 fs/ceph/metric.h | 44 +++++++++++++++++++++++++++++++-------------
 2 files changed, 50 insertions(+), 30 deletions(-)
fs/ceph/metric.c +19 -17
index e00b1c2ce25b..cb332ae2411f 100644
@@ -8,6 +8,13 @@
 #include "metric.h"
 #include "mds_client.h"
 
+static void to_ceph_timespec(struct ceph_timespec *ts, ktime_t val)
+{
+	struct timespec64 t = ktime_to_timespec64(val);
+	ts->tv_sec = cpu_to_le32(t.tv_sec);
+	ts->tv_nsec = cpu_to_le32(t.tv_nsec);
+}
+
 static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 				   struct ceph_mds_session *s)
 {
@@ -20,8 +27,6 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	struct ceph_client_metric *m = &mdsc->metric;
 	u64 nr_caps = atomic64_read(&m->total_caps);
 	struct ceph_msg *msg;
-	struct timespec64 ts;
-	s64 sum;
 	s32 items = 0;
 	s32 len;
 
@@ -51,37 +56,34 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	/* encode the read latency metric */
 	read = (struct ceph_metric_read_latency *)(cap + 1);
 	read->type = cpu_to_le32(CLIENT_METRIC_TYPE_READ_LATENCY);
-	read->ver = 1;
+	read->ver = 2;
 	read->compat = 1;
 	read->data_len = cpu_to_le32(sizeof(*read) - 10);
-	sum = m->read_latency_sum;
-	jiffies_to_timespec64(sum, &ts);
-	read->lat.tv_sec = cpu_to_le32(ts.tv_sec);
-	read->lat.tv_nsec = cpu_to_le32(ts.tv_nsec);
+	to_ceph_timespec(&read->lat, m->read_latency_sum);
+	to_ceph_timespec(&read->avg, m->avg_read_latency);
+	to_ceph_timespec(&read->stdev, m->read_latency_stdev);
 	items++;
 
 	/* encode the write latency metric */
 	write = (struct ceph_metric_write_latency *)(read + 1);
 	write->type = cpu_to_le32(CLIENT_METRIC_TYPE_WRITE_LATENCY);
-	write->ver = 1;
+	write->ver = 2;
 	write->compat = 1;
 	write->data_len = cpu_to_le32(sizeof(*write) - 10);
-	sum = m->write_latency_sum;
-	jiffies_to_timespec64(sum, &ts);
-	write->lat.tv_sec = cpu_to_le32(ts.tv_sec);
-	write->lat.tv_nsec = cpu_to_le32(ts.tv_nsec);
+	to_ceph_timespec(&write->lat, m->write_latency_sum);
+	to_ceph_timespec(&write->avg, m->avg_write_latency);
+	to_ceph_timespec(&write->stdev, m->write_latency_stdev);
 	items++;
 
 	/* encode the metadata latency metric */
 	meta = (struct ceph_metric_metadata_latency *)(write + 1);
 	meta->type = cpu_to_le32(CLIENT_METRIC_TYPE_METADATA_LATENCY);
-	meta->ver = 1;
+	meta->ver = 2;
 	meta->compat = 1;
 	meta->data_len = cpu_to_le32(sizeof(*meta) - 10);
-	sum = m->metadata_latency_sum;
-	jiffies_to_timespec64(sum, &ts);
-	meta->lat.tv_sec = cpu_to_le32(ts.tv_sec);
-	meta->lat.tv_nsec = cpu_to_le32(ts.tv_nsec);
+	to_ceph_timespec(&meta->lat, m->metadata_latency_sum);
+	to_ceph_timespec(&meta->avg, m->avg_metadata_latency);
+	to_ceph_timespec(&meta->stdev, m->metadata_latency_stdev);
 	items++;
 
 	/* encode the dentry lease metric */
fs/ceph/metric.h +31 -13

77 lines not on this page · raw message

Signature · 1 line
2.27.0
#4 lore raw

PATCH 4/4 ceph: use tracked average r/w/m latencies to display metrics in debugfs

In reply to Venky Shankar
---
 fs/ceph/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ceph/debugfs.c +3 -3
index 9153bc233e08..e3fccf7c6fb5 100644
@@ -173,7 +173,7 @@ static int metric_show(struct seq_file *s, void *p)
 	spin_lock(&m->read_latency_lock);
 	total = m->total_reads;
 	sum = m->read_latency_sum;
-	avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
+	avg = m->avg_read_latency;
 	min = m->read_latency_min;
 	max = m->read_latency_max;
 	sq = m->read_latency_stdev;
@@ -183,7 +183,7 @@ static int metric_show(struct seq_file *s, void *p)
 	spin_lock(&m->write_latency_lock);
 	total = m->total_writes;
 	sum = m->write_latency_sum;
-	avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
+	avg = m->avg_write_latency;
 	min = m->write_latency_min;
 	max = m->write_latency_max;
 	sq = m->write_latency_stdev;
@@ -193,7 +193,7 @@ static int metric_show(struct seq_file *s, void *p)
 	spin_lock(&m->metadata_latency_lock);
 	total = m->total_metadatas;
 	sum = m->metadata_latency_sum;
-	avg = total > 0 ? DIV64_U64_ROUND_CLOSEST(sum, total) : 0;
+	avg = m->avg_metadata_latency;
 	min = m->metadata_latency_min;
 	max = m->metadata_latency_max;
 	sq = m->metadata_latency_stdev;
Signature · 1 line
2.27.0
#5 lore raw
In reply to Venky Shankar
Quoted 27 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

The math involved in keeping track of the average latency and stdev seems incorrect, so, this series fixes that up too (closely mimics how its done in userspace with some restrictions obviously) as per::

NEW_AVG = OLD_AVG + ((latency - OLD_AVG) / total_ops)
NEW_STDEV = SQRT(((OLD_STDEV + (latency - OLD_AVG)*(latency - NEW_AVG)) / (total_ops - 1)))

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Venky Shankar (4):
ceph: use "struct ceph_timespec" for r/w/m latencies
ceph: track average/stdev r/w/m latency
ceph: include average/stddev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 5 lines
 fs/ceph/debugfs.c | 12 +++----
 fs/ceph/metric.c  | 81 +++++++++++++++++++++++++----------------------
 fs/ceph/metric.h  | 64 +++++++++++++++++++++++--------------
 3 files changed, 90 insertions(+), 67 deletions(-)

This looks reasonably sane. I'll plan to go ahead and pull this into the testing kernels and do some testing with them. If anyone has objections (Xiubo?) let me know and I can take them out.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#6 lore raw
Quoted 34 lines · Jeff Layton
Quoted 27 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

The math involved in keeping track of the average latency and stdev seems incorrect, so, this series fixes that up too (closely mimics how its done in userspace with some restrictions obviously) as per::

NEW_AVG = OLD_AVG + ((latency - OLD_AVG) / total_ops)
NEW_STDEV = SQRT(((OLD_STDEV + (latency - OLD_AVG)*(latency - NEW_AVG)) / (total_ops - 1)))

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Venky Shankar (4):
ceph: use "struct ceph_timespec" for r/w/m latencies
ceph: track average/stdev r/w/m latency
ceph: include average/stddev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 5 lines
 fs/ceph/debugfs.c | 12 +++----
 fs/ceph/metric.c  | 81 +++++++++++++++++++++++++----------------------
 fs/ceph/metric.h  | 64 +++++++++++++++++++++++--------------
 3 files changed, 90 insertions(+), 67 deletions(-)
Quoted 5 lines

This looks reasonably sane. I'll plan to go ahead and pull this into the testing kernels and do some testing with them. If anyone has objections (Xiubo?) let me know and I can take them out.

Thanks,

Hmm...I take it back. There are some non-trivial merge conflicts in this series vs. the current testing branch. Venky can you rebase this onto the ceph-client/testing branch and resubmit?

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#7 lore raw
Quoted 40 lines · Jeff Layton
Quoted 38 lines · Jeff Layton
Quoted 27 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

          https://github.com/ceph/ceph/pull/41397

The math involved in keeping track of the average latency and stdev seems incorrect, so, this series fixes that up too (closely mimics how its done in userspace with some restrictions obviously) as per::

NEW_AVG = OLD_AVG + ((latency - OLD_AVG) / total_ops)
NEW_STDEV = SQRT(((OLD_STDEV + (latency - OLD_AVG)*(latency - NEW_AVG)) / (total_ops - 1)))

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Venky Shankar (4):
ceph: use "struct ceph_timespec" for r/w/m latencies
ceph: track average/stdev r/w/m latency
ceph: include average/stddev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 5 lines
 fs/ceph/debugfs.c | 12 +++----
 fs/ceph/metric.c  | 81 +++++++++++++++++++++++++----------------------
 fs/ceph/metric.h  | 64 +++++++++++++++++++++++--------------
 3 files changed, 90 insertions(+), 67 deletions(-)

This looks reasonably sane. I'll plan to go ahead and pull this into the testing kernels and do some testing with them. If anyone has objections (Xiubo?) let me know and I can take them out.

Quoted 5 lines
Quoted 1 line

Thanks,

Hmm...I take it back. There are some non-trivial merge conflicts in this series vs. the current testing branch. Venky can you rebase this onto the ceph-client/testing branch and resubmit?

Sure, will do.

Quoted 5 lines

Thanks,
--
Jeff Layton <[email protected]>

Signature · 2 lines
Cheers,
Venky
#8 lore raw
In reply to Jeff Layton
Quoted 28 lines · Jeff Layton
Quoted 27 lines · Venky Shankar

Right now, cumulative read/write/metadata latencies are tracked and are periodically forwarded to the MDS. These meterics are not particularly useful. A much more useful metric is the average latency and standard deviation (stdev) which is what this series of patches aims to do.

The userspace (libcephfs+tool) changes are here::

           https://github.com/ceph/ceph/pull/41397

The math involved in keeping track of the average latency and stdev seems incorrect, so, this series fixes that up too (closely mimics how its done in userspace with some restrictions obviously) as per::

NEW_AVG = OLD_AVG + ((latency - OLD_AVG) / total_ops)
NEW_STDEV = SQRT(((OLD_STDEV + (latency - OLD_AVG)*(latency - NEW_AVG)) / (total_ops - 1)))

Note that the cumulative latencies are still forwarded to the MDS but the tool (cephfs-top) ignores it altogether.

Venky Shankar (4):
ceph: use "struct ceph_timespec" for r/w/m latencies
ceph: track average/stdev r/w/m latency
ceph: include average/stddev r/w/m latency in mds metrics
ceph: use tracked average r/w/m latencies to display metrics in
debugfs

Quoted 8 lines
Quoted 5 lines
  fs/ceph/debugfs.c | 12 +++----
  fs/ceph/metric.c  | 81 +++++++++++++++++++++++++----------------------
  fs/ceph/metric.h  | 64 +++++++++++++++++++++++--------------
  3 files changed, 90 insertions(+), 67 deletions(-)

This looks reasonably sane. I'll plan to go ahead and pull this into the testing kernels and do some testing with them. If anyone has objections (Xiubo?) let me know and I can take them out.

Sorry I think I missed this patch set.

Comment it in the V2.

Thanks.

Quoted 2 lines

Thanks,