1 /* $Id: pager.c,v 1.18 2004/08/15 16:39:08 chorns Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/pager.c
6 * PURPOSE: Moves infrequently used data out of memory
7 * PROGRAMMER: David Welch (welch@cwcom.net)
12 /* INCLUDES ****************************************************************/
16 #include <internal/debug.h>
18 /* GLOBALS *******************************************************************/
21 static HANDLE PagerThreadHandle
;
22 static CLIENT_ID PagerThreadId
;
23 static KEVENT PagerThreadEvent
;
24 static BOOLEAN PagerThreadShouldTerminate
;
25 static ULONG PagerThreadWorkCount
;
28 /* FUNCTIONS *****************************************************************/
34 return(PsGetCurrentThreadId() == PagerThreadId
.UniqueThread
);
38 MiStartPagerThread(VOID
)
42 WasWorking
= InterlockedIncrement(&PagerThreadWorkCount
);
45 KeSetEvent(&PagerThreadEvent
, IO_NO_INCREMENT
, FALSE
);
50 MiStopPagerThread(VOID
)
52 (VOID
)InterlockedDecrement(&PagerThreadWorkCount
);
55 static NTSTATUS STDCALL
56 MmPagerThreadMain(PVOID Ignored
)
62 /* Wake for a low memory situation or a terminate request. */
63 Status
= KeWaitForSingleObject(&PagerThreadEvent
,
68 if (!NT_SUCCESS(Status
))
70 DbgPrint("PagerThread: Wait failed\n");
73 if (PagerThreadShouldTerminate
)
75 DbgPrint("PagerThread: Terminating\n");
76 return(STATUS_SUCCESS
);
80 /* Try and make some memory available to the system. */
81 MmRebalanceMemoryConsumers();
83 while(PagerThreadWorkCount
> 0);
87 NTSTATUS
MmInitPagerThread(VOID
)
91 PagerThreadShouldTerminate
= FALSE
;
92 PagerThreadWorkCount
= 0;
93 KeInitializeEvent(&PagerThreadEvent
,
97 Status
= PsCreateSystemThread(&PagerThreadHandle
,
102 (PKSTART_ROUTINE
) MmPagerThreadMain
,
104 if (!NT_SUCCESS(Status
))
109 return(STATUS_SUCCESS
);