Author: ros-arm-bringup
Date: Thu Feb 14 22:24:02 2008
New Revision: 32360
URL:
http://svn.reactos.org/svn/reactos?rev=32360&view=rev
Log:
Prepare for getting rid of the Freelist hacks and use memory descriptors instead, by
detecting the highest free memory descriptor, and allocating the page array PTEs from
there (gets rid of the "LastPage" variable).
Modified:
trunk/reactos/ntoskrnl/mm/freelist.c
trunk/reactos/ntoskrnl/mm/mminit.c
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 (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c Thu Feb 14 22:24:02 2008
@@ -280,21 +280,22 @@
PVOID
INIT_FUNCTION
NTAPI
-MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
- ULONG_PTR LastPhysKernelAddress,
- ULONG MemorySizeInPages,
- ULONG_PTR LastKernelAddress,
- PADDRESS_RANGE BIOSMemoryMap,
- ULONG AddressRangeCount)
+MmInitializePageList(IN ULONG_PTR FirstPhysKernelAddress,
+ IN ULONG_PTR LastPhysKernelAddress,
+ IN ULONG HighestPage,
+ IN ULONG_PTR LastKernelAddress,
+ IN PADDRESS_RANGE BIOSMemoryMap,
+ IN ULONG AddressRangeCount)
{
ULONG i;
ULONG Reserved;
NTSTATUS Status;
- PFN_TYPE LastPage, Pfn = 0;
+ PFN_TYPE Pfn = 0;
ULONG PdeStart = PsGetCurrentProcess()->Pcb.DirectoryTableBase.LowPart;
ULONG PdePageStart, PdePageEnd;
ULONG VideoPageStart, VideoPageEnd;
ULONG KernelPageStart, KernelPageEnd;
+ extern PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
/* Initialize the page lists */
KeInitializeSpinLock(&PageListLock);
@@ -303,7 +304,7 @@
InitializeListHead(&FreeZeroedPageListHead);
/* Set the size and start of the PFN Database */
- MmPageArraySize = MemorySizeInPages;
+ MmPageArraySize = HighestPage;
MmPageArray = (PHYSICAL_PAGE *)LastKernelAddress;
Reserved = PAGE_ROUND_UP((MmPageArraySize * sizeof(PHYSICAL_PAGE))) / PAGE_SIZE;
@@ -311,10 +312,6 @@
LastKernelAddress = ((ULONG_PTR)LastKernelAddress + (Reserved * PAGE_SIZE));
LastPhysKernelAddress = (ULONG_PTR)LastPhysKernelAddress + (Reserved * PAGE_SIZE);
- /* Find the highest usable page */
- LastPage = MmPageArraySize;
- while (TRUE) if (MiIsPfnRam(BIOSMemoryMap, AddressRangeCount, --LastPage)) break;
-
/* Loop every page required to hold the PFN database */
for (i = 0; i < Reserved; i++)
{
@@ -324,7 +321,8 @@
if (!MmIsPagePresent(NULL, Address))
{
/* Use one of our highest usable pages */
- Pfn = LastPage--;
+ Pfn = MiFreeDescriptor->BasePage + MiFreeDescriptor->PageCount - 1;
+ MiFreeDescriptor->PageCount--;
/* Set the PFN */
Status = MmCreateVirtualMappingForKernel(Address,
@@ -422,7 +420,7 @@
MmPageArray[i].MapCount = 1;
MmStats.NrSystemPages++;
}
- else if (i > LastPage)
+ else if (i > (MiFreeDescriptor->BasePage +
MiFreeDescriptor->PageCount - 1))
{
/* These are pages we allocated above to hold the PFN DB */
MmPageArray[i].Flags.Type = MM_PHYSICAL_PAGE_USED;
Modified: trunk/reactos/ntoskrnl/mm/mminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mminit.c?rev=3…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mminit.c (original)
+++ trunk/reactos/ntoskrnl/mm/mminit.c Thu Feb 14 22:24:02 2008
@@ -50,6 +50,7 @@
PVOID MiNonPagedPoolStart;
ULONG MiNonPagedPoolLength;
ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
+PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
extern KMUTANT MmSystemLoadLock;
BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_
@@ -207,6 +208,7 @@
{
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Md;
+ ULONG FreePages = 0;
for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
@@ -240,6 +242,21 @@
/* Update the highest page */
MmHighestPhysicalPage = Md->BasePage + Md->PageCount - 1;
}
+
+ /* Check if this is free memory */
+ if ((Md->MemoryType == LoaderFree) ||
+ (Md->MemoryType == LoaderLoadedProgram) ||
+ (Md->MemoryType == LoaderFirmwareTemporary) ||
+ (Md->MemoryType == LoaderOsloaderStack))
+ {
+ /* Check if this is the largest memory descriptor */
+ if (Md->PageCount > FreePages)
+ {
+ /* For now, it is */
+ FreePages = Md->PageCount;
+ MiFreeDescriptor = Md;
+ }
+ }
}
}
}