diff options
author | ilnurkh <ilnurkh@yandex-team.com> | 2023-07-22 11:25:20 +0300 |
---|---|---|
committer | ilnurkh <ilnurkh@yandex-team.com> | 2023-07-22 11:25:20 +0300 |
commit | 4efbd184ae7df23cb21866c1dca53f02da01921b (patch) | |
tree | fb3ef295e350c1160d5a5fabd63f93c768a77c94 | |
parent | e9f0ae38ec1b4d0d25fb84a5e40430561075ddcb (diff) | |
download | ydb-4efbd184ae7df23cb21866c1dca53f02da01921b.tar.gz |
add some warnings (even in release build) if host memory estimation was wrong
-rw-r--r-- | util/memory/pool.cpp | 7 | ||||
-rw-r--r-- | util/memory/pool.h | 6 | ||||
-rw-r--r-- | util/memory/pool_ut.cpp | 4 |
3 files changed, 12 insertions, 5 deletions
diff --git a/util/memory/pool.cpp b/util/memory/pool.cpp index 9a011f0e4f..2ada039802 100644 --- a/util/memory/pool.cpp +++ b/util/memory/pool.cpp @@ -28,8 +28,10 @@ void TMemoryPool::AddChunk(size_t hint) { Chunks_.PushBack(Current_); } -void TMemoryPool::DoClear(bool keepfirst) noexcept { +size_t TMemoryPool::DoClear(bool keepfirst) noexcept { + size_t chunksUsed = 0; while (!Chunks_.Empty()) { + chunksUsed += 1; TChunk* c = Chunks_.PopBack(); if (keepfirst && Chunks_.Empty()) { @@ -39,7 +41,7 @@ void TMemoryPool::DoClear(bool keepfirst) noexcept { BlockSize_ = c->BlockLength() - sizeof(TChunk); MemoryAllocatedBeforeCurrent_ = 0; MemoryWasteBeforeCurrent_ = 0; - return; + return chunksUsed; } TBlock b = {c, c->BlockLength()}; @@ -52,4 +54,5 @@ void TMemoryPool::DoClear(bool keepfirst) noexcept { BlockSize_ = Origin_; MemoryAllocatedBeforeCurrent_ = 0; MemoryWasteBeforeCurrent_ = 0; + return chunksUsed; } diff --git a/util/memory/pool.h b/util/memory/pool.h index 13c8b6b9ed..a7f09cd37b 100644 --- a/util/memory/pool.h +++ b/util/memory/pool.h @@ -244,6 +244,10 @@ public: DoClear(true); } + inline size_t ClearReturnUsedChunkCount(bool keepFirstChunk) noexcept { + return DoClear(keepFirstChunk); + } + inline size_t MemoryAllocated() const noexcept { return MemoryAllocatedBeforeCurrent_ + (Current_ != &Empty_ ? Current_->Used() : 0); } @@ -291,7 +295,7 @@ protected: private: void AddChunk(size_t hint); - void DoClear(bool keepfirst) noexcept; + size_t DoClear(bool keepfirst) noexcept; private: TChunk Empty_; diff --git a/util/memory/pool_ut.cpp b/util/memory/pool_ut.cpp index 1158a8ca42..e7c055f36a 100644 --- a/util/memory/pool_ut.cpp +++ b/util/memory/pool_ut.cpp @@ -115,7 +115,7 @@ private: memset(m, 0, i); } - pool.ClearKeepFirstChunk(); + UNIT_ASSERT_VALUES_EQUAL(pool.ClearReturnUsedChunkCount(true), 11); UNIT_ASSERT_VALUES_EQUAL(memalloc - 8, pool.MemoryAllocated()); UNIT_ASSERT_VALUES_EQUAL(memwaste + 8, pool.MemoryWaste()); @@ -127,7 +127,7 @@ private: memset(m, 0, i); } - pool.Clear(); + UNIT_ASSERT_VALUES_EQUAL(pool.ClearReturnUsedChunkCount(false), 12); UNIT_ASSERT_VALUES_EQUAL(0, pool.MemoryAllocated()); UNIT_ASSERT_VALUES_EQUAL(0, pool.MemoryWaste()); |