[NTOSKRNL] Reimplement the lazy writer in Cc and remove the "basic" one in Mm.

This removes the "modified page writer" thread in Mm that was regularly blindly
attempting to flush dirty pages to the disk.
Instead, this commit introduces a lazy writer that will monitor dirty pages count
and will flush them to disk when this count is above a threshold. The threshold is
computed on Cc init.
Compared to what was done previously, this lazy writer will only write down files
that are not marked as temporary.
The mechanisms involved in this lazy writer worker are well described in Windows
Internals 4th editions (constants are coming from it ;-)).
Also fixed a bad (and old!) bug in CcRosFlushDirtyPages() where target count could
be overflow and the function would spin forever while holding the VACBs lock. This is
mandatory as now lazy writer will call it with "random" values.
This also allows implementing CcWaitForCurrentLazyWriterActivity() :-).
Also renamed DirtyPageCount to its MS equivalent.

CORE-14235
This commit is contained in:
Pierre Schweitzer 2018-01-23 19:07:25 +01:00
parent 2382435e88
commit c7ad200f8b
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
9 changed files with 205 additions and 100 deletions

View file

@ -19,9 +19,6 @@
VOID NTAPI MiInitializeUserPfnBitmap(VOID);
HANDLE MpwThreadHandle;
KEVENT MpwThreadEvent;
BOOLEAN Mm64BitPhysicalAddress = FALSE;
ULONG MmReadClusterSize;
//
@ -169,76 +166,6 @@ MiDbgDumpAddressSpace(VOID)
"Non Paged Pool Expansion PTE Space");
}
VOID
NTAPI
MmMpwThreadMain(PVOID Parameter)
{
NTSTATUS Status;
#ifndef NEWCC
ULONG PagesWritten;
#endif
LARGE_INTEGER Timeout;
UNREFERENCED_PARAMETER(Parameter);
Timeout.QuadPart = -50000000;
for(;;)
{
Status = KeWaitForSingleObject(&MpwThreadEvent,
0,
KernelMode,
FALSE,
&Timeout);
if (!NT_SUCCESS(Status))
{
DbgPrint("MpwThread: Wait failed\n");
KeBugCheck(MEMORY_MANAGEMENT);
return;
}
#ifndef NEWCC
PagesWritten = 0;
// XXX arty -- we flush when evicting pages or destorying cache
// sections.
CcRosFlushDirtyPages(128, &PagesWritten, FALSE);
#endif
}
}
NTSTATUS
NTAPI
INIT_FUNCTION
MmInitMpwThread(VOID)
{
KPRIORITY Priority;
NTSTATUS Status;
CLIENT_ID MpwThreadId;
KeInitializeEvent(&MpwThreadEvent, SynchronizationEvent, FALSE);
Status = PsCreateSystemThread(&MpwThreadHandle,
THREAD_ALL_ACCESS,
NULL,
NULL,
&MpwThreadId,
MmMpwThreadMain,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Priority = 27;
NtSetInformationThread(MpwThreadHandle,
ThreadPriority,
&Priority,
sizeof(Priority));
return(STATUS_SUCCESS);
}
NTSTATUS
NTAPI
INIT_FUNCTION
@ -338,11 +265,6 @@ MmInitSystem(IN ULONG Phase,
*/
MiInitBalancerThread();
/*
* Initialise the modified page writer.
*/
MmInitMpwThread();
/* Initialize the balance set manager */
MmInitBsmThread();