Sync with trunk head (r49139)
[reactos.git] / ntoskrnl / mm / mminit.c
index d2db58e..60ea7f7 100644 (file)
@@ -17,6 +17,8 @@
 
 /* GLOBALS *******************************************************************/
 
+VOID NTAPI MiInitializeUserPfnBitmap(VOID);
+
 PCHAR
 MemType[] =
 {
@@ -48,6 +50,9 @@ MemType[] =
     "LoaderXIPRom      "
 };
 
+HANDLE MpwThreadHandle;
+KEVENT MpwThreadEvent;
+
 BOOLEAN Mm64BitPhysicalAddress = FALSE;
 ULONG MmReadClusterSize;
 //
@@ -198,21 +203,6 @@ MiInitSystemMemoryAreas()
                                 BoundaryAddressMultiple);
     ASSERT(Status == STATUS_SUCCESS);
     
-    //
-    // And now, ReactOS paged pool
-    //
-    BaseAddress = MmPagedPoolBase;
-    Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
-                                MEMORY_AREA_PAGED_POOL | MEMORY_AREA_STATIC,
-                                &BaseAddress,
-                                MmPagedPoolSize,
-                                PAGE_READWRITE,
-                                &MArea,
-                                TRUE,
-                                0,
-                                BoundaryAddressMultiple);
-    ASSERT(Status == STATUS_SUCCESS);
-    
     //
     // Next, the KPCR
     //
@@ -260,7 +250,7 @@ MiInitSystemMemoryAreas()
 
 #if defined(_X86_)
     //
-    // Finally, reserve the 2  pages we currently make use of for HAL mappings
+    // Finally, reserve the 2 pages we currently make use of for HAL mappings
     //
     BaseAddress = (PVOID)0xFFC00000;
     Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
@@ -287,10 +277,6 @@ MiDbgDumpAddressSpace(VOID)
             MmSystemRangeStart,
             (ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
             "Boot Loaded Image");
-    DPRINT1("          0x%p - 0x%p\t%s\n",
-            MmPagedPoolBase,
-            (ULONG_PTR)MmPagedPoolBase + MmPagedPoolSize,
-            "Paged Pool");
     DPRINT1("          0x%p - 0x%p\t%s\n",
             MmPfnDatabase,
             (ULONG_PTR)MmPfnDatabase + (MxPfnAllocation << PAGE_SHIFT),
@@ -349,7 +335,88 @@ MiDbgDumpMemoryDescriptors(VOID)
     DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
 }
 
-VOID NTAPI MiInitializeUserPfnBitmap(VOID);
+NTSTATUS NTAPI
+MmMpwThreadMain(PVOID Ignored)
+{
+   NTSTATUS Status;
+   ULONG PagesWritten;
+   LARGE_INTEGER Timeout;
+
+   Timeout.QuadPart = -50000000;
+
+   for(;;)
+   {
+      Status = KeWaitForSingleObject(&MpwThreadEvent,
+                                     0,
+                                     KernelMode,
+                                     FALSE,
+                                     &Timeout);
+      if (!NT_SUCCESS(Status))
+      {
+         DbgPrint("MpwThread: Wait failed\n");
+         KeBugCheck(MEMORY_MANAGEMENT);
+         return(STATUS_UNSUCCESSFUL);
+      }
+
+      PagesWritten = 0;
+
+      CcRosFlushDirtyPages(128, &PagesWritten);
+   }
+}
+
+NTSTATUS
+NTAPI
+MmInitMpwThread(VOID)
+{
+   KPRIORITY Priority;
+   NTSTATUS Status;
+   CLIENT_ID MpwThreadId;
+   
+   KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
+
+   Status = PsCreateSystemThread(&MpwThreadHandle,
+                                 THREAD_ALL_ACCESS,
+                                 NULL,
+                                 NULL,
+                                 &MpwThreadId,
+                                 (PKSTART_ROUTINE) MmMpwThreadMain,
+                                 NULL);
+   if (!NT_SUCCESS(Status))
+   {
+      return(Status);
+   }
+
+   Priority = 27;
+   NtSetInformationThread(MpwThreadHandle,
+                          ThreadPriority,
+                          &Priority,
+                          sizeof(Priority));
+
+   return(STATUS_SUCCESS);
+}
+
+NTSTATUS
+NTAPI
+MmInitBsmThread(VOID)
+{
+    NTSTATUS Status;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    HANDLE ThreadHandle;
+
+    /* Create the thread */
+    InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
+    Status = PsCreateSystemThread(&ThreadHandle,
+                                  THREAD_ALL_ACCESS,
+                                  &ObjectAttributes,
+                                  NULL,
+                                  NULL,
+                                  KeBalanceSetManager,
+                                  NULL);
+
+    /* Close the handle and return status */
+    ZwClose(ThreadHandle);
+    return Status;
+}
 
 BOOLEAN
 NTAPI
@@ -373,12 +440,7 @@ MmInitSystem(IN ULONG Phase,
         
         /* Initialize ARMĀ³ in phase 0 */
         MmArmInitSystem(0, KeLoaderBlock);    
-        
-        /* Put the paged pool after the loaded modules */
-        MmPagedPoolBase = (PVOID)PAGE_ROUND_UP((ULONG_PTR)MmSystemRangeStart +
-                                               MmBootImageSize);
-        MmPagedPoolSize = MM_PAGED_POOL_SIZE;
-        
+
         /* Intialize system memory areas */
         MiInitSystemMemoryAreas();
 
@@ -387,7 +449,6 @@ MmInitSystem(IN ULONG Phase,
     }
     else if (Phase == 1)
     {
-        MmInitializePagedPool();
         MiInitializeUserPfnBitmap();
         MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
         MmInitializeRmapList();