[ros-diffs] [ros-arm-bringup] 32360: 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).
ros-arm-bringup at svn.reactos.org
ros-arm-bringup at svn.reactos.org
Thu Feb 14 20:24:03 CET 2008
- Previous message: [ros-diffs] [ros-arm-bringup] 32359: We were looping the memory descriptors in order to find the number of pages that are available to the system, that is to say, your RAM, minus pages that the BIOS said belong to it. This part is good. Next up, we were creating the page array for these pages, up to the highest entry, which we called, the number of pages on the system. This is the problem. Suppose we had 1000 pages somewhere in low memory that were used by the BIOS, we'd now call the total pages RAM - 1000 (correct). However, we'd also set the highest page array entry to RAM - 1000, which is wrong, because esssentially this eats up 10MB of memory, since the top 10MB (which are FREE, usable memory) are never entered into the database. So really, what we want to do is differentiate the TOTAL amount of usable RAM, versus the HIGHEST page that is usable (which is actually what should be the highest entry in the page array). This will reclaim the lost RAM ReactOS has been eating up all these days. But it gets better: eventually, someone noticed ReactOS was eating memory, and added 1MB more to the "total", making the highest entry "1mb higher". This ...kind of... fixes the problem above by giving you one more MB, but what if ReactOS was only eating up 150KB, as was more the case? Then ReactOS would believe that the other 850KB of memory are "Free physical memory", when actually, they're pages that don't even exist. Wow! Fixed these bugs.
- Next message: [ros-diffs] [ros-arm-bringup] 32361: Stop lying that the PCR, KUSER_SHARED_DATA, and PDEs are "BIOS" pages, they're USED pages. Stop initializing fields to 0 if we've already cleared the entire array! Stop setting arbitrary values for MapCount and ReferenceCount -- both the KPCR, KUSER_SHARED_DATA and PDE are mapped! Stop saying Video ROM has a reference count, it's the same as BIOS memory, except the MiIsPfnRam function doesn't detect it and we have a hack for it.
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
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=32360&r1=32359&r2=32360&view=diff
==============================================================================
--- 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=32360&r1=32359&r2=32360&view=diff
==============================================================================
--- 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;
+ }
+ }
}
}
}
- Previous message: [ros-diffs] [ros-arm-bringup] 32359: We were looping the memory descriptors in order to find the number of pages that are available to the system, that is to say, your RAM, minus pages that the BIOS said belong to it. This part is good. Next up, we were creating the page array for these pages, up to the highest entry, which we called, the number of pages on the system. This is the problem. Suppose we had 1000 pages somewhere in low memory that were used by the BIOS, we'd now call the total pages RAM - 1000 (correct). However, we'd also set the highest page array entry to RAM - 1000, which is wrong, because esssentially this eats up 10MB of memory, since the top 10MB (which are FREE, usable memory) are never entered into the database. So really, what we want to do is differentiate the TOTAL amount of usable RAM, versus the HIGHEST page that is usable (which is actually what should be the highest entry in the page array). This will reclaim the lost RAM ReactOS has been eating up all these days. But it gets better: eventually, someone noticed ReactOS was eating memory, and added 1MB more to the "total", making the highest entry "1mb higher". This ...kind of... fixes the problem above by giving you one more MB, but what if ReactOS was only eating up 150KB, as was more the case? Then ReactOS would believe that the other 850KB of memory are "Free physical memory", when actually, they're pages that don't even exist. Wow! Fixed these bugs.
- Next message: [ros-diffs] [ros-arm-bringup] 32361: Stop lying that the PCR, KUSER_SHARED_DATA, and PDEs are "BIOS" pages, they're USED pages. Stop initializing fields to 0 if we've already cleared the entire array! Stop setting arbitrary values for MapCount and ReferenceCount -- both the KPCR, KUSER_SHARED_DATA and PDE are mapped! Stop saying Video ROM has a reference count, it's the same as BIOS memory, except the MiIsPfnRam function doesn't detect it and we have a hack for it.
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Ros-diffs
mailing list