3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/mpw.c
6 * PURPOSE: Writes data that has been modified in memory but not on
9 * PROGRAMMERS: David Welch (welch@cwcom.net)
12 /* INCLUDES ****************************************************************/
16 #include <internal/debug.h>
18 /* GLOBALS *******************************************************************/
20 static HANDLE MpwThreadHandle
;
21 static CLIENT_ID MpwThreadId
;
22 static KEVENT MpwThreadEvent
;
23 static volatile BOOLEAN MpwThreadShouldTerminate
;
25 /* FUNCTIONS *****************************************************************/
28 MmWriteDirtyPages(ULONG Target
, PULONG Actual
)
34 Page
= MmGetLRUFirstUserPage();
35 while (Page
!= 0 && Target
> 0)
38 * FIXME: While the current page is write back it is possible
39 * that the next page is freed and not longer a user page.
41 NextPage
= MmGetLRUNextUserPage(Page
);
42 if (MmIsDirtyPageRmap(Page
))
44 Status
= MmWritePagePhysicalAddress(Page
);
45 if (NT_SUCCESS(Status
))
53 return(STATUS_SUCCESS
);
57 MmMpwThreadMain(PVOID Ignored
)
61 LARGE_INTEGER Timeout
;
63 Timeout
.QuadPart
= -50000000;
67 Status
= KeWaitForSingleObject(&MpwThreadEvent
,
72 if (!NT_SUCCESS(Status
))
74 DbgPrint("MpwThread: Wait failed\n");
76 return(STATUS_UNSUCCESSFUL
);
78 if (MpwThreadShouldTerminate
)
80 DbgPrint("MpwThread: Terminating\n");
81 return(STATUS_SUCCESS
);
87 * FIXME: MmWriteDirtyPages doesn't work correctly.
89 MmWriteDirtyPages(128, &PagesWritten
);
92 CcRosFlushDirtyPages(128, &PagesWritten
);
103 MpwThreadShouldTerminate
= FALSE
;
104 KeInitializeEvent(&MpwThreadEvent
, SynchronizationEvent
, FALSE
);
106 Status
= PsCreateSystemThread(&MpwThreadHandle
,
111 (PKSTART_ROUTINE
) MmMpwThreadMain
,
113 if (!NT_SUCCESS(Status
))
119 NtSetInformationThread(MpwThreadHandle
,
124 return(STATUS_SUCCESS
);