Author: sir_richard
Date: Tue Sep 28 16:47:25 2010
New Revision: 48922
URL:
http://svn.reactos.org/svn/reactos?rev=48922&view=rev
Log:
[NTOS]: Switch to using an ARM3, much more correct MmZeroPageThread. Stub support for
discarding sections and listening to the Power Manager Idle Timer.
[NTOS]: Use a synchronization (auto-reset) instead of notification event for the zero page
thread, this way we don't have to reset it manually and query its state. Instead, a
boolean MmZeroingPageThreadActive is checked instead.
[NTOS]: Once we switch to colored lists, major improvements can be done for speed.
Added:
trunk/reactos/ntoskrnl/mm/ARM3/zeropage.c (with props)
Modified:
trunk/reactos/ntoskrnl/ex/init.c
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c
trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
trunk/reactos/ntoskrnl/mm/ARM3/mminit.c
trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
trunk/reactos/ntoskrnl/mm/freelist.c
trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild
Modified: trunk/reactos/ntoskrnl/ex/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/init.c?rev=489…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/init.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ex/init.c [iso-8859-1] Tue Sep 28 16:47:25 2010
@@ -1951,5 +1951,5 @@
Phase1InitializationDiscard(Context);
/* Jump into zero page thread */
- MmZeroPageThreadMain(NULL);
+ MmZeroPageThread();
}
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] Tue Sep 28 16:47:25 2010
@@ -1164,10 +1164,10 @@
BOOLEAN ZeroPages
);
-NTSTATUS
-NTAPI
-MmZeroPageThreadMain(
- PVOID Context
+VOID
+NTAPI
+MmZeroPageThread(
+ VOID
);
/* hypermap.c *****************************************************************/
Modified: trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/i386/init…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c [iso-8859-1] Tue Sep 28 16:47:25 2010
@@ -145,8 +145,6 @@
}
}
-extern KEVENT ZeroPageThreadEvent;
-
NTSTATUS
NTAPI
MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
@@ -496,10 +494,7 @@
/* Initialize the color tables */
MiInitializeColorTables();
-
- /* ReactOS Stuff */
- KeInitializeEvent(&ZeroPageThreadEvent, NotificationEvent, TRUE);
-
+
/* Build the PFN Database */
MiInitializePfnDatabase(LoaderBlock);
MmInitializeBalancer(MmAvailablePages, 0);
Modified: trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/miarm.h?r…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Tue Sep 28 16:47:25 2010
@@ -439,6 +439,8 @@
extern PFN_NUMBER MmSystemPageDirectory[PD_COUNT];
extern PMMPTE MmSharedUserDataPte;
extern LIST_ENTRY MmProcessList;
+extern BOOLEAN MmZeroingPageThreadActive;
+extern KEVENT MmZeroingPageEvent;
#define MI_PFN_TO_PFNENTRY(x) (&MmPfnDatabase[1][x])
#define MI_PFNENTRY_TO_PFN(x) (x - MmPfnDatabase[1])
Modified: trunk/reactos/ntoskrnl/mm/ARM3/mminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/mminit.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] Tue Sep 28 16:47:25 2010
@@ -1811,7 +1811,11 @@
/* Initialize the Loader Lock */
KeInitializeMutant(&MmSystemLoadLock, FALSE);
-
+
+ /* Set the zero page event */
+ KeInitializeEvent(&MmZeroingPageEvent, SynchronizationEvent, FALSE);
+ MmZeroingPageThreadActive = FALSE;
+
//
// Count physical pages on the system
//
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] Tue Sep 28 16:47:25 2010
@@ -397,8 +397,6 @@
return PageIndex;
}
-extern KEVENT ZeroPageThreadEvent;
-
VOID
NTAPI
MiInsertPageInFreeList(IN PFN_NUMBER PageFrameIndex)
@@ -507,10 +505,11 @@
#endif
/* Notify zero page thread if enough pages are on the free list now */
- if ((MmFreePageListHead.Total > 8) &&
!(KeReadStateEvent(&ZeroPageThreadEvent)))
- {
- /* This is ReactOS-specific */
- KeSetEvent(&ZeroPageThreadEvent, IO_NO_INCREMENT, FALSE);
+ if ((ListHead->Total >= 8) && !(MmZeroingPageThreadActive))
+ {
+ /* Set the event */
+ MmZeroingPageThreadActive = TRUE;
+ KeSetEvent(&MmZeroingPageEvent, IO_NO_INCREMENT, FALSE);
}
}
Added: trunk/reactos/ntoskrnl/mm/ARM3/zeropage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/zeropage.…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/zeropage.c (added)
+++ trunk/reactos/ntoskrnl/mm/ARM3/zeropage.c [iso-8859-1] Tue Sep 28 16:47:25 2010
@@ -1,0 +1,98 @@
+/*
+ * PROJECT: ReactOS Kernel
+ * LICENSE: BSD - See COPYING.ARM in the top level directory
+ * FILE: ntoskrnl/mm/ARM3/zeropage.c
+ * PURPOSE: ARM Memory Manager Zero Page Thread Support
+ * PROGRAMMERS: ReactOS Portable Systems Group
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#line 15 "ARM³::ZEROPAGE"
+#define MODULE_INVOLVED_IN_ARM3
+#include "../ARM3/miarm.h"
+
+/* GLOBALS ********************************************************************/
+
+BOOLEAN MmZeroingPageThreadActive;
+KEVENT MmZeroingPageEvent;
+
+/* PRIVATE FUNCTIONS **********************************************************/
+
+VOID
+NTAPI
+MmZeroPageThread(VOID)
+{
+ PKTHREAD Thread = KeGetCurrentThread();
+ //PVOID StartAddress, EndAddress;
+ PVOID WaitObjects[2];
+ NTSTATUS Status;
+ KIRQL OldIrql;
+ PVOID ZeroAddress;
+ PFN_NUMBER PageIndex, FreePage;
+ PMMPFN Pfn1;
+
+ /* FIXME: Get the discardable sections to free them */
+// MiFindInitializationCode(&StartAddress, &EndAddress);
+// if (StartAddress) MiFreeInitializationCode(StartAddress, EndAddress);
+
+ /* Set our priority to 0 */
+ Thread->BasePriority = 0;
+ KeSetPriorityThread(Thread, 0);
+
+ /* Setup the wait objects */
+ WaitObjects[0] = &MmZeroingPageEvent;
+// WaitObjects[1] = &PoSystemIdleTimer; FIXME: Implement idle timer
+
+ while (TRUE)
+ {
+ Status = KeWaitForMultipleObjects(1, // 2
+ WaitObjects,
+ WaitAny,
+ WrFreePage,
+ KernelMode,
+ FALSE,
+ NULL,
+ NULL);
+ OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
+ while (TRUE)
+ {
+ if (!MmFreePageListHead.Total)
+ {
+ MmZeroingPageThreadActive = FALSE;
+ KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
+ break;
+ }
+
+ PageIndex = MmFreePageListHead.Flink;
+ Pfn1 = MiGetPfnEntry(PageIndex);
+ FreePage = MiRemoveAnyPage(0); // FIXME: Use real color
+ if (FreePage != PageIndex)
+ {
+ KeBugCheckEx(PFN_LIST_CORRUPT,
+ 0x8F,
+ FreePage,
+ PageIndex,
+ 0);
+ }
+
+ Pfn1->u1.Flink = LIST_HEAD;
+ KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
+
+ ZeroAddress = MiMapPagesToZeroInHyperSpace(Pfn1, 1);
+ ASSERT(ZeroAddress);
+ RtlZeroMemory(ZeroAddress, PAGE_SIZE);
+ MiUnmapPagesInZeroSpace(ZeroAddress, 1);
+
+ OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
+
+ MiInsertPageInList(&MmZeroedPageListHead, PageIndex);
+ }
+ }
+}
+
+/* EOF */
Propchange: trunk/reactos/ntoskrnl/mm/ARM3/zeropage.c
------------------------------------------------------------------------------
svn:eol-style = native
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] Tue Sep 28 16:47:25 2010
@@ -48,8 +48,6 @@
SIZE_T MmPeakCommitment;
SIZE_T MmtotalCommitLimitMaximum;
-KEVENT ZeroPageThreadEvent;
-static BOOLEAN ZeroPageThreadShouldTerminate = FALSE;
static RTL_BITMAP MiUserPfnBitMap;
/* FUNCTIONS *************************************************************/
@@ -625,72 +623,4 @@
return PfnOffset;
}
-NTSTATUS
-NTAPI
-MmZeroPageThreadMain(PVOID Ignored)
-{
- NTSTATUS Status;
- KIRQL oldIrql;
- PMMPFN Pfn1;
- PFN_NUMBER PageIndex, FreePage;
- ULONG Count;
- PVOID ZeroAddress;
-
- /* Free initial kernel memory */
- //MiFreeInitMemory();
-
- /* Set our priority to 0 */
- KeGetCurrentThread()->BasePriority = 0;
- KeSetPriorityThread(KeGetCurrentThread(), 0);
-
- while(1)
- {
- Status = KeWaitForSingleObject(&ZeroPageThreadEvent,
- 0,
- KernelMode,
- FALSE,
- NULL);
-
- if (ZeroPageThreadShouldTerminate)
- {
- DPRINT1("ZeroPageThread: Terminating\n");
- return STATUS_SUCCESS;
- }
- Count = 0;
- oldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
- while (MmFreePageListHead.Total)
- {
- PageIndex = MmFreePageListHead.Flink;
- Pfn1 = MiGetPfnEntry(PageIndex);
- FreePage = MiRemoveAnyPage(0); // FIXME: Use real color
- if (FreePage != PageIndex)
- {
- KeBugCheckEx(PFN_LIST_CORRUPT,
- 0x8F,
- FreePage,
- PageIndex,
- 0);
- }
-
- Pfn1->u1.Flink = LIST_HEAD;
- KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
-
- ZeroAddress = MiMapPagesToZeroInHyperSpace(Pfn1, 1);
- ASSERT(ZeroAddress);
- RtlZeroMemory(ZeroAddress, PAGE_SIZE);
- MiUnmapPagesInZeroSpace(ZeroAddress, 1);
-
- oldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
-
- MiInsertPageInList(&MmZeroedPageListHead, PageIndex);
- Count++;
- }
- DPRINT("Zeroed %d pages.\n", Count);
- KeResetEvent(&ZeroPageThreadEvent);
- KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
- }
-
- return STATUS_SUCCESS;
-}
-
/* EOF */
Modified: trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl-generic.…
==============================================================================
--- trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild [iso-8859-1] Tue Sep 28 16:47:25 2010
@@ -463,6 +463,7 @@
<file>syspte.c</file>
<file>vadnode.c</file>
<file>virtual.c</file>
+ <file>zeropage.c</file>
</directory>
<file>anonmem.c</file>
<file>balance.c</file>