Author: tkreuzer
Date: Thu Jul 29 01:01:28 2010
New Revision: 48346
URL:
http://svn.reactos.org/svn/reactos?rev=48346&view=rev
Log:
[NTOS]
Implement a new early page allocator MiEarlyAllocPages that allocates the pages from
global variables instead of inconsistently allocating them from the either the
MxFreeDescriptor or in other places manually removing pages. Instead the MxFreeDescriptor
is set to a temporary value, with the consumed pages substracted, while the pfn database
is build. This last step will also become obsolete as soon as the pfn database is
initialized in a more proper sequence.
Modified:
branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/i386/init.c
branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/miarm.h
branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/mminit.c
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/i386/init.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/i386/init.c [iso-8859-1]
(original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/i386/init.c [iso-8859-1] Thu Jul
29 01:01:28 2010
@@ -285,7 +285,7 @@
// Now we actually need to get these many physical pages. Nonpaged pool
// is actually also physically contiguous (but not the expansion)
//
- PageFrameIndex = MxGetNextPage(MxPfnAllocation +
+ PageFrameIndex = MiEarlyAllocPages(MxPfnAllocation +
(MmSizeOfNonPagedPoolInBytes >> PAGE_SHIFT));
ASSERT(PageFrameIndex != 0);
DPRINT("PFN DB PA PFN begins at: %lx\n", PageFrameIndex);
@@ -305,7 +305,7 @@
//
// Get a page
//
- TempPde.u.Hard.PageFrameNumber = MxGetNextPage(1);
+ TempPde.u.Hard.PageFrameNumber = MiEarlyAllocPages(1);
MI_WRITE_VALID_PTE(StartPde, TempPde);
//
@@ -331,7 +331,7 @@
//
// Get a page
//
- TempPde.u.Hard.PageFrameNumber = MxGetNextPage(1);
+ TempPde.u.Hard.PageFrameNumber = MiEarlyAllocPages(1);
MI_WRITE_VALID_PTE(StartPde, TempPde);
//
@@ -385,6 +385,10 @@
/* ReactOS Stuff */
KeInitializeEvent(&ZeroPageThreadEvent, NotificationEvent, TRUE);
+ /* Hide the pages, that we already used from the descriptor */
+ MxFreeDescriptor->BasePage = MiEarlyAllocBase;
+ MxFreeDescriptor->PageCount = MiEarlyAllocCount;
+
/* Build the PFN Database */
MiInitializePfnDatabase(LoaderBlock);
MmInitializeBalancer(MmAvailablePages, 0);
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/miarm.h
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Thu Jul 29
01:01:28 2010
@@ -442,6 +442,8 @@
extern PMMPTE MmSharedUserDataPte;
extern LIST_ENTRY MmProcessList;
extern PFN_NUMBER MiNumberOfFreePages;
+extern PFN_NUMBER MiEarlyAllocCount;
+extern PFN_NUMBER MiEarlyAllocBase;
#define MI_PFN_TO_PFNENTRY(x) (&MmPfnDatabase[1][x])
#define MI_PFNENTRY_TO_PFN(x) (x - MmPfnDatabase[1])
@@ -787,6 +789,12 @@
IN PFN_NUMBER PageCount
);
+PFN_NUMBER
+NTAPI
+MiEarlyAllocPages(
+ IN PFN_NUMBER PageCount
+);
+
PPHYSICAL_MEMORY_DESCRIPTOR
NTAPI
MmInitializeMemoryLimits(
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/mminit.c
URL:
http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntosk…
==============================================================================
--- branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] (original)
+++ branches/ros-amd64-bringup/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] Thu Jul 29
01:01:28 2010
@@ -359,6 +359,7 @@
PFN_NUMBER MiNumberOfFreePages = 0;
PFN_NUMBER MiEarlyAllocCount = 0;
+PFN_NUMBER MiEarlyAllocBase;
ULONG MiNumberDescriptors = 0;
/* PRIVATE FUNCTIONS **********************************************************/
@@ -475,29 +476,30 @@
// Save original values of the free descriptor, since it'll be
// altered by early allocations
MxOldFreeDescriptor = *MxFreeDescriptor;
+ MiEarlyAllocBase = MxFreeDescriptor->BasePage;
}
PFN_NUMBER
NTAPI
-MxGetNextPage(IN PFN_NUMBER PageCount)
+MiEarlyAllocPages(IN PFN_NUMBER PageCount)
{
PFN_NUMBER Pfn;
/* Make sure we have enough pages */
- if (PageCount > MxFreeDescriptor->PageCount)
+ if (PageCount > MiEarlyAllocCount)
{
/* Crash the system */
KeBugCheckEx(INSTALL_MORE_MEMORY,
MmNumberOfPhysicalPages,
+ MiEarlyAllocCount,
MxFreeDescriptor->PageCount,
- MxOldFreeDescriptor.PageCount,
PageCount);
}
/* Use our lowest usable free pages */
- Pfn = MxFreeDescriptor->BasePage;
- MxFreeDescriptor->BasePage += PageCount;
- MxFreeDescriptor->PageCount -= PageCount;
+ Pfn = MiEarlyAllocBase;
+ MiEarlyAllocBase += PageCount;
+ MiEarlyAllocCount -= PageCount;
return Pfn;
}
@@ -576,7 +578,7 @@
if (PointerPte->u.Hard.Valid == 0)
{
/* Get a page and map it */
- TempPte.u.Hard.PageFrameNumber = MxGetNextPage(1);
+ TempPte.u.Hard.PageFrameNumber = MiEarlyAllocPages(1);
MI_WRITE_VALID_PTE(PointerPte, TempPte);
/* Zero out the page */
@@ -665,16 +667,11 @@
NTAPI
MiMapPfnDatabase(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
- ULONG FreePage, FreePageCount, PagesLeft, BasePage, PageCount;
+ ULONG BasePage, PageCount;
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
PMMPTE PointerPte, LastPte;
MMPTE TempPte = ValidKernelPte;
-
- /* Get current page data, since we won't be using MxGetNextPage as it would
corrupt our state */
- FreePage = MxFreeDescriptor->BasePage;
- FreePageCount = MxFreeDescriptor->PageCount;
- PagesLeft = 0;
/* Loop the memory descriptors */
NextEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
@@ -693,19 +690,9 @@
continue;
}
- /* Next, check if this is our special free descriptor we've found */
- if (MdBlock == MxFreeDescriptor)
- {
- /* Use the real numbers instead */
- BasePage = MxOldFreeDescriptor.BasePage;
- PageCount = MxOldFreeDescriptor.PageCount;
- }
- else
- {
- /* Use the descriptor's numbers */
- BasePage = MdBlock->BasePage;
- PageCount = MdBlock->PageCount;
- }
+ /* Use the descriptor's numbers */
+ BasePage = MdBlock->BasePage;
+ PageCount = MdBlock->PageCount;
/* Get the PTEs for this range */
PointerPte = MiAddressToPte(&MmPfnDatabase[BasePage]);
@@ -719,24 +706,9 @@
if (PointerPte->u.Hard.Valid == 0)
{
/* Use the next free page */
- TempPte.u.Hard.PageFrameNumber = FreePage;
- ASSERT(FreePageCount != 0);
-
- /* Consume free pages */
- FreePage++;
- FreePageCount--;
- if (!FreePageCount)
- {
- /* Out of memory */
- KeBugCheckEx(INSTALL_MORE_MEMORY,
- MmNumberOfPhysicalPages,
- FreePageCount,
- MxOldFreeDescriptor.PageCount,
- 1);
- }
+ TempPte.u.Hard.PageFrameNumber = MiEarlyAllocPages(1);
/* Write out this PTE */
- PagesLeft++;
MI_WRITE_VALID_PTE(PointerPte, TempPte);
/* Zero this page */
@@ -750,10 +722,6 @@
/* Do the next address range */
NextEntry = MdBlock->ListEntry.Flink;
}
-
- /* Now update the free descriptors to consume the pages we used up during the PFN
allocation loop */
- MxFreeDescriptor->BasePage = FreePage;
- MxFreeDescriptor->PageCount = FreePageCount;
}
VOID