From c35963967f995f7811a948810712551cc73db4bb Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 18 Jan 2021 01:28:36 +0300 Subject: [PATCH] Add inode space usage statistics tracking to blockstore --- src/blockstore.cpp | 5 +++++ src/blockstore.h | 3 +++ src/blockstore_impl.h | 3 +++ src/blockstore_init.cpp | 4 ++++ src/blockstore_stable.cpp | 9 +++++++++ 5 files changed, 24 insertions(+) diff --git a/src/blockstore.cpp b/src/blockstore.cpp index c1bc574d..783db4fa 100644 --- a/src/blockstore.cpp +++ b/src/blockstore.cpp @@ -43,6 +43,11 @@ std::unordered_map & blockstore_t::get_unstable_writes() return impl->unstable_writes; } +std::map & blockstore_t::get_inode_space_stats() +{ + return impl->inode_space_stats; +} + uint32_t blockstore_t::get_block_size() { return impl->get_block_size(); diff --git a/src/blockstore.h b/src/blockstore.h index c0b24a7d..bc4bc29a 100644 --- a/src/blockstore.h +++ b/src/blockstore.h @@ -183,6 +183,9 @@ public: // Unstable writes are added here (map of object_id -> version) std::unordered_map & get_unstable_writes(); + // Get per-inode space usage statistics + std::map & get_inode_space_stats(); + // FIXME rename to object_size uint32_t get_block_size(); uint64_t get_block_count(); diff --git a/src/blockstore_impl.h b/src/blockstore_impl.h index 035ca280..1376cb28 100644 --- a/src/blockstore_impl.h +++ b/src/blockstore_impl.h @@ -327,6 +327,9 @@ public: // Unstable writes are added here (map of object_id -> version) std::unordered_map unstable_writes; + // Space usage statistics + std::map inode_space_stats; + inline uint32_t get_block_size() { return block_size; } inline uint64_t get_block_count() { return block_count; } inline uint64_t get_free_block_count() { return data_alloc->get_free_count(); } diff --git a/src/blockstore_init.cpp b/src/blockstore_init.cpp index 406d8eed..49c4ff0a 100644 --- a/src/blockstore_init.cpp +++ b/src/blockstore_init.cpp @@ -118,6 +118,10 @@ void blockstore_init_meta::handle_entries(void* entries, unsigned count, int blo #endif bs->data_alloc->set(clean_it->second.location >> block_order, false); } + else + { + bs->inode_space_stats[entry->oid.inode] += bs->block_size; + } entries_loaded++; #ifdef BLOCKSTORE_DEBUG printf("Allocate block (clean entry) %lu: %lx:%lx v%lu\n", done_cnt+i, entry->oid.inode, entry->oid.stripe, entry->version); diff --git a/src/blockstore_stable.cpp b/src/blockstore_stable.cpp index 370d5c50..34fa80c7 100644 --- a/src/blockstore_stable.cpp +++ b/src/blockstore_stable.cpp @@ -190,6 +190,15 @@ void blockstore_impl_t::mark_stable(const obj_ver_id & v, bool forget_dirty) if ((dirty_it->second.state & BS_ST_WORKFLOW_MASK) == BS_ST_SYNCED) { dirty_it->second.state = (dirty_it->second.state & ~BS_ST_WORKFLOW_MASK) | BS_ST_STABLE; + // Allocations and deletions are counted when they're stabilized + if (IS_BIG_WRITE(dirty_it->second.state)) + { + inode_space_stats[dirty_it->first.oid.inode] += block_size; + } + else if (IS_DELETE(dirty_it->second.state)) + { + inode_space_stats[dirty_it->first.oid.inode] -= block_size; + } } if (forget_dirty && (IS_BIG_WRITE(dirty_it->second.state) || IS_DELETE(dirty_it->second.state)))