]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
tls: adding an allocation histogram
authorAlex Markuze <amarkuze@redhat.com>
Wed, 26 Feb 2025 15:04:52 +0000 (15:04 +0000)
committerAlex Markuze <amarkuze@redhat.com>
Wed, 26 Feb 2025 15:11:32 +0000 (15:11 +0000)
fs/ceph/debugfs.c
fs/ceph/super.h
include/linux/ceph/ceph_san.h
net/ceph/ceph_san.c

index 9fa6203bb74114e3a658092d6b9183d9eda9fd24..2f2bd49cc4824aa036a3cba0bfe98bbf2b57d321 100644 (file)
 #include "mds_client.h"
 #include "metric.h"
 
+static int histogram_show(struct seq_file *s, void *p)
+{
+       struct ceph_san_tls_logger *tls;
+       size_t cpu;
+       u64 total_histogram[16] = {0};
+       int i;
+
+       seq_printf(s, "Ceph TLS Histogram Summary:\n");
+       seq_printf(s, "%-10s %-16s\n", "Bucket", "Count");
+       seq_printf(s, "-------------------------\n");
+
+       /* Sum up histograms from all CPUs */
+       for_each_possible_cpu(cpu) {
+               tls = &per_cpu(ceph_san_tls, cpu);
+
+               /* Add each CPU's histogram data to the total */
+               for (i = 0; i < 16; i++) {
+                               total_histogram[i] += tls->histogram.counters[i];
+               }
+       }
+
+       /* Calculate total sum for normalization */
+       u64 sum = 0;
+       for (i = 0; i < 16; i++) {
+               sum += total_histogram[i];
+       }
+
+       /* Display normalized histogram with stars and percentages */
+       for (i = 0; i < 16; i++) {
+               int stars = sum ? (total_histogram[i] * 128) / sum : 0;
+               u64 percent = sum ? (total_histogram[i] * 100) / sum : 0;
+               seq_printf(s, "%-4d [%3.1f%%] ", i, percent);
+               while (stars-- > 0)
+                       seq_printf(s, "*");
+               seq_printf(s, "\n");
+       }
+
+       return 0;
+}
+
 static int ceph_san_show(struct seq_file *s, void *p)
 {
        struct ceph_san_tls_logger *tls;
@@ -413,6 +453,7 @@ DEFINE_SHOW_ATTRIBUTE(metrics_latency);
 DEFINE_SHOW_ATTRIBUTE(metrics_size);
 DEFINE_SHOW_ATTRIBUTE(metrics_caps);
 DEFINE_SHOW_ATTRIBUTE(ceph_san);
+DEFINE_SHOW_ATTRIBUTE(histogram);
 
 
 /*
@@ -449,6 +490,7 @@ void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)
        debugfs_remove(fsc->debugfs_status);
        debugfs_remove(fsc->debugfs_mdsc);
        debugfs_remove(fsc->debugfs_cephsan);
+       debugfs_remove(fsc->debugfs_histogram);
        debugfs_remove_recursive(fsc->debugfs_metrics_dir);
        doutc(fsc->client, "done\n");
 }
@@ -507,6 +549,12 @@ void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)
                                                        fsc,
                                                        &ceph_san_fops);
 
+       fsc->debugfs_histogram = debugfs_create_file("histogram",
+                                                       0444,
+                                                       fsc->client->debugfs_dir,
+                                                       fsc,
+                                                       &histogram_fops);
+
        fsc->debugfs_metrics_dir = debugfs_create_dir("metrics",
                                                      fsc->client->debugfs_dir);
 
index d7e52f0c79a4c0c23ed5f029d3687c983655121c..4f901006cb48e50b3a3d39e57b9a5b828c7b2282 100644 (file)
@@ -154,6 +154,7 @@ struct ceph_fs_client {
        struct dentry *debugfs_mds_sessions;
        struct dentry *debugfs_metrics_dir;
        struct dentry *debugfs_cephsan;
+       struct dentry *debugfs_histogram;
 #endif
 
 #ifdef CONFIG_CEPH_FSCACHE
index e6d3c34ce6cae5120fa39116abcf6f9304c661e9..ee1445a2f37b14412a07fe6f55909b7303de7af4 100644 (file)
@@ -5,7 +5,7 @@
 #include <linux/list.h>
 #include <linux/spinlock.h>
 #include <linux/sched.h>
-
+#include <linux/slab.h>
 
 DECLARE_PER_CPU(struct ceph_san_tls_logger, ceph_san_tls);
 DECLARE_PER_CPU(struct cephsan_pagefrag, ceph_san_pagefrag);
@@ -94,11 +94,14 @@ struct ceph_san_log_entry {
     pid_t pid;
     u32 len;
 };
-
+struct histogram {
+       u64 counters[16];
+};
 struct ceph_san_tls_logger {
     size_t head_idx;
     struct page *pages;
     struct ceph_san_log_entry *logs;
+    struct histogram histogram;
 };
 #else /* CONFIG_DEBUG_FS */
 
index ed6592b5b0ea6a642756623ebefd5f5b5b8bad44..5b41ce8b0f12b99dd49de9f65c635777c4ee27c3 100644 (file)
@@ -26,7 +26,7 @@ void log_cephsan(char *buf) {
     struct ceph_san_tls_logger *tls = this_cpu_ptr(&ceph_san_tls);
     struct cephsan_pagefrag *pf = this_cpu_ptr(&ceph_san_pagefrag);
 
-    int head_idx = tls->head_idx++ & (CEPH_SAN_MAX_LOGS - 1);
+    int head_idx = tls->head_idx + 1 & (CEPH_SAN_MAX_LOGS - 1);
     int pre_len = tls->logs[head_idx].len;
 
     buf[len-1] = '\0';
@@ -35,9 +35,12 @@ void log_cephsan(char *buf) {
     memcpy(tls->logs[head_idx].comm, current->comm, TASK_COMM_LEN);
 
     cephsan_pagefrag_free(pf, pre_len);
+    tls->logs[head_idx].len = 0;
 
     buf_idx = cephsan_pagefrag_alloc(pf, len);
     if (buf_idx) {
+               tls->head_idx = head_idx;
+               tls->histogram.counters[len >> 3]++;
                tls->logs[head_idx].len = len;
         tls->logs[head_idx].buf = cephsan_pagefrag_get_ptr(pf, buf_idx);
                memcpy(tls->logs[head_idx].buf, buf, len);
@@ -71,7 +74,6 @@ int cephsan_init(void)
        struct ceph_san_tls_logger *tls;
        struct cephsan_pagefrag *pf;
 
-       struct task_struct *task = current;
        for_each_possible_cpu(cpu) {
                tls = per_cpu_ptr(&ceph_san_tls, cpu);
                tls->pages = alloc_pages(GFP_KERNEL, get_order(CEPH_SAN_MAX_LOGS * sizeof(struct ceph_san_log_entry)));