From fae9aa5c48785389f53dc004bb9188a30faddda9 Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Sun, 24 Feb 2008 10:43:56 +0000 Subject: [PATCH] - Save original value of the free descriptor we're using to alloc early pages from. - Fix handling of PFN database pages inside PFN: largest free descriptor does not always end with the highest usable physical page (MmPageArraySize). This removes the need for a "good hack" introduced in revision 32405. As a result, the memory above the largest free descriptor (if it exists) is now correctly marked in the PFN database as free and added to the unzeroed list. svn path=/trunk/; revision=32463 --- reactos/ntoskrnl/include/internal/mm.h | 1 + reactos/ntoskrnl/mm/freelist.c | 22 ++++++++-------------- reactos/ntoskrnl/mm/mminit.c | 5 +++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index b034db263f3..b897fb77d30 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -19,6 +19,7 @@ extern PVOID MmPagedPoolBase; extern ULONG MmPagedPoolSize; extern PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor; +extern MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg; extern ULONG MmHighestPhysicalPage; extern PVOID MmPfnDatabase; diff --git a/reactos/ntoskrnl/mm/freelist.c b/reactos/ntoskrnl/mm/freelist.c index bcedb80fc5c..207031b7c87 100644 --- a/reactos/ntoskrnl/mm/freelist.c +++ b/reactos/ntoskrnl/mm/freelist.c @@ -54,13 +54,13 @@ MiGetPfnEntry(IN PFN_TYPE Pfn) /* Make sure the PFN number is valid */ ASSERT(Pfn <= MmPageArraySize); - + /* Get the entry */ Page = &MmPageArray[Pfn]; - + /* Make sure it's valid */ ASSERT_PFN(Page); - + /* Return it */ return Page; } @@ -368,20 +368,14 @@ MmInitializePageList(VOID) } } } - + /* Finally handle the pages describing the PFN database themselves */ for (i = (MiFreeDescriptor->BasePage + MiFreeDescriptor->PageCount); - i <= MmPageArraySize; + i < (MiFreeDescriptorOrg.BasePage + MiFreeDescriptorOrg.PageCount); i++) { - /* If this page was marked as free it should be removed from - the unzeroed free pages list */ - if (MmPageArray[i].Flags.Type == MM_PHYSICAL_PAGE_FREE) - { - RemoveEntryList(&MmPageArray[i].ListEntry); - UnzeroedPageCount--; - MmStats.NrFreePages--; - } + /* Ensure this page was not added previously */ + ASSERT(MmPageArray[i].Flags.Type == 0); /* Mark it as used kernel memory */ MmPageArray[i] = UsedPage; @@ -764,7 +758,7 @@ MmAllocPage(ULONG Consumer, SWAPENTRY SavedSwapEntry) MiZeroPage(PfnOffset); return PfnOffset; } - + DPRINT1("MmAllocPage(): Out of memory\n"); KeReleaseSpinLock(&PageListLock, oldIrql); return 0; diff --git a/reactos/ntoskrnl/mm/mminit.c b/reactos/ntoskrnl/mm/mminit.c index 92898d9e7ae..7578d0d5645 100644 --- a/reactos/ntoskrnl/mm/mminit.c +++ b/reactos/ntoskrnl/mm/mminit.c @@ -55,6 +55,7 @@ ULONG_PTR MiKSeg0Start, MiKSeg0End; PVOID MmPfnDatabase; ULONG_PTR MmPfnDatabaseEnd; PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor; +MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg; extern KMUTANT MmSystemLoadLock; BOOLEAN MiDbgEnableMdDump = #ifdef _ARM_ @@ -246,6 +247,10 @@ MiCountFreePagesInLoaderBlock(PLOADER_PARAMETER_BLOCK LoaderBlock) } } } + + /* Save original values of the free descriptor, since it'll be + altered by early allocations */ + MiFreeDescriptorOrg = *MiFreeDescriptor; } VOID