3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/mm/mpw.c
23 * PURPOSE: Writes data that has been modified in memory but not on
25 * PROGRAMMER: David Welch (welch@cwcom.net)
30 /* INCLUDES ****************************************************************/
32 #include <ddk/ntddk.h>
33 #include <internal/ps.h>
34 #include <internal/mm.h>
35 #include <internal/cc.h>
38 #include <internal/debug.h>
40 /* GLOBALS *******************************************************************/
42 static HANDLE MpwThreadHandle;
43 static CLIENT_ID MpwThreadId;
44 static KEVENT MpwThreadEvent;
45 static volatile BOOLEAN MpwThreadShouldTerminate;
47 /* FUNCTIONS *****************************************************************/
50 MmWriteDirtyPages(ULONG Target, PULONG Actual)
52 PHYSICAL_ADDRESS Page;
53 PHYSICAL_ADDRESS NextPage;
56 Page = MmGetLRUFirstUserPage();
57 while (Page.QuadPart != 0LL && Target > 0)
59 NextPage = MmGetLRUNextUserPage(Page);
60 if (MmIsDirtyPageRmap(Page))
62 Status = MmWritePagePhysicalAddress(Page);
63 if (NT_SUCCESS(Status))
71 return(STATUS_SUCCESS);
75 MmMpwThreadMain(PVOID Ignored)
79 LARGE_INTEGER Timeout;
81 Timeout.QuadPart = -50000000;
85 Status = KeWaitForSingleObject(&MpwThreadEvent,
90 if (!NT_SUCCESS(Status))
92 DbgPrint("MpwThread: Wait failed\n");
94 return(STATUS_UNSUCCESSFUL);
96 if (MpwThreadShouldTerminate)
98 DbgPrint("MpwThread: Terminating\n");
99 return(STATUS_SUCCESS);
103 MmWriteDirtyPages(128, &PagesWritten);
104 CcRosFlushDirtyPages(128, &PagesWritten);
108 NTSTATUS MmInitMpwThread(VOID)
113 MpwThreadShouldTerminate = FALSE;
114 KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
116 Status = PsCreateSystemThread(&MpwThreadHandle,
123 if (!NT_SUCCESS(Status))
129 NtSetInformationThread(MpwThreadHandle,
134 return(STATUS_SUCCESS);