diff --git a/src/blockstore_sync.cpp b/src/blockstore_sync.cpp index 50891a13..d29035b5 100644 --- a/src/blockstore_sync.cpp +++ b/src/blockstore_sync.cpp @@ -76,6 +76,7 @@ int blockstore_impl_t::continue_sync(blockstore_op_t *op) // 2nd step: Data device is synced, prepare & write journal entries // Check space in the journal and journal memory buffers blockstore_journal_check_t space_check(this); + auto reservation = (unstable_writes.size()+unstable_unsynced+PRIV(op)->sync_big_writes.size())*journal.block_size; if (dsk.csum_block_size) { // More complex check because all journal entries have different lengths @@ -85,15 +86,14 @@ int blockstore_impl_t::continue_sync(blockstore_op_t *op) left--; auto & dirty_entry = dirty_db.at(sbw); uint64_t dyn_size = dsk.dirty_dyn_size(dirty_entry.offset, dirty_entry.len); - if (!space_check.check_available(op, 1, sizeof(journal_entry_big_write) + dyn_size, 0)) + if (!space_check.check_available(op, 1, sizeof(journal_entry_big_write) + dyn_size, left ? 0 : reservation)) { return 0; } } } else if (!space_check.check_available(op, PRIV(op)->sync_big_writes.size(), - sizeof(journal_entry_big_write) + dsk.clean_entry_bitmap_size, - (unstable_writes.size()+unstable_unsynced)*journal.block_size)) + sizeof(journal_entry_big_write) + dsk.clean_entry_bitmap_size, reservation)) { return 0; } diff --git a/src/blockstore_write.cpp b/src/blockstore_write.cpp index 8f314ccf..fe768f88 100644 --- a/src/blockstore_write.cpp +++ b/src/blockstore_write.cpp @@ -320,7 +320,7 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op) blockstore_journal_check_t space_check(this); if (!space_check.check_available(op, unsynced_big_write_count + 1, sizeof(journal_entry_big_write) + dsk.clean_dyn_size, - (unstable_writes.size()+unstable_unsynced)*journal.block_size)) + (unstable_writes.size()+unstable_unsynced+((dirty_it->second.state & BS_ST_INSTANT) ? 0 : 1))*journal.block_size)) { return 0; } @@ -412,7 +412,7 @@ int blockstore_impl_t::dequeue_write(blockstore_op_t *op) sizeof(journal_entry_big_write) + dsk.clean_dyn_size, 0) || !space_check.check_available(op, 1, sizeof(journal_entry_small_write) + dyn_size, - op->len + (unstable_writes.size()+unstable_unsynced)*journal.block_size)) + op->len + (unstable_writes.size()+unstable_unsynced+((dirty_it->second.state & BS_ST_INSTANT) ? 0 : 1))*journal.block_size)) { return 0; } @@ -549,7 +549,7 @@ resume_2: uint64_t dyn_size = dsk.dirty_dyn_size(op->offset, op->len); blockstore_journal_check_t space_check(this); if (!space_check.check_available(op, 1, sizeof(journal_entry_big_write) + dyn_size, - (unstable_writes.size()+unstable_unsynced)*journal.block_size)) + (unstable_writes.size()+unstable_unsynced+((dirty_it->second.state & BS_ST_INSTANT) ? 0 : 1))*journal.block_size)) { return 0; }