From: Alex Markuze Date: Wed, 26 Feb 2025 15:04:52 +0000 (+0000) Subject: tls: adding an allocation histogram X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=764e50ba296da76e7332d2d08223d3e484aea2b3;p=ceph-client.git tls: adding an allocation histogram --- diff --git a/fs/ceph/debugfs.c b/fs/ceph/debugfs.c index 9fa6203bb741..2f2bd49cc482 100644 --- a/fs/ceph/debugfs.c +++ b/fs/ceph/debugfs.c @@ -23,6 +23,46 @@ #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); diff --git a/fs/ceph/super.h b/fs/ceph/super.h index d7e52f0c79a4..4f901006cb48 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -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 diff --git a/include/linux/ceph/ceph_san.h b/include/linux/ceph/ceph_san.h index e6d3c34ce6ca..ee1445a2f37b 100644 --- a/include/linux/ceph/ceph_san.h +++ b/include/linux/ceph/ceph_san.h @@ -5,7 +5,7 @@ #include #include #include - +#include 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 */ diff --git a/net/ceph/ceph_san.c b/net/ceph/ceph_san.c index ed6592b5b0ea..5b41ce8b0f12 100644 --- a/net/ceph/ceph_san.c +++ b/net/ceph/ceph_san.c @@ -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)));