Skip to contentSkip to conversation

bpf: Allocate bpf_event_entry with node info

PATCH In review Namhyung Kim 3 participants 5 messages May 29, 2024 BPF

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: Allocate bpf_event_entry with node info

It was reported that accessing perf_event map entry caused pretty high LLC misses in get_map_perf_counter(). As reading perf_event is allowed for the local CPU only, I think we can use the target CPU of the event as hint for the allocation like in perf_event_alloc() so that the event and the entry can be in the same node at least.

---
v2) fix build errors

 kernel/bpf/arraymap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/arraymap.c +9 -2
index feabc0193852..067f7cf27042 100644
@@ -1194,10 +1194,17 @@ static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,
 						   struct file *map_file)
 {
 	struct bpf_event_entry *ee;
+	struct perf_event *event = perf_file->private_data;
+	int node = -1;
 
-	ee = kzalloc(sizeof(*ee), GFP_KERNEL);
+#ifdef CONFIG_PERF_EVENTS
+	if (event->cpu >= 0)
+		node = cpu_to_node(event->cpu);
+#endif
+
+	ee = kzalloc_node(sizeof(*ee), GFP_KERNEL, node);
 	if (ee) {
-		ee->event = perf_file->private_data;
+		ee->event = event;
 		ee->perf_file = perf_file;
 		ee->map_file = map_file;
 	}
Signature · 1 line
2.45.1.288.g0e0cd299f1-goog
#1 lore raw
Quoted 5 lines · Namhyung Kim

It was reported that accessing perf_event map entry caused pretty high LLC misses in get_map_perf_counter(). As reading perf_event is allowed for the local CPU only, I think we can use the target CPU of the event as hint for the allocation like in perf_event_alloc() so that the event and the entry can be in the same node at least.

looks good, is there any profile to prove the gain?

jirka

Quoted 38 lines

---
v2) fix build errors

 kernel/bpf/arraymap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/arraymap.c +9 -2
index feabc0193852..067f7cf27042 100644
@@ -1194,10 +1194,17 @@ static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,
 						   struct file *map_file)
 {
 	struct bpf_event_entry *ee;
+	struct perf_event *event = perf_file->private_data;
+	int node = -1;
 
-	ee = kzalloc(sizeof(*ee), GFP_KERNEL);
+#ifdef CONFIG_PERF_EVENTS
+	if (event->cpu >= 0)
+		node = cpu_to_node(event->cpu);
+#endif
+
+	ee = kzalloc_node(sizeof(*ee), GFP_KERNEL, node);
 	if (ee) {
-		ee->event = perf_file->private_data;
+		ee->event = event;
 		ee->perf_file = perf_file;
 		ee->map_file = map_file;
 	}
Signature · 1 line
2.45.1.288.g0e0cd299f1-goog
#2 lore raw

Hi Jiri,

Quoted 9 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim

It was reported that accessing perf_event map entry caused pretty high LLC misses in get_map_perf_counter(). As reading perf_event is allowed for the local CPU only, I think we can use the target CPU of the event as hint for the allocation like in perf_event_alloc() so that the event and the entry can be in the same node at least.

looks good, is there any profile to prove the gain?

No, at this point. I'm not sure if it'd help LLC hit ratio but I think it should improve the memory latency.

Thanks,
Namhyung

Quoted 39 lines
Quoted 39 lines

---
v2) fix build errors

 kernel/bpf/arraymap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/arraymap.c +9 -3
index feabc0193852..067f7cf27042 100644
@@ -1194,10 +1194,17 @@ static struct bpf_event_entry *bpf_event_entry_gen(struct file *perf_file,
                                                 struct file *map_file)
 {
      struct bpf_event_entry *ee;
+     struct perf_event *event = perf_file->private_data;
+     int node = -1;
 
-     ee = kzalloc(sizeof(*ee), GFP_KERNEL);
+#ifdef CONFIG_PERF_EVENTS
+     if (event->cpu >= 0)
+             node = cpu_to_node(event->cpu);
+#endif
+
+     ee = kzalloc_node(sizeof(*ee), GFP_KERNEL, node);
      if (ee) {
-             ee->event = perf_file->private_data;
+             ee->event = event;
              ee->perf_file = perf_file;
              ee->map_file = map_file;
      }
--

2.45.1.288.g0e0cd299f1-goog

#3 lore raw
Quoted 12 lines · Namhyung Kim

Hi Jiri,

Quoted 8 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim

It was reported that accessing perf_event map entry caused pretty high LLC misses in get_map_perf_counter(). As reading perf_event is allowed for the local CPU only, I think we can use the target CPU of the event as hint for the allocation like in perf_event_alloc() so that the event and the entry can be in the same node at least.

Quoted 4 lines
Quoted 1 line

looks good, is there any profile to prove the gain?

No, at this point. I'm not sure if it'd help LLC hit ratio but I think it should improve the memory latency.

I have the same concern as Jiri.
Without numbers this is just a code churn.
Does this patch really make a difference?
Without numbers maintainers would have to believe the "just trust me" part. So..
pw-bot: cr

#4 lore raw

Hi Alexei,

Quoted 19 lines · Alexei Starovoitov
Quoted 12 lines · Namhyung Kim

Hi Jiri,

Quoted 8 lines · Jiri Olsa
Quoted 5 lines · Namhyung Kim

It was reported that accessing perf_event map entry caused pretty high LLC misses in get_map_perf_counter(). As reading perf_event is allowed for the local CPU only, I think we can use the target CPU of the event as hint for the allocation like in perf_event_alloc() so that the event and the entry can be in the same node at least.

Quoted 4 lines
Quoted 1 line

looks good, is there any profile to prove the gain?

No, at this point. I'm not sure if it'd help LLC hit ratio but I think it should improve the memory latency.

Quoted 6 lines

I have the same concern as Jiri.
Without numbers this is just a code churn.
Does this patch really make a difference?
Without numbers maintainers would have to believe the "just trust me" part. So..
pw-bot: cr

Ok, then I'll come back with numbers later.

Thanks,
Namhyung