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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Dec 22, 2020, at 11:53 AM, Andrii Nakryiko <andrii@xxxxxxxxxx> 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 <songliubraving@xxxxxx>
> Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>

Thanks for the fix!

Acked-by: Song Liu <songliubraving@xxxxxx>

With one minor nitpick below

> ---
> 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
> 






[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux