[ros-diffs] [amunger] 32673: Simplify and rename the functions that touch UserPageListHead. They were confusingly coded to accept any flavor of PFN_TYPE, which resulted in at least one bug. Constrained the calls to the MmRequest/ReleasePageMemoryConsumer and MmTrimUserMemory.

amunger at svn.reactos.org amunger at svn.reactos.org
Thu Mar 13 16:26:17 CET 2008


Author: amunger
Date: Thu Mar 13 10:26:17 2008
New Revision: 32673

URL: http://svn.reactos.org/svn/reactos?rev=3D32673&view=3Drev
Log:
Simplify and rename the functions that touch UserPageListHead.
They were confusingly coded to accept any flavor of PFN_TYPE, which resulte=
d in at least one bug.
Constrained the calls to the MmRequest/ReleasePageMemoryConsumer and MmTrim=
UserMemory.

Modified:
    trunk/reactos/ntoskrnl/include/internal/mm.h
    trunk/reactos/ntoskrnl/mm/balance.c
    trunk/reactos/ntoskrnl/mm/freelist.c
    trunk/reactos/ntoskrnl/mm/wset.c

Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/inte=
rnal/mm.h?rev=3D32673&r1=3D32672&r2=3D32673&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/include/internal/mm.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h Thu Mar 13 10:26:17 2008
@@ -1025,7 +1025,11 @@
 =

 VOID
 NTAPI
-MmSetLRULastPage(PFN_TYPE Page);
+MmInsertLRULastUserPage(PFN_TYPE Page);
+
+VOID
+NTAPI
+MmRemoveLRUUserPage(PFN_TYPE Page);
 =

 VOID
 NTAPI

Modified: trunk/reactos/ntoskrnl/mm/balance.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/balance.c=
?rev=3D32673&r1=3D32672&r2=3D32673&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/balance.c (original)
+++ trunk/reactos/ntoskrnl/mm/balance.c Thu Mar 13 10:26:17 2008
@@ -114,6 +114,7 @@
          Entry =3D RemoveHeadList(&AllocationListHead);
          Request =3D CONTAINING_RECORD(Entry, MM_ALLOCATION_REQUEST, ListE=
ntry);
          KeReleaseSpinLock(&AllocationListLock, oldIrql);
+         if(Consumer =3D=3D MC_USER) MmRemoveLRUUserPage(Page);
          Request->Page =3D Page;
          KeSetEvent(&Request->Event, IO_NO_INCREMENT, FALSE);
       }
@@ -121,6 +122,7 @@
    else
    {
       KeReleaseSpinLock(&AllocationListLock, oldIrql);
+      if(Consumer =3D=3D MC_USER) MmRemoveLRUUserPage(Page);
       MmDereferencePage(Page);
    }
 =

@@ -262,7 +264,9 @@
       {
          KEBUGCHECK(NO_PAGES_AVAILABLE);
       }
-      MmSetLRULastPage(Page);
+      /* Update the Consumer */
+      MiGetPfnEntry(Page)->Flags.Consumer =3D Consumer;
+      if(Consumer =3D=3D MC_USER) MmInsertLRULastUserPage(Page);
       *AllocatedPage =3D Page;
       (void)InterlockedDecrementUL(&MiPagesRequired);
       return(STATUS_SUCCESS);
@@ -276,6 +280,7 @@
    {
       KEBUGCHECK(NO_PAGES_AVAILABLE);
    }
+   if(Consumer =3D=3D MC_USER) MmInsertLRULastUserPage(Page);
    *AllocatedPage =3D Page;
 =

    return(STATUS_SUCCESS);

