Author: ros-arm-bringup
Date: Thu Feb 14 21:33:38 2008
New Revision: 32359
URL:
http://svn.reactos.org/svn/reactos?rev=32359&view=rev
Log:
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.
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 21:33:38 2008
@@ -290,7 +290,7 @@
ULONG i;
ULONG Reserved;
NTSTATUS Status;
- PFN_TYPE LastPage, Pfn;
+ PFN_TYPE LastPage, Pfn = 0;
ULONG PdeStart = PsGetCurrentProcess()->Pcb.DirectoryTableBase.LowPart;
ULONG PdePageStart, PdePageEnd;
ULONG VideoPageStart, VideoPageEnd;
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 21:33:38 2008
@@ -49,7 +49,7 @@
PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
PVOID MiNonPagedPoolStart;
ULONG MiNonPagedPoolLength;
-ULONG MmNumberOfPhysicalPages;
+ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
extern KMUTANT MmSystemLoadLock;
BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_
@@ -201,13 +201,12 @@
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
}
-ULONG
+VOID
NTAPI
MiCountFreePagesInLoaderBlock(PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Md;
- ULONG TotalPages = 0;
for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
@@ -215,19 +214,51 @@
{
Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
- if (Md->MemoryType == LoaderBad ||
- Md->MemoryType == LoaderFirmwarePermanent ||
- Md->MemoryType == LoaderSpecialMemory ||
- Md->MemoryType == LoaderBBTMemory)
+ /* Skip invisible memory */
+ if ((Md->MemoryType != LoaderFirmwarePermanent) &&
+ (Md->MemoryType != LoaderSpecialMemory) &&
+ (Md->MemoryType != LoaderHALCachedMemory) &&
+ (Md->MemoryType != LoaderBBTMemory))
{
- /* Don't count these blocks */
- continue;
+ /* Check if BURNMEM was used */
+ if (Md->MemoryType != LoaderBad)
+ {
+ /* Count this in the total of pages */
+ MmNumberOfPhysicalPages += Md->PageCount;
+ }
+
+ /* Check if this is the new lowest page */
+ if (Md->BasePage < MmLowestPhysicalPage)
+ {
+ /* Update the lowest page */
+ MmLowestPhysicalPage = Md->BasePage;
+ }
+
+ /* Check if this is the new highest page */
+ if ((Md->BasePage + Md->PageCount) > MmHighestPhysicalPage)
+ {
+ /* Update the highest page */
+ MmHighestPhysicalPage = Md->BasePage + Md->PageCount - 1;
+ }
}
-
- TotalPages += Md->PageCount;
- }
-
- return TotalPages;
+ }
+}
+
+VOID
+NTAPI
+MiDbgDumpBiosMap(IN PADDRESS_RANGE BIOSMemoryMap,
+ IN ULONG AddressRangeCount)
+{
+ ULONG i;
+
+ DPRINT1("Base\t\tLength\t\tType\n");
+ for (i = 0; i < AddressRangeCount; i++)
+ {
+ DPRINT1("%08lX\t%08lX\t%d\n",
+ BIOSMemoryMap[i].BaseAddrLow,
+ BIOSMemoryMap[i].LengthLow,
+ BIOSMemoryMap[i].Type);
+ }
}
VOID
@@ -269,8 +300,7 @@
Md->MemoryType == LoaderHalCode)
{
if (Md->BasePage+Md->PageCount > LastKrnlPhysAddr)
- LastKrnlPhysAddr = Md->BasePage+Md->PageCount;
-
+ LastKrnlPhysAddr = Md->BasePage+Md->PageCount;
}
}
@@ -293,6 +323,7 @@
/* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
+ if (MiDbgEnableMdDump) MiDbgDumpBiosMap(BIOSMemoryMap, AddressRangeCount);
/* Set the page directory */
PsGetCurrentProcess()->Pcb.DirectoryTableBase.LowPart =
(ULONG)MmGetPageDirectory();
@@ -322,19 +353,9 @@
RtlZeroMemory(&MmStats, sizeof(MmStats));
/* Count RAM */
- MmStats.NrTotalPages = MiCountFreePagesInLoaderBlock(KeLoaderBlock);
- MmNumberOfPhysicalPages = MmStats.NrTotalPages;
- if (!MmStats.NrTotalPages)
- {
- DbgPrint("Memory not detected, default to 8 MB\n");
- MmStats.NrTotalPages = 2048;
- }
- else
- {
- /* HACK: add 1MB for standard memory (not extended). Why? */
- DbgPrint("Used memory %dKb\n", (MmStats.NrTotalPages * PAGE_SIZE) /
1024);
- MmStats.NrTotalPages += 256;
- }
+ MiCountFreePagesInLoaderBlock(KeLoaderBlock);
+ MmStats.NrTotalPages = MmNumberOfPhysicalPages;
+ DbgPrint("Used memory %dKb\n", (MmStats.NrTotalPages * PAGE_SIZE) / 1024);
/* Initialize the kernel address space */
MmInitializeKernelAddressSpace();
@@ -343,7 +364,7 @@
/* Initialize the page list */
LastKernelAddress = (ULONG_PTR)MmInitializePageList(FirstKrnlPhysAddr,
LastKrnlPhysAddr,
- MmStats.NrTotalPages,
+ MmHighestPhysicalPage,
PAGE_ROUND_UP(LastKernelAddress),
BIOSMemoryMap,
AddressRangeCount);