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
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES ****************************************************************/
15 #include <internal/debug.h>
17 /* GLOBALS *******************************************************************/
20 static HANDLE PagerThreadHandle
;
21 static CLIENT_ID PagerThreadId
;
22 static KEVENT PagerThreadEvent
;
23 static BOOLEAN PagerThreadShouldTerminate
;
24 static ULONG PagerThreadWorkCount
;
27 /* FUNCTIONS *****************************************************************/
33 return(PsGetCurrentThreadId() == PagerThreadId
.UniqueThread
);
37 MiStartPagerThread(VOID
)
41 WasWorking
= InterlockedIncrement(&PagerThreadWorkCount
);
44 KeSetEvent(&PagerThreadEvent
, IO_NO_INCREMENT
, FALSE
);
49 MiStopPagerThread(VOID
)
51 (VOID
)InterlockedDecrement(&PagerThreadWorkCount
);
54 static NTSTATUS STDCALL
55 MmPagerThreadMain(PVOID Ignored
)
61 /* Wake for a low memory situation or a terminate request. */
62 Status
= KeWaitForSingleObject(&PagerThreadEvent
,
67 if (!NT_SUCCESS(Status
))
69 DbgPrint("PagerThread: Wait failed\n");
72 if (PagerThreadShouldTerminate
)
74 DbgPrint("PagerThread: Terminating\n");
75 return(STATUS_SUCCESS
);
79 /* Try and make some memory available to the system. */
80 MmRebalanceMemoryConsumers();
82 while(PagerThreadWorkCount
> 0);
86 NTSTATUS
MmInitPagerThread(VOID
)
90 PagerThreadShouldTerminate
= FALSE
;
91 PagerThreadWorkCount
= 0;
92 KeInitializeEvent(&PagerThreadEvent
,
96 Status
= PsCreateSystemThread(&PagerThreadHandle
,
101 (PKSTART_ROUTINE
) MmPagerThreadMain
,
103 if (!NT_SUCCESS(Status
))
108 return(STATUS_SUCCESS
);