The goal of these tracepoints is to be able to debug lock contention
issues. This lock is acquired on most (all?) mmap / munmap / page fault
operations, so a multi-threaded process which does a lot of these can
experience significant contention.
We trace just before we start acquisition, when the acquisition returns
(whether it succeeded or not), and when the lock is released (or
downgraded). The events are broken out by lock type (read / write).
The events are also broken out by memcg path. For container-based
workloads, users often think of several processes in a memcg as a single
logical "task", so collecting statistics at this level is useful.
The end goal is to get latency information. This isn't directly included
in the trace events. Instead, users are expected to compute the time
between "start locking" and "acquire returned", using e.g. synthetic
events or BPF. The benefit we get from this is simpler code.
Because we use tracepoint_enabled() to decide whether or not to trace,
this patch has effectively no overhead unless tracepoints are enabled at
runtime. If tracepoints are enabled, there is a performance impact, but
how much depends on exactly what e.g. the BPF program does.
[firstname.lastname@example.org: fix use-after-free race and css ref leak in tracepoints]
[email@example.com: in-depth examples of tracepoint_enabled() usage, and per-cpu-per-context buffer design]
Signed-off-by: Axel Rasmussen <firstname.lastname@example.org>
Acked-by: Vlastimil Babka <email@example.com>
Cc: Steven Rostedt <firstname.lastname@example.org>
Cc: Ingo Molnar <email@example.com>
Cc: Michel Lespinasse <firstname.lastname@example.org>
Cc: Daniel Jordan <email@example.com>
Cc: Jann Horn <firstname.lastname@example.org>
Cc: Chinwen Chang <email@example.com>
Cc: Davidlohr Bueso <firstname.lastname@example.org>
Cc: David Rientjes <email@example.com>
Cc: Laurent Dufour <firstname.lastname@example.org>
Cc: Yafang Shao <email@example.com>
Signed-off-by: Andrew Morton <firstname.lastname@example.org>
Signed-off-by: Linus Torvalds <email@example.com>