Another experiment: store writes in mallocs

This commit is contained in:
Vitaliy Filippov
2025-12-02 01:52:12 +03:00
parent 371e630f52
commit 1e5a01def8
4 changed files with 189 additions and 404 deletions
+13 -31
View File
@@ -25,7 +25,9 @@ static int count_writes(blockstore_heap_t & heap, heap_entry_t *obj)
bool check_used_space(blockstore_heap_t & heap, blockstore_disk_t & dsk, uint32_t block_num)
{
uint8_t *data = heap.get_meta_block(block_num);
// FIXME
return true;
/* uint8_t *data = heap.get_meta_block(block_num);
uint8_t *end = data+dsk.meta_block_size;
uint32_t used = 0;
while (data < end)
@@ -37,26 +39,7 @@ bool check_used_space(blockstore_heap_t & heap, blockstore_disk_t & dsk, uint32_
}
data += (wr->size & ~FREE_SPACE_BIT);
}
return used == heap.get_meta_block_used_space(block_num);
}
int count_free_fragments(blockstore_heap_t & heap, blockstore_disk_t & dsk, uint32_t block_num)
{
uint8_t *data = heap.get_meta_block(block_num);
uint8_t *end = data+dsk.meta_block_size;
int fragments = 0;
bool is_free = false;
while (data < end)
{
uint16_t region_marker = *((uint16_t*)data);
if ((region_marker & FREE_SPACE_BIT) && !is_free)
{
fragments++;
}
is_free = !!(region_marker & FREE_SPACE_BIT);
data += (region_marker & ~FREE_SPACE_BIT);
}
return fragments;
return used == heap.get_meta_block_used_space(block_num);*/
}
int _test_do_big_write(blockstore_heap_t & heap, blockstore_disk_t & dsk, uint64_t inode, uint64_t stripe, uint64_t version, uint64_t location,
@@ -296,8 +279,8 @@ void test_defrag_block()
uint32_t big_write_size = heap.get_big_entry_size();
uint32_t small_write_size = heap.get_small_entry_size(0, 4096);
assert(big_write_size == 188);
assert(small_write_size == 72);
assert(big_write_size == 192);
assert(small_write_size == 76);
uint32_t nwr = 0;
bool add = false;
if ((dsk.meta_block_size % (big_write_size+small_write_size)) >= big_write_size)
@@ -308,7 +291,9 @@ void test_defrag_block()
(dsk.meta_block_size-small_write_size) % (big_write_size+small_write_size)) >= big_write_size;
}
else
nwr = dsk.meta_block_size/(big_write_size+small_write_size);
{
nwr = dsk.meta_block_size/(big_write_size+small_write_size)*2-1;
}
{
uint32_t used = 0;
@@ -348,9 +333,6 @@ void test_defrag_block()
heap.start_block_write(mblock);
heap.complete_block_write(mblock);
}
// Check fragmentation - everything is compacted multiple times :)
assert(count_free_fragments(heap, dsk, 0) == 1);
assert(count_free_fragments(heap, dsk, 1) == 1);
}
printf("OK test_defrag_block\n");
@@ -546,7 +528,7 @@ void test_recheck(bool async, bool csum, bool intent)
// persist
assert(heap.get_meta_block_used_space(0) > 0);
tmp.resize(dsk.meta_block_size);
memcpy(tmp.data(), heap.get_meta_block(0), dsk.meta_block_size);
heap.get_meta_block(0, tmp.data());
}
// reload heap
@@ -640,7 +622,7 @@ void test_corruption()
assert(heap.get_meta_block_used_space(0) > 0);
assert(heap.get_meta_block_used_space(1) == 0);
tmp.resize(dsk.meta_block_size);
memcpy(tmp.data(), heap.get_meta_block(0), dsk.meta_block_size);
heap.get_meta_block(0, tmp.data());
}
// reload heap with corruption
@@ -1088,8 +1070,8 @@ void test_full_alloc()
uint32_t big_write_size = heap.get_big_entry_size();
uint32_t small_write_size = heap.get_small_entry_size(0, 4096);
assert(big_write_size == 188);
assert(small_write_size == 72);
assert(big_write_size == 192);
assert(small_write_size == 76);
uint32_t epb = dsk.meta_block_size/big_write_size;
for (int j = 0; j < 4; j++)
{