https://git.reactos.org/?p=reactos.git;a=commitdiff;h=047dc9729f0cbf0b7b757…
commit 047dc9729f0cbf0b7b7571ae522a9f8677943959
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Thu Apr 6 08:42:32 2023 +0300
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sat Jul 29 14:00:44 2023 +0300
[NTOS:Mm] Implement MmRebalanceMemoryConsumersAndWait
---
ntoskrnl/mm/balance.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/ntoskrnl/mm/balance.c b/ntoskrnl/mm/balance.c
index f81027a65cd..ab71d0f195b 100644
--- a/ntoskrnl/mm/balance.c
+++ b/ntoskrnl/mm/balance.c
@@ -33,6 +33,7 @@ static ULONG MiMinimumPagesPerRun;
static CLIENT_ID MiBalancerThreadId;
static HANDLE MiBalancerThreadHandle = NULL;
static KEVENT MiBalancerEvent;
+static KEVENT MiBalancerDoneEvent;
static KTIMER MiBalancerTimer;
static LONG PageOutThreadActive;
@@ -296,6 +297,19 @@ MmRebalanceMemoryConsumers(VOID)
}
}
+VOID
+NTAPI
+MmRebalanceMemoryConsumersAndWait(VOID)
+{
+ ASSERT(PsGetCurrentProcess()->AddressCreationLock.Owner != KeGetCurrentThread());
+ ASSERT(!MM_ANY_WS_LOCK_HELD(PsGetCurrentThread()));
+ ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
+
+ KeResetEvent(&MiBalancerDoneEvent);
+ MmRebalanceMemoryConsumers();
+ KeWaitForSingleObject(&MiBalancerDoneEvent, Executive, KernelMode, FALSE, NULL);
+}
+
NTSTATUS
NTAPI
MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait,
@@ -334,6 +348,7 @@ MiBalancerThread(PVOID Unused)
while (1)
{
+ KeSetEvent(&MiBalancerDoneEvent, IO_NO_INCREMENT, FALSE);
Status = KeWaitForMultipleObjects(2,
WaitObjects,
WaitAny,
@@ -388,6 +403,7 @@ MiInitBalancerThread(VOID)
LARGE_INTEGER Timeout;
KeInitializeEvent(&MiBalancerEvent, SynchronizationEvent, FALSE);
+ KeInitializeEvent(&MiBalancerDoneEvent, SynchronizationEvent, FALSE);
KeInitializeTimerEx(&MiBalancerTimer, SynchronizationTimer);
Timeout.QuadPart = -20000000; /* 2 sec */