Author: tkreuzer
Date: Sat Sep 24 00:12:58 2011
New Revision: 53822
URL:
http://svn.reactos.org/svn/reactos?rev=53822&view=rev
Log:
[NTOSKRNL]
Add MiScanMemoryDescriptors, that combines the work of MiPagesInLoaderBlock, the loop in
MmInitializeMemoryLimits and the loop in MiInitMachineDependent.
Modified:
trunk/reactos/ntoskrnl/mm/ARM3/i386/init.c
trunk/reactos/ntoskrnl/mm/ARM3/mminit.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] Sat Sep 24 00:12:58 2011
@@ -28,6 +28,8 @@
/* Template PTE for prototype page */
MMPTE PrototypePte = {{(MM_READWRITE << MM_PTE_SOFTWARE_PROTECTION_BITS) |
PTE_PROTOTYPE | (MI_PTE_LOOKUP_NEEDED << PAGE_SHIFT)}};
+
+extern PFN_NUMBER MiNumberOfFreePages;
/* PRIVATE FUNCTIONS **********************************************************/
@@ -152,9 +154,6 @@
INIT_FUNCTION
MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
- PLIST_ENTRY NextEntry;
- PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
- ULONG FreePages = 0;
PFN_NUMBER PageFrameIndex;
PMMPTE StartPde, EndPde, PointerPte, LastPte;
MMPTE TempPde, TempPte;
@@ -190,101 +189,8 @@
EndPde = MiAddressToPde(KSEG0_BASE);
RtlZeroMemory(StartPde, (EndPde - StartPde) * sizeof(MMPTE));
- //
- // Loop the memory descriptors
- //
- NextEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
- while (NextEntry != &LoaderBlock->MemoryDescriptorListHead)
- {
- //
- // Get the memory block
- //
- MdBlock = CONTAINING_RECORD(NextEntry,
- MEMORY_ALLOCATION_DESCRIPTOR,
- ListEntry);
-
- //
- // Skip invisible memory
- //
- if ((MdBlock->MemoryType != LoaderFirmwarePermanent) &&
- (MdBlock->MemoryType != LoaderSpecialMemory) &&
- (MdBlock->MemoryType != LoaderHALCachedMemory) &&
- (MdBlock->MemoryType != LoaderBBTMemory))
- {
- //
- // Check if BURNMEM was used
- //
- if (MdBlock->MemoryType != LoaderBad)
- {
- //
- // Count this in the total of pages
- //
- MmNumberOfPhysicalPages += MdBlock->PageCount;
- }
-
- //
- // Check if this is the new lowest page
- //
- if (MdBlock->BasePage < MmLowestPhysicalPage)
- {
- //
- // Update the lowest page
- //
- MmLowestPhysicalPage = MdBlock->BasePage;
- }
-
- //
- // Check if this is the new highest page
- //
- PageFrameIndex = MdBlock->BasePage + MdBlock->PageCount;
- if (PageFrameIndex > MmHighestPhysicalPage)
- {
- //
- // Update the highest page
- //
- MmHighestPhysicalPage = PageFrameIndex - 1;
- }
-
- //
- // Check if this is free memory
- //
- if ((MdBlock->MemoryType == LoaderFree) ||
- (MdBlock->MemoryType == LoaderLoadedProgram) ||
- (MdBlock->MemoryType == LoaderFirmwareTemporary) ||
- (MdBlock->MemoryType == LoaderOsloaderStack))
- {
- //
- // Check if this is the largest memory descriptor
- //
- if (MdBlock->PageCount > FreePages)
- {
- //
- // For now, it is
- //
- MxFreeDescriptor = MdBlock;
- }
-
- //
- // More free pages
- //
- FreePages += MdBlock->PageCount;
- }
- }
-
- //
- // Keep going
- //
- NextEntry = MdBlock->ListEntry.Flink;
- }
-
- //
- // Save original values of the free descriptor, since it'll be
- // altered by early allocations
- //
- MxOldFreeDescriptor = *MxFreeDescriptor;
-
/* Compute non paged pool limits and size */
- MiComputeNonPagedPoolVa(FreePages);
+ MiComputeNonPagedPoolVa(MiNumberOfFreePages);
/* Compute color information (L2 cache-separated paging lists) */
MiComputeColorInformation();
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] Sat Sep 24 00:12:58 2011
@@ -364,7 +364,93 @@
FALSE;
#endif
+/* Number of memory descriptors in the loader block */
+ULONG MiNumberDescriptors = 0;
+
+/* Number of free pages in the loader block */
+PFN_NUMBER MiNumberOfFreePages = 0;
+
+
/* PRIVATE FUNCTIONS **********************************************************/
+
+VOID
+NTAPI
+MiScanMemoryDescriptors(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
+{
+ PLIST_ENTRY ListEntry;
+ PMEMORY_ALLOCATION_DESCRIPTOR Descriptor;
+ PFN_NUMBER PageFrameIndex, FreePages = 0;
+
+ /* Loop the memory descriptors */
+ for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
+ ListEntry != &LoaderBlock->MemoryDescriptorListHead;
+ ListEntry = ListEntry->Flink)
+ {
+ /* Get the descriptor */
+ Descriptor = CONTAINING_RECORD(ListEntry,
+ MEMORY_ALLOCATION_DESCRIPTOR,
+ ListEntry);
+ DPRINT("MD Type: %lx Base: %lx Count: %lx\n",
+ Descriptor->MemoryType, Descriptor->BasePage,
Descriptor->PageCount);
+
+ /* Count this descriptor */
+ MiNumberDescriptors++;
+
+ /* Check if this is invisible memory */
+ if ((Descriptor->MemoryType == LoaderFirmwarePermanent) &&
+ (Descriptor->MemoryType == LoaderSpecialMemory) &&
+ (Descriptor->MemoryType == LoaderHALCachedMemory) &&
+ (Descriptor->MemoryType == LoaderBBTMemory))
+ {
+ /* Skip this descriptor */
+ continue;
+ }
+
+ /* Check if this is bad memory */
+ if (Descriptor->MemoryType != LoaderBad)
+ {
+ /* Count this in the total of pages */
+ MmNumberOfPhysicalPages += Descriptor->PageCount;
+ }
+
+ /* Check if this is the new lowest page */
+ if (Descriptor->BasePage < MmLowestPhysicalPage)
+ {
+ /* Update the lowest page */
+ MmLowestPhysicalPage = Descriptor->BasePage;
+ }
+
+ /* Check if this is the new highest page */
+ PageFrameIndex = Descriptor->BasePage + Descriptor->PageCount;
+ if (PageFrameIndex > MmHighestPhysicalPage)
+ {
+ /* Update the highest page */
+ MmHighestPhysicalPage = PageFrameIndex - 1;
+ }
+
+ /* Check if this is free memory */
+ if ((Descriptor->MemoryType == LoaderFree) ||
+ (Descriptor->MemoryType == LoaderLoadedProgram) ||
+ (Descriptor->MemoryType == LoaderFirmwareTemporary) ||
+ (Descriptor->MemoryType == LoaderOsloaderStack))
+ {
+ /* Count it too free pages */
+ MiNumberOfFreePages += Descriptor->PageCount;
+
+ /* Check if this is the largest memory descriptor */
+ if (Descriptor->PageCount > FreePages)
+ {
+ /* Remember it */
+ MxFreeDescriptor = Descriptor;
+ FreePages = Descriptor->PageCount;
+ }
+ }
+ }
+
+ /* Save original values of the free descriptor, since it'll be
+ * altered by early allocations */
+ MxOldFreeDescriptor = *MxFreeDescriptor;
+}
PFN_NUMBER
NTAPI
@@ -1375,48 +1461,6 @@
KeLowerIrql(OldIrql);
}
-PFN_NUMBER
-NTAPI
-MiPagesInLoaderBlock(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
- IN PBOOLEAN IncludeType)
-{
- PLIST_ENTRY NextEntry;
- PFN_NUMBER PageCount = 0;
- PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
-
- //
- // Now loop through the descriptors
- //
- NextEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
- while (NextEntry != &LoaderBlock->MemoryDescriptorListHead)
- {
- //
- // Grab each one, and check if it's one we should include
- //
- MdBlock = CONTAINING_RECORD(NextEntry,
- MEMORY_ALLOCATION_DESCRIPTOR,
- ListEntry);
- if ((MdBlock->MemoryType < LoaderMaximum) &&
- (IncludeType[MdBlock->MemoryType]))
- {
- //
- // Add this to our running total
- //
- PageCount += MdBlock->PageCount;
- }
-
- //
- // Try the next descriptor
- //
- NextEntry = MdBlock->ListEntry.Flink;
- }
-
- //
- // Return the total
- //
- return PageCount;
-}
-
PPHYSICAL_MEMORY_DESCRIPTOR
NTAPI
INIT_FUNCTION
@@ -1424,23 +1468,15 @@
IN PBOOLEAN IncludeType)
{
PLIST_ENTRY NextEntry;
- ULONG Run = 0, InitialRuns = 0;
+ ULONG Run = 0, InitialRuns;
PFN_NUMBER NextPage = -1, PageCount = 0;
PPHYSICAL_MEMORY_DESCRIPTOR Buffer, NewBuffer;
PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
//
- // Scan the memory descriptors
- //
- NextEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
- while (NextEntry != &LoaderBlock->MemoryDescriptorListHead)
- {
- //
- // For each one, increase the memory allocation estimate
- //
- InitialRuns++;
- NextEntry = NextEntry->Flink;
- }
+ // Start with the maximum we might need
+ //
+ InitialRuns = MiNumberDescriptors;
//
// Allocate the maximum we'll ever need
@@ -1970,7 +2006,8 @@
//
// Count physical pages on the system
//
- PageCount = MiPagesInLoaderBlock(LoaderBlock, IncludeType);
+ MiScanMemoryDescriptors(LoaderBlock);
+ PageCount = MmNumberOfPhysicalPages;
//
// Check if this is a machine with less than 19MB of RAM