https://git.reactos.org/?p=reactos.git;a=commitdiff;h=625f27336176c7f1db4ad…
commit 625f27336176c7f1db4ad5ade75597a3820853ed
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Fri Jan 29 18:47:26 2021 +0100
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Wed Feb 3 09:41:23 2021 +0100
[NTOS:MM] More fine-tuning of the memory balancer
---
ntoskrnl/mm/balance.c | 21 +++++++++++----------
ntoskrnl/mm/rmap.c | 10 ----------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/ntoskrnl/mm/balance.c b/ntoskrnl/mm/balance.c
index 04231e86951..1cab99be0ec 100644
--- a/ntoskrnl/mm/balance.c
+++ b/ntoskrnl/mm/balance.c
@@ -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
{
diff --git a/ntoskrnl/mm/rmap.c b/ntoskrnl/mm/rmap.c
index f926afb8471..e40d9554038 100644
--- a/ntoskrnl/mm/rmap.c
+++ b/ntoskrnl/mm/rmap.c
@@ -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);