[NTOS:MM] More fine-tuning of the memory balancer

This commit is contained in:
Jérôme Gardou 2021-01-29 18:47:26 +01:00
parent 41475dfcd7
commit 625f273361
2 changed files with 11 additions and 20 deletions

View file

@ -37,6 +37,8 @@ static HANDLE MiBalancerThreadHandle = NULL;
static KEVENT MiBalancerEvent;
static KTIMER MiBalancerTimer;
static LONG PageOutThreadActive;
/* FUNCTIONS ****************************************************************/
CODE_SEG("INIT")
@ -102,19 +104,16 @@ MiTrimMemoryConsumer(ULONG Consumer, ULONG InitialTarget)
return InitialTarget;
}
if (MiMemoryConsumers[Consumer].PagesUsed > MiMemoryConsumers[Consumer].PagesTarget)
{
/* Consumer page limit exceeded */
Target = max(Target, MiMemoryConsumers[Consumer].PagesUsed - MiMemoryConsumers[Consumer].PagesTarget);
}
if (MmAvailablePages < MiMinimumAvailablePages)
{
/* Global page limit exceeded */
Target = (ULONG)max(Target, MiMinimumAvailablePages - MmAvailablePages);
}
/* Don't be too greedy in one run */
Target = min(Target, 256);
else if (MiMemoryConsumers[Consumer].PagesUsed > MiMemoryConsumers[Consumer].PagesTarget)
{
/* Consumer page limit exceeded */
Target = max(Target, MiMemoryConsumers[Consumer].PagesUsed - MiMemoryConsumers[Consumer].PagesTarget);
}
if (Target)
{
@ -265,8 +264,7 @@ VOID
NTAPI
MmRebalanceMemoryConsumers(VOID)
{
if (MiBalancerThreadHandle != NULL &&
!MiIsBalancerThread())
if (InterlockedCompareExchange(&PageOutThreadActive, 0, 1) == 0)
{
KeSetEvent(&MiBalancerEvent, IO_NO_INCREMENT, FALSE);
}
@ -366,6 +364,9 @@ MiBalancerThread(PVOID Unused)
}
}
while (InitialTarget != 0);
if (Status == STATUS_WAIT_0)
InterlockedDecrement(&PageOutThreadActive);
}
else
{

View file

@ -68,16 +68,6 @@ GetEntry:
while (entry && RMAP_IS_SEGMENT(entry->Address))
entry = entry->Next;
/* See if we are retrying because the page is actively used */
while (entry && ((entry->Address < Address) || RMAP_IS_SEGMENT(entry->Address)))
entry = entry->Next;
if (entry && (entry->Address == Address))
{
while (entry && ((entry->Process <= Process) || RMAP_IS_SEGMENT(entry->Address)))
entry = entry->Next;
}
if (entry == NULL)
{
MiReleasePfnLock(OldIrql);