[NTOSKRNL]
authorCameron Gutman <aicommander@gmail.com>
Tue, 29 Nov 2011 17:05:56 +0000 (17:05 +0000)
committerCameron Gutman <aicommander@gmail.com>
Tue, 29 Nov 2011 17:05:56 +0000 (17:05 +0000)
- Don't signal the balancer from within the balancer
- Optimize usage of the balancer a bit so we don't have to wait on it as much

svn path=/trunk/; revision=54537

reactos/ntoskrnl/mm/balance.c

index 8c6e4fe..2f33c41 100644 (file)
@@ -262,7 +262,8 @@ MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait,
       if (Consumer == MC_USER) MmInsertLRULastUserPage(Page);
       *AllocatedPage = Page;
       if (MmAvailablePages <= MiMinimumAvailablePages &&
-            MiBalancerThreadHandle != NULL)
+          MiBalancerThreadHandle != NULL &&
+          !MiIsBalancerThread())
       {
          KeSetEvent(&MiBalancerEvent, IO_NO_INCREMENT, FALSE);
       }
@@ -311,6 +312,13 @@ MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait,
 
       *AllocatedPage = Page;
       (void)InterlockedDecrementUL(&MiPagesRequired);
+       
+      if (MmAvailablePages <= MiMinimumAvailablePages &&
+          MiBalancerThreadHandle != NULL &&
+          !MiIsBalancerThread())
+      {
+          KeSetEvent(&MiBalancerEvent, IO_NO_INCREMENT, FALSE);
+      }
 
       return(STATUS_SUCCESS);
    }
@@ -327,6 +335,13 @@ MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait,
    }
    if(Consumer == MC_USER) MmInsertLRULastUserPage(Page);
    *AllocatedPage = Page;
+    
+   if (MmAvailablePages <= MiMinimumAvailablePages &&
+       MiBalancerThreadHandle != NULL &&
+       !MiIsBalancerThread())
+   {
+       KeSetEvent(&MiBalancerEvent, IO_NO_INCREMENT, FALSE);
+   }
 
    return(STATUS_SUCCESS);
 }