Modified: trunk/reactos/ntoskrnl/mm/freelist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.=
c?rev=3D32673&r1=3D32672&r2=3D32673&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/freelist.c (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c Thu Mar 13 10:26:17 2008
@@ -31,8 +31,12 @@
 ULONG MmPageArraySize;
 =

 static KSPIN_LOCK PageListLock;
+/* List of pages allocated to the MC_USER Consumer */
 static LIST_ENTRY UserPageListHead;
+/* List of pages zeroed by the ZPW (MmZeroPageThreadMain) */
 static LIST_ENTRY FreeZeroedPageListHead;
+/* List of free pages, filled by MmGetReferenceCountPage and
+ * and MmInitializePageList */
 static LIST_ENTRY FreeUnzeroedPageListHead;
 =

 static KEVENT ZeroPageThreadEvent;
@@ -65,19 +69,16 @@
 =

 VOID
 NTAPI
-MmSetLRULastPage(PFN_TYPE Pfn)
+MmInsertLRULastUserPage(PFN_TYPE Pfn)
 {
    KIRQL oldIrql;
    PPHYSICAL_PAGE Page;
 =

    KeAcquireSpinLock(&PageListLock, &oldIrql);
    Page =3D MiGetPfnEntry(Pfn);
-   if (Page->Flags.Type =3D=3D MM_PHYSICAL_PAGE_USED &&
-       Page->Flags.Consumer =3D=3D MC_USER)
-   {
-      RemoveEntryList(&Page->ListEntry);
-      InsertTailList(&UserPageListHead, &Page->ListEntry);
-   }
+   ASSERT(Page->Flags.Type =3D=3D MM_PHYSICAL_PAGE_USED);
+   ASSERT(Page->Flags.Consumer =3D=3D MC_USER);
+   InsertTailList(&UserPageListHead, &Page->ListEntry);
    KeReleaseSpinLock(&PageListLock, oldIrql);
 }
 =

@@ -92,15 +93,9 @@
 =

    KeAcquireSpinLock(&PageListLock, &oldIrql);
    Page =3D MiGetPfnEntry(PreviousPfn);
-   if (Page->Flags.Type !=3D MM_PHYSICAL_PAGE_USED ||
-       Page->Flags.Consumer !=3D MC_USER)
-   {
-      NextListEntry =3D UserPageListHead.Flink;
-   }
-   else
-   {
-      NextListEntry =3D Page->ListEntry.Flink;
-   }
+   ASSERT(Page->Flags.Type =3D=3D MM_PHYSICAL_PAGE_USED);
+   ASSERT(Page->Flags.Consumer =3D=3D MC_USER);
+   NextListEntry =3D Page->ListEntry.Flink;
    if (NextListEntry =3D=3D &UserPageListHead)
    {
       KeReleaseSpinLock(&PageListLock, oldIrql);
@@ -109,6 +104,13 @@
    PageDescriptor =3D CONTAINING_RECORD(NextListEntry, PHYSICAL_PAGE, List=
Entry);
    KeReleaseSpinLock(&PageListLock, oldIrql);
    return PageDescriptor - MmPageArray;
+}
+
+VOID
+NTAPI
+MmRemoveLRUUserPage(PFN_TYPE Page)
+{
+   RemoveEntryList(&MiGetPfnEntry(Page)->ListEntry);
 }
 =

 PFN_TYPE
@@ -782,7 +784,6 @@
    KeReleaseSpinLock(&PageListLock, oldIrql);
 =

    PfnOffset =3D PageDescriptor - MmPageArray;
-   MmSetLRULastPage(PfnOffset);
    if (NeedClear)
    {
       MiZeroPage(PfnOffset);
@@ -882,7 +883,7 @@
          /* Remember the page */
          pfn =3D PageDescriptor - MmPageArray;
          Pages[NumberOfPagesFound++] =3D pfn;
-         MmSetLRULastPage(pfn);
+         if(Consumer =3D=3D MC_USER) MmInsertLRULastUserPage(pfn);
       }
    }
    else
@@ -917,7 +918,6 @@
 =

             /* Remember the page */
             Pages[NumberOfPagesFound++] =3D pfn;
-            MmSetLRULastPage(pfn);
             if (NumberOfPagesFound =3D=3D NumberOfPages)
                break;
          }

Modified: trunk/reactos/ntoskrnl/mm/wset.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/wset.c?re=
v=3D32673&r1=3D32672&r2=3D32673&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/ntoskrnl/mm/wset.c (original)
+++ trunk/reactos/ntoskrnl/mm/wset.c Thu Mar 13 10:26:17 2008
@@ -38,7 +38,8 @@
       }
       else if (Status =3D=3D STATUS_PAGEFILE_QUOTA)
       {
-         MmSetLRULastPage(CurrentPage);
+         MmRemoveLRUUserPage(CurrentPage);
+         MmInsertLRULastUserPage(CurrentPage);
       }
 =

       CurrentPage =3D NextPage;




More information about the Ros-diffs mailing list