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).

svn path=/trunk/; revision=32360
This commit is contained in:
ReactOS Portable Systems Group
2008-02-14 19:24:02 +00:00
parent 7ca0ac88f8
commit b4a63ba74a
2 changed files with 29 additions and 14 deletions
+12 -14
View File
@@ -280,21 +280,22 @@ MiIsPfnRam(PADDRESS_RANGE BIOSMemoryMap,
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 @@ MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
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 @@ MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
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 @@ MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
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 @@ MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
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;
+17
View File
@@ -50,6 +50,7 @@ PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
PVOID MiNonPagedPoolStart;
ULONG MiNonPagedPoolLength;
ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
extern KMUTANT MmSystemLoadLock;
BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_
@@ -207,6 +208,7 @@ MiCountFreePagesInLoaderBlock(PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Md;
ULONG FreePages = 0;
for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
@@ -240,6 +242,21 @@ MiCountFreePagesInLoaderBlock(PLOADER_PARAMETER_BLOCK LoaderBlock)
/* 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;
}
}
}
}
}