Thread (3 messages) 3 messages, 3 authors, 2020-12-23

Re: [PATCH bpf] selftests/bpf: work-around EBUSY errors from hashmap update/delete

From: Song Liu <hidden>
Date: 2020-12-22 23:59:51
Also in: bpf

On Dec 22, 2020, at 11:53 AM, Andrii Nakryiko [off-list ref] wrote:

20b6cc34ea74 ("bpf: Avoid hashtab deadlock with map_locked") introduced
a possibility of getting EBUSY error on lock contention, which seems to happen
very deterministically in test_maps when running 1024 threads on low-CPU
machine. In libbpf CI case, it's a 2 CPU VM and it's hitting this 100% of the
time. Work around by retrying on EBUSY (and EAGAIN, while we are at it) after
a small sleep. sched_yield() is too agressive and fails even after 20 retries,
so I went with usleep(1) for backoff.

Also log actual error returned to make it easier to see what's going on.

Fixes: 20b6cc34ea74 ("bpf: Avoid hashtab deadlock with map_locked")
Cc: Song Liu <redacted>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Thanks for the fix!

Acked-by: Song Liu <redacted>

With one minor nitpick below
quoted hunk ↗ jump to hunk
---
tools/testing/selftests/bpf/test_maps.c | 46 +++++++++++++++++++++----
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
index 0ad3e6305ff0..809004f4995f 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -1312,22 +1312,56 @@ static void test_map_stress(void)
#define DO_UPDATE 1
#define DO_DELETE 0
[...]
+				printf("error %d %d\n", err, errno);
+			assert(err == 0);
+			err = map_update_retriable(fd, &key, &value, BPF_EXIST, 20);
+			if (err)
+				printf("error %d %d\n", err, errno);
+			assert(err == 0);
		} else {
-			assert(bpf_map_delete_elem(fd, &key) == 0);
+			err = map_delete_retriable(fd, &key, 5);
nit: Why 5 here vs. 20 above?
+			if (err)
+				printf("error %d %d\n", err, errno);
+			assert(err == 0);
		}
	}
}
-- 
2.24.1
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help