@@ -8,7 +8,7 @@ obj-$(CONFIG_CEPH_FS) += ceph.o
ceph-y := super.o inode.o dir.o file.o locks.o addr.o ioctl.o \
export.o caps.o snap.o xattr.o quota.o io.o \
mds_client.o mdsmap.o strings.o ceph_frag.o \
- debugfs.o util.o
+ debugfs.o util.o metric.o
ceph-$(CONFIG_CEPH_FSCACHE) += cache.o
ceph-$(CONFIG_CEPH_FS_POSIX_ACL) += acl.o
@@ -4326,90 +4326,6 @@ static void delayed_work(struct work_struct *work)
schedule_delayed(mdsc);
}
-static int ceph_mdsc_metric_init(struct ceph_client_metric *metric)
-{
- int ret;
-
- if (!metric)
- return -EINVAL;
-
- atomic64_set(&metric->total_dentries, 0);
- ret = percpu_counter_init(&metric->d_lease_hit, 0, GFP_KERNEL);
- if (ret)
- return ret;
-
- ret = percpu_counter_init(&metric->d_lease_mis, 0, GFP_KERNEL);
- if (ret)
- goto err_d_lease_mis;
-
- ret = percpu_counter_init(&metric->i_caps_hit, 0, GFP_KERNEL);
- if (ret)
- goto err_i_caps_hit;
-
- ret = percpu_counter_init(&metric->i_caps_mis, 0, GFP_KERNEL);
- if (ret)
- goto err_i_caps_mis;
-
- ret = percpu_counter_init(&metric->total_reads, 0, GFP_KERNEL);
- if (ret)
- goto err_total_reads;
-
- ret = percpu_counter_init(&metric->read_latency_sum, 0, GFP_KERNEL);
- 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;
-
- ret = percpu_counter_init(&metric->write_latency_sum, 0, GFP_KERNEL);
- 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;
-
- ret = percpu_counter_init(&metric->metadata_latency_sum, 0, GFP_KERNEL);
- 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:
- percpu_counter_destroy(&metric->total_metadatas);
-err_total_metadatas:
- percpu_counter_destroy(&metric->write_latency_sum);
-err_write_latency_sum:
- percpu_counter_destroy(&metric->total_writes);
-err_total_writes:
- percpu_counter_destroy(&metric->read_latency_sum);
-err_read_latency_sum:
- percpu_counter_destroy(&metric->total_reads);
-err_total_reads:
- percpu_counter_destroy(&metric->i_caps_mis);
-err_i_caps_mis:
- percpu_counter_destroy(&metric->i_caps_hit);
-err_i_caps_hit:
- percpu_counter_destroy(&metric->d_lease_mis);
-err_d_lease_mis:
- percpu_counter_destroy(&metric->d_lease_hit);
-
- return ret;
-}
-
int ceph_mdsc_init(struct ceph_fs_client *fsc)
{
@@ -4747,16 +4663,7 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
ceph_mdsc_stop(mdsc);
- percpu_counter_destroy(&mdsc->metric.metadata_latency_sum);
- percpu_counter_destroy(&mdsc->metric.total_metadatas);
- percpu_counter_destroy(&mdsc->metric.write_latency_sum);
- percpu_counter_destroy(&mdsc->metric.total_writes);
- percpu_counter_destroy(&mdsc->metric.read_latency_sum);
- percpu_counter_destroy(&mdsc->metric.total_reads);
- percpu_counter_destroy(&mdsc->metric.i_caps_mis);
- percpu_counter_destroy(&mdsc->metric.i_caps_hit);
- percpu_counter_destroy(&mdsc->metric.d_lease_mis);
- percpu_counter_destroy(&mdsc->metric.d_lease_hit);
+ ceph_mdsc_metric_destroy(&mdsc->metric);
fsc->mdsc = NULL;
kfree(mdsc);
new file mode 100644
@@ -0,0 +1,177 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/atomic.h>
+#include <linux/percpu_counter.h>
+#include <linux/spinlock.h>
+
+#include "metric.h"
+
+int ceph_mdsc_metric_init(struct ceph_client_metric *m)
+{
+ int ret;
+
+ atomic64_set(&m->total_dentries, 0);
+ ret = percpu_counter_init(&m->d_lease_hit, 0, GFP_KERNEL);
+ if (ret)
+ return ret;
+
+ ret = percpu_counter_init(&m->d_lease_mis, 0, GFP_KERNEL);
+ if (ret)
+ goto err_d_lease_mis;
+
+ ret = percpu_counter_init(&m->i_caps_hit, 0, GFP_KERNEL);
+ if (ret)
+ goto err_i_caps_hit;
+
+ ret = percpu_counter_init(&m->i_caps_mis, 0, GFP_KERNEL);
+ if (ret)
+ goto err_i_caps_mis;
+
+ ret = percpu_counter_init(&m->total_reads, 0, GFP_KERNEL);
+ if (ret)
+ goto err_total_reads;
+
+ ret = percpu_counter_init(&m->read_latency_sum, 0, GFP_KERNEL);
+ if (ret)
+ goto err_read_latency_sum;
+
+ spin_lock_init(&m->read_latency_lock);
+ atomic64_set(&m->read_latency_min, S64_MAX);
+ atomic64_set(&m->read_latency_max, 0);
+
+ ret = percpu_counter_init(&m->total_writes, 0, GFP_KERNEL);
+ if (ret)
+ goto err_total_writes;
+
+ ret = percpu_counter_init(&m->write_latency_sum, 0, GFP_KERNEL);
+ if (ret)
+ goto err_write_latency_sum;
+
+ spin_lock_init(&m->write_latency_lock);
+ atomic64_set(&m->write_latency_min, S64_MAX);
+ atomic64_set(&m->write_latency_max, 0);
+
+ ret = percpu_counter_init(&m->total_metadatas, 0, GFP_KERNEL);
+ if (ret)
+ goto err_total_metadatas;
+
+ ret = percpu_counter_init(&m->metadata_latency_sum, 0, GFP_KERNEL);
+ if (ret)
+ goto err_metadata_latency_sum;
+
+ spin_lock_init(&m->metadata_latency_lock);
+ atomic64_set(&m->metadata_latency_min, S64_MAX);
+ atomic64_set(&m->metadata_latency_max, 0);
+
+ return 0;
+
+err_metadata_latency_sum:
+ percpu_counter_destroy(&m->total_metadatas);
+err_total_metadatas:
+ percpu_counter_destroy(&m->write_latency_sum);
+err_write_latency_sum:
+ percpu_counter_destroy(&m->total_writes);
+err_total_writes:
+ percpu_counter_destroy(&m->read_latency_sum);
+err_read_latency_sum:
+ percpu_counter_destroy(&m->total_reads);
+err_total_reads:
+ percpu_counter_destroy(&m->i_caps_mis);
+err_i_caps_mis:
+ percpu_counter_destroy(&m->i_caps_hit);
+err_i_caps_hit:
+ percpu_counter_destroy(&m->d_lease_mis);
+err_d_lease_mis:
+ percpu_counter_destroy(&m->d_lease_hit);
+
+ return ret;
+}
+
+void ceph_mdsc_metric_destroy(struct ceph_client_metric *m)
+{
+ percpu_counter_destroy(&m->metadata_latency_sum);
+ percpu_counter_destroy(&m->total_metadatas);
+ percpu_counter_destroy(&m->write_latency_sum);
+ percpu_counter_destroy(&m->total_writes);
+ percpu_counter_destroy(&m->read_latency_sum);
+ percpu_counter_destroy(&m->total_reads);
+ percpu_counter_destroy(&m->i_caps_mis);
+ percpu_counter_destroy(&m->i_caps_hit);
+ percpu_counter_destroy(&m->d_lease_mis);
+ percpu_counter_destroy(&m->d_lease_hit);
+}
+
+void ceph_update_read_latency(struct ceph_client_metric *m,
+ unsigned long r_start,
+ 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, lat);
+
+ if (lat >= atomic64_read(&m->read_latency_min) &&
+ lat <= atomic64_read(&m->read_latency_max))
+ 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);
+}
+
+void ceph_update_write_latency(struct ceph_client_metric *m,
+ unsigned long r_start,
+ unsigned long r_end,
+ int rc)
+{
+ unsigned long lat = r_end - r_start;
+
+ if (rc && rc != -ETIMEDOUT)
+ return;
+
+ percpu_counter_inc(&m->total_writes);
+ percpu_counter_add(&m->write_latency_sum, r_end - r_start);
+
+ if (lat >= atomic64_read(&m->write_latency_min) &&
+ lat <= atomic64_read(&m->write_latency_max))
+ return;
+
+ spin_lock(&m->write_latency_lock);
+ if (lat < atomic64_read(&m->write_latency_min))
+ atomic64_set(&m->write_latency_min, lat);
+ if (lat > atomic64_read(&m->write_latency_max))
+ atomic64_set(&m->write_latency_max, lat);
+ spin_unlock(&m->write_latency_lock);
+}
+
+void ceph_update_metadata_latency(struct ceph_client_metric *m,
+ unsigned long r_start,
+ unsigned long r_end,
+ int rc)
+{
+ unsigned long lat = r_end - r_start;
+
+ if (rc && rc != -ENOENT)
+ return;
+
+ percpu_counter_inc(&m->total_metadatas);
+ percpu_counter_add(&m->metadata_latency_sum, r_end - r_start);
+
+ if (lat >= atomic64_read(&m->metadata_latency_min) &&
+ lat <= atomic64_read(&m->metadata_latency_max))
+ return;
+
+ spin_lock(&m->metadata_latency_lock);
+ if (lat < atomic64_read(&m->metadata_latency_min))
+ atomic64_set(&m->metadata_latency_min, lat);
+ if (lat > atomic64_read(&m->metadata_latency_max))
+ atomic64_set(&m->metadata_latency_max, lat);
+ spin_unlock(&m->metadata_latency_lock);
+}
@@ -3,7 +3,7 @@
#define _FS_CEPH_MDS_METRIC_H
#include <linux/atomic.h>
-#include <linux/percpu.h>
+#include <linux/percpu_counter.h>
#include <linux/spinlock.h>
/* This is the global metrics */
@@ -44,78 +44,18 @@ static inline void ceph_update_cap_mis(struct ceph_client_metric *m)
percpu_counter_inc(&m->i_caps_mis);
}
-static inline void ceph_update_read_latency(struct ceph_client_metric *m,
- unsigned long r_start,
- 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, lat);
-
- if (lat >= atomic64_read(&m->read_latency_min) &&
- lat <= atomic64_read(&m->read_latency_max))
- 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);
-}
-
-static inline void ceph_update_write_latency(struct ceph_client_metric *m,
- unsigned long r_start,
- unsigned long r_end,
- int rc)
-{
- unsigned long lat = r_end - r_start;
-
- if (rc && rc != -ETIMEDOUT)
- return;
-
- percpu_counter_inc(&m->total_writes);
- percpu_counter_add(&m->write_latency_sum, r_end - r_start);
-
- if (lat >= atomic64_read(&m->write_latency_min) &&
- lat <= atomic64_read(&m->write_latency_max))
- return;
-
- spin_lock(&m->write_latency_lock);
- if (lat < atomic64_read(&m->write_latency_min))
- atomic64_set(&m->write_latency_min, lat);
- if (lat > atomic64_read(&m->write_latency_max))
- atomic64_set(&m->write_latency_max, lat);
- spin_unlock(&m->write_latency_lock);
-}
-
-static inline void ceph_update_metadata_latency(struct ceph_client_metric *m,
- unsigned long r_start,
- unsigned long r_end,
- int rc)
-{
- unsigned long lat = r_end - r_start;
-
- if (rc && rc != -ENOENT)
- return;
-
- percpu_counter_inc(&m->total_metadatas);
- percpu_counter_add(&m->metadata_latency_sum, r_end - r_start);
-
- if (lat >= atomic64_read(&m->metadata_latency_min) &&
- lat <= atomic64_read(&m->metadata_latency_max))
- return;
-
- spin_lock(&m->metadata_latency_lock);
- if (lat < atomic64_read(&m->metadata_latency_min))
- atomic64_set(&m->metadata_latency_min, lat);
- if (lat > atomic64_read(&m->metadata_latency_max))
- atomic64_set(&m->metadata_latency_max, lat);
- spin_unlock(&m->metadata_latency_lock);
-}
+extern int ceph_mdsc_metric_init(struct ceph_client_metric *m);
+extern void ceph_mdsc_metric_destroy(struct ceph_client_metric *m);
+extern void ceph_update_read_latency(struct ceph_client_metric *m,
+ unsigned long r_start,
+ unsigned long r_end,
+ int rc);
+extern void ceph_update_write_latency(struct ceph_client_metric *m,
+ unsigned long r_start,
+ unsigned long r_end,
+ int rc);
+extern void ceph_update_metadata_latency(struct ceph_client_metric *m,
+ unsigned long r_start,
+ unsigned long r_end,
+ int rc);
#endif /* _FS_CEPH_MDS_METRIC_H */