Skip to content

YQL-18327 Disable yellow zone of allocator on 50%. Update yellow zone on free #4298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
14 changes: 14 additions & 0 deletions ydb/library/yql/minikql/aligned_page_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ void TAlignedPagePoolImpl<T>::ReturnBlock(void* ptr, size_t size) noexcept {
Y_DEBUG_ABORT_UNLESS(ActiveBlocks.erase(ptr));
}
#endif
UpdateMemoryYellowZone();
}

template<typename T>
Expand Down Expand Up @@ -500,6 +501,19 @@ void TAlignedPagePoolImpl<T>::Free(void* ptr, size_t size) noexcept {
}
}

template<typename T>
void TAlignedPagePoolImpl<T>::UpdateMemoryYellowZone() {
if (IncreaseMemoryLimitCallback) return;
if (Limit == 0) return;

ui8 usedMemoryPercent = 100 * GetUsed() / Limit;
if (usedMemoryPercent >= EnableMemoryYellowZoneThreshold) {
IsMemoryYellowZoneReached = true;
} else if (usedMemoryPercent <= DisableMemoryYellowZoneThreshold) {
IsMemoryYellowZoneReached = false;
}
}

template<typename T>
bool TAlignedPagePoolImpl<T>::TryIncreaseLimit(ui64 required) {
if (!IncreaseMemoryLimitCallback) {
Expand Down
14 changes: 5 additions & 9 deletions ydb/library/yql/minikql/aligned_page_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,7 @@ class TAlignedPagePoolImpl {
UpdateMemoryYellowZone();
}

void UpdateMemoryYellowZone() {
if (IncreaseMemoryLimitCallback) return;

if (Limit != 0) {
IsMemoryYellowZoneReached = (100 * GetUsed() / Limit) > MemoryYellowZoneThreshold;
}
}
void UpdateMemoryYellowZone();

bool TryIncreaseLimit(ui64 required);

Expand Down Expand Up @@ -279,8 +273,10 @@ class TAlignedPagePoolImpl {
// Indicates when memory limit is almost reached.
bool IsMemoryYellowZoneReached = false;
// This theshold is used to determine is memory limit is almost reached.
// If TIncreaseMemoryLimitCallback is set this threshold should be ignored.
const ui8 MemoryYellowZoneThreshold = 80;
// If TIncreaseMemoryLimitCallback is set this thresholds should be ignored.
// The yellow zone turns on when memory consumption reaches 80% and turns off when consumption drops below 50%.
const ui8 EnableMemoryYellowZoneThreshold = 80;
const ui8 DisableMemoryYellowZoneThreshold = 50;
};

using TAlignedPagePool = TAlignedPagePoolImpl<>;
Expand Down
43 changes: 43 additions & 0 deletions ydb/library/yql/minikql/aligned_page_pool_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,49 @@ Y_UNIT_TEST(UnalignedMmapUnalignedSize) {
);
}

Y_UNIT_TEST(YellowZoneSwitchesCorrectlyBlock) {
TAlignedPagePool::ResetGlobalsUT();
TAlignedPagePoolImpl alloc(__LOCATION__);

// choose relatively big chunk so ALLOC_AHEAD_PAGES don't affect the correctness of the test
auto size = 1024 * TAlignedPagePool::POOL_PAGE_SIZE;

alloc.SetLimit(size * 10);

// 50% allocated -> no yellow zone
auto block1 = alloc.GetBlock(size * 5);
UNIT_ASSERT_VALUES_EQUAL(false, alloc.IsMemoryYellowZoneEnabled());

// 70% allocated -> no yellow zone
auto block2 = alloc.GetBlock(size * 2);
UNIT_ASSERT_VALUES_EQUAL(false, alloc.IsMemoryYellowZoneEnabled());

// 90% allocated -> yellow zone is enabled (> 80%)
auto block3 = alloc.GetBlock(size * 2);
UNIT_ASSERT_VALUES_EQUAL(true, alloc.IsMemoryYellowZoneEnabled());

// 70% allocated -> yellow zone is still enabled (> 50%)
alloc.ReturnBlock(block3, size * 2);
UNIT_ASSERT_VALUES_EQUAL(true, alloc.IsMemoryYellowZoneEnabled());

// 50% allocated -> yellow zone is disabled
alloc.ReturnBlock(block2, size * 2);
UNIT_ASSERT_VALUES_EQUAL(false, alloc.IsMemoryYellowZoneEnabled());

// 0% allocated -> yellow zone is disabled
alloc.ReturnBlock(block1, size * 5);
UNIT_ASSERT_VALUES_EQUAL(false, alloc.IsMemoryYellowZoneEnabled());
}

Y_UNIT_TEST(YellowZoneZeroDivision) {
TAlignedPagePool::ResetGlobalsUT();
TAlignedPagePoolImpl alloc(__LOCATION__);

alloc.SetLimit(0);

UNIT_ASSERT_EQUAL(false, alloc.IsMemoryYellowZoneEnabled());
}

} // Y_UNIT_TEST_SUITE(TAlignedPagePoolTest)

} // namespace NMiniKQL
Expand Down
Loading