[v2,3/7] mmap_lock: add a histogram structure to struct mm_struct
diff mbox series

Message ID 20200528235256.76129-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:52 p.m. UTC
This histogram will be used to measure lock acquisition latency, when
the acquisition is contended. Cases where we acquire the lock
immediately with no contention are recorded as "0" (to avoid incurring
the cost of really computing the time, while retaining the ability to
get an accurate total lock acquisition count).

Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
---
 include/linux/mm_types.h | 11 +++++++++++
 mm/Kconfig               | 13 +++++++++++++
 2 files changed, 24 insertions(+)

Patch
diff mbox series

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index d13b90399c16..efeb5db1959d 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -376,6 +376,10 @@  struct core_state {
 	struct completion startup;
 };
 
+#ifdef CONFIG_MMAP_LOCK_HISTOGRAMS
+struct histogram_rcu;
+#endif
+
 struct kioctx_table;
 struct mm_struct {
 	struct {
@@ -437,6 +441,13 @@  struct mm_struct {
 					     * counters
 					     */
 		struct rw_semaphore mmap_lock;
+#ifdef CONFIG_MMAP_LOCK_HISTOGRAMS
+		/* Histogram of mmap_lock contended acquire delays. kmalloc'd
+		 * so we can use a forward declaration, to avoid circular
+		 * dependencies between headers.
+		 */
+		struct histogram_rcu *mmap_lock_contention;
+#endif
 
 		struct list_head mmlist; /* List of maybe swapped mm's.	These
 					  * are globally strung together off
diff --git a/mm/Kconfig b/mm/Kconfig
index c1acc34c1c35..231862afc2ce 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -817,6 +817,19 @@  config DEVICE_PRIVATE
 config FRAME_VECTOR
 	bool
 
+config MMAP_LOCK_HISTOGRAMS
+	bool "mmap_lock histograms"
+	select HISTOGRAM
+	default n
+
+	help
+	  Record and report latency histograms describing mmap_lock
+	  contention. Stats can be read from /proc/<pid>/mmap_lock_contention.
+	  True latency is only computed for *contended* acquires, to minimize
+	  overhead. Uncontended acquires are recorded as having "0" latency.
+
+	  If unsure, say "n".
+
 config ARCH_USES_HIGH_VMA_FLAGS
 	bool
 config ARCH_HAS_PKEYS