https://git.reactos.org/?p=reactos.git;a=commitdiff;h=aab24ed1b1a3269de23db…
commit aab24ed1b1a3269de23dbaa334a67741434bc4c1
Author: Jérôme Gardou <jerome.gardou(a)reactos.org>
AuthorDate: Mon Dec 7 11:42:47 2020 +0100
Commit: Jérôme Gardou <jerome.gardou(a)reactos.org>
CommitDate: Wed Feb 3 09:41:22 2021 +0100
[NTOS:MM] Have the legacy Mm be less greedy about the number of pages it wants
---
ntoskrnl/mm/balance.c | 33 ++++++++-------------------------
1 file changed, 8 insertions(+), 25 deletions(-)
diff --git a/ntoskrnl/mm/balance.c b/ntoskrnl/mm/balance.c
index 29c0dfc6f47..34dddf5dbfa 100644
--- a/ntoskrnl/mm/balance.c
+++ b/ntoskrnl/mm/balance.c
@@ -28,7 +28,6 @@ MM_ALLOCATION_REQUEST, *PMM_ALLOCATION_REQUEST;
MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
static ULONG MiMinimumAvailablePages;
-static ULONG MiNrTotalPages;
static LIST_ENTRY AllocationListHead;
static KSPIN_LOCK AllocationListLock;
static ULONG MiMinimumPagesPerRun;
@@ -49,12 +48,10 @@ MmInitializeBalancer(ULONG NrAvailablePages, ULONG NrSystemPages)
InitializeListHead(&AllocationListHead);
KeInitializeSpinLock(&AllocationListLock);
- MiNrTotalPages = NrAvailablePages;
-
/* Set up targets. */
MiMinimumAvailablePages = 256;
MiMinimumPagesPerRun = 256;
- MiMemoryConsumers[MC_USER].PagesTarget = NrAvailablePages - MiMinimumAvailablePages;
+ MiMemoryConsumers[MC_USER].PagesTarget = NrAvailablePages / 2;
}
CODE_SEG("INIT")
@@ -120,15 +117,12 @@ MiTrimMemoryConsumer(ULONG Consumer, ULONG InitialTarget)
Target = (ULONG)max(Target, MiMinimumAvailablePages - MmAvailablePages);
}
+ /* Don't be too greedy if we're not in a hurry */
+ if (MmAvailablePages > MiMinimumAvailablePages)
+ Target = min(Target, 256);
+
if (Target)
{
- if (!InitialTarget)
- {
- /* If there was no initial target,
- * swap at least MiMinimumPagesPerRun */
- Target = max(Target, MiMinimumPagesPerRun);
- }
-
/* Now swap the pages out */
Status = MiMemoryConsumers[Consumer].Trim(Target, 0, &NrFreedPages);
@@ -138,21 +132,10 @@ MiTrimMemoryConsumer(ULONG Consumer, ULONG InitialTarget)
{
KeBugCheck(MEMORY_MANAGEMENT);
}
-
- /* Update the target */
- if (NrFreedPages < Target)
- Target -= NrFreedPages;
- else
- Target = 0;
-
- /* Return the remaining pages needed to meet the target */
- return Target;
- }
- else
- {
- /* Initial target is zero and we don't have anything else to add */
- return 0;
}
+
+ /* Return the page count needed to be freed to meet the initial target */
+ return (InitialTarget > NrFreedPages) ? (InitialTarget - NrFreedPages) : 0;
}
NTSTATUS