Skip to contentSkip to conversation

ceph: periodically send perf metrics to ceph

PATCH Superseded [email protected] 2 participants 9 messages Jun 16, 2020 – Jun 17, 2020

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover ceph: periodically send perf metrics to ceph

From: Xiubo Li <[email protected]>

This series is based the previous patches of the metrics in kceph[1] and mds daemons record and forward client side metrics to manager[2].

This will send the caps/read/write/metadata metrics to any available MDS only once per second as default, which will be the same as the userland client, or every metric_send_interval seconds, which is a module parameter, the valid values for metric_send_interval will be 1~5 seconds.

And will also send the metric flags to MDS, currently it supports the cap, read latency, write latency and metadata latency.

[1] https://patchwork.kernel.org/project/ceph-devel/list/?series=238907 [Merged]
[2] https://github.com/ceph/ceph/pull/26004 [Merged]

Xiubo Li (2):
ceph: periodically send perf metrics to ceph
ceph: send client provided metric flags in client metadata

 fs/ceph/mds_client.c         |  93 +++++++++++++++++++++++-------
 fs/ceph/mds_client.h         |   4 ++
 fs/ceph/metric.c             | 133 +++++++++++++++++++++++++++++++++++++++++++
 fs/ceph/metric.h             |  91 +++++++++++++++++++++++++++++
 fs/ceph/super.c              |  29 ++++++++++
 include/linux/ceph/ceph_fs.h |   1 +
 6 files changed, 332 insertions(+), 19 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 ceph: periodically send perf metrics to ceph

From: Xiubo Li <[email protected]>

This will send the caps/read/write/metadata metrics to any available MDS only once per second as default, which will be the same as the userland client, or every metric_send_interval seconds, which is a module parameter.

URL: https://tracker.ceph.com/issues/43215

---
 fs/ceph/mds_client.c         |  46 +++++++++------
 fs/ceph/mds_client.h         |   4 ++
 fs/ceph/metric.c             | 133 +++++++++++++++++++++++++++++++++++++++++++
 fs/ceph/metric.h             |  78 +++++++++++++++++++++++++
 fs/ceph/super.c              |  29 ++++++++++
 include/linux/ceph/ceph_fs.h |   1 +
 6 files changed, 274 insertions(+), 17 deletions(-)
fs/ceph/mds_client.c +29 -17
index a504971..f996363 100644
@@ -4263,6 +4263,30 @@ static void maybe_recover_session(struct ceph_mds_client *mdsc)
 	ceph_force_reconnect(fsc->sb);
 }
 
+bool check_session_state(struct ceph_mds_client *mdsc,
+			 struct ceph_mds_session *s)
+{
+	if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
+		dout("resending session close request for mds%d\n",
+				s->s_mds);
+		request_close_session(mdsc, s);
+		return false;
+	}
+	if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
+		if (s->s_state == CEPH_MDS_SESSION_OPEN) {
+			s->s_state = CEPH_MDS_SESSION_HUNG;
+			pr_info("mds%d hung\n", s->s_mds);
+		}
+	}
+	if (s->s_state == CEPH_MDS_SESSION_NEW ||
+	    s->s_state == CEPH_MDS_SESSION_RESTARTING ||
+	    s->s_state == CEPH_MDS_SESSION_REJECTED)
+		/* this mds is failed or recovering, just wait */
+		return false;
+
+	return true;
+}
+
 /*
  * delayed work -- periodically trim expired leases, renew caps with mds
  */
@@ -4294,23 +4318,8 @@ static void delayed_work(struct work_struct *work)
 		struct ceph_mds_session *s = __ceph_lookup_mds_session(mdsc, i);
 		if (!s)
 			continue;
-		if (s->s_state == CEPH_MDS_SESSION_CLOSING) {
-			dout("resending session close request for mds%d\n",
-			     s->s_mds);
-			request_close_session(mdsc, s);
-			ceph_put_mds_session(s);
-			continue;
-		}
-		if (s->s_ttl && time_after(jiffies, s->s_ttl)) {
-			if (s->s_state == CEPH_MDS_SESSION_OPEN) {
-				s->s_state = CEPH_MDS_SESSION_HUNG;
-				pr_info("mds%d hung\n", s->s_mds);
-			}
-		}
-		if (s->s_state == CEPH_MDS_SESSION_NEW ||
-		    s->s_state == CEPH_MDS_SESSION_RESTARTING ||
-		    s->s_state == CEPH_MDS_SESSION_REJECTED) {
-			/* this mds is failed or recovering, just wait */
+
+		if (!check_session_state(mdsc, s)) {
 			ceph_put_mds_session(s);
 			continue;
 		}
@@ -4616,6 +4625,7 @@ void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc)
 
 	cancel_work_sync(&mdsc->cap_reclaim_work);
 	cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
+	cancel_delayed_work_sync(&mdsc->metric.delayed_work); /* cancel timer */
 
 	dout("stopped\n");
 }
