[v2,5/7] mmap_lock: add /proc/<pid>/mmap_lock_contention interface
diff mbox series

Message ID 20200528235303.77873-1-axelrasmussen@google.com
State New
Headers show
Series
  • Add histogram measuring mmap_lock contention latency
Related show

Commit Message

Axel Rasmussen May 28, 2020, 11:53 p.m. UTC
When this file is read, we print a human-readable listing of histogram
buckets, as well as the number of samples recorded in each bucket.

Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
---
 fs/proc/base.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Patch
diff mbox series

diff --git a/fs/proc/base.c b/fs/proc/base.c
index a96377557db7..42d706474971 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -96,6 +96,8 @@ 
 #include <linux/posix-timers.h>
 #include <linux/time_namespace.h>
 #include <linux/resctrl.h>
+#include <linux/histogram.h>
+#include <linux/mm_types.h>
 #include <trace/events/oom.h>
 #include "internal.h"
 #include "fd.h"
@@ -3115,6 +3117,26 @@  static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
 }
 #endif /* CONFIG_STACKLEAK_METRICS */
 
+#ifdef CONFIG_MMAP_LOCK_HISTOGRAMS
+static int proc_pid_mmap_lock_contention_show(struct seq_file *m,
+					      struct pid_namespace *ns,
+					      struct pid *pid,
+					      struct task_struct *task)
+{
+	int rc;
+
+	if (unlikely(!task->mm->mmap_lock_contention))
+		return 0;
+
+	rc = histogram_print_buckets_rcu(
+		task->mm->mmap_lock_contention,
+		m->buf + m->count, m->size - m->count);
+	if (rc > 0)
+		m->count += rc;
+	return 0;
+}
+#endif /* CONFIG_MMAP_LOCK_HISTOGRAMS */
+
 /*
  * Thread groups
  */
@@ -3228,6 +3250,9 @@  static const struct pid_entry tgid_base_stuff[] = {
 #ifdef CONFIG_PROC_PID_ARCH_STATUS
 	ONE("arch_status", S_IRUGO, proc_pid_arch_status),
 #endif
+#ifdef CONFIG_MMAP_LOCK_HISTOGRAMS
+	ONE("mmap_lock_contention", S_IRUGO, proc_pid_mmap_lock_contention_show),
+#endif
 };
 
 static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)