[ros-diffs] [sir_richard] 46971: [NTOS]: Read almost all the Memory Management variables into the system configuration vector. These includes pool limits, percentages, debugging flags, behavioral changes, and others. [NTOS]: Minimal stubbed support for some large page functionality in case it gets implemented later and these things would've been ignored. One critical change is that now the MmProcessList is initialized, and the system process is added to it. Other processes should be added later. [NTOS]: Add stubbed support for parsing the registry list of drivers that should have large pages enabled. [NTOS]: Initialize the loaded module list before working set work. [NTOS]: Reload the boot drivers much earlier, as part of ARM3 initialization. [NTOS]: Start doing some minor MmResidentAvailablePages accounting during bootup. [NTOS]: Start doing the math required for computing the appropriate MmSystemCacheWsMinimum on the booting system (based on RAM). [NTOS]: Now that we use the HAL heap, add the code to scan it for I/O mappings. These are dangerous because we need to sync up caching attributes (not yet used in ReactOS, so not a problem for now). [NTOS]: Add more header definitions, and helper definitions such as PDE_MAPPED_VA instead of doing the math by hand. [NTOS]: Move MmPageEntireDriver and MmResetDriverPaging to sysldr.c since drvmgmt.c is more for Driver Verifier-style functionality.

sir_richard at svn.reactos.org sir_richard at svn.reactos.org
Wed Apr 21 00:47:52 CEST 2010


Author: sir_richard
Date: Wed Apr 21 00:47:51 2010
New Revision: 46971

URL: http://svn.reactos.org/svn/reactos?rev=46971&view=rev
Log:
[NTOS]: Read almost all the Memory Management variables into the system configuration vector. These includes pool limits, percentages, debugging flags, behavioral changes, and others.
[NTOS]: Minimal stubbed support for some large page functionality in case it gets implemented later and these things would've been ignored. One critical change is that now the MmProcessList is initialized, and the system process is added to it. Other processes should be added later.
[NTOS]: Add stubbed support for parsing the registry list of drivers that should have large pages enabled.
[NTOS]: Initialize the loaded module list before working set work.
[NTOS]: Reload the boot drivers much earlier, as part of ARM3 initialization.
[NTOS]: Start doing some minor MmResidentAvailablePages accounting during bootup.
[NTOS]: Start doing the math required for computing the appropriate MmSystemCacheWsMinimum on the booting system (based on RAM).
[NTOS]: Now that we use the HAL heap, add the code to scan it for I/O mappings. These are dangerous because we need to sync up caching attributes (not yet used in ReactOS, so not a problem for now).
[NTOS]: Add more header definitions, and helper definitions such as PDE_MAPPED_VA instead of doing the math by hand.
[NTOS]: Move MmPageEntireDriver and MmResetDriverPaging to sysldr.c since drvmgmt.c is more for Driver Verifier-style functionality.

Added:
    trunk/reactos/ntoskrnl/mm/ARM3/largepag.c   (with props)
Modified:
    trunk/reactos/ntoskrnl/config/cmdata.c
    trunk/reactos/ntoskrnl/mm/ARM3/drvmgmt.c
    trunk/reactos/ntoskrnl/mm/ARM3/mdlsup.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/ARM3/pool.c
    trunk/reactos/ntoskrnl/mm/freelist.c
    trunk/reactos/ntoskrnl/mm/mminit.c
    trunk/reactos/ntoskrnl/mm/pagefile.c
    trunk/reactos/ntoskrnl/mm/section.c
    trunk/reactos/ntoskrnl/mm/sysldr.c
    trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild

Modified: trunk/reactos/ntoskrnl/config/cmdata.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmdata.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmdata.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmdata.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -11,7 +11,8 @@
 #include "ntoskrnl.h"
 #define NDEBUG
 #include "debug.h"
- 
+#include "./../mm/ARM3/miarm.h"
+
 /* GLOBALS *******************************************************************/
 
 ULONG DummyData;
@@ -252,7 +253,7 @@
     {
         L"Session Manager\\Memory Management",
         L"DynamicMemory",
-        &DummyData,
+        &MmDynamicPfn,
         NULL,
         NULL
     },
@@ -260,7 +261,7 @@
     {
         L"Session Manager\\Memory Management",
         L"Mirroring",
-        &DummyData,
+        &MmMirroring,
         NULL,
         NULL
     },
@@ -275,14 +276,6 @@
 
     {
         L"Session Manager\\Memory Management",
-        L"SessionViewSize",
-        &DummyData,
-        NULL,
-        NULL
-    },
-
-    {
-        L"Session Manager\\Memory Management",
         L"SessionImageSize",
         &DummyData,
         NULL,
@@ -300,7 +293,7 @@
     {
         L"Session Manager\\Memory Management",
         L"PoolUsageMaximum",
-        &DummyData,
+        &MmConsumedPoolPercentage,
         NULL,
         NULL
     },
@@ -308,7 +301,7 @@
     {
         L"Session Manager\\Memory Management",
         L"MapAllocationFragment",
-        &DummyData,
+        &MmAllocationFragment,
         NULL,
         NULL
     },
@@ -316,7 +309,7 @@
     {
         L"Session Manager\\Memory Management",
         L"PagedPoolSize",
-        &DummyData,
+        &MmSizeOfPagedPoolInBytes,
         NULL,
         NULL
     },
@@ -324,7 +317,7 @@
     {
         L"Session Manager\\Memory Management",
         L"NonPagedPoolSize",
-        &DummyData,
+        &MmSizeOfNonPagedPoolInBytes,
         NULL,
         NULL
     },
@@ -340,7 +333,7 @@
     {
         L"Session Manager\\Memory Management",
         L"LargeSystemCache",
-        &DummyData,
+        &MmLargeSystemCache,
         NULL,
         NULL
     },
@@ -356,7 +349,7 @@
     {
         L"Session Manager\\Memory Management",
         L"SystemPages",
-        &DummyData,
+        &MmNumberOfSystemPtes,
         NULL,
         NULL
     },
@@ -364,7 +357,7 @@
     {
         L"Session Manager\\Memory Management",
         L"LowMemoryThreshold",
-        &DummyData,
+        &MmLowMemoryThreshold,
         NULL,
         NULL
     },
@@ -372,7 +365,7 @@
     {
         L"Session Manager\\Memory Management",
         L"HighMemoryThreshold",
-        &DummyData,
+        &MmHighMemoryThreshold,
         NULL,
         NULL
     },
@@ -396,7 +389,7 @@
     {
         L"Session Manager\\Memory Management",
         L"SecondLevelDataCache",
-        &DummyData,
+        &MmSecondaryColors,
         NULL,
         NULL
     },
@@ -404,7 +397,7 @@
     {
         L"Session Manager\\Memory Management",
         L"ClearPageFileAtShutdown",
-        &DummyData,
+        &MmZeroPageFile,
         NULL,
         NULL
     },
@@ -452,7 +445,7 @@
     {
         L"Session Manager\\Memory Management",
         L"ProtectNonPagedPool",
-        &DummyData,
+        &MmProtectFreedNonPagedPool,
         NULL,
         NULL
     },
@@ -460,7 +453,7 @@
     {
         L"Session Manager\\Memory Management",
         L"TrackLockedPages",
-        &DummyData,
+        &MmTrackLockedPages,
         NULL,
         NULL
     },
@@ -468,7 +461,7 @@
     {
         L"Session Manager\\Memory Management",
         L"TrackPtes",
-        &DummyData,
+        &MmTrackPtes,
         NULL,
         NULL
     },
@@ -476,15 +469,15 @@
     {
         L"Session Manager\\Memory Management",
         L"VerifyDrivers",
-        &DummyData,
-        &DummyData,
-        &DummyData
+        MmVerifyDriverBuffer,
+        &MmVerifyDriverBufferLength,
+        &MmVerifyDriverBufferType
     },
 
     {
         L"Session Manager\\Memory Management",
         L"VerifyDriverLevel",
-        &DummyData,
+        &MmVerifyDriverLevel,
         NULL,
         NULL
     },
@@ -508,7 +501,7 @@
     {
         L"Session Manager\\Memory Management",
         L"EnforceWriteProtection",
-        &DummyData,
+        &MmEnforceWriteProtection,
         NULL,
         NULL
     },
@@ -516,7 +509,7 @@
     {
         L"Session Manager\\Memory Management",
         L"MakeLowMemory",
-        &DummyData,
+        &MmMakeLowMemory,
         NULL,
         NULL
     },

Modified: trunk/reactos/ntoskrnl/mm/ARM3/drvmgmt.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/drvmgmt.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/drvmgmt.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/drvmgmt.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -21,55 +21,12 @@
 MM_DRIVER_VERIFIER_DATA MmVerifierData;
 LIST_ENTRY MiVerifierDriverAddedThunkListHead;
 ULONG MiActiveVerifierThunks;
-
-/* PRIVATE FUNCTIONS *********************************************************/
-
-PLDR_DATA_TABLE_ENTRY
-NTAPI
-MiLookupDataTableEntry(IN PVOID Address)
-{
-    PLDR_DATA_TABLE_ENTRY LdrEntry, FoundEntry = NULL;
-    PLIST_ENTRY NextEntry;
-    PAGED_CODE();
-    
-    //
-    // Loop entries
-    //
-    NextEntry = PsLoadedModuleList.Flink;
-    do
-    {
-        //
-        // Get the loader entry
-        //
-        LdrEntry =  CONTAINING_RECORD(NextEntry,
-                                      LDR_DATA_TABLE_ENTRY,
-                                      InLoadOrderLinks);
-        
-        //
-        // Check if the address matches
-        //
-        if ((Address >= LdrEntry->DllBase) &&
-            (Address < (PVOID)((ULONG_PTR)LdrEntry->DllBase +
-                               LdrEntry->SizeOfImage)))
-        {
-            //
-            // Found a match
-            //
-            FoundEntry = LdrEntry;
-            break;
-        }
-        
-        //
-        // Move on
-        //
-        NextEntry = NextEntry->Flink;
-    } while(NextEntry != &PsLoadedModuleList);
-    
-    //
-    // Return the entry
-    //
-    return FoundEntry;
-}
+WCHAR MmVerifyDriverBuffer[512] = {0};
+ULONG MmVerifyDriverBufferLength = sizeof(MmVerifyDriverBuffer);
+ULONG MmVerifyDriverBufferType = REG_NONE;
+ULONG MmVerifyDriverLevel = -1;
+PVOID MmTriageActionTaken;
+PVOID KernelVerifier;
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
@@ -105,68 +62,6 @@
     //
     UNIMPLEMENTED;
     return AddressWithinSection;
-}
-
-/*
- * @unimplemented
- */
-PVOID
-NTAPI
-MmPageEntireDriver(IN PVOID AddressWithinSection)
-{
-    //PMMPTE StartPte, EndPte;
-    PLDR_DATA_TABLE_ENTRY LdrEntry;
-    PAGED_CODE();
-
-    //
-    // Get the loader entry
-    //
-    LdrEntry = MiLookupDataTableEntry(AddressWithinSection);
-    if (!LdrEntry) return NULL;
-
-    //
-    // Check if paging of kernel mode is disabled or if the driver is mapped as
-    // an image
-    //
-    if ((MmDisablePagingExecutive & 0x1) || (LdrEntry->SectionPointer))
-    {
-        //
-        // Don't do anything, just return the base address
-        //
-        return LdrEntry->DllBase;
-    }
-
-    //
-    // Wait for active DPCs to finish before we page out the driver
-    //
-    KeFlushQueuedDpcs();
-
-    //
-    // Get the PTE range for the whole driver image
-    //
-    //StartPte = MiGetPteAddress(LdrEntry->DllBase);
-    //EndPte = MiGetPteAddress(LdrEntry->DllBase +
-    //                         LdrEntry->SizeOfImage);
-
-    //
-    // Enable paging for the PTE range
-    //
-    //MiSetPagingOfDriver(StartPte, EndPte);
-
-    //
-    // Return the base address
-    //
-    return LdrEntry->DllBase;
-}
-
-/*
- * @unimplemented
- */
-VOID
-NTAPI
-MmResetDriverPaging(IN PVOID AddressWithinSection)
-{
-    UNIMPLEMENTED;
 }
 
 /*

Added: trunk/reactos/ntoskrnl/mm/ARM3/largepag.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/largepag.c?rev=46971&view=auto
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/largepag.c (added)
+++ trunk/reactos/ntoskrnl/mm/ARM3/largepag.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -1,0 +1,102 @@
+/*
+ * PROJECT:         ReactOS Kernel
+ * LICENSE:         BSD - See COPYING.ARM in the top level directory
+ * FILE:            ntoskrnl/mm/ARM3/largepag.c
+ * PURPOSE:         ARM Memory Manager Large Page Support
+ * PROGRAMMERS:     ReactOS Portable Systems Group
+ */
+
+/* INCLUDES *******************************************************************/
+
+#include <ntoskrnl.h>
+#define NDEBUG
+#include <debug.h>
+
+#line 15 "ARM³::LARGEPAGE"
+#define MODULE_INVOLVED_IN_ARM3
+#include "../ARM3/miarm.h"
+
+/* GLOBALS ********************************************************************/
+
+LIST_ENTRY MmProcessList;
+PMMPTE MiLargePageHyperPte;
+ULONG MiLargePageRangeIndex;
+MI_LARGE_PAGE_RANGES MiLargePageRanges[64];
+WCHAR MmLargePageDriverBuffer[512] = {0};
+ULONG MmLargePageDriverBufferLength = -1;
+LIST_ENTRY MiLargePageDriverList;
+BOOLEAN MiLargePageAllDrivers;
+
+/* FUNCTIONS ******************************************************************/
+
+VOID
+NTAPI
+MiInitializeLargePageSupport(VOID)
+{
+#if _MI_PAGING_LEVELS > 2
+#error "PAE/x64 Not Implemented"
+#else
+    /* Initialize the large-page hyperspace PTE used for initial mapping */
+    MiLargePageHyperPte = MiReserveSystemPtes(1, SystemPteSpace);
+    ASSERT(MiLargePageHyperPte);
+    MiLargePageHyperPte->u.Long = 0;
+
+    /* Initialize the process tracking list, and insert the system process */
+    InitializeListHead(&MmProcessList);
+    InsertTailList(&MmProcessList, &PsGetCurrentProcess()->MmProcessLinks);
+#endif    
+}
+
+VOID
+NTAPI
+MiSyncCachedRanges(VOID)
+{
+    ULONG i;
+
+    /* Scan every range */
+    for (i = 0; i < MiLargePageRangeIndex; i++)
+    {
+        DPRINT1("No support for large pages\n");
+        while (TRUE);
+    }
+}
+
+VOID
+NTAPI
+MiInitializeDriverLargePageList(VOID)
+{
+    PWCHAR p, pp;
+
+    /* Initialize the list */
+    InitializeListHead(&MiLargePageDriverList);
+
+    /* Bail out if there's nothing */
+    if (MmLargePageDriverBufferLength == 0xFFFFFFFF) return;
+
+    /* Loop from start to finish */
+    p = MmLargePageDriverBuffer;
+    pp = MmLargePageDriverBuffer + (MmLargePageDriverBufferLength / sizeof(WCHAR));
+    while (p < pp)
+    {
+        /* Skip whitespaces */
+        if ((*p == L' ') || (*p == L'\n') || (*p == L'\r') || (*p == L'\t'))
+        {
+            /* Skip the character */
+            p++;
+            continue;
+        }
+        
+        /* A star means everything */
+        if (*p == L'*')
+        {
+            /* No need to keep going */
+            MiLargePageAllDrivers = TRUE;
+            break;
+        }
+        
+        DPRINT1("Large page drivers not supported\n");
+        ASSERT(FALSE);
+    }
+}
+
+/* EOF */

Propchange: trunk/reactos/ntoskrnl/mm/ARM3/largepag.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/reactos/ntoskrnl/mm/ARM3/mdlsup.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/mdlsup.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/mdlsup.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/mdlsup.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -15,6 +15,9 @@
 #line 15 "ARM³::MDLSUP"
 #define MODULE_INVOLVED_IN_ARM3
 #include "../ARM3/miarm.h"
+
+BOOLEAN MmTrackPtes;
+BOOLEAN MmTrackLockedPages;
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 

Modified: trunk/reactos/ntoskrnl/mm/ARM3/miarm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/miarm.h?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -41,6 +41,9 @@
 /* Make the code cleaner with some definitions for size multiples */
 #define _1KB (1024)
 #define _1MB (1024 * _1KB)
+
+/* Are mapped by a PDE */
+#define PDE_MAPPED_VA   (PTE_COUNT * PAGE_SIZE)
 
 /* Size of a PDE directory, and size of a page table */
 #define PDE_SIZE (PDE_COUNT * sizeof(MMPDE))
@@ -58,6 +61,40 @@
 #else
 #error Define these please!
 #endif
+
+#ifdef _M_IX86
+#define IMAGE_FILE_MACHINE_NATIVE   IMAGE_FILE_MACHINE_I386
+#elif _M_ARM
+#define IMAGE_FILE_MACHINE_NATIVE   IMAGE_FILE_MACHINE_ARM
+#elif _M_AMD64
+#define IMAGE_FILE_MACHINE_NATIVE   IMAGE_FILE_MACHINE_AMD64
+#else
+#error Define these please!
+#endif
+
+//
+// Protection Bits part of the internal memory manager Protection Mask
+// Taken from http://www.reactos.org/wiki/Techwiki:Memory_management_in_the_Windows_XP_kernel
+// and public assertions.
+//
+#define MM_ZERO_ACCESS         0
+#define MM_READONLY            1 
+#define MM_EXECUTE             2 
+#define MM_EXECUTE_READ        3 
+#define MM_READWRITE           4
+#define MM_WRITECOPY           5 
+#define MM_EXECUTE_READWRITE   6 
+#define MM_EXECUTE_WRITECOPY   7 
+#define MM_NOCACHE             8 
+#define MM_DECOMMIT            0x10 
+#define MM_NOACCESS            (MM_DECOMMIT | MM_NOCACHE)
+
+//
+// Special values for LoadedImports
+//
+#define MM_SYSLDR_NO_IMPORTS   (PVOID)0xFFFFFFFE
+#define MM_SYSLDR_BOOT_LOADED  (PVOID)0xFFFFFFFF
+#define MM_SYSLDR_SINGLE_ENTRY 0x1
 
 //
 // PFN List Sentinel
@@ -168,10 +205,34 @@
     PFN_NUMBER Count;
 } MMCOLOR_TABLES, *PMMCOLOR_TABLES;
 
+typedef struct _MI_LARGE_PAGE_RANGES
+{
+    PFN_NUMBER StartFrame;
+    PFN_NUMBER LastFrame;
+} MI_LARGE_PAGE_RANGES, *PMI_LARGE_PAGE_RANGES;
+
 extern MMPTE HyperTemplatePte;
 extern MMPTE ValidKernelPde;
 extern MMPTE ValidKernelPte;
-
+extern BOOLEAN MmLargeSystemCache;
+extern BOOLEAN MmZeroPageFile;
+extern BOOLEAN MmProtectFreedNonPagedPool;
+extern BOOLEAN MmTrackLockedPages;
+extern BOOLEAN MmTrackPtes;
+extern BOOLEAN MmDynamicPfn;
+extern BOOLEAN MmMirroring;
+extern BOOLEAN MmMakeLowMemory;
+extern BOOLEAN MmEnforceWriteProtection;
+extern ULONG MmAllocationFragment;
+extern ULONG MmConsumedPoolPercentage;
+extern ULONG MmVerifyDriverBufferType;
+extern ULONG MmVerifyDriverLevel;
+extern WCHAR MmVerifyDriverBuffer[512];
+extern WCHAR MmLargePageDriverBuffer[512];
+extern LIST_ENTRY MiLargePageDriverList;
+extern BOOLEAN MiLargePageAllDrivers;
+extern ULONG MmVerifyDriverBufferLength;
+extern ULONG MmLargePageDriverBufferLength;
 extern ULONG MmSizeOfNonPagedPoolInBytes;
 extern ULONG MmMaximumNonPagedPoolInBytes;
 extern PFN_NUMBER MmMaximumNonPagedPoolInPages;
@@ -243,10 +304,31 @@
 extern PFN_NUMBER MmPlentyFreePages;
 extern PFN_NUMBER MiExpansionPoolPagesInitialCharge;
 extern PFN_NUMBER MmResidentAvailablePages;
-extern PFN_NUMBER MmResidentAvailablePagesAtInit;
+extern PFN_NUMBER MmResidentAvailableAtInit;
+extern ULONG MmTotalFreeSystemPtes[MaximumPtePoolTypes];
+extern PFN_NUMBER MmTotalSystemDriverPages;
+extern PVOID MiSessionImageStart;
+extern PVOID MiSessionImageEnd;
 
 #define MI_PFN_TO_PFNENTRY(x)     (&MmPfnDatabase[1][x])
 #define MI_PFNENTRY_TO_PFN(x)     (x - MmPfnDatabase[1])
+
+#define MI_IS_SESSION_IMAGE_ADDRESS(Address) \
+    (((Address) >= MiSessionImageStart) && ((Address) < MiSessionImageEnd))
+
+#define MI_IS_SESSION_ADDRESS(Address) \
+    (((Address) >= MmSessionBase) && ((Address) < MiSessionSpaceEnd))
+        
+FORCEINLINE
+BOOLEAN
+MI_IS_PHYSICAL_ADDRESS(IN PVOID Address)
+{
+    PMMPDE PointerPde;
+    
+    /* Large pages are never paged out, always physically resident */
+    PointerPde = MiAddressToPde(Address);
+    return ((PointerPde->u.Hard.LargePage) && (PointerPde->u.Hard.Valid));
+}
 
 NTSTATUS
 NTAPI
@@ -457,4 +539,28 @@
     IN PFN_NUMBER PageFrameIndex
 );
 
+PLDR_DATA_TABLE_ENTRY
+NTAPI
+MiLookupDataTableEntry(
+    IN PVOID Address
+);
+
+VOID
+NTAPI
+MiInitializeDriverLargePageList(
+    VOID
+);
+
+VOID
+NTAPI
+MiInitializeLargePageSupport(
+    VOID
+);
+
+VOID
+NTAPI
+MiSyncCachedRanges(
+    VOID
+);
+
 /* EOF */

Modified: trunk/reactos/ntoskrnl/mm/ARM3/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/mminit.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -300,6 +300,20 @@
 /* These values store the type of system this is (small, med, large) and if server */
 ULONG MmProductType;
 MM_SYSTEMSIZE MmSystemSize;
+
+/*
+ * These values store the cache working set minimums and maximums, in pages
+ *
+ * The minimum value is boosted on systems with more than 24MB of RAM, and cut
+ * down to only 32 pages on embedded (<24MB RAM) systems.
+ *
+ * An extra boost of 2MB is given on systems with more than 33MB of RAM.
+ */
+PFN_NUMBER MmSystemCacheWsMinimum = 288;
+PFN_NUMBER MmSystemCacheWsMaximum = 350;
+
+/* FIXME: Move to cache/working set code later */
+BOOLEAN MmLargeSystemCache;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 
@@ -742,7 +756,7 @@
         else
         {
             /* Next PDE mapped address */
-            BaseAddress += PTE_COUNT * PAGE_SIZE;
+            BaseAddress += PDE_MAPPED_VA;
         }
         
         /* Next PTE */
@@ -1161,6 +1175,61 @@
 
 VOID
 NTAPI
+MiAddHalIoMappings(VOID)
+{
+    PVOID BaseAddress;
+    PMMPTE PointerPde;
+    PMMPTE PointerPte;
+    ULONG i, j, PdeCount;
+    PFN_NUMBER PageFrameIndex;
+
+    /* HAL Heap address -- should be on a PDE boundary */
+    BaseAddress = (PVOID)0xFFC00000;
+    ASSERT(MiAddressToPteOffset(BaseAddress) == 0);
+
+    /* Check how many PDEs the heap has */
+    PointerPde = MiAddressToPde(BaseAddress);
+    PdeCount = PDE_COUNT - ADDR_TO_PDE_OFFSET(BaseAddress);
+    for (i = 0; i < PdeCount; i++)
+    {
+        /* Does the HAL own this mapping? */
+        if ((PointerPde->u.Hard.Valid == 1) &&
+            (PointerPde->u.Hard.LargePage == 0))
+        {
+            /* Get the PTE for it and scan each page */
+            PointerPte = MiAddressToPte(BaseAddress);
+            for (j = 0 ; j < PTE_COUNT; j++)
+            {
+                /* Does the HAL own this page? */
+                if (PointerPte->u.Hard.Valid == 1)
+                {
+                    /* Is the HAL using it for device or I/O mapped memory? */
+                    PageFrameIndex = PFN_FROM_PTE(PointerPte);
+                    if (!MiGetPfnEntry(PageFrameIndex))
+                    {
+                        /* FIXME: For PAT, we need to track I/O cache attributes for coherency */
+                        DPRINT1("HAL I/O Mapping at %p is unsafe\n", BaseAddress);
+                    }
+                }
+
+                /* Move to the next page */
+                BaseAddress = (PVOID)((ULONG_PTR)BaseAddress + PAGE_SIZE);
+                PointerPte++;
+            }
+        }
+        else
+        {
+            /* Move to the next address */
+            BaseAddress = (PVOID)((ULONG_PTR)BaseAddress + PDE_MAPPED_VA);
+        }
+
+        /* Move to the next PDE */
+        PointerPde++;
+    }
+}
+
+VOID
+NTAPI
 MmDumpArmPfnDatabase(VOID)
 {
     ULONG i;
@@ -1813,11 +1882,26 @@
             }
         }
         
-        //
-        // Size up paged pool and build the shadow system page directory
-        //
-        MiBuildPagedPool();
-        
+        /* Look for large page cache entries that need caching */
+        MiSyncCachedRanges();
+
+        /* Loop for HAL Heap I/O device mappings that need coherency tracking */
+        MiAddHalIoMappings();
+
+        /* Set the initial resident page count */
+        MmResidentAvailablePages = MmAvailablePages - 32;
+
+        /* Initialize large page structures on PAE/x64, and MmProcessList on x86 */
+        MiInitializeLargePageSupport();
+
+        /* Check if the registry says any drivers should be loaded with large pages */
+        MiInitializeDriverLargePageList();
+
+        /* Relocate the boot drivers into system PTE space and fixup their PFNs */
+        MiReloadBootLoadedDrivers(LoaderBlock);
+
+        /* FIXME: Call out into Driver Verifier for initialization  */
+
         /* Check how many pages the system has */
         if (MmNumberOfPhysicalPages <= (13 * _1MB))
         {
@@ -1826,13 +1910,22 @@
         }
         else if (MmNumberOfPhysicalPages <= (19 * _1MB))
         {
-            /* Set small system */
+            /* Set small system and add 100 pages for the cache */
             MmSystemSize = MmSmallSystem;
+            MmSystemCacheWsMinimum += 100;
         }
         else
         {
-            /* Set medium system */
+            /* Set medium system and add 400 pages for the cache */
             MmSystemSize = MmMediumSystem;
+            MmSystemCacheWsMinimum += 400;
+        }
+        
+        /* Check for less than 24MB */
+        if (MmNumberOfPhysicalPages < ((24 * _1MB) / PAGE_SIZE))
+        {
+            /* No more than 32 pages */
+            MmSystemCacheWsMinimum = 32;
         }
 
         /* Check for more than 32MB */
@@ -1854,7 +1947,14 @@
                 }
             }
         }
-
+        
+        /* Check for more than 33 MB */
+        if (MmNumberOfPhysicalPages > ((33 * _1MB) / PAGE_SIZE))
+        {
+            /* Add another 500 pages to the cache */
+            MmSystemCacheWsMinimum += 500;
+        }
+        
         /* Now setup the shared user data fields */
         ASSERT(SharedUserData->NumberOfPhysicalPages == 0);
         SharedUserData->NumberOfPhysicalPages = MmNumberOfPhysicalPages;
@@ -1888,6 +1988,20 @@
 
         /* Update working set tuning parameters */
         MiAdjustWorkingSetManagerParameters(!MmProductType);
+
+        /* Finetune the page count by removing working set and NP expansion */
+        MmResidentAvailablePages -= MiExpansionPoolPagesInitialCharge;
+        MmResidentAvailablePages -= MmSystemCacheWsMinimum;
+        MmResidentAvailableAtInit = MmResidentAvailablePages;
+        if (MmResidentAvailablePages <= 0)
+        {
+            /* This should not happen */
+            DPRINT1("System cache working set too big\n");
+            return FALSE;
+        }
+        
+        /* Size up paged pool and build the shadow system page directory */
+        MiBuildPagedPool();
     }
     
     //

Modified: trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/pfnlist.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -17,6 +17,9 @@
 #include "../ARM3/miarm.h"
 
 /* GLOBALS ********************************************************************/
+
+BOOLEAN MmDynamicPfn;
+BOOLEAN MmMirroring;
 
 MMPFNLIST MmZeroedPageListHead = {0, ZeroedPageList, LIST_HEAD, LIST_HEAD};
 MMPFNLIST MmFreePageListHead = {0, FreePageList, LIST_HEAD, LIST_HEAD};

Modified: trunk/reactos/ntoskrnl/mm/ARM3/pool.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/pool.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/pool.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/pool.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -26,6 +26,8 @@
 MM_PAGED_POOL_INFO MmPagedPoolInfo;
 SIZE_T MmAllocatedNonPagedPool;
 ULONG MmSpecialPoolTag;
+ULONG MmConsumedPoolPercentage;
+BOOLEAN MmProtectFreedNonPagedPool;
 
 /* PRIVATE FUNCTIONS **********************************************************/
 

Modified: trunk/reactos/ntoskrnl/mm/freelist.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/freelist.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -36,8 +36,9 @@
 /* The first array contains ReactOS PFNs, the second contains ARM3 PFNs */
 PPHYSICAL_PAGE MmPfnDatabase[2];
 
-ULONG MmAvailablePages;
-ULONG MmResidentAvailablePages;
+PFN_NUMBER MmAvailablePages;
+PFN_NUMBER MmResidentAvailablePages;
+PFN_NUMBER MmResidentAvailableAtInit;
 
 SIZE_T MmTotalCommitLimit;
 SIZE_T MmTotalCommittedPages;

Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -398,15 +398,12 @@
         /* Initialize paged pool */
         MmInitializePagedPool();
         
+        /* Initialize the loaded module list */
+        MiInitializeLoadedModuleList(LoaderBlock);
+        
         /* Initialize working sets */
         MiInitializeUserPfnBitmap();
         MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
-
-        /* Reload boot drivers */
-        MiReloadBootLoadedDrivers(LoaderBlock);
-
-        /* Initialize the loaded module list */
-        MiInitializeLoadedModuleList(LoaderBlock);
     }
     else if (Phase == 1)
     {

Modified: trunk/reactos/ntoskrnl/mm/pagefile.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/pagefile.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/pagefile.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/pagefile.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -86,6 +86,8 @@
 /* Number of pages that have been allocated for swapping */
 ULONG MiUsedSwapPages;
 
+BOOLEAN MmZeroPageFile;
+
 /*
  * Number of pages that have been reserved for swapping but not yet allocated
  */

Modified: trunk/reactos/ntoskrnl/mm/section.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -70,6 +70,8 @@
 /* GLOBALS *******************************************************************/
 
 POBJECT_TYPE MmSectionObjectType = NULL;
+
+BOOLEAN MmAllocationFragment;
 
 ULONG_PTR MmSubsectionBase;
 

Modified: trunk/reactos/ntoskrnl/mm/sysldr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/sysldr.c?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/sysldr.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/sysldr.c [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -43,6 +43,9 @@
 PVOID MmLastUnloadedDrivers;
 PVOID MmTriageActionTaken;
 PVOID KernelVerifier;
+
+BOOLEAN MmMakeLowMemory;
+BOOLEAN MmEnforceWriteProtection = TRUE;
 
 /* FUNCTIONS ******************************************************************/
 
@@ -2040,6 +2043,87 @@
     return Status;
 }
 
+PLDR_DATA_TABLE_ENTRY
+NTAPI
+MiLookupDataTableEntry(IN PVOID Address)
+{
+    PLDR_DATA_TABLE_ENTRY LdrEntry, FoundEntry = NULL;
+    PLIST_ENTRY NextEntry;
+    PAGED_CODE();
+    
+    /* Loop entries */
+    NextEntry = PsLoadedModuleList.Flink;
+    do
+    {
+        /* Get the loader entry */
+        LdrEntry =  CONTAINING_RECORD(NextEntry,
+                                      LDR_DATA_TABLE_ENTRY,
+                                      InLoadOrderLinks);
+        
+        /* Check if the address matches */
+        if ((Address >= LdrEntry->DllBase) &&
+            (Address < (PVOID)((ULONG_PTR)LdrEntry->DllBase +
+                               LdrEntry->SizeOfImage)))
+        {
+            /* Found a match */
+            FoundEntry = LdrEntry;
+            break;
+        }
+        
+        /* Move on */
+        NextEntry = NextEntry->Flink;
+    } while(NextEntry != &PsLoadedModuleList);
+    
+    /* Return the entry */
+    return FoundEntry;
+}
+
+/*
+ * @implemented
+ */
+PVOID
+NTAPI
+MmPageEntireDriver(IN PVOID AddressWithinSection)
+{
+    PMMPTE StartPte, EndPte;
+    PLDR_DATA_TABLE_ENTRY LdrEntry;
+    PAGED_CODE();
+
+    /* Get the loader entry */
+    LdrEntry = MiLookupDataTableEntry(AddressWithinSection);
+    if (!LdrEntry) return NULL;
+
+    /* Check if paging of kernel mode is disabled or if the driver is mapped as an image */
+    if ((MmDisablePagingExecutive) || (LdrEntry->SectionPointer))
+    {
+        /* Don't do anything, just return the base address */
+        return LdrEntry->DllBase;
+    }
+
+    /* Wait for active DPCs to finish before we page out the driver */
+    KeFlushQueuedDpcs();
+
+    /* Get the PTE range for the whole driver image */
+    StartPte = MiAddressToPte((ULONG_PTR)LdrEntry->DllBase);
+    EndPte = MiAddressToPte((ULONG_PTR)LdrEntry->DllBase + LdrEntry->SizeOfImage);
+#if 0
+    /* Enable paging for the PTE range */
+    ASSERT(MI_IS_SESSION_IMAGE_ADDRESS(AddressWithinSection) == FALSE);
+    MiSetPagingOfDriver(StartPte, EndPte);
+#endif
+    /* Return the base address */
+    return LdrEntry->DllBase;
+}
+
+/*
+ * @unimplemented
+ */
+VOID
+NTAPI
+MmResetDriverPaging(IN PVOID AddressWithinSection)
+{
+    UNIMPLEMENTED;
+}
 /*
  * @implemented
  */

Modified: trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild?rev=46971&r1=46970&r2=46971&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ntoskrnl-generic.rbuild [iso-8859-1] Wed Apr 21 00:47:51 2010
@@ -394,6 +394,7 @@
 			<file>expool.c</file>
 			<file>hypermap.c</file>
 			<file>iosup.c</file>
+			<file>largepag.c</file>
 			<file>mdlsup.c</file>
 			<file>mminit.c</file>
 			<file>mmsup.c</file>




More information about the Ros-diffs mailing list