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)
60 * FIXME: While the current page is write back it is possible
61 * that the next page is freed and not longer a user page.
63 NextPage = MmGetLRUNextUserPage(Page);
64 if (MmIsDirtyPageRmap(Page))
66 Status = MmWritePagePhysicalAddress(Page);
67 if (NT_SUCCESS(Status))
75 return(STATUS_SUCCESS);
79 MmMpwThreadMain(PVOID Ignored)
83 LARGE_INTEGER Timeout;
85 Timeout.QuadPart = -50000000;
89 Status = KeWaitForSingleObject(&MpwThreadEvent,
94 if (!NT_SUCCESS(Status))
96 DbgPrint("MpwThread: Wait failed\n");
98 return(STATUS_UNSUCCESSFUL);
100 if (MpwThreadShouldTerminate)
102 DbgPrint("MpwThread: Terminating\n");
103 return(STATUS_SUCCESS);
109 * FIXME: MmWriteDirtyPages doesn't work correctly.
111 MmWriteDirtyPages(128, &PagesWritten);
113 CcRosFlushDirtyPages(128, &PagesWritten);
117 NTSTATUS MmInitMpwThread(VOID)
122 MpwThreadShouldTerminate = FALSE;
123 KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
125 Status = PsCreateSystemThread(&MpwThreadHandle,
130 (PKSTART_ROUTINE) MmMpwThreadMain,
132 if (!NT_SUCCESS(Status))
138 NtSetInformationThread(MpwThreadHandle,
143 return(STATUS_SUCCESS);