Trim journal on start

blocking-uring-test
Vitaliy Filippov 2019-11-29 02:13:30 +03:00
parent 45f34fb3b2
commit 40781c67b2
6 changed files with 48 additions and 38 deletions

View File

@ -71,7 +71,6 @@ void blockstore::loop()
{
metadata_init_reader = new blockstore_init_meta(this);
initialized = 1;
printf("reading blockstore metadata\n");
}
if (initialized == 1)
{
@ -82,7 +81,6 @@ void blockstore::loop()
metadata_init_reader = NULL;
journal_init_reader = new blockstore_init_journal(this);
initialized = 2;
printf("reading blockstore journal\n");
}
}
if (initialized == 2)

View File

@ -475,43 +475,10 @@ resume_0:
if (!((++flusher->journal_trim_counter) % flusher->journal_trim_interval))
{
flusher->journal_trim_counter = 0;
journal_used_it = bs->journal.used_sectors.lower_bound(bs->journal.used_start);
#ifdef BLOCKSTORE_DEBUG
printf(
"Trimming journal (used_start=%lu, next_free=%lu, first_used=%lu, usage_count=%lu)\n",
bs->journal.used_start, bs->journal.next_free,
journal_used_it == bs->journal.used_sectors.end() ? 0 : journal_used_it->first,
journal_used_it == bs->journal.used_sectors.end() ? 0 : journal_used_it->second
);
#endif
if (journal_used_it == bs->journal.used_sectors.end())
if (!bs->journal.trim())
{
// Journal is cleared to its end, restart from the beginning
journal_used_it = bs->journal.used_sectors.begin();
if (journal_used_it == bs->journal.used_sectors.end())
{
// Journal is empty
bs->journal.used_start = bs->journal.next_free;
}
else
{
bs->journal.used_start = journal_used_it->first;
// next_free does not need updating here
}
}
else if (journal_used_it->first > bs->journal.used_start)
{
// Journal is cleared up to <journal_used_it>
bs->journal.used_start = journal_used_it->first;
}
else
{
// Can't trim journal
goto do_not_trim;
}
#ifdef BLOCKSTORE_DEBUG
printf("Journal trimmed to %lu (next_free=%lu)\n", bs->journal.used_start, bs->journal.next_free);
#endif
// Update journal "superblock"
await_sqe(12);
data->callback = simple_callback_w;

View File

@ -37,7 +37,6 @@ class journal_flusher_co
uint64_t offset, len, submit_offset, submit_len, clean_loc, old_clean_loc, meta_sector, meta_pos;
std::map<uint64_t, meta_sector_t>::iterator meta_it;
std::map<object_id, uint64_t>::iterator repeat_it;
std::map<uint64_t, uint64_t>::iterator journal_used_it;
std::function<void(ring_data_t*)> simple_callback_r, simple_callback_w;
std::list<flusher_sync_t>::iterator cur_sync;
friend class journal_flusher_t;

View File

@ -24,6 +24,7 @@ int blockstore_init_meta::loop()
{
if (wait_state == 1)
goto resume_1;
printf("Reading blockstore metadata\n");
metadata_buffer = (uint8_t*)memalign(512, 2*bs->metadata_buf_size);
if (!metadata_buffer)
throw std::bad_alloc();
@ -173,6 +174,7 @@ int blockstore_init_journal::loop()
goto resume_3;
else if (wait_state == 4)
goto resume_4;
printf("Reading blockstore journal\n");
if (!bs->journal.inmemory)
{
journal_buffer = (uint8_t*)memalign(DISK_ALIGNMENT, 2*JOURNAL_BUFFER_SIZE);
@ -293,7 +295,8 @@ resume_1:
}
}
}
// FIXME Trim journal on start so we don't stall when all entries are older
// Trim journal on start so we don't stall when all entries are older
bs->journal.trim();
printf("Journal entries loaded: %lu, free blocks: %lu / %lu\n", entries_loaded, bs->data_alloc->get_free_count(), bs->block_count);
if (!bs->journal.inmemory)
{

View File

@ -121,3 +121,45 @@ journal_t::~journal_t()
sector_info = NULL;
buffer = NULL;
}
bool journal_t::trim()
{
auto journal_used_it = used_sectors.lower_bound(used_start);
#ifdef BLOCKSTORE_DEBUG
printf(
"Trimming journal (used_start=%lu, next_free=%lu, first_used=%lu, usage_count=%lu)\n",
used_start, next_free,
journal_used_it == used_sectors.end() ? 0 : journal_used_it->first,
journal_used_it == used_sectors.end() ? 0 : journal_used_it->second
);
#endif
if (journal_used_it == used_sectors.end())
{
// Journal is cleared to its end, restart from the beginning
journal_used_it = used_sectors.begin();
if (journal_used_it == used_sectors.end())
{
// Journal is empty
used_start = next_free;
}
else
{
used_start = journal_used_it->first;
// next_free does not need updating here
}
}
else if (journal_used_it->first > used_start)
{
// Journal is cleared up to <journal_used_it>
used_start = journal_used_it->first;
}
else
{
// Can't trim journal
return false;
}
#ifdef BLOCKSTORE_DEBUG
printf("Journal trimmed to %lu (next_free=%lu)\n", used_start, next_free);
#endif
return true;
}

View File

@ -134,6 +134,7 @@ struct journal_t
std::map<uint64_t, uint64_t> used_sectors;
~journal_t();
bool trim();
};
struct blockstore_journal_check_t