forked from vitalif/vitastor
Fix allocator bug
parent
ff7469ee91
commit
6ac1d5db08
2
Makefile
2
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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue