Skip to content

Add histogram measuring mmap_lock contention latency

Axel Rasmussen linux-mm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest7 patches 6 repliesIn review

Changes in v2 from the cover letter

- Added a tracepoint to the contended case.
- Modified mmap_write_lock_nested to split the {un,}contended cases.
- Removed support for having more than one histogram in mm_struct.
- Removed any histogram code not explicitly used in this patchset.
- Whitespace cleanups.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7histogram: add struct histograminclude/linux/histogram.h lib/Kconfig lib/Makefile +1 more+432 -00 replies
2/7histogram: add helper function to expose histograms to userspaceinclude/linux/histogram.h lib/histogram.c+78 -00 replies
3/7mmap_lock: add a histogram structure to struct mm_structinclude/linux/mm_types.h mm/Kconfig+24 -00 replies
4/7mmap_lock: allocate histogram (if enabled) in mm_initkernel/fork.c+55 -00 replies
5/7mmap_lock: add /proc/<pid>/mmap_lock_contention interfacefs/proc/base.c+25 -00 replies
6/7mmap_lock: increment histogram whenever mmap_lock is acquiredinclude/linux/mmap_lock.h kernel/locking/rwsem.c mm/Makefile +1 more+117 -90 replies
7/7mmap_lock: add a tracepoint to contended acquisitionsinclude/linux/mmap_lock.h include/trace/events/mmap_lock.h mm/mmap_lock.c+53 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/7] Add histogram measuring mmap_lock contention latency

The overall goal of this patchset is to add a latency histogram which measures mmap_lock acquisition time. This is useful to measure the impact of ongoing work like maple trees and range locks (https://lwn.net/Articles/787629/), and it is also useful to debug userspace processes which experience long waits due to lock contention.

This patchset is built upon [email protected]'s new mmap_lock API
(https://lkml.org/lkml/2020/4/21/1307). In its current form, it should apply cleanly to a 5.7-rc7 tree to which Michel's patchset has already been applied.

To summarize the changes being made at a high level:

- Add a histogram library: a struct histogram is effectively an array of thresholds (i.e., buckets), and an array of per-cpu u64 counts of the number of samples in each bucket.

- Modify Michel's mmap_lock API to record samples in a histogram, owned by the mm_struct, on each lock acquisition. For contended lock acquisitions, we compute the amount of time spent waiting, which determines the bucket.

- For uncontended cases, we still record a sample, but with "0" latency. The reasoning for this is, a) we don't want to incur the overhead of actually measuring the time, but b) we still want to end up with an accurate count of acquisition attempts, as this lets us compute latency percentiles (e.g., "x% of lock acquisitions completed in <= y ns").

Changes since v1 (sent to a few folks within Google for initial review):

- Added a tracepoint to the contended case.
- Modified mmap_write_lock_nested to split the {un,}contended cases.
- Removed support for having more than one histogram in mm_struct.
- Removed any histogram code not explicitly used in this patchset.
- Whitespace cleanups.

Axel Rasmussen (7):
histogram: add struct histogram
histogram: add helper function to expose histograms to userspace
mmap_lock: add a histogram structure to struct mm_struct
mmap_lock: allocate histogram (if enabled) in mm_init
mmap_lock: add /proc/<pid>/mmap_lock_contention interface
mmap_lock: increment histogram whenever mmap_lock is acquired
mmap_lock: add a tracepoint to contended acquisitions

 fs/proc/base.c                   |  25 +++
 include/linux/histogram.h        | 293 +++++++++++++++++++++++++++++++
 include/linux/mm_types.h         |  11 ++
 include/linux/mmap_lock.h        |  92 +++++++++-
 include/trace/events/mmap_lock.h |  34 ++++
 kernel/fork.c                    |  55 ++++++
 kernel/locking/rwsem.c           |   4 +-
 lib/Kconfig                      |   3 +
 lib/Makefile                     |   2 +
 lib/histogram.c                  | 212 ++++++++++++++++++++++
 mm/Kconfig                       |  13 ++
 mm/Makefile                      |   1 +
 mm/mmap_lock.c                   |  46 +++++
 13 files changed, 782 insertions(+), 9 deletions(-)
 create mode 100644 include/linux/histogram.h
 create mode 100644 include/trace/events/mmap_lock.h
 create mode 100644 lib/histogram.c
 create mode 100644 mm/mmap_lock.c

--
2.27.0.rc0.183.gde8f92d652-goog