1 // SPDX-License-Identifier: GPL-2.0
2 #define CREATE_TRACE_POINTS
3 #include <trace/events/mmap_lock.h>
6 #include <linux/cgroup.h>
7 #include <linux/memcontrol.h>
8 #include <linux/mmap_lock.h>
9 #include <linux/mutex.h>
10 #include <linux/percpu.h>
11 #include <linux/rcupdate.h>
12 #include <linux/smp.h>
13 #include <linux/trace_events.h>
14 #include <linux/local_lock.h>
16 EXPORT_TRACEPOINT_SYMBOL(mmap_lock_start_locking
);
17 EXPORT_TRACEPOINT_SYMBOL(mmap_lock_acquire_returned
);
18 EXPORT_TRACEPOINT_SYMBOL(mmap_lock_released
);
23 * Size of the buffer for memcg path names. Ignoring stack trace support,
24 * trace_events_hist.c uses MAX_FILTER_STR_VAL for this, so we also use it.
26 #define MEMCG_PATH_BUF_SIZE MAX_FILTER_STR_VAL
28 #define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \
30 if (trace_mmap_lock_##type##_enabled()) { \
31 char buf[MEMCG_PATH_BUF_SIZE]; \
32 get_mm_memcg_path(mm, buf, sizeof(buf)); \
33 trace_mmap_lock_##type(mm, buf, ##__VA_ARGS__); \
37 #else /* !CONFIG_MEMCG */
39 #define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \
40 trace_mmap_lock_##type(mm, "", ##__VA_ARGS__)
42 #endif /* CONFIG_MEMCG */
47 * Write the given mm_struct's memcg path to a buffer. If the path cannot be
48 * determined, empty string is written.
50 static void get_mm_memcg_path(struct mm_struct
*mm
, char *buf
, size_t buflen
)
52 struct mem_cgroup
*memcg
;
55 memcg
= get_mem_cgroup_from_mm(mm
);
58 if (memcg
->css
.cgroup
)
59 cgroup_path(memcg
->css
.cgroup
, buf
, buflen
);
63 #endif /* CONFIG_MEMCG */
66 * Trace calls must be in a separate file, as otherwise there's a circular
67 * dependency between linux/mmap_lock.h and trace/events/mmap_lock.h.
70 void __mmap_lock_do_trace_start_locking(struct mm_struct
*mm
, bool write
)
72 TRACE_MMAP_LOCK_EVENT(start_locking
, mm
, write
);
74 EXPORT_SYMBOL(__mmap_lock_do_trace_start_locking
);
76 void __mmap_lock_do_trace_acquire_returned(struct mm_struct
*mm
, bool write
,
79 TRACE_MMAP_LOCK_EVENT(acquire_returned
, mm
, write
, success
);
81 EXPORT_SYMBOL(__mmap_lock_do_trace_acquire_returned
);
83 void __mmap_lock_do_trace_released(struct mm_struct
*mm
, bool write
)
85 TRACE_MMAP_LOCK_EVENT(released
, mm
, write
);
87 EXPORT_SYMBOL(__mmap_lock_do_trace_released
);
88 #endif /* CONFIG_TRACING */