Author: ros-arm-bringup
Date: Sun Jun 21 13:08:05 2009
New Revision: 41511
URL: http://svn.reactos.org/svn/reactos?rev=41511&view=rev
Log:
- MC_NPPOOL is special-cased in the memory balancer core to always force the allocation of a page, even in low-memory conditions (which in ReactOS, occur early-on because, in a stroke of typical ReactOS genius, the balancer core is called before the balancer initailizes its values and thresholds). Make MC_SYSTEM special-cased as well, so we never fail to allocate page tables early-on.
- This fixes booting on systems which required enough page tables such that the balancer refused the allocation of new pages (around 64+16 pages for page tables of 4KB each, ie. 320MB).
Modified:
trunk/reactos/ntoskrnl/mm/balance.c
Modified: trunk/reactos/ntoskrnl/mm/balance.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/balance.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/balance.c [iso-8859-1] Sun Jun 21 13:08:05 2009
@@ -85,6 +85,8 @@
MiMemoryConsumers[MC_PPOOL].PagesTarget = NrAvailablePages / 2;
MiMemoryConsumers[MC_NPPOOL].PagesTarget = 0xFFFFFFFF;
MiMemoryConsumers[MC_NPPOOL].PagesUsed = NrSystemPages;
+ MiMemoryConsumers[MC_SYSTEM].PagesTarget = 0xFFFFFFFF;
+ MiMemoryConsumers[MC_SYSTEM].PagesUsed = 0;
}
VOID
@@ -221,7 +223,7 @@
/*
* Allocate always memory for the non paged pool and for the pager thread.
*/
- if (Consumer == MC_NPPOOL || MiIsBalancerThread())
+ if ((Consumer == MC_NPPOOL) || (Consumer == MC_SYSTEM) || MiIsBalancerThread())
{
Page = MmAllocPage(Consumer, 0);
if (Page == 0)
Author: ros-arm-bringup
Date: Sun Jun 21 09:46:50 2009
New Revision: 41509
URL: http://svn.reactos.org/svn/reactos?rev=41509&view=rev
Log:
- Introduce a new MEMORY_AREA flag, MEMORY_AREA_STATIC:
- MEMORY_AREA structures are typically allocated from nonpaged pool, under the assumption it exists.
- However, nonpaged pool itself is described by a MEMORY_AREA. Right now, this MEMORY_AREA is created after nonpaged pool has been initialized (it is a miracle this works).
- This new flag allows MEMORY_AREA structures to be allocated statically, allowing the description of certain system address space components, themselves prerequisites to nonpaged pool creation, as well as the nonpaged pool component itself, before nonpaged pool has been initialized.
- This is not yet used.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 09:46:50 2009
@@ -28,6 +28,8 @@
struct _MM_PAGEOP;
typedef ULONG SWAPENTRY;
typedef ULONG PFN_TYPE, *PPFN_TYPE;
+
+#define MI_STATIC_MEMORY_AREAS (1)
#define MEMORY_AREA_INVALID (0)
#define MEMORY_AREA_SECTION_VIEW (1)
@@ -43,6 +45,7 @@
#define MEMORY_AREA_PAGED_POOL (12)
#define MEMORY_AREA_NO_ACCESS (13)
#define MEMORY_AREA_PEB_OR_TEB (14)
+#define MEMORY_AREA_STATIC (0x80000000)
#define MM_PHYSICAL_PAGE_MPW_PENDING (0x8)
Modified: trunk/reactos/ntoskrnl/mm/marea.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/marea.c?rev=41…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/marea.c [iso-8859-1] Sun Jun 21 09:46:50 2009
@@ -49,6 +49,9 @@
#pragma alloc_text(INIT, MmInitMemoryAreas)
#endif
+MEMORY_AREA MiStaticMemoryAreas[MI_STATIC_MEMORY_AREAS];
+ULONG MiStaticMemoryAreaCount;
+
/* #define VALIDATE_MEMORY_AREAS */
/* FUNCTIONS *****************************************************************/
@@ -986,9 +989,28 @@
return STATUS_CONFLICTING_ADDRESSES;
}
}
-
- MemoryArea = ExAllocatePoolWithTag(NonPagedPool, sizeof(MEMORY_AREA),
- TAG_MAREA);
+
+ //
+ // Is this a static memory area?
+ //
+ if (Type & MEMORY_AREA_STATIC)
+ {
+ //
+ // Use the static array instead of the pool
+ //
+ ASSERT(MiStaticMemoryAreaCount < MI_STATIC_MEMORY_AREAS);
+ MemoryArea = &MiStaticMemoryAreas[MiStaticMemoryAreaCount++];
+ }
+ else
+ {
+ //
+ // Allocate the memory area from nonpaged pool
+ //
+ MemoryArea = ExAllocatePoolWithTag(NonPagedPool,
+ sizeof(MEMORY_AREA),
+ TAG_MAREA);
+ }
+
RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA));
MemoryArea->Type = Type;
MemoryArea->StartingAddress = *BaseAddress;
Author: ros-arm-bringup
Date: Sun Jun 21 09:33:48 2009
New Revision: 41508
URL: http://svn.reactos.org/svn/reactos?rev=41508&view=rev
Log:
- Define a new consumer: MC_SYSTEM:
- Right now, it is only used for allocating new page tables for kernel-mode mappings.
- This consumer's pages are never zeroed automatically (this is a more endemic ReactOS problem -- kernel pages are zeroed when they shouldn't be).
- New page tables, however, should indeed be zeroed, so now they are zeroed manually with RtlZeroMemory.
- The page zero function is not called anymore, and a useless zero-space hyperspace mapping is thus saved each time this happens.
- Because of this, zero-space hyperspace mappings are required much later in the Memory Manager's initialization steps than before.
Modified:
trunk/reactos/ntoskrnl/include/internal/mm.h
trunk/reactos/ntoskrnl/mm/freelist.c
trunk/reactos/ntoskrnl/mm/i386/page.c
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 09:33:48 2009
@@ -102,7 +102,8 @@
#define MC_USER (1)
#define MC_PPOOL (2)
#define MC_NPPOOL (3)
-#define MC_MAXIMUM (4)
+#define MC_SYSTEM (4)
+#define MC_MAXIMUM (5)
#define PAGED_POOL_MASK 1
#define MUST_SUCCEED_POOL_MASK 2
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 [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/freelist.c [iso-8859-1] Sun Jun 21 09:33:48 2009
@@ -777,7 +777,7 @@
KeReleaseQueuedSpinLock(LockQueuePfnLock, oldIrql);
PfnOffset = PageDescriptor - MmPfnDatabase;
- if (NeedClear)
+ if ((NeedClear) && (Consumer != MC_SYSTEM))
{
MiZeroPage(PfnOffset);
}
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/page.c?re…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c [iso-8859-1] Sun Jun 21 09:33:48 2009
@@ -310,7 +310,7 @@
{
return NULL;
}
- Status = MmRequestPageMemoryConsumer(MC_NPPOOL, FALSE, &Pfn);
+ Status = MmRequestPageMemoryConsumer(MC_SYSTEM, FALSE, &Pfn);
if (!NT_SUCCESS(Status) || Pfn == 0)
{
KeBugCheck(MEMORY_MANAGEMENT);
@@ -322,8 +322,11 @@
}
if(0 != InterlockedCompareExchangePte(&MmGlobalKernelPageDirectory[PdeOffset], Entry, 0))
{
- MmReleasePageMemoryConsumer(MC_NPPOOL, Pfn);
+ MmReleasePageMemoryConsumer(MC_SYSTEM, Pfn);
}
+ InterlockedExchangePte(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
+ RtlZeroMemory(MiPteToAddress(PageDir), PAGE_SIZE);
+ return (PULONG)MiAddressToPte(Address);
}
InterlockedExchangePte(PageDir, MmGlobalKernelPageDirectory[PdeOffset]);
}
Author: ros-arm-bringup
Date: Sun Jun 21 08:28:31 2009
New Revision: 41507
URL: http://svn.reactos.org/svn/reactos?rev=41507&view=rev
Log:
- Add another helper: MiGetPfnEntryIndex. This returns the page frame number (PFN) for a given MMPFN entry.
- Also add MiPteToAddress to complement MiAddressToPte. This returns the VA for a given PTE. Bonus points if you can figure out the bit magic.
Modified:
trunk/reactos/ntoskrnl/include/internal/i386/mm.h
trunk/reactos/ntoskrnl/include/internal/mm.h
Modified: trunk/reactos/ntoskrnl/include/internal/i386/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/i386/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/i386/mm.h [iso-8859-1] Sun Jun 21 08:28:31 2009
@@ -23,6 +23,11 @@
#define MiAddressToPteOffset(x) \
((((ULONG)(x)) << 10) >> 22)
+//
+// Convert a PTE into a corresponding address
+//
+#define MiPteToAddress(PTE) ((PVOID)((ULONG)(PTE) << 10))
+
#define ADDR_TO_PAGE_TABLE(v) (((ULONG)(v)) / (1024 * PAGE_SIZE))
#define ADDR_TO_PDE_OFFSET(v) ((((ULONG)(v)) / (1024 * PAGE_SIZE)))
#define ADDR_TO_PTE_OFFSET(v) ((((ULONG)(v)) % (1024 * PAGE_SIZE)) / PAGE_SIZE)
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h [iso-8859-1] Sun Jun 21 08:28:31 2009
@@ -1050,6 +1050,16 @@
return Page;
};
+FORCEINLINE
+PFN_NUMBER
+MiGetPfnEntryIndex(IN PMMPFN Pfn1)
+{
+ //
+ // This will return the Page Frame Number (PFN) from the MMPFN
+ //
+ return Pfn1 - MmPfnDatabase;
+}
+
PFN_TYPE
NTAPI
MmGetLRUNextUserPage(PFN_TYPE PreviousPage);