Author: tkreuzer
Date: Wed Oct  8 00:30:50 2014
New Revision: 64586

URL: http://svn.reactos.org/svn/reactos?rev=64586&view=rev
Log:
[NTOSKRNL]
Move acquisition of PFN lock into MmAllocPage and MmDereferencePage

Modified:
    trunk/reactos/ntoskrnl/mm/balance.c
    trunk/reactos/ntoskrnl/mm/freelist.c

Modified: trunk/reactos/ntoskrnl/mm/balance.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/balance.c?rev=64586&r1=64585&r2=64586&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] Wed Oct  8 00:30:50 2014
@@ -98,7 +98,6 @@
 {
     PMM_ALLOCATION_REQUEST Request;
     PLIST_ENTRY Entry;
-    KIRQL OldIrql;
 
     if (Page == 0)
     {
@@ -112,9 +111,7 @@
         (void)InterlockedDecrementUL(&MiMemoryConsumers[Consumer].PagesUsed);
         if ((Entry = ExInterlockedRemoveHeadList(&AllocationListHead, 
&AllocationListLock)) == NULL)
         {
-            OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
             MmDereferencePage(Page);
-            KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
         }
         else
         {
@@ -126,9 +123,7 @@
     }
     else
     {
-        OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
         MmDereferencePage(Page);
-        KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
     }
 
     return(STATUS_SUCCESS);
@@ -259,7 +254,6 @@
 {
     ULONG PagesUsed;
     PFN_NUMBER Page;
-    KIRQL OldIrql;
 
     /*
      * Make sure we don't exceed our individual target.
@@ -276,9 +270,7 @@
      */
     if ((Consumer == MC_SYSTEM) || MiIsBalancerThread())
     {
-        OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
         Page = MmAllocPage(Consumer);
-        KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
         if (Page == 0)
         {
             KeBugCheck(NO_PAGES_AVAILABLE);
@@ -337,9 +329,7 @@
     /*
      * Actually allocate the page.
      */
-    OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
     Page = MmAllocPage(Consumer);
-    KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
     if (Page == 0)
     {
         KeBugCheck(NO_PAGES_AVAILABLE);

Modified: trunk/reactos/ntoskrnl/mm/freelist.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.c?rev=64586&r1=64585&r2=64586&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/freelist.c        [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c        [iso-8859-1] Wed Oct  8 
00:30:50 2014
@@ -532,7 +532,10 @@
 MmDereferencePage(PFN_NUMBER Pfn)
 {
     PMMPFN Pfn1;
+    KIRQL OldIrql;
     DPRINT("MmDereferencePage(PhysicalAddress %x)\n", Pfn << PAGE_SHIFT);
+
+    OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
 
     Pfn1 = MiGetPfnEntry(Pfn);
     ASSERT(Pfn1);
@@ -552,6 +555,8 @@
         DPRINT("Legacy free: %lx\n", Pfn);
         MiInsertPageInFreeList(Pfn);
     }
+
+    KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
 }
 
 PFN_NUMBER
@@ -560,13 +565,14 @@
 {
     PFN_NUMBER PfnOffset;
     PMMPFN Pfn1;
+    KIRQL OldIrql;
+
+    OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
 
     PfnOffset = MiRemoveZeroPage(MI_GET_NEXT_COLOR());
-
     if (!PfnOffset)
     {
-        DPRINT1("MmAllocPage(): Out of memory\n");
-        return 0;
+        KeBugCheck(NO_PAGES_AVAILABLE);
     }
 
     DPRINT("Legacy allocate: %lx\n", PfnOffset);
@@ -581,6 +587,7 @@
     Pfn1->u1.SwapEntry = 0;
     Pfn1->RmapListHead = NULL;
 
+    KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
     return PfnOffset;
 }
 


Reply via email to