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 ****************************************************************/
34 #include <internal/debug.h>
36 /* GLOBALS *******************************************************************/
38 static HANDLE MpwThreadHandle
;
39 static CLIENT_ID MpwThreadId
;
40 static KEVENT MpwThreadEvent
;
41 static volatile BOOLEAN MpwThreadShouldTerminate
;
43 /* FUNCTIONS *****************************************************************/
46 MmWriteDirtyPages(ULONG Target
, PULONG Actual
)
52 Page
= MmGetLRUFirstUserPage();
53 while (Page
!= 0 && Target
> 0)
56 * FIXME: While the current page is write back it is possible
57 * that the next page is freed and not longer a user page.
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
);
105 * FIXME: MmWriteDirtyPages doesn't work correctly.
107 MmWriteDirtyPages(128, &PagesWritten
);
110 CcRosFlushDirtyPages(128, &PagesWritten
);
114 NTSTATUS
MmInitMpwThread(VOID
)
119 MpwThreadShouldTerminate
= FALSE
;
120 KeInitializeEvent(&MpwThreadEvent
, SynchronizationEvent
, FALSE
);
122 Status
= PsCreateSystemThread(&MpwThreadHandle
,
127 (PKSTART_ROUTINE
) MmMpwThreadMain
,
129 if (!NT_SUCCESS(Status
))
135 NtSetInformationThread(MpwThreadHandle
,
140 return(STATUS_SUCCESS
);