-/*
+/*
* PROJECT: ReactOS Kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: ntoskrnl/mm/mminit.c
* PURPOSE: Memory Manager Initialization
- * PROGRAMMERS:
+ * PROGRAMMERS:
*/
/* INCLUDES ******************************************************************/
PMMPTE MmSharedUserDataPte;
PMMSUPPORT MmKernelAddressSpace;
+extern KEVENT MmWaitPageEvent;
+extern FAST_MUTEX MiGlobalPageOperation;
+extern LIST_ENTRY MiSegmentList;
+extern NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed);
+
/* PRIVATE FUNCTIONS *********************************************************/
VOID
MiInitSystemMemoryAreas()
{
PVOID BaseAddress;
- PHYSICAL_ADDRESS BoundaryAddressMultiple;
PMEMORY_AREA MArea;
NTSTATUS Status;
- BoundaryAddressMultiple.QuadPart = 0;
-
+
+ //
+ // Create the memory area to define the loader mappings
+ //
+ BaseAddress = (PVOID)KSEG0_BASE;
+ Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+ MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
+ &BaseAddress,
+ MmBootImageSize,
+ PAGE_EXECUTE_READWRITE,
+ &MArea,
+ TRUE,
+ 0,
+ PAGE_SIZE);
+ ASSERT(Status == STATUS_SUCCESS);
+
//
// Create the memory area to define the PTE base
//
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
&BaseAddress,
- 4 * 1024 * 1024,
+ PTE_TOP - PTE_BASE + 1,
PAGE_READWRITE,
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// Create the memory area to define Hyperspace
//
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
&BaseAddress,
- 4 * 1024 * 1024,
+ HYPER_SPACE_END - HYPER_SPACE + 1,
PAGE_READWRITE,
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// Protect the PFN database
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// ReactOS requires a memory area to keep the initial NP area off-bounds
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// And we need one more for the system NP
//
Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
&BaseAddress,
- (ULONG_PTR)MmNonPagedPoolEnd -
- (ULONG_PTR)MmNonPagedSystemStart,
+ MiNonPagedSystemSize,
PAGE_READWRITE,
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// We also need one for system view space
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// And another for session space
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+
//
// One more for ARM paged pool
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+#ifndef _M_AMD64
//
// Next, the KPCR
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
-
+#endif
//
// Now the KUSER_SHARED_DATA
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
//
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
#if defined(_X86_)
&MArea,
TRUE,
0,
- BoundaryAddressMultiple);
+ PAGE_SIZE);
ASSERT(Status == STATUS_SUCCESS);
#endif
}
// Print the memory layout
//
DPRINT1(" 0x%p - 0x%p\t%s\n",
- MmSystemRangeStart,
- (ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
+ KSEG0_BASE,
+ (ULONG_PTR)KSEG0_BASE + MmBootImageSize,
"Boot Loaded Image");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmPfnDatabase,
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmNonPagedPoolStart,
(ULONG_PTR)MmNonPagedPoolStart + MmSizeOfNonPagedPoolInBytes,
- "ARM³ Non Paged Pool");
+ "ARM3 Non Paged Pool");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MiSystemViewStart,
(ULONG_PTR)MiSystemViewStart + MmSystemViewSize,
- "System View Space");
+ "System View Space");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmSessionBase,
MiSessionSpaceEnd,
"Session Space");
DPRINT1(" 0x%p - 0x%p\t%s\n",
- PTE_BASE, PDE_BASE,
+ PTE_BASE, PTE_TOP,
"Page Tables");
DPRINT1(" 0x%p - 0x%p\t%s\n",
- PDE_BASE, HYPER_SPACE,
+ PDE_BASE, PDE_TOP,
"Page Directories");
DPRINT1(" 0x%p - 0x%p\t%s\n",
- HYPER_SPACE, HYPER_SPACE + (4 * 1024 * 1024),
+ HYPER_SPACE, HYPER_SPACE_END,
"Hyperspace");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmPagedPoolStart,
(ULONG_PTR)MmPagedPoolStart + MmSizeOfPagedPoolInBytes,
- "ARM³ Paged Pool");
+ "ARM3 Paged Pool");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmNonPagedSystemStart, MmNonPagedPoolExpansionStart,
"System PTE Space");
"Non Paged Pool Expansion PTE Space");
}
-NTSTATUS NTAPI
-MmMpwThreadMain(PVOID Ignored)
+VOID
+NTAPI
+MmMpwThreadMain(PVOID Parameter)
{
NTSTATUS Status;
ULONG PagesWritten;
LARGE_INTEGER Timeout;
+ UNREFERENCED_PARAMETER(Parameter);
+
Timeout.QuadPart = -50000000;
for(;;)
{
DbgPrint("MpwThread: Wait failed\n");
KeBugCheck(MEMORY_MANAGEMENT);
- return(STATUS_UNSUCCESSFUL);
+ return;
}
PagesWritten = 0;
#ifndef NEWCC
- // XXX arty -- we flush when evicting pages or destorying cache
- // sections.
- CcRosFlushDirtyPages(128, &PagesWritten);
+ // XXX arty -- we flush when evicting pages or destorying cache
+ // sections.
+ CcRosFlushDirtyPages(128, &PagesWritten, FALSE);
#endif
}
}
KPRIORITY Priority;
NTSTATUS Status;
CLIENT_ID MpwThreadId;
-
+
KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
Status = PsCreateSystemThread(&MpwThreadHandle,
NULL,
NULL,
&MpwThreadId,
- (PKSTART_ROUTINE) MmMpwThreadMain,
+ MmMpwThreadMain,
NULL);
if (!NT_SUCCESS(Status))
{
PMMPTE PointerPte;
MMPTE TempPte = ValidKernelPte;
PFN_NUMBER PageFrameNumber;
-
+
/* Initialize the kernel address space */
ASSERT(Phase == 1);
- KeInitializeGuardedMutex(&PsIdleProcess->AddressCreationLock);
+
+ InitializeListHead(&MiSegmentList);
+ ExInitializeFastMutex(&MiGlobalPageOperation);
+ KeInitializeEvent(&MmWaitPageEvent, SynchronizationEvent, FALSE);
+ // Until we're fully demand paged, we can do things the old way through
+ // the balance manager
+ MmInitializeMemoryConsumer(MC_CACHE, MiRosTrimCache);
+
MmKernelAddressSpace = &PsIdleProcess->Vm;
/* Intialize system memory areas */
MiInitializeUserPfnBitmap();
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
MmInitializeRmapList();
- MmInitializePageOp();
MmInitSectionImplementation();
MmInitPagingFile();
-
+
//
// Create a PTE to double-map the shared data section. We allocate it
// from paged pool so that we can't fault when trying to touch the PTE
sizeof(MMPTE),
' mM');
if (!MmSharedUserDataPte) return FALSE;
-
+
//
// Now get the PTE for shared data, and read the PFN that holds it
//
PointerPte = MiAddressToPte((PVOID)KI_USER_SHARED_DATA);
ASSERT(PointerPte->u.Hard.Valid == 1);
PageFrameNumber = PFN_FROM_PTE(PointerPte);
-
+
/* Build the PTE and write it */
MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte,
PointerPte,
MM_READONLY,
PageFrameNumber);
*MmSharedUserDataPte = TempPte;
-
+
+ /* Initialize session working set support */
+ MiInitializeSessionWsSupport();
+
+ /* Setup session IDs */
+ MiInitializeSessionIds();
+
/* Setup the memory threshold events */
if (!MiInitializeMemoryEvents()) return FALSE;
-
+
/*
* Unmap low memory
*/
MiInitBalancerThread();
-
+
/*
* Initialise the modified page writer.
*/
MmInitMpwThread();
-
+
/* Initialize the balance set manager */
MmInitBsmThread();