Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

count buffer/cache into MemInfo #550

Merged
merged 3 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/common/base/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/common/base/test/MemoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(mem->usedInKB() - 100) / mem->totalInKB();
ASSERT(mem->hitsHighWatermark(ratio));
Expand Down