From 6ac1d5db08dd363ca9338a06aa3effc8cfffab7b Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 27 Nov 2019 01:12:25 +0300 Subject: [PATCH] Fix allocator bug --- Makefile | 2 ++ allocator.cpp | 4 ++-- test_allocator.cpp | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test_allocator.cpp diff --git a/Makefile b/Makefile index 65afb203..185fb44f 100644 --- a/Makefile +++ b/Makefile @@ -11,5 +11,7 @@ test: test.cpp g++ -g -O3 -o test -luring test.cpp test_blockstore: $(BLOCKSTORE_OBJS) test_blockstore.cpp g++ -g -o test_blockstore -luring test_blockstore.cpp $(BLOCKSTORE_OBJS) +test_allocator: test_allocator.cpp allocator.o + g++ -g -o test_allocator test_allocator.cpp allocator.o libfio_blockstore.so: fio_engine.cpp $(BLOCKSTORE_OBJS) g++ -g -Wno-pointer-arith -fPIC -shared -luring -o libfio_blockstore.so fio_engine.cpp $(BLOCKSTORE_OBJS) diff --git a/allocator.cpp b/allocator.cpp index 3f697cda..991aadd1 100644 --- a/allocator.cpp +++ b/allocator.cpp @@ -57,7 +57,7 @@ void allocator::set(uint64_t addr, bool value) { if (value) { - mask[last] = mask[last] | (1 << bit); + mask[last] = mask[last] | (1l << bit); if (mask[last] != (!is_last || cur_addr/64 < size/64 ? UINT64_MAX : last_one_mask)) { @@ -66,7 +66,7 @@ void allocator::set(uint64_t addr, bool value) } else { - mask[last] = mask[last] & ~(1 << bit); + mask[last] = mask[last] & ~(1l << bit); if (mask[last] != 0) { break; diff --git a/test_allocator.cpp b/test_allocator.cpp new file mode 100644 index 00000000..8b101192 --- /dev/null +++ b/test_allocator.cpp @@ -0,0 +1,18 @@ +#include +#include "allocator.h" + +int main(int narg, char *args[]) +{ + allocator a(8192); + for (int i = 0; i < 8192; i++) + { + uint64_t x = a.find_free(); + if (x == UINT64_MAX) + { + printf("ran out of space %d\n", i); + return 1; + } + a.set(x, true); + } + return 0; +}