From a95141111c89803347c36501185a76fc73a9764a Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 5 May 2023 09:39:13 +0200 Subject: Fixed a bug in hot page global storage The original algorithm was suffering from an ABA race condition: A: fp = page_stack B: completely allocates the same page and writes into it some data A: unsuspecting, loads (invalid) next = fp->next B: finishes working with the page and returns it back to page_stack A: compare-exchange page_stack: fp => next succeeds and writes garbage to page_stack Fixed this by using an implicit spinlock in hot page allocator. --- sysdep/unix/alloc_test.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 sysdep/unix/alloc_test.c (limited to 'sysdep/unix/alloc_test.c') diff --git a/sysdep/unix/alloc_test.c b/sysdep/unix/alloc_test.c new file mode 100644 index 00000000..202af2b2 --- /dev/null +++ b/sysdep/unix/alloc_test.c @@ -0,0 +1,74 @@ +/* + * BIRD -- Allocator Tests + * + * (c) 2023 CZ.NIC z.s.p.o. + * (c) 2023 Maria Matejka + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#include "test/birdtest.h" +#include "test/bt-utils.h" +#include "lib/resource.h" + +#include +#include + +#define ALLOC_AND_TREE_LIMIT (1 << 14) + +static void * +alloc_and_free_main(void *data UNUSED) +{ +#define BLOCK_SIZE 32 + void *block[BLOCK_SIZE]; + + for (int i=0; i