@@ -4658,6 +4668,7 @@ static void ceph_mdsc_stop(struct ceph_mds_client *mdsc)
 {
 	dout("stop\n");
 	cancel_delayed_work_sync(&mdsc->delayed_work); /* cancel timer */
+	cancel_delayed_work_sync(&mdsc->metric.delayed_work); /* cancel timer */
 	if (mdsc->mdsmap)
 		ceph_mdsmap_destroy(mdsc->mdsmap);
 	kfree(mdsc->sessions);
@@ -4815,6 +4826,7 @@ void ceph_mdsc_handle_mdsmap(struct ceph_mds_client *mdsc, struct ceph_msg *msg)
 
 	mutex_unlock(&mdsc->mutex);
 	schedule_delayed(mdsc);
+	metric_schedule_delayed(&mdsc->metric);
 	return;
 
 bad_unlock:
fs/ceph/mds_client.h +4 -0
index 5e0c407..bcb3892 100644
@@ -18,6 +18,7 @@
 #include <linux/ceph/auth.h>
 
 #include "metric.h"
+#include "super.h"
 
 /* The first 8 bits are reserved for old ceph releases */
 enum ceph_feature_type {
@@ -476,6 +477,9 @@ struct ceph_mds_client {
 
 extern const char *ceph_mds_op_name(int op);
 
+extern bool check_session_state(struct ceph_mds_client *mdsc,
+				struct ceph_mds_session *s);
+
 extern struct ceph_mds_session *
 __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
 
fs/ceph/metric.c +133 -0

149 lines not on this page · raw message

fs/ceph/metric.h +78 -0

92 lines not on this page · raw message

fs/ceph/super.c +29 -0
index c9784eb1..66a940c 100644
@@ -1282,6 +1282,35 @@ static void __exit exit_ceph(void)
 	destroy_caches();
 }
 
+static int param_set_metric_interval(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+	unsigned int interval;
+
+	ret = kstrtouint(val, 0, &interval);
+	if (ret < 0) {
+		pr_err("Failed to parse metric interval '%s'\n", val);
+		return ret;
+	}
+
+	if (interval > 5 || interval < 1) {
+		pr_err("Invalid metric interval %u\n", interval);
+		return -EINVAL;
+	}
+
+	metric_send_interval = interval;
+	return 0;
+}
+
+static const struct kernel_param_ops param_ops_metric_interval = {
+	.set = param_set_metric_interval,
+	.get = param_get_uint,
+};
+
+unsigned int metric_send_interval = 1;
+module_param_cb(metric_send_interval, &param_ops_metric_interval, &metric_send_interval, 0644);
+MODULE_PARM_DESC(metric_send_interval, "Interval (in seconds) of sending perf metric to ceph cluster, valid values are 1~5 (default: 1)");
+
 module_init(init_ceph);
 module_exit(exit_ceph);
 
include/linux/ceph/ceph_fs.h +1 -0
index ebf5ba6..455e9b9 100644
@@ -130,6 +130,7 @@ struct ceph_dir_layout {
 #define CEPH_MSG_CLIENT_REQUEST         24
 #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
 #define CEPH_MSG_CLIENT_REPLY           26
+#define CEPH_MSG_CLIENT_METRICS         29
 #define CEPH_MSG_CLIENT_CAPS            0x310
 #define CEPH_MSG_CLIENT_LEASE           0x311
 #define CEPH_MSG_CLIENT_SNAP            0x312
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 9 lines · On Tue, 2020-06-16 at 08:52 -0400, [email protected] wrote:

From: Xiubo Li <[email protected]>

This will send the caps/read/write/metadata metrics to any available MDS only once per second as default, which will be the same as the userland client, or every metric_send_interval seconds, which is a module parameter.

URL: https://tracker.ceph.com/issues/43215

Quoted 9 lines
---
 fs/ceph/mds_client.c         |  46 +++++++++------
 fs/ceph/mds_client.h         |   4 ++
 fs/ceph/metric.c             | 133 +++++++++++++++++++++++++++++++++++++++++++
 fs/ceph/metric.h             |  78 +++++++++++++++++++++++++
 fs/ceph/super.c              |  29 ++++++++++
 include/linux/ceph/ceph_fs.h |   1 +
 6 files changed, 274 insertions(+), 17 deletions(-)

Long patch! Might not hurt to break out some of the cleanups into separate patches, but they're fairly straighforward so I won't require it.

[...]

Quoted 12 lines

/* This is the global metrics */
struct ceph_client_metric {

fs/ceph/metric.h +3 -0
 	atomic64_t            total_dentries;
@@ -35,8 +100,21 @@ struct ceph_client_metric {
 	ktime_t metadata_latency_sq_sum;
 	ktime_t metadata_latency_min;
 	ktime_t metadata_latency_max;
+
+	struct delayed_work delayed_work;  /* delayed work */
 };
 
+static inline void metric_schedule_delayed(struct ceph_client_metric *m)

fs/ceph/metric.h struct ceph_client_metric { · line 117

Quoted 10 lines
fs/ceph/metric.h +10 -0
+{
+	/* per second as default */
+	unsigned int hz = round_jiffies_relative(HZ * metric_send_interval);
+
+	if (!metric_send_interval)
+		return;
+
+	schedule_delayed_work(&m->delayed_work, hz);
+}
+

Should this also be gated on a MDS feature bit or anything? What happens if we're running against a really old MDS that doesn't support these stats? Does it just drop them on the floor? Should we disable sending them in that case?

Quoted 30 lines
fs/ceph/metric.h +0 -0
 extern int ceph_metric_init(struct ceph_client_metric *m);
 extern void ceph_metric_destroy(struct ceph_client_metric *m);
 
fs/ceph/super.c +19 -0
index c9784eb1..66a940c 100644
@@ -1282,6 +1282,35 @@ static void __exit exit_ceph(void)
 	destroy_caches();
 }
 
+static int param_set_metric_interval(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+	unsigned int interval;
+
+	ret = kstrtouint(val, 0, &interval);
+	if (ret < 0) {
+		pr_err("Failed to parse metric interval '%s'\n", val);
+		return ret;
+	}
+
+	if (interval > 5 || interval < 1) {
+		pr_err("Invalid metric interval %u\n", interval);
+		return -EINVAL;
+	}
+
+	metric_send_interval = interval;
+	return 0;
+}

fs/ceph/super.c static void __exit exit_ceph(void) · line 1313

Quoted 10 lines
fs/ceph/super.c +10 -0
+
+static const struct kernel_param_ops param_ops_metric_interval = {
+	.set = param_set_metric_interval,
+	.get = param_get_uint,
+};
+
+unsigned int metric_send_interval = 1;
+module_param_cb(metric_send_interval, &param_ops_metric_interval, &metric_send_interval, 0644);
+MODULE_PARM_DESC(metric_send_interval, "Interval (in seconds) of sending perf metric to ceph cluster, valid values are 1~5 (default: 1)");
+

Aren't valid values 0-5, with 0 disabling this feature? That's what metric_schedule_delayed() seems to indicate...

Quoted 15 lines
fs/ceph/super.c +0 -0
 module_init(init_ceph);
 module_exit(exit_ceph);
 
include/linux/ceph/ceph_fs.h +1 -0
index ebf5ba6..455e9b9 100644
@@ -130,6 +130,7 @@ struct ceph_dir_layout {
 #define CEPH_MSG_CLIENT_REQUEST         24
 #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
 #define CEPH_MSG_CLIENT_REPLY           26
+#define CEPH_MSG_CLIENT_METRICS         29
 #define CEPH_MSG_CLIENT_CAPS            0x310
 #define CEPH_MSG_CLIENT_LEASE           0x311
 #define CEPH_MSG_CLIENT_SNAP            0x312
Signature · 1 line
Jeff Layton <[email protected]>
author
#3 lore raw
Quoted 19 lines · Jeff Layton
Quoted 9 lines · On Tue, 2020-06-16 at 08:52 -0400,[email protected] wrote:

From: Xiubo Li<[email protected]>

This will send the caps/read/write/metadata metrics to any available MDS only once per second as default, which will be the same as the userland client, or every metric_send_interval seconds, which is a module parameter.

URL:https://tracker.ceph.com/issues/43215

Quoted 9 lines
---
  fs/ceph/mds_client.c         |  46 +++++++++------
  fs/ceph/mds_client.h         |   4 ++
  fs/ceph/metric.c             | 133 +++++++++++++++++++++++++++++++++++++++++++
  fs/ceph/metric.h             |  78 +++++++++++++++++++++++++
  fs/ceph/super.c              |  29 ++++++++++
  include/linux/ceph/ceph_fs.h |   1 +
  6 files changed, 274 insertions(+), 17 deletions(-)
Quoted 3 lines

Long patch! Might not hurt to break out some of the cleanups into separate patches, but they're fairly straighforward so I won't require it.

Sure, I will split the patch into small ones if possible.

Quoted 13 lines

[...]

Quoted 11 lines

/* This is the global metrics */
struct ceph_client_metric {
atomic64_t total_dentries;

fs/ceph/metric.h +2 -0
@@ -35,8 +100,21 @@ struct ceph_client_metric {
  	ktime_t metadata_latency_sq_sum;
  	ktime_t metadata_latency_min;
  	ktime_t metadata_latency_max;
+
+	struct delayed_work delayed_work;  /* delayed work */
  };
 
Quoted 15 lines

fs/ceph/metric.h struct ceph_client_metric { · line 117

Quoted 11 lines
fs/ceph/metric.h +11 -0
+static inline void metric_schedule_delayed(struct ceph_client_metric *m)
+{
+	/* per second as default */
+	unsigned int hz = round_jiffies_relative(HZ * metric_send_interval);
+
+	if (!metric_send_interval)
+		return;
+
+	schedule_delayed_work(&m->delayed_work, hz);
+}
+

Should this also be gated on a MDS feature bit or anything? What happens if we're running against a really old MDS that doesn't support these stats? Does it just drop them on the floor? Should we disable sending them in that case?

Tested without metric code in the ceph and when ceph saw a unknown type message, it will close the socket connection directly.

Quoted 34 lines
Quoted 34 lines
fs/ceph/metric.h +0 -0
  extern int ceph_metric_init(struct ceph_client_metric *m);
  extern void ceph_metric_destroy(struct ceph_client_metric *m);
 
fs/ceph/super.c +23 -0
index c9784eb1..66a940c 100644
@@ -1282,6 +1282,35 @@ static void __exit exit_ceph(void)
  	destroy_caches();
  }
 
+static int param_set_metric_interval(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+	unsigned int interval;
+
+	ret = kstrtouint(val, 0, &interval);
+	if (ret < 0) {
+		pr_err("Failed to parse metric interval '%s'\n", val);
+		return ret;
+	}
+
+	if (interval > 5 || interval < 1) {
+		pr_err("Invalid metric interval %u\n", interval);
+		return -EINVAL;
+	}
+
+	metric_send_interval = interval;
+	return 0;
+}
+
+static const struct kernel_param_ops param_ops_metric_interval = {
+	.set = param_set_metric_interval,
+	.get = param_get_uint,
Quoted 8 lines

fs/ceph/super.c static void __exit exit_ceph(void) · line 1313

Quoted 6 lines
fs/ceph/super.c +6 -0
+};
+
+unsigned int metric_send_interval = 1;
+module_param_cb(metric_send_interval, &param_ops_metric_interval, &metric_send_interval, 0644);
+MODULE_PARM_DESC(metric_send_interval, "Interval (in seconds) of sending perf metric to ceph cluster, valid values are 1~5 (default: 1)");
+

Aren't valid values 0-5, with 0 disabling this feature? That's what metric_schedule_delayed() seems to indicate...

What value should it be as default ? 0 to disable it or 1 ?

Maybe in future we should let the ceph side send a notification/request to all the clients if it wants to collect the metrics and then we could enable it here, and defautly just disable it.

Quoted 15 lines
Quoted 15 lines
fs/ceph/super.c +0 -0
  module_init(init_ceph);
  module_exit(exit_ceph);
 
include/linux/ceph/ceph_fs.h +1 -0
index ebf5ba6..455e9b9 100644
@@ -130,6 +130,7 @@ struct ceph_dir_layout {
  #define CEPH_MSG_CLIENT_REQUEST         24
  #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
  #define CEPH_MSG_CLIENT_REPLY           26
+#define CEPH_MSG_CLIENT_METRICS         29
  #define CEPH_MSG_CLIENT_CAPS            0x310
  #define CEPH_MSG_CLIENT_LEASE           0x311
  #define CEPH_MSG_CLIENT_SNAP            0x312
#4 lore raw
Quoted 56 lines · Xiubo Li
Quoted 19 lines · Jeff Layton
Quoted 9 lines · On Tue, 2020-06-16 at 08:52 -0400,[email protected] wrote:

From: Xiubo Li<[email protected]>

This will send the caps/read/write/metadata metrics to any available MDS only once per second as default, which will be the same as the userland client, or every metric_send_interval seconds, which is a module parameter.

URL:https://tracker.ceph.com/issues/43215

Quoted 9 lines
---
  fs/ceph/mds_client.c         |  46 +++++++++------
  fs/ceph/mds_client.h         |   4 ++
  fs/ceph/metric.c             | 133 +++++++++++++++++++++++++++++++++++++++++++
  fs/ceph/metric.h             |  78 +++++++++++++++++++++++++
  fs/ceph/super.c              |  29 ++++++++++
  include/linux/ceph/ceph_fs.h |   1 +
  6 files changed, 274 insertions(+), 17 deletions(-)
Quoted 3 lines

Long patch! Might not hurt to break out some of the cleanups into separate patches, but they're fairly straighforward so I won't require it.

Sure, I will split the patch into small ones if possible.

Quoted 13 lines

[...]

Quoted 11 lines

/* This is the global metrics */
struct ceph_client_metric {
atomic64_t total_dentries;

fs/ceph/metric.h +2 -0
@@ -35,8 +100,21 @@ struct ceph_client_metric {
  	ktime_t metadata_latency_sq_sum;
  	ktime_t metadata_latency_min;
  	ktime_t metadata_latency_max;
+
+	struct delayed_work delayed_work;  /* delayed work */
  };
 
Quoted 15 lines

fs/ceph/metric.h struct ceph_client_metric { · line 117

Quoted 11 lines
fs/ceph/metric.h +11 -0
+static inline void metric_schedule_delayed(struct ceph_client_metric *m)
+{
+	/* per second as default */
+	unsigned int hz = round_jiffies_relative(HZ * metric_send_interval);
+
+	if (!metric_send_interval)
+		return;
+
+	schedule_delayed_work(&m->delayed_work, hz);
+}
+

Should this also be gated on a MDS feature bit or anything? What happens if we're running against a really old MDS that doesn't support these stats? Does it just drop them on the floor? Should we disable sending them in that case?

Quoted 3 lines

Tested without metric code in the ceph and when ceph saw a unknown type message, it will close the socket connection directly.

Ouch, that sounds bad. How does the userland client handle this? This seems like the kind of thing we usually add a feature bit for somewhere...

Quoted 44 lines
Quoted 35 lines
Quoted 35 lines
fs/ceph/metric.h +0 -0
  extern int ceph_metric_init(struct ceph_client_metric *m);
  extern void ceph_metric_destroy(struct ceph_client_metric *m);
 
fs/ceph/super.c +23 -0
index c9784eb1..66a940c 100644
@@ -1282,6 +1282,35 @@ static void __exit exit_ceph(void)
  	destroy_caches();
  }
 
+static int param_set_metric_interval(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+	unsigned int interval;
+
+	ret = kstrtouint(val, 0, &interval);
+	if (ret < 0) {
+		pr_err("Failed to parse metric interval '%s'\n", val);
+		return ret;
+	}
+
+	if (interval > 5 || interval < 1) {
+		pr_err("Invalid metric interval %u\n", interval);
+		return -EINVAL;
+	}
+
+	metric_send_interval = interval;
+	return 0;
+}
+
+static const struct kernel_param_ops param_ops_metric_interval = {
+	.set = param_set_metric_interval,
+	.get = param_get_uint,
Quoted 8 lines

fs/ceph/super.c static void __exit exit_ceph(void) · line 1313

Quoted 6 lines
fs/ceph/super.c +6 -0
+};
+
+unsigned int metric_send_interval = 1;
+module_param_cb(metric_send_interval, &param_ops_metric_interval, &metric_send_interval, 0644);
+MODULE_PARM_DESC(metric_send_interval, "Interval (in seconds) of sending perf metric to ceph cluster, valid values are 1~5 (default: 1)");
+

Aren't valid values 0-5, with 0 disabling this feature? That's what metric_schedule_delayed() seems to indicate...

Quoted 2 lines

What value should it be as default ? 0 to disable it or 1 ?

I don't have strong preference here. It's probably safe enough to make it 1. I do like the ability to turn this off though, as that gives us a workaround in the event that it does cause trouble.

Quoted 4 lines

Maybe in future we should let the ceph side send a notification/request to all the clients if it wants to collect the metrics and then we could enable it here, and defautly just disable it.

That seems like a heavier-weight solution than is called for here. This seems like something that ought to have a feature bit. Then if that's turned off, we can just disable this altogether.

Quoted 18 lines
Quoted 16 lines
Quoted 16 lines
fs/ceph/super.c +0 -0
  module_init(init_ceph);
  module_exit(exit_ceph);
 
include/linux/ceph/ceph_fs.h +1 -0
index ebf5ba6..455e9b9 100644
@@ -130,6 +130,7 @@ struct ceph_dir_layout {
  #define CEPH_MSG_CLIENT_REQUEST         24
  #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
  #define CEPH_MSG_CLIENT_REPLY           26
+#define CEPH_MSG_CLIENT_METRICS         29
  #define CEPH_MSG_CLIENT_CAPS            0x310
  #define CEPH_MSG_CLIENT_LEASE           0x311
  #define CEPH_MSG_CLIENT_SNAP            0x312
Signature · 1 line
Jeff Layton <[email protected]>
author
#5 lore raw
Quoted 55 lines · Jeff Layton
Quoted 54 lines · Xiubo Li
Quoted 19 lines · Jeff Layton
Quoted 9 lines · On Tue, 2020-06-16 at 08:52 -0400,[email protected] wrote:

From: Xiubo Li<[email protected]>

This will send the caps/read/write/metadata metrics to any available MDS only once per second as default, which will be the same as the userland client, or every metric_send_interval seconds, which is a module parameter.

URL:https://tracker.ceph.com/issues/43215

Quoted 9 lines
---
   fs/ceph/mds_client.c         |  46 +++++++++------
   fs/ceph/mds_client.h         |   4 ++
   fs/ceph/metric.c             | 133 +++++++++++++++++++++++++++++++++++++++++++
   fs/ceph/metric.h             |  78 +++++++++++++++++++++++++
   fs/ceph/super.c              |  29 ++++++++++
   include/linux/ceph/ceph_fs.h |   1 +
   6 files changed, 274 insertions(+), 17 deletions(-)
Quoted 3 lines

Long patch! Might not hurt to break out some of the cleanups into separate patches, but they're fairly straighforward so I won't require it.

Sure, I will split the patch into small ones if possible.

Quoted 28 lines

[...]

Quoted 12 lines
   /* This is the global metrics */
   struct ceph_client_metric {
   	atomic64_t            total_dentries;
fs/ceph/metric.h +3 -0
@@ -35,8 +100,21 @@ struct ceph_client_metric {
   	ktime_t metadata_latency_sq_sum;
   	ktime_t metadata_latency_min;
   	ktime_t metadata_latency_max;
+
+	struct delayed_work delayed_work;  /* delayed work */
   };
 
+static inline void metric_schedule_delayed(struct ceph_client_metric *m)

fs/ceph/metric.h struct ceph_client_metric { · line 117

Quoted 10 lines
fs/ceph/metric.h +10 -0
+{
+	/* per second as default */
+	unsigned int hz = round_jiffies_relative(HZ * metric_send_interval);
+
+	if (!metric_send_interval)
+		return;
+
+	schedule_delayed_work(&m->delayed_work, hz);
+}
+

Should this also be gated on a MDS feature bit or anything? What happens if we're running against a really old MDS that doesn't support these stats? Does it just drop them on the floor? Should we disable sending them in that case?

Quoted 6 lines
Quoted 3 lines

Tested without metric code in the ceph and when ceph saw a unknown type message, it will close the socket connection directly.

Ouch, that sounds bad. How does the userland client handle this? This seems like the kind of thing we usually add a feature bit for somewhere...

The userland doesn't handle this case too, I will try to add a feature bit or something to fix it.

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 30 lines
fs/ceph/metric.h +0 -0
   extern int ceph_metric_init(struct ceph_client_metric *m);
   extern void ceph_metric_destroy(struct ceph_client_metric *m);
 
fs/ceph/super.c +19 -0
index c9784eb1..66a940c 100644
@@ -1282,6 +1282,35 @@ static void __exit exit_ceph(void)
   	destroy_caches();
   }
 
+static int param_set_metric_interval(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+	unsigned int interval;
+
+	ret = kstrtouint(val, 0, &interval);
+	if (ret < 0) {
+		pr_err("Failed to parse metric interval '%s'\n", val);
+		return ret;
+	}
+
+	if (interval > 5 || interval < 1) {
+		pr_err("Invalid metric interval %u\n", interval);
+		return -EINVAL;
+	}
+
+	metric_send_interval = interval;
+	return 0;
+}

fs/ceph/super.c static void __exit exit_ceph(void) · line 1313

Quoted 10 lines
fs/ceph/super.c +10 -0
+
+static const struct kernel_param_ops param_ops_metric_interval = {
+	.set = param_set_metric_interval,
+	.get = param_get_uint,
+};
+
+unsigned int metric_send_interval = 1;
+module_param_cb(metric_send_interval, &param_ops_metric_interval, &metric_send_interval, 0644);
+MODULE_PARM_DESC(metric_send_interval, "Interval (in seconds) of sending perf metric to ceph cluster, valid values are 1~5 (default: 1)");
+

Aren't valid values 0-5, with 0 disabling this feature? That's what metric_schedule_delayed() seems to indicate...

Quoted 5 lines
Quoted 2 lines

What value should it be as default ? 0 to disable it or 1 ?

I don't have strong preference here. It's probably safe enough to make it 1. I do like the ability to turn this off though, as that gives us a workaround in the event that it does cause trouble.

Sure, I will add it back.

Quoted 8 lines
Quoted 5 lines

Maybe in future we should let the ceph side send a notification/request to all the clients if it wants to collect the metrics and then we could enable it here, and defautly just disable it.

That seems like a heavier-weight solution than is called for here. This seems like something that ought to have a feature bit. Then if that's turned off, we can just disable this altogether.

Okay, sounds better.

Thanks

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines
fs/ceph/super.c +0 -0
   module_init(init_ceph);
   module_exit(exit_ceph);
 
include/linux/ceph/ceph_fs.h +1 -0
index ebf5ba6..455e9b9 100644
@@ -130,6 +130,7 @@ struct ceph_dir_layout {
   #define CEPH_MSG_CLIENT_REQUEST         24
   #define CEPH_MSG_CLIENT_REQUEST_FORWARD 25
   #define CEPH_MSG_CLIENT_REPLY           26
+#define CEPH_MSG_CLIENT_METRICS         29
   #define CEPH_MSG_CLIENT_CAPS            0x310
   #define CEPH_MSG_CLIENT_LEASE           0x311
   #define CEPH_MSG_CLIENT_SNAP            0x312
#6 lore raw

PATCH 2/2 ceph: send client provided metric flags in client metadata

In reply to [email protected]

From: Xiubo Li <[email protected]>

Will send the metric flags to MDS, currently it supports the cap, read latency, write latency and metadata latency.

URL: https://tracker.ceph.com/issues/43435

---
 fs/ceph/mds_client.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 fs/ceph/metric.h     | 13 +++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +45 -2
index f996363..8b7ff41 100644
@@ -1188,6 +1188,41 @@ static void encode_supported_features(void **p, void *end)
 	}
 }
 
+static const unsigned char metric_bits[] = CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED;
+#define METRIC_BYTES(cnt) (DIV_ROUND_UP((size_t)metric_bits[cnt - 1] + 1, 64) * 8)
+static void encode_metric_spec(void **p, void *end)
+{
+	static const size_t count = ARRAY_SIZE(metric_bits);
+
+	/* header */
+	BUG_ON(*p + 2 > end);
+	ceph_encode_8(p, 1); /* version */
+	ceph_encode_8(p, 1); /* compat */
+
+	if (count > 0) {
+		size_t i;
+		size_t size = METRIC_BYTES(count);
+
+		BUG_ON(*p + 4 + 4 + size > end);
+
+		/* metric spec info length */
+		ceph_encode_32(p, 4 + size);
+
+		/* metric spec */
+		ceph_encode_32(p, size);
+		memset(*p, 0, size);
+		for (i = 0; i < count; i++)
+			((unsigned char *)(*p))[i / 8] |= BIT(metric_bits[i] % 8);
+		*p += size;
+	} else {
+		BUG_ON(*p + 4 + 4 > end);
+		/* metric spec info length */
+		ceph_encode_32(p, 4);
+		/* metric spec */
+		ceph_encode_32(p, 0);
+	}
+}
+
 /*
  * session message, specialization for CEPH_SESSION_REQUEST_OPEN
  * to include additional client metadata fields.
@@ -1227,6 +1262,13 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 		size = FEATURE_BYTES(count);
 	extra_bytes += 4 + size;
 
+	/* metric spec */
+	size = 0;
+	count = ARRAY_SIZE(metric_bits);
+	if (count > 0)
+		size = METRIC_BYTES(count);
+	extra_bytes += 2 + 4 + 4 + size;
+
 	/* Allocate the message */
 	msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + extra_bytes,
 			   GFP_NOFS, false);
@@ -1245,9 +1287,9 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 	 * Serialize client metadata into waiting buffer space, using
 	 * the format that userspace expects for map<string, string>
 	 *
-	 * ClientSession messages with metadata are v3
+	 * ClientSession messages with metadata are v4
 	 */
-	msg->hdr.version = cpu_to_le16(3);
+	msg->hdr.version = cpu_to_le16(4);
 	msg->hdr.compat_version = cpu_to_le16(1);
 
 	/* The write pointer, following the session_head structure */
@@ -1270,6 +1312,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 	}
 
 	encode_supported_features(&p, end);
+	encode_metric_spec(&p, end);
 	msg->front.iov_len = p - msg->front.iov_base;
 	msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
 
fs/ceph/metric.h +13 -0
index 2af9e0b..f34adf7 100644
@@ -18,6 +18,19 @@ enum ceph_metric_type {
 	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
 };
 
+/*
+ * This will always have the highest metric bit value
+ * as the last element of the array.
+ */
+#define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED {	\
+	CLIENT_METRIC_TYPE_CAP_INFO,		\
+	CLIENT_METRIC_TYPE_READ_LATENCY,	\
+	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
+	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
+						\
+	CLIENT_METRIC_TYPE_MAX,			\
+}
+
 /* metric caps header */
 struct ceph_metric_cap {
 	__le32 type;     /* ceph metric type */
Signature · 1 line
1.8.3.1
#7 lore raw

Re: [PATCH 2/2] ceph: send client provided metric flags in client metadata

Quoted 27 lines · On Tue, 2020-06-16 at 08:52 -0400, [email protected] wrote:

From: Xiubo Li <[email protected]>

Will send the metric flags to MDS, currently it supports the cap, read latency, write latency and metadata latency.

URL: https://tracker.ceph.com/issues/43435

---
 fs/ceph/mds_client.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 fs/ceph/metric.h     | 13 +++++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +7 -0
index f996363..8b7ff41 100644
@@ -1188,6 +1188,41 @@ static void encode_supported_features(void **p, void *end)
 	}
 }
 
+static const unsigned char metric_bits[] = CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED;
+#define METRIC_BYTES(cnt) (DIV_ROUND_UP((size_t)metric_bits[cnt - 1] + 1, 64) * 8)
+static void encode_metric_spec(void **p, void *end)
+{
+	static const size_t count = ARRAY_SIZE(metric_bits);
+
+	/* header */

fs/ceph/mds_client.c static void encode_supported_features(void **p, void *end) · line 1207

Quoted 10 lines
fs/ceph/mds_client.c +10 -0
+	BUG_ON(*p + 2 > end);
+	ceph_encode_8(p, 1); /* version */
+	ceph_encode_8(p, 1); /* compat */
+
+	if (count > 0) {
+		size_t i;
+		size_t size = METRIC_BYTES(count);
+
+		BUG_ON(*p + 4 + 4 + size > end);
+

I know it's unlikely to ever trip, but let's not BUG_ON here. Maybe just WARN and return an error...

Of course, we'd probably want that error to bubble up to the callers of __open_session() but none of its callers check the return value. Would you mind fixing that while you're in there too?

Quoted 79 lines
fs/ceph/mds_client.c +28 -2
+		/* metric spec info length */
+		ceph_encode_32(p, 4 + size);
+
+		/* metric spec */
+		ceph_encode_32(p, size);
+		memset(*p, 0, size);
+		for (i = 0; i < count; i++)
+			((unsigned char *)(*p))[i / 8] |= BIT(metric_bits[i] % 8);
+		*p += size;
+	} else {
+		BUG_ON(*p + 4 + 4 > end);
+		/* metric spec info length */
+		ceph_encode_32(p, 4);
+		/* metric spec */
+		ceph_encode_32(p, 0);
+	}
+}
+
 /*
  * session message, specialization for CEPH_SESSION_REQUEST_OPEN
  * to include additional client metadata fields.
@@ -1227,6 +1262,13 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 		size = FEATURE_BYTES(count);
 	extra_bytes += 4 + size;
 
+	/* metric spec */
+	size = 0;
+	count = ARRAY_SIZE(metric_bits);
+	if (count > 0)
+		size = METRIC_BYTES(count);
+	extra_bytes += 2 + 4 + 4 + size;
+
 	/* Allocate the message */
 	msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + extra_bytes,
 			   GFP_NOFS, false);
@@ -1245,9 +1287,9 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 	 * Serialize client metadata into waiting buffer space, using
 	 * the format that userspace expects for map<string, string>
 	 *
-	 * ClientSession messages with metadata are v3
+	 * ClientSession messages with metadata are v4
 	 */
-	msg->hdr.version = cpu_to_le16(3);
+	msg->hdr.version = cpu_to_le16(4);
 	msg->hdr.compat_version = cpu_to_le16(1);
 
 	/* The write pointer, following the session_head structure */
@@ -1270,6 +1312,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 	}
 
 	encode_supported_features(&p, end);
+	encode_metric_spec(&p, end);
 	msg->front.iov_len = p - msg->front.iov_base;
 	msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
 
fs/ceph/metric.h +13 -0
index 2af9e0b..f34adf7 100644
@@ -18,6 +18,19 @@ enum ceph_metric_type {
 	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
 };
 
+/*
+ * This will always have the highest metric bit value
+ * as the last element of the array.
+ */
+#define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED {	\
+	CLIENT_METRIC_TYPE_CAP_INFO,		\
+	CLIENT_METRIC_TYPE_READ_LATENCY,	\
+	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
+	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
+						\
+	CLIENT_METRIC_TYPE_MAX,			\
+}
+
 /* metric caps header */
 struct ceph_metric_cap {
 	__le32 type;     /* ceph metric type */
Signature · 1 line
Jeff Layton <[email protected]>
author
#8 lore raw

Re: [PATCH 2/2] ceph: send client provided metric flags in client metadata

Quoted 41 lines · Jeff Layton
Quoted 27 lines · On Tue, 2020-06-16 at 08:52 -0400, [email protected] wrote:

From: Xiubo Li <[email protected]>

Will send the metric flags to MDS, currently it supports the cap, read latency, write latency and metadata latency.

URL: https://tracker.ceph.com/issues/43435

---
  fs/ceph/mds_client.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
  fs/ceph/metric.h     | 13 +++++++++++++
  2 files changed, 58 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +7 -0
index f996363..8b7ff41 100644
@@ -1188,6 +1188,41 @@ static void encode_supported_features(void **p, void *end)
  	}
  }
 
+static const unsigned char metric_bits[] = CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED;
+#define METRIC_BYTES(cnt) (DIV_ROUND_UP((size_t)metric_bits[cnt - 1] + 1, 64) * 8)
+static void encode_metric_spec(void **p, void *end)
+{
+	static const size_t count = ARRAY_SIZE(metric_bits);
+
+	/* header */

fs/ceph/mds_client.c static void encode_supported_features(void **p, void *end) · line 1207

Quoted 10 lines
fs/ceph/mds_client.c +10 -0
+	BUG_ON(*p + 2 > end);
+	ceph_encode_8(p, 1); /* version */
+	ceph_encode_8(p, 1); /* compat */
+
+	if (count > 0) {
+		size_t i;
+		size_t size = METRIC_BYTES(count);
+
+		BUG_ON(*p + 4 + 4 + size > end);
+

I know it's unlikely to ever trip, but let's not BUG_ON here. Maybe just WARN and return an error...

Quoted 3 lines

Of course, we'd probably want that error to bubble up to the callers of __open_session() but none of its callers check the return value. Would you mind fixing that while you're in there too?

Sure, this makes sense and the checkpatch.pl also suggests to use WARN, I will fix them all later.

Thanks
BRs
Xiubo

Quoted 80 lines
Quoted 80 lines
fs/ceph/mds_client.c +28 -2
+		/* metric spec info length */
+		ceph_encode_32(p, 4 + size);
+
+		/* metric spec */
+		ceph_encode_32(p, size);
+		memset(*p, 0, size);
+		for (i = 0; i < count; i++)
+			((unsigned char *)(*p))[i / 8] |= BIT(metric_bits[i] % 8);
+		*p += size;
+	} else {
+		BUG_ON(*p + 4 + 4 > end);
+		/* metric spec info length */
+		ceph_encode_32(p, 4);
+		/* metric spec */
+		ceph_encode_32(p, 0);
+	}
+}
+
  /*
   * session message, specialization for CEPH_SESSION_REQUEST_OPEN
   * to include additional client metadata fields.
@@ -1227,6 +1262,13 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
  		size = FEATURE_BYTES(count);
  	extra_bytes += 4 + size;
 
+	/* metric spec */
+	size = 0;
+	count = ARRAY_SIZE(metric_bits);
+	if (count > 0)
+		size = METRIC_BYTES(count);
+	extra_bytes += 2 + 4 + 4 + size;
+
  	/* Allocate the message */
  	msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + extra_bytes,
  			   GFP_NOFS, false);
