Author: sir_richard
Date: Mon Sep 27 21:58:54 2010
New Revision: 48912
URL:
http://svn.reactos.org/svn/reactos?rev=48912&view=rev
Log:
- Remove MiZeroPage, use MiZeroPhysicalPage instead. They work pretty much the same except
the needless raise to DISPATCH_LEVEL.
- Get rid of the messed up MiMapPageToZeroInHyperSpace which was hacking into
MiMapPagesToZeroInHyperSpace. Now MiMapPagesToZeroInHyperSpace is properly implemented to
use chained PFNs, and the MmZeroPageThread code has been modified to correctly use the new
mechanism.
- Zero page mapping now happens at PASSIVE trough MiMapPAgesToZeroInHyperSpace, not
DISPATCH anymore.
- More fixes are coming to remove the remaining MiRemoveHeadList and rewrite the zero page
loop. Should fix more possible corruptions.
Modified:
trunk/reactos/ntoskrnl/cc/copy.c
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/ARM3/hypermap.c
trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
trunk/reactos/ntoskrnl/mm/balance.c
trunk/reactos/ntoskrnl/mm/freelist.c
Modified: trunk/reactos/ntoskrnl/cc/copy.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cc/copy.c?rev=489…
==============================================================================
--- trunk/reactos/ntoskrnl/cc/copy.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/cc/copy.c [iso-8859-1] Mon Sep 27 21:58:54 2010
@@ -31,6 +31,12 @@
VOID
NTAPI
+MiZeroPhysicalPage(
+ IN PFN_NUMBER PageFrameIndex
+);
+
+VOID
+NTAPI
CcInitCacheZeroPage(VOID)
{
NTSTATUS Status;
@@ -41,12 +47,7 @@
DbgPrint("Can't allocate CcZeroPage.\n");
KeBugCheck(CACHE_MANAGER);
}
- Status = MiZeroPage(CcZeroPage);
- if (!NT_SUCCESS(Status))
- {
- DbgPrint("Can't zero out CcZeroPage.\n");
- KeBugCheck(CACHE_MANAGER);
- }
+ MiZeroPhysicalPage(CcZeroPage);
}
NTSTATUS
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Mon Sep 27 21:58:54 2010
@@ -1189,7 +1189,7 @@
PVOID
NTAPI
-MiMapPagesToZeroInHyperSpace(IN PMMPFN *Pages,
+MiMapPagesToZeroInHyperSpace(IN PMMPFN Pfn1,
IN PFN_NUMBER NumberOfPages);
VOID
@@ -1206,14 +1206,6 @@
{
HyperProcess = (PEPROCESS)KeGetCurrentThread()->ApcState.Process;
return MiMapPageInHyperSpace(HyperProcess, Page, &HyperIrql);
-}
-
-FORCEINLINE
-PVOID
-MiMapPageToZeroInHyperSpace(IN PFN_NUMBER Page)
-{
- PMMPFN Pfn1 = MiGetPfnEntry(Page);
- return MiMapPagesToZeroInHyperSpace(&Pfn1, 1);
}
#define MmDeleteHyperspaceMapping(x) MiUnmapPageInHyperSpace(HyperProcess, x,
HyperIrql);
Modified: trunk/reactos/ntoskrnl/mm/ARM3/hypermap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/hypermap.…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/hypermap.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/hypermap.c [iso-8859-1] Mon Sep 27 21:58:54 2010
@@ -112,18 +112,17 @@
PVOID
NTAPI
-MiMapPagesToZeroInHyperSpace(IN PMMPFN *Pages,
+MiMapPagesToZeroInHyperSpace(IN PMMPFN Pfn1,
IN PFN_NUMBER NumberOfPages)
{
MMPTE TempPte;
PMMPTE PointerPte;
PFN_NUMBER Offset, PageFrameIndex;
- PMMPFN Page;
//
// Sanity checks
//
- ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
+ ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
ASSERT(NumberOfPages != 0);
ASSERT(NumberOfPages <= (MI_ZERO_PTES - 1));
@@ -151,19 +150,17 @@
//
PointerPte->u.Hard.PageFrameNumber = Offset - NumberOfPages;
- //
- // Write the current PTE
- //
+ /* Choose the correct PTE to use, and which template */
PointerPte += (Offset + 1);
TempPte = ValidKernelPte;
MI_MAKE_LOCAL_PAGE(&TempPte); // Hyperspace is local!
- do
+
+ /* Make sure the list isn't empty and loop it */
+ ASSERT(Pfn1 != (PVOID)LIST_HEAD);
+ while (Pfn1 != (PVOID)LIST_HEAD)
{
- //
- // Get the first page entry and its PFN
- //
- Page = *Pages++;
- PageFrameIndex = MiGetPfnEntryIndex(Page);
+ /* Get the page index for this PFN */
+ PageFrameIndex = MiGetPfnEntryIndex(Pfn1);
//
// Write the PFN
@@ -175,7 +172,10 @@
//
PointerPte--;
MI_WRITE_VALID_PTE(PointerPte, TempPte);
- } while (--NumberOfPages);
+
+ /* Move to the next PFN */
+ Pfn1 = (PMMPFN)Pfn1->u1.Flink;
+ }
//
// Return the address
@@ -193,7 +193,7 @@
//
// Sanity checks
//
- ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL);
+ ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
ASSERT (NumberOfPages != 0);
ASSERT (NumberOfPages <= (MI_ZERO_PTES - 1));
Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] Mon Sep 27 21:58:54 2010
@@ -66,6 +66,7 @@
/* Map in hyperspace, then wipe it using XMMI or MEMSET */
VirtualAddress = MiMapPageInHyperSpace(Process, PageFrameIndex, &OldIrql);
+ ASSERT(VirtualAddress);
KeZeroPages(VirtualAddress, PAGE_SIZE);
MiUnmapPageInHyperSpace(Process, VirtualAddress, OldIrql);
}
Modified: trunk/reactos/ntoskrnl/mm/balance.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/balance.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] Mon Sep 27 21:58:54 2010
@@ -99,6 +99,12 @@
MiMemoryConsumers[Consumer].Trim = Trim;
}
+VOID
+NTAPI
+MiZeroPhysicalPage(
+ IN PFN_NUMBER PageFrameIndex
+);
+
NTSTATUS
NTAPI
MmReleasePageMemoryConsumer(ULONG Consumer, PFN_NUMBER Page)
@@ -131,7 +137,7 @@
Request = CONTAINING_RECORD(Entry, MM_ALLOCATION_REQUEST, ListEntry);
KeReleaseSpinLock(&AllocationListLock, OldIrql);
if(Consumer == MC_USER) MmRemoveLRUUserPage(Page);
- MiZeroPage(Page);
+ MiZeroPhysicalPage(Page);
Request->Page = Page;
KeSetEvent(&Request->Event, IO_NO_INCREMENT, FALSE);
}
Modified: trunk/reactos/ntoskrnl/mm/freelist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] Mon Sep 27 21:58:54 2010
@@ -360,7 +360,7 @@
//
Pfn1 = MiGetPfnEntry(Page);
ASSERT(Pfn1);
- if (Pfn1->u3.e1.PageLocation != ZeroedPageList) MiZeroPage(Page);
+ if (Pfn1->u3.e1.PageLocation != ZeroedPageList) MiZeroPhysicalPage(Page);
Pfn1->u3.e1.PageLocation = ActiveAndValid;
}
@@ -627,25 +627,6 @@
NTSTATUS
NTAPI
-MiZeroPage(PFN_NUMBER Page)
-{
- KIRQL Irql;
- PVOID TempAddress;
-
- Irql = KeRaiseIrqlToDpcLevel();
- TempAddress = MiMapPageToZeroInHyperSpace(Page);
- if (TempAddress == NULL)
- {
- return(STATUS_NO_MEMORY);
- }
- memset(TempAddress, 0, PAGE_SIZE);
- MiUnmapPagesInZeroSpace(TempAddress, 1);
- KeLowerIrql(Irql);
- return(STATUS_SUCCESS);
-}
-
-NTSTATUS
-NTAPI
MmZeroPageThreadMain(PVOID Ignored)
{
NTSTATUS Status;
@@ -653,6 +634,7 @@
PPHYSICAL_PAGE PageDescriptor;
PFN_NUMBER Pfn;
ULONG Count;
+ PVOID ZeroAddress;
/* Free initial kernel memory */
//MiFreeInitMemory();
@@ -679,22 +661,19 @@
while (MmFreePageListHead.Total)
{
PageDescriptor = MiRemoveHeadList(&MmFreePageListHead);
- /* We set the page to used, because MmCreateVirtualMapping failed with unused
pages */
+ Pfn = MiGetPfnEntryIndex(PageDescriptor);
KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
- Pfn = MiGetPfnEntryIndex(PageDescriptor);
- Status = MiZeroPage(Pfn);
+
+ PageDescriptor->u1.Flink = LIST_HEAD;
+ ZeroAddress = MiMapPagesToZeroInHyperSpace(PageDescriptor, 1);
+ ASSERT(ZeroAddress);
+ RtlZeroMemory(ZeroAddress, PAGE_SIZE);
+ MiUnmapPagesInZeroSpace(ZeroAddress, 1);
oldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
- if (NT_SUCCESS(Status))
- {
- MiInsertZeroListAtBack(Pfn);
- Count++;
- }
- else
- {
- MiInsertInListTail(&MmFreePageListHead, PageDescriptor);
- PageDescriptor->u3.e1.PageLocation = FreePageList;
- }
+
+ MiInsertZeroListAtBack(Pfn);
+ Count++;
}
DPRINT("Zeroed %d pages.\n", Count);