Use 32-bit big write location (OK for up to 512 TB OSDs)

This commit is contained in:
Vitaliy Filippov
2025-11-23 19:08:24 +03:00
parent 923c41b928
commit ec10a25905
9 changed files with 63 additions and 46 deletions
+2 -2
View File
@@ -224,7 +224,7 @@ resume_1:
goto resume_0;
}
assert(!end_wr->next() && end_wr->entry_type == (BS_HEAP_BIG_WRITE|BS_HEAP_STABLE));
clean_loc = end_wr->big().location;
clean_loc = end_wr->big_location(bs->heap);
if (bs->log_level > 10)
printf("Compacting %jx:%jx l%ju .. l%ju (last l%ju)\n", cur_oid.inode, cur_oid.stripe, end_wr->lsn, begin_wr->lsn, compact_lsn);
flusher->active_flushers++;
@@ -409,7 +409,7 @@ void journal_flusher_co::fill_partial_checksum_blocks()
.copy_flags = COPY_BUF_DATA | copy_flags,
.offset = blk_begin,
.len = blk_end - blk_begin,
.disk_loc = end_wr->big().location,
.disk_loc = end_wr->big_location(bs->heap),
.disk_offset = blk_begin,
.disk_len = blk_end - blk_begin,
.buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, blk_end - blk_begin),
+20 -8
View File
@@ -146,6 +146,17 @@ uint32_t *heap_write_t::get_checksum(blockstore_heap_t *heap)
return (uint32_t*)((uint8_t*)this + sizeof(heap_small_write_t) + heap->dsk->clean_entry_bitmap_size);
}
uint64_t heap_write_t::big_location(blockstore_heap_t *heap)
{
return ((uint64_t)big().block_num) * heap->dsk->data_block_size;
}
void heap_write_t::set_big_location(blockstore_heap_t *heap, uint64_t location)
{
assert(!(location % heap->dsk->data_block_size));
big().block_num = location / heap->dsk->data_block_size;
}
heap_write_t *heap_object_t::get_writes()
{
return (heap_write_t*)((uint8_t*)this + write_pos);
@@ -192,6 +203,7 @@ blockstore_heap_t::blockstore_heap_t(blockstore_disk_t *dsk, uint8_t *buffer_are
assert(dsk->journal_len > 0);
meta_alloc = new multilist_index_t(meta_block_count, 1 + dsk->meta_block_size/MIN_ALLOC, 0);
block_info.resize(meta_block_count);
assert(dsk->block_count <= 0xFFFF0000);
data_alloc = new allocator_t(dsk->block_count);
if (!target_block_free_space)
target_block_free_space = 800;
@@ -468,7 +480,7 @@ skip_unseen:
abort();
goto skip_object;
}
if (wr->type() == BS_HEAP_BIG_WRITE && is_data_used(wr->big().location))
if (wr->type() == BS_HEAP_BIG_WRITE && is_data_used(wr->big_location(this)))
{
fprintf(stderr, "Error: write %jx:%jx v%lu (l%lu) data overlaps with other writes, skipping object\n",
obj->inode, obj->stripe, wr->version, wr->lsn);
@@ -560,7 +572,7 @@ uint64_t blockstore_heap_t::load_blocks(uint64_t disk_offset, uint64_t size, uin
else if (wr->type() == BS_HEAP_BIG_WRITE)
{
// Mark data block as used
use_data(obj->inode, wr->big().location);
use_data(obj->inode, wr->big_location(this));
}
if (wr->lsn > this->compacted_lsn)
{
@@ -781,7 +793,7 @@ bool blockstore_heap_t::recheck_small_writes(std::function<void(bool is_data, ui
{
auto next_wr = wr->next();
assert(next_wr && next_wr->entry_type == (BS_HEAP_BIG_WRITE | (wr->entry_type & BS_HEAP_STABLE)));
loc = wr->small().offset + next_wr->big().location;
loc = wr->small().offset + next_wr->big_location(this);
}
recheck_in_progress++;
uint8_t *buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, wr->small().len);
@@ -1482,7 +1494,7 @@ bool blockstore_heap_t::mvcc_save_copy(heap_object_t *obj)
{
if (wr->type() == BS_HEAP_BIG_WRITE)
{
mvcc_data_refs[wr->big().location] += add_ref;
mvcc_data_refs[wr->big_location(this)] += add_ref;
if (wr->entry_type & BS_HEAP_STABLE)
{
if (!for_obj)
@@ -1511,8 +1523,8 @@ void blockstore_heap_t::mark_overwritten(uint64_t over_lsn, uint64_t inode, heap
}
if (wr->type() == BS_HEAP_BIG_WRITE)
{
overwrite_ref_queue.push_back((heap_refqi_t){ .lsn = over_lsn, .inode = inode, .location = wr->big().location, .len = 0, .is_data = true });
mvcc_data_refs[wr->big().location] += !tracking_active;
overwrite_ref_queue.push_back((heap_refqi_t){ .lsn = over_lsn, .inode = inode, .location = wr->big_location(this), .len = 0, .is_data = true });
mvcc_data_refs[wr->big_location(this)] += !tracking_active;
}
else if (wr->type() == BS_HEAP_SMALL_WRITE && wr->small().len > 0)
{
@@ -1609,7 +1621,7 @@ int blockstore_heap_t::update_object(uint32_t block_num, heap_object_t *obj, hea
// MVCC reference tracking is in action for the object, increase the refcount
if (wr->type() == BS_HEAP_BIG_WRITE)
{
mvcc_data_refs[wr->big().location]++;
mvcc_data_refs[wr->big_location(this)]++;
}
else if (wr->type() == BS_HEAP_SMALL_WRITE && wr->small().len > 0)
{
@@ -1974,7 +1986,7 @@ void blockstore_heap_t::free_object_space(inode_t inode, heap_write_t *from, hea
{
if (wr->type() == BS_HEAP_BIG_WRITE)
{
deref_data(inode, wr->big().location, mode != BS_HEAP_FREE_MAIN);
deref_data(inode, wr->big_location(this), mode != BS_HEAP_FREE_MAIN);
if (mode == BS_HEAP_FREE_MVCC && (wr->entry_type & BS_HEAP_STABLE))
{
// Stop at the last visible version
+3 -1
View File
@@ -50,7 +50,7 @@ struct __attribute__((__packed__)) heap_big_write_t
uint8_t flags;
uint64_t lsn;
uint64_t version;
uint64_t location;
uint32_t block_num;
};
struct __attribute__((__packed__)) heap_tombstone_t
@@ -90,6 +90,8 @@ struct __attribute__((__packed__)) heap_write_t
uint8_t *get_int_bitmap(blockstore_heap_t *heap);
uint8_t *get_checksums(blockstore_heap_t *heap);
uint32_t *get_checksum(blockstore_heap_t *heap);
uint64_t big_location(blockstore_heap_t *heap);
void set_big_location(blockstore_heap_t *heap, uint64_t location);
};
struct __attribute__((__packed__)) heap_object_t
+2 -2
View File
@@ -252,9 +252,9 @@ void blockstore_impl_t::prepare_disk_read(std::vector<copy_buffer_t> & read_vec,
.copy_flags = (wr->type() == BS_HEAP_SMALL_WRITE ? COPY_BUF_JOURNAL : COPY_BUF_DATA) | copy_flags,
.offset = start,
.len = end-start,
.disk_loc = (wr->type() == BS_HEAP_INTENT_WRITE ? wr->next()->big().location
.disk_loc = (wr->type() == BS_HEAP_INTENT_WRITE ? wr->next()->big_location(heap)
: (wr->type() == BS_HEAP_SMALL_WRITE ? wr->small().location-wr->small().offset
: wr->big().location)),
: wr->big_location(heap))),
.disk_offset = blk_start,
.disk_len = blk_end - blk_start,
.wr_lsn = wr->lsn,
+3 -3
View File
@@ -149,12 +149,12 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op)
BS_SUBMIT_CHECK_SQES(1);
if (obj->get_writes()->type() == BS_HEAP_BIG_WRITE)
{
PRIV(op)->location = obj->get_writes()->big().location;
PRIV(op)->location = obj->get_writes()->big_location(heap);
}
else
{
assert(obj->get_writes()->next()->type() == BS_HEAP_BIG_WRITE);
PRIV(op)->location = obj->get_writes()->next()->big().location;
PRIV(op)->location = obj->get_writes()->next()->big_location(heap);
}
process_intent:
uint8_t wr_buf[heap->get_max_write_entry_size()];
@@ -269,7 +269,7 @@ int blockstore_impl_t::make_big_write(blockstore_op_t *op, uint32_t offset, uint
heap_write_t *wr = (heap_write_t*)wr_buf;
wr->entry_type = BS_HEAP_BIG_WRITE | (op->opcode == BS_OP_WRITE_STABLE ? BS_HEAP_STABLE : 0);
wr->version = op->version;
wr->big().location = PRIV(op)->location;
wr->set_big_location(heap, PRIV(op)->location);
if (op->bitmap)
memcpy(wr->get_ext_bitmap(heap), op->bitmap, dsk.clean_entry_bitmap_size);
memset(wr->get_int_bitmap(heap), 0, dsk.clean_entry_bitmap_size);
+1 -1
View File
@@ -61,7 +61,7 @@ int disk_tool_t::trim_data(std::string device)
{
if ((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_BIG_WRITE)
{
data_alloc->set(wr->big().location / dsk.data_block_size, true);
data_alloc->set(wr->big_location(heap) / dsk.data_block_size, true);
}
}
},
+9 -6
View File
@@ -346,10 +346,10 @@ void disk_tool_t::dump_heap_entry_as_old(blockstore_heap_t *heap, heap_object_t
return;
}
printf(
#define ENTRY_FMT "{\"block\":%ju,\"pool\":%u,\"inode\":\"0x%jx\",\"stripe\":\"0x%jx\",\"version\":%ju"
#define ENTRY_FMT "{\"block\":%u,\"pool\":%u,\"inode\":\"0x%jx\",\"stripe\":\"0x%jx\",\"version\":%ju"
(first_entry ? ENTRY_FMT : (",\n" ENTRY_FMT)),
#undef ENTRY_FMT
wr->big().location/dsk.data_block_size, INODE_POOL(obj->inode), INODE_NO_POOL(obj->inode),
wr->big().block_num, INODE_POOL(obj->inode), INODE_NO_POOL(obj->inode),
obj->stripe, wr->version
);
printf(",\"bitmap\":\"");
@@ -406,7 +406,7 @@ void disk_tool_t::dump_heap_entry(blockstore_heap_t *heap, heap_object_t *obj)
);
if ((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_BIG_WRITE)
{
printf(",\"location\":%ju", wr->big().location);
printf(",\"location\":%ju", wr->big_location(heap));
}
else if ((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_INTENT_WRITE)
{
@@ -670,7 +670,10 @@ int disk_tool_t::write_json_heap(json11::Json meta, json11::Json journal)
}
else if (wr_type == BS_HEAP_BIG_WRITE)
{
wr->big().location = write_entry["location"].uint64_value();
uint64_t loc = write_entry["location"].uint64_value();
assert(!(loc % dsk.data_block_size));
assert((loc / dsk.data_block_size) < 0xFFFF0000);
wr->set_big_location(new_heap, loc);
}
if (write_entry["bitmap"].is_string() && wr->get_int_bitmap(new_heap))
{
@@ -794,7 +797,7 @@ close_err:
wr->entry_type = BS_HEAP_BIG_WRITE|BS_HEAP_STABLE;
wr->lsn = ++next_lsn;
wr->version = sscanf_json(NULL, meta_entry["version"]);
wr->big().location = meta_entry["block"].uint64_value() * new_meta_hdr->data_block_size;
wr->set_big_location(&heap, meta_entry["block"].uint64_value() * new_meta_hdr->data_block_size);
wr->size = wr->get_size(&heap);
fromhexstr(meta_entry["bitmap"].string_value(), new_clean_entry_bitmap_size, wr->get_int_bitmap(&heap));
fromhexstr(meta_entry["ext_bitmap"].string_value(), new_clean_entry_bitmap_size, wr->get_ext_bitmap(&heap));
@@ -836,7 +839,7 @@ close_err:
else if (rec["type"] == "big_write" || rec["type"] == "big_write_instant")
{
wr->entry_type = BS_HEAP_BIG_WRITE | (rec["type"] == "big_write_instant" ? BS_HEAP_STABLE : 0);
wr->big().location = sscanf_json(NULL, rec["loc"]);
wr->set_big_location(&heap, sscanf_json(NULL, rec["loc"]));
bitmap_set(wr->get_int_bitmap(&heap), wr_offset, wr_len, new_meta_hdr->bitmap_granularity);
fromhexstr(rec["bitmap"].string_value(), new_clean_entry_bitmap_size, wr->get_ext_bitmap(&heap));
if (new_meta_hdr->data_csum_type != 0)
+6 -6
View File
@@ -43,7 +43,7 @@ int disk_tool_t::raw_resize()
{
if ((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_BIG_WRITE)
{
data_alloc->set(wr->big().location / dsk.data_block_size, true);
data_alloc->set(wr->big().block_num, true);
}
}
},
@@ -569,7 +569,7 @@ int disk_tool_t::resize_rebuild_meta()
{
if ((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_BIG_WRITE)
{
auto block_num = wr->big().location / dsk.data_block_size;
uint64_t block_num = wr->big().block_num;
auto remap_it = data_remap.find(block_num);
if (remap_it != data_remap.end())
block_num = remap_it->second;
@@ -579,7 +579,7 @@ int disk_tool_t::resize_rebuild_meta()
exit(1);
}
block_num += data_idx_diff;
wr->big().location = block_num * dsk.data_block_size;
wr->big().block_num = block_num;
}
else if ((wr->entry_type & BS_HEAP_TYPE) == BS_HEAP_SMALL_WRITE)
{
@@ -648,7 +648,7 @@ int disk_tool_t::resize_rebuild_meta()
}
else
{
je->big_write.location = wr->big().location;
je->big_write.location = wr->big_location(heap);
}
memcpy((uint8_t*)je + je->size, wr->get_ext_bitmap(heap), new_clean_entry_bitmap_size);
if (dsk.data_csum_type != 0 && wr->get_checksums(heap))
@@ -663,7 +663,7 @@ int disk_tool_t::resize_rebuild_meta()
if (writes[writes.size()-1]->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE)
{
auto big_wr = writes[writes.size()-1];
uint64_t block_num = big_wr->big().location / dsk.data_block_size;
uint64_t block_num = big_wr->big().block_num;
clean_disk_entry *new_entry = (clean_disk_entry*)(new_meta_buf + dsk.meta_block_size +
dsk.meta_block_size*(block_num / new_entries_per_block) +
new_clean_entry_size*(block_num % new_entries_per_block));
@@ -694,7 +694,7 @@ int disk_tool_t::resize_rebuild_meta()
uint8_t wr_buf[new_heap->get_max_write_entry_size()];
heap_write_t *wr = (heap_write_t*)wr_buf;
wr->entry_type = BS_HEAP_BIG_WRITE|BS_HEAP_STABLE;
wr->big().location = block_num * dsk.data_block_size;
wr->big().block_num = block_num;
wr->next_pos = 0;
wr->size = wr->get_size(new_heap);
if (bitmap)
+17 -17
View File
@@ -67,7 +67,7 @@ int _test_do_big_write(blockstore_heap_t & heap, blockstore_disk_t & dsk, uint64
uint8_t wr_buf[heap.get_max_write_entry_size()];
heap_write_t *wr = (heap_write_t*)wr_buf;
wr->version = version;
wr->big().location = location;
wr->set_big_location(&heap, location);
wr->entry_type = BS_HEAP_BIG_WRITE | (stable ? BS_HEAP_STABLE : 0);
assert(heap.get_max_write_entry_size() >= wr->get_size(&heap));
assert(wr->get_size(&heap) == sizeof(heap_big_write_t) + 2*dsk.clean_entry_bitmap_size + (dsk.csum_block_size
@@ -188,7 +188,7 @@ void test_mvcc(bool csum)
assert(wr->lsn == 1);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->version == 1);
assert(wr->big().location == 0);
assert(wr->big_location(&heap) == 0);
uint64_t old_size = obj->size + wr->size;
assert(heap.read_locked_entry(oid, copy_id) == obj);
@@ -291,9 +291,9 @@ void test_compact_block()
uint32_t big_write_size = (sizeof(heap_object_t) + sizeof(heap_big_write_t) + 2*dsk.clean_entry_bitmap_size + dsk.data_block_size/dsk.csum_block_size*4);
uint32_t small_write_size = (sizeof(heap_small_write_t) + dsk.clean_entry_bitmap_size + 4);
assert(big_write_size == 190);
assert(big_write_size == 186);
assert(small_write_size == 45);
uint32_t nwr = (dsk.meta_block_size-heap.get_max_write_entry_size())/(big_write_size+small_write_size);
uint32_t nwr = dsk.meta_block_size/(big_write_size+small_write_size);
{
for (uint32_t i = 0; i < nwr*2; i++)
@@ -559,7 +559,7 @@ void test_recheck(bool async, bool csum, bool intent)
assert(wr->lsn == 1);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->version == 1);
assert(wr->big().location == 0x20000);
assert(wr->big_location(&heap) == 0x20000);
// read object 2 - both writes should be present
oid = { .inode = INODE_WITH_POOL(1, 2), .stripe = 0 };
@@ -648,7 +648,7 @@ void test_corruption()
assert(count_writes(obj) == 1);
heap_write_t *wr = obj->get_writes();
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->big().location == 0x40000);
assert(wr->big_location(&heap) == 0x40000);
// object 3 should be present
oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0x40000 };
@@ -657,7 +657,7 @@ void test_corruption()
assert(count_writes(obj) == 1);
wr = obj->get_writes();
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->big().location == 0x60000);
assert(wr->big_location(&heap) == 0x60000);
// object 4 should be a tombstone
oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0x60000 };
@@ -737,7 +737,7 @@ void test_full_overwrite(bool stable)
wr = wr->next();
assert(wr->version == 3);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->big().location == 0x40000);
assert(wr->big_location(&heap) == 0x40000);
// check that the data block 0x20000 is freed and 0x40000 is used
assert(!heap.is_data_used(0x20000));
@@ -1186,7 +1186,7 @@ void test_rollback()
wr = wr->next();
assert(wr->version == 1);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->big().location == 0x20000);
assert(wr->big_location(&heap) == 0x20000);
assert(heap.is_data_used(0x20000));
assert(!heap.is_data_used(0x40000));
@@ -1298,12 +1298,12 @@ void test_full_alloc()
uint32_t big_write_size = (sizeof(heap_object_t) + sizeof(heap_big_write_t) + 2*dsk.clean_entry_bitmap_size + dsk.data_block_size/dsk.csum_block_size*4);
uint32_t small_write_size = (sizeof(heap_small_write_t) + dsk.clean_entry_bitmap_size + 4);
assert(big_write_size == 190);
assert(big_write_size == 186);
assert(small_write_size == 45);
uint32_t b_4s = (big_write_size + 4*small_write_size);
assert(b_4s == 370);
assert(b_4s == 366);
const uint32_t min_alloc = (sizeof(heap_object_t) + sizeof(heap_tombstone_t));
uint32_t epb = (4096 - 800 + 800 % min_alloc + b_4s-1) / b_4s;
uint32_t epb = (4096 - 800 + 800 % min_alloc) / b_4s;
for (int j = 0; j < 4; j++)
{
assert(heap.get_meta_nearfull_blocks() == j);
@@ -1338,7 +1338,7 @@ void test_full_alloc()
assert(_test_do_big_write(heap, dsk, 1, (epb*4+nwr2)*0x20000, 1, (epb*4+nwr2)*0x20000) == ENOSPC);
// Overwrites are, however, allowed until the block is almost empty
const int nwr3 = 4;
const int nwr3 = 5;
for (int i = 0; i < nwr3; i++)
{
assert(_test_do_small_write(heap, dsk, 1, 0, 6+i, 0, 4096, epb*4*16384+i*4096) == 0);
@@ -1410,7 +1410,7 @@ void test_duplicate()
heap_write_t *wr = obj->get_writes();
assert(wr->version == 2);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->big().location == 0x40000);
assert(wr->big_location(&heap) == 0x40000);
assert(heap.get_meta_block_used_space(0) == 0);
assert(heap.get_meta_block_used_space(1) == obj->size+wr->size);
@@ -1434,7 +1434,7 @@ void test_duplicate()
heap_write_t *wr = obj->get_writes();
assert(wr->version == 2);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->big().location == 0x40000);
assert(wr->big_location(&heap) == 0x40000);
assert(heap.get_meta_block_used_space(0) == 0);
assert(heap.get_meta_block_used_space(1) == obj->size+wr->size);
@@ -1518,7 +1518,7 @@ void test_autocompact(bool csum)
assert(wr->lsn == 3);
assert(wr->entry_type == BS_HEAP_BIG_WRITE|BS_HEAP_STABLE);
assert(wr->version == 3);
assert(wr->big().location == 0x20000);
assert(wr->big_location(&heap) == 0x20000);
// check that blocks are auto-freed
assert(heap.is_data_used(0x20000));
@@ -1600,7 +1600,7 @@ void test_move()
uint32_t big_write_size = (sizeof(heap_object_t) + sizeof(heap_big_write_t) + 2*dsk.clean_entry_bitmap_size + dsk.data_block_size/dsk.csum_block_size*4);
uint32_t small_write_size = (sizeof(heap_small_write_t) + dsk.clean_entry_bitmap_size + 4);
assert(big_write_size == 190);
assert(big_write_size == 186);
assert(small_write_size == 45);
// Fill block 1 almost completely with unstable small writes