Skip to content
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

Force IsGroupInRedZone to do all checks #1004

Draft
wants to merge 1 commit into
base: adb-6.x-dev
Choose a base branch
from
Draft
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
29 changes: 17 additions & 12 deletions src/backend/utils/resgroup/resgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -4614,28 +4614,33 @@ IsGroupInRedZone(void)
/*
* IsGroupInRedZone is called frequently, we should put the
* condition which returns with higher probability in front.
*
* safe: global shared memory is not in redzone
*
* We're in RedZone if number of remained chunks on segment host
* is less than totalChunks * (100 - runaway_detector_activation_percent)
*/
remainGlobalSharedMem = (uint32) pg_atomic_read_u32(&pResGroupControl->freeChunks);
safeChunksThreshold100 = (uint32) pg_atomic_read_u32(&pResGroupControl->safeChunksThreshold100);
if (remainGlobalSharedMem * 100 >= safeChunksThreshold100)
return false;
if (remainGlobalSharedMem * 100 < safeChunksThreshold100)
return true;

AssertImply(slot != NULL, group != NULL);
if (!slot)
return false;

/* safe: slot memory is not used up */
if (slot->memQuota > slot->memUsage)
return false;
/* We're in RedZone if group's shared memory is exceeded */
if (group->memSharedGranted < group->memSharedUsage)
return true;

/* safe: group shared memory is not in redzone */
if (group->memSharedGranted > group->memSharedUsage)
return false;
/*
* This check is here for the cases when a single process
* solely consumes the entire group quota. Not sure if it's
* a common case, so let's put it in the end
*/
if (slot->memUsage > group->memQuotaGranted + group->memSharedGranted)
return true;

/* memory usage in this group is in RedZone */
return true;
/* All checks are passed, we're not in RedZone */
return false;
}

/*
Expand Down
Loading