diff --git a/src/common/base/Memory.h b/src/common/base/Memory.h index 8d4b5a2d7..7a6ab6b67 100644 --- a/src/common/base/Memory.h +++ b/src/common/base/Memory.h @@ -29,8 +29,12 @@ class MemInfo final : protected cpp::NonCopyable, protected cpp::NonMovable { return (info_->freeram * info_->mem_unit) >> 10; } + uint64_t bufferInKB() const { + return (info_->bufferram * info_->mem_unit) >> 10; + } + uint64_t usedInKB() const { - return totalInKB() - freeInKB(); + return totalInKB() - freeInKB() - bufferInKB(); } bool hitsHighWatermark(float ratio = 0.8f) const { diff --git a/src/common/base/test/MemoryTest.cpp b/src/common/base/test/MemoryTest.cpp index 35dffda9e..d4eab1ca9 100644 --- a/src/common/base/test/MemoryTest.cpp +++ b/src/common/base/test/MemoryTest.cpp @@ -15,7 +15,9 @@ TEST(MemInfoTest, TestMemInfo) { ASSERT(status.ok()); auto mem = std::move(status).value(); ASSERT_GE(mem->totalInKB(), mem->usedInKB()); - ASSERT_EQ(mem->totalInKB(), mem->usedInKB() + mem->freeInKB()); + ASSERT_GE(mem->totalInKB(), mem->freeInKB()); + ASSERT_GE(mem->totalInKB(), mem->bufferInKB()); + ASSERT_EQ(mem->totalInKB(), mem->usedInKB() + mem->freeInKB() + mem->bufferInKB()); float ratio = static_cast(mem->usedInKB() - 100) / mem->totalInKB(); ASSERT(mem->hitsHighWatermark(ratio));