Skip to contentSkip to conversation

bpf: add schedule points in percpu arrays management

PATCH Applied Eric Dumazet 2 participants 2 messages Feb 22, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: add schedule points in percpu arrays management

From: Eric Dumazet <[email protected]>

syszbot managed to trigger RCU detected stalls in
bpf_array_free_percpu()

It takes time to allocate a huge percpu map, but even more time to free it.

Since we run in process context, use cond_resched() to yield cpu if needed.

Fixes a10423b87a7e ("bpf: introduce BPF_MAP_TYPE_PERCPU_ARRAY map")

---
 kernel/bpf/arraymap.c |    5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/arraymap.c +4 -1
index a364c408f25a54a8175c92b6004a5e7e15f198cb..14750e7c5ee4872e4a7426e960bea7ae001e6623 100644
@@ -26,8 +26,10 @@ static void bpf_array_free_percpu(struct bpf_array *array)
 {
 	int i;
 
-	for (i = 0; i < array->map.max_entries; i++)
+	for (i = 0; i < array->map.max_entries; i++) {
 		free_percpu(array->pptrs[i]);
+		cond_resched();
+	}
 }
 
 static int bpf_array_alloc_percpu(struct bpf_array *array)
@@ -43,6 +45,7 @@ static int bpf_array_alloc_percpu(struct bpf_array *array)
 			return -ENOMEM;
 		}
 		array->pptrs[i] = ptr;
+		cond_resched();
 	}
 
 	return 0;
maintainer Applied
#1 lore raw

[ +Dennis for mm/pcpu ]

Quoted 8 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

syszbot managed to trigger RCU detected stalls in
bpf_array_free_percpu()

It takes time to allocate a huge percpu map, but even more time to free it.

Quoted 6 lines

Since we run in process context, use cond_resched() to yield cpu if needed.

Fixes a10423b87a7e ("bpf: introduce BPF_MAP_TYPE_PERCPU_ARRAY map")

Applied to bpf tree, thanks Eric!

Quoted 28 lines

---
 kernel/bpf/arraymap.c |    5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/arraymap.c +4 -1
index a364c408f25a54a8175c92b6004a5e7e15f198cb..14750e7c5ee4872e4a7426e960bea7ae001e6623 100644
@@ -26,8 +26,10 @@ static void bpf_array_free_percpu(struct bpf_array *array)
 {
 	int i;
 
-	for (i = 0; i < array->map.max_entries; i++)
+	for (i = 0; i < array->map.max_entries; i++) {
 		free_percpu(array->pptrs[i]);
+		cond_resched();
+	}
 }
 
 static int bpf_array_alloc_percpu(struct bpf_array *array)
@@ -43,6 +45,7 @@ static int bpf_array_alloc_percpu(struct bpf_array *array)
 			return -ENOMEM;
 		}
 		array->pptrs[i] = ptr;
+		cond_resched();
 	}
 
 	return 0;