Skip to content

Commit 9b5c87d

Browse files
tehcasterakpm00
authored andcommitted
mm: mmap_lock: check trace_mmap_lock_$type_enabled() instead of regcount
Since 7d6be67 ("mm: mmap_lock: replace get_memcg_path_buf() with on-stack buffer") we use trace_mmap_lock_reg()/unreg() only to maintain an atomic reg_refcount which is checked to avoid performing get_mm_memcg_path() in case none of the tracepoints using it is enabled. This can be achieved directly by putting all the work needed for the tracepoint behind the trace_mmap_lock_##type##_enabled(), as suggested by Documentation/trace/tracepoints.rst and with the following advantages: - uses the tracepoint's static key instead of evaluating a branch - the check tracepoint specific, not shared by all of them - we can get rid of trace_mmap_lock_reg()/unreg() completely Thus use the trace_..._enabled() check and remove unnecessary code. Link: https://lkml.kernel.org/r/20241105113456.95066-2-vbabka@suse.cz Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Axel Rasmussen <axelrasmussen@google.com> Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 9f3310c commit 9b5c87d

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

include/trace/events/mmap_lock.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
struct mm_struct;
1212

13-
extern int trace_mmap_lock_reg(void);
14-
extern void trace_mmap_lock_unreg(void);
15-
1613
DECLARE_EVENT_CLASS(mmap_lock,
1714

1815
TP_PROTO(struct mm_struct *mm, const char *memcg_path, bool write),
@@ -40,16 +37,15 @@ DECLARE_EVENT_CLASS(mmap_lock,
4037
);
4138

4239
#define DEFINE_MMAP_LOCK_EVENT(name) \
43-
DEFINE_EVENT_FN(mmap_lock, name, \
40+
DEFINE_EVENT(mmap_lock, name, \
4441
TP_PROTO(struct mm_struct *mm, const char *memcg_path, \
4542
bool write), \
46-
TP_ARGS(mm, memcg_path, write), \
47-
trace_mmap_lock_reg, trace_mmap_lock_unreg)
43+
TP_ARGS(mm, memcg_path, write))
4844

4945
DEFINE_MMAP_LOCK_EVENT(mmap_lock_start_locking);
5046
DEFINE_MMAP_LOCK_EVENT(mmap_lock_released);
5147

52-
TRACE_EVENT_FN(mmap_lock_acquire_returned,
48+
TRACE_EVENT(mmap_lock_acquire_returned,
5349

5450
TP_PROTO(struct mm_struct *mm, const char *memcg_path, bool write,
5551
bool success),
@@ -76,9 +72,7 @@ TRACE_EVENT_FN(mmap_lock_acquire_returned,
7672
__get_str(memcg_path),
7773
__entry->write ? "true" : "false",
7874
__entry->success ? "true" : "false"
79-
),
80-
81-
trace_mmap_lock_reg, trace_mmap_lock_unreg
75+
)
8276
);
8377

8478
#endif /* _TRACE_MMAP_LOCK_H */

mm/mmap_lock.c

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,23 @@ EXPORT_TRACEPOINT_SYMBOL(mmap_lock_released);
1919

2020
#ifdef CONFIG_MEMCG
2121

22-
static atomic_t reg_refcount;
23-
2422
/*
2523
* Size of the buffer for memcg path names. Ignoring stack trace support,
2624
* trace_events_hist.c uses MAX_FILTER_STR_VAL for this, so we also use it.
2725
*/
2826
#define MEMCG_PATH_BUF_SIZE MAX_FILTER_STR_VAL
2927

30-
int trace_mmap_lock_reg(void)
31-
{
32-
atomic_inc(&reg_refcount);
33-
return 0;
34-
}
35-
36-
void trace_mmap_lock_unreg(void)
37-
{
38-
atomic_dec(&reg_refcount);
39-
}
40-
41-
#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \
42-
do { \
43-
char buf[MEMCG_PATH_BUF_SIZE]; \
44-
get_mm_memcg_path(mm, buf, sizeof(buf)); \
45-
trace_mmap_lock_##type(mm, buf, ##__VA_ARGS__); \
28+
#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \
29+
do { \
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__); \
34+
} \
4635
} while (0)
4736

4837
#else /* !CONFIG_MEMCG */
4938

50-
int trace_mmap_lock_reg(void)
51-
{
52-
return 0;
53-
}
54-
55-
void trace_mmap_lock_unreg(void)
56-
{
57-
}
58-
5939
#define TRACE_MMAP_LOCK_EVENT(type, mm, ...) \
6040
trace_mmap_lock_##type(mm, "", ##__VA_ARGS__)
6141

@@ -65,16 +45,13 @@ void trace_mmap_lock_unreg(void)
6545
#ifdef CONFIG_MEMCG
6646
/*
6747
* Write the given mm_struct's memcg path to a buffer. If the path cannot be
68-
* determined or the trace event is being unregistered, empty string is written.
48+
* determined, empty string is written.
6949
*/
7050
static void get_mm_memcg_path(struct mm_struct *mm, char *buf, size_t buflen)
7151
{
7252
struct mem_cgroup *memcg;
7353

7454
buf[0] = '\0';
75-
/* No need to get path if no trace event is registered. */
76-
if (!atomic_read(&reg_refcount))
77-
return;
7855
memcg = get_mem_cgroup_from_mm(mm);
7956
if (memcg == NULL)
8057
return;

0 commit comments

Comments
 (0)