@@ -1245,9 +1287,9 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
  	 * Serialize client metadata into waiting buffer space, using
  	 * the format that userspace expects for map<string, string>
  	 *
-	 * ClientSession messages with metadata are v3
+	 * ClientSession messages with metadata are v4
  	 */
-	msg->hdr.version = cpu_to_le16(3);
+	msg->hdr.version = cpu_to_le16(4);
  	msg->hdr.compat_version = cpu_to_le16(1);
 
  	/* The write pointer, following the session_head structure */
@@ -1270,6 +1312,7 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
  	}
 
  	encode_supported_features(&p, end);
+	encode_metric_spec(&p, end);
  	msg->front.iov_len = p - msg->front.iov_base;
  	msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
 
fs/ceph/metric.h +13 -0
index 2af9e0b..f34adf7 100644
@@ -18,6 +18,19 @@ enum ceph_metric_type {
  	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
  };
 
+/*
+ * This will always have the highest metric bit value
+ * as the last element of the array.
+ */
+#define CEPHFS_METRIC_SPEC_CLIENT_SUPPORTED {	\
+	CLIENT_METRIC_TYPE_CAP_INFO,		\
+	CLIENT_METRIC_TYPE_READ_LATENCY,	\
+	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
+	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
+						\
+	CLIENT_METRIC_TYPE_MAX,			\
+}
+
  /* metric caps header */
  struct ceph_metric_cap {
  	__le32 type;     /* ceph metric type */