From b4a63ba74ae19d7dfe3164e2d21f106a21393bc4 Mon Sep 17 00:00:00 2001 From: ReactOS Portable Systems Group Date: Thu, 14 Feb 2008 19:24:02 +0000 Subject: [PATCH] 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 --- reactos/ntoskrnl/mm/freelist.c | 26 ++++++++++++-------------- reactos/ntoskrnl/mm/mminit.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/mm/freelist.c b/reactos/ntoskrnl/mm/freelist.c index 64d176ba4ca..bae8b3b6de4 100644 --- a/reactos/ntoskrnl/mm/freelist.c +++ b/reactos/ntoskrnl/mm/freelist.c @@ -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; diff --git a/reactos/ntoskrnl/mm/mminit.c b/reactos/ntoskrnl/mm/mminit.c index 291ee60b193..1f455360d4e 100644 --- a/reactos/ntoskrnl/mm/mminit.c +++ b/reactos/ntoskrnl/mm/mminit.c @@ -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; + } + } } } }