Skip to contentSkip to conversation

perf report: Do not process non-JIT BPF ksymbol events

PATCH Applied Namhyung Kim 3 participants 7 messages Mar 5, 2025 – Mar 7, 2025

Subsystems (2)
lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf report: Do not process non-JIT BPF ksymbol events

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

Probably there's a bug in the kernel map/symbol handling in perf tools. But I think we need to fix this anyway.

---
 tools/perf/util/machine.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/machine.c +4 -0
index 3f1faf94198dbe56..c7d27384f0736408 100644
@@ -779,6 +779,10 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused,
 	if (dump_trace)
 		perf_event__fprintf_ksymbol(event, stdout);
 
+	/* no need to process non-JIT BPF as it cannot get samples */
+	if (event->ksymbol.len == 0)
+		return 0;
+
 	if (event->ksymbol.flags & PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER)
 		return machine__process_ksymbol_unregister(machine, event,
 							   sample);
Signature · 1 line
2.48.1.711.g2feabab25a-goog
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Namhyung Kim

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

Quoted 6 lines

Probably there's a bug in the kernel map/symbol handling in perf tools. But I think we need to fix this anyway.

reviewer
#2 lore raw
In reply to Namhyung Kim
Quoted 26 lines · Namhyung Kim

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

Probably there's a bug in the kernel map/symbol handling in perf tools. But I think we need to fix this anyway.

---
 tools/perf/util/machine.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/machine.c +0 -0
index 3f1faf94198dbe56..c7d27384f0736408 100644

tools/perf/util/machine.c int machine__process_ksymbol(struct machine *machine __maybe_unused, · line 784

Quoted 6 lines
tools/perf/util/machine.c +3 -0
@@ -779,6 +779,10 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused,
 	if (dump_trace)
 		perf_event__fprintf_ksymbol(event, stdout);
 
+	/* no need to process non-JIT BPF as it cannot get samples */
+	if (event->ksymbol.len == 0)
+		return 0;

Are all ksymbol events BPF? Maybe it is OK
for PERF_RECORD_KSYMBOL_TYPE_OOL also. Perhaps adjust the comment in that case.

Quoted 4 lines
tools/perf/util/machine.c +1 -0
+
 	if (event->ksymbol.flags & PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER)
 		return machine__process_ksymbol_unregister(machine, event,
 							   sample);
author maintainer
#3 lore raw

Hello,

Quoted 30 lines · Adrian Hunter
Quoted 29 lines · Namhyung Kim

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

Probably there's a bug in the kernel map/symbol handling in perf tools. But I think we need to fix this anyway.

---
 tools/perf/util/machine.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/machine.c +0 -0
index 3f1faf94198dbe56..c7d27384f0736408 100644
@@ -779,6 +779,10 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused,
 	if (dump_trace)
 		perf_event__fprintf_ksymbol(event, stdout);
 
Quoted 7 lines

tools/perf/util/machine.c int machine__process_ksymbol(struct machine *machine __maybe_unused, · line 784

Quoted 3 lines
tools/perf/util/machine.c +3 -0
+	/* no need to process non-JIT BPF as it cannot get samples */
+	if (event->ksymbol.len == 0)
+		return 0;

Are all ksymbol events BPF? Maybe it is OK
for PERF_RECORD_KSYMBOL_TYPE_OOL also. Perhaps adjust the comment in that case.

Probably, but I didn't see OOL with zero length yet. Is it possible?

Thanks,
Namhyung

reviewer
#4 lore raw
Quoted 41 lines · Namhyung Kim

Hello,

Quoted 30 lines · Adrian Hunter
Quoted 29 lines · Namhyung Kim

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

Probably there's a bug in the kernel map/symbol handling in perf tools. But I think we need to fix this anyway.

---
 tools/perf/util/machine.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/machine.c +0 -0
index 3f1faf94198dbe56..c7d27384f0736408 100644
@@ -779,6 +779,10 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused,
 	if (dump_trace)
 		perf_event__fprintf_ksymbol(event, stdout);
 
Quoted 7 lines

tools/perf/util/machine.c int machine__process_ksymbol(struct machine *machine __maybe_unused, · line 784

Quoted 3 lines
tools/perf/util/machine.c +3 -0
+	/* no need to process non-JIT BPF as it cannot get samples */
+	if (event->ksymbol.len == 0)
+		return 0;

Are all ksymbol events BPF? Maybe it is OK
for PERF_RECORD_KSYMBOL_TYPE_OOL also. Perhaps adjust the comment in that case.

Quoted 1 line

Probably, but I didn't see OOL with zero length yet. Is it possible?

Probably not

author maintainer
#5 lore raw
Quoted 42 lines · Adrian Hunter
Quoted 41 lines · Namhyung Kim

Hello,

Quoted 37 lines · Adrian Hunter
Quoted 26 lines · Namhyung Kim

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

Probably there's a bug in the kernel map/symbol handling in perf tools. But I think we need to fix this anyway.

---
 tools/perf/util/machine.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/machine.c +0 -0
index 3f1faf94198dbe56..c7d27384f0736408 100644

tools/perf/util/machine.c int machine__process_ksymbol(struct machine *machine __maybe_unused, · line 784

Quoted 6 lines
tools/perf/util/machine.c +3 -0
@@ -779,6 +779,10 @@ int machine__process_ksymbol(struct machine *machine __maybe_unused,
 	if (dump_trace)
 		perf_event__fprintf_ksymbol(event, stdout);
 
+	/* no need to process non-JIT BPF as it cannot get samples */
+	if (event->ksymbol.len == 0)
+		return 0;

Are all ksymbol events BPF? Maybe it is OK
for PERF_RECORD_KSYMBOL_TYPE_OOL also. Perhaps adjust the comment in that case.

Quoted 3 lines
Quoted 1 line

Probably, but I didn't see OOL with zero length yet. Is it possible?

Probably not

Then I think it's ok to leave the comment as is.

Thanks,
Namhyung

author maintainer Applied
#6 lore raw
In reply to Namhyung Kim
Quoted 5 lines · Namhyung Kim

The length of PERF_RECORD_KSYMBOL for BPF is a size of JITed code so it'd be 0 when it's not JITed. The ksymbol is needed to symbolize the code when it gets samples in the region but non-JITed code cannot get samples. Thus it'd be ok to ignore them.

Quoted 7 lines

Actually it caused a performance issue in the perf tools on old ARM kernels where it can refuse to JIT some BPF codes. It ended up splitting the existing kernel map (kallsyms). And later lookup for a kernel symbol would create a new kernel map from kallsyms and then split it again and again. :(

[...]

Applied to perf-tools-next, thanks!

Best regards,
Namhyung