mirror of
https://github.com/reactos/reactos.git
synced 2025-08-11 04:25:32 +00:00
[NTOSKRNL] Drop the always running thread for lazy writer.
Instead move to a threading model like the Windows one. We'll queue several work items to be executed in a system thread (Cc worker) when there are VACB that have been marked as dirty. Furthermore, some delay will be observed before action to avoid killing the system with IOs. This new threading model opens way for read ahead and write behind implementation. Also, moved the initialization of the lazy writer to CcInitializeCacheManager() it has nothing to do with views and shouldn't be initialized there. Also, moved the lazy writer implementation to its own file. Modified CcDeferWrite() and CcRosMarkDirtyVacb() to take into account the new threading model. Introduced new functions: - CcPostWorkQueue(): post an item to be handled by Cc worker and spawn a worker if required - CcScanDpc(): called after some time (not to have lazy writer always running) to queue a lazy scan - CcLazyWriteScan(): the lazy writer we used to have - CcScheduleLazyWriteScan(): function to call when you want to start a lazy writer run. It will make a DPC after some time and queue execution - CcWorkerThread(): the worker thread that will handle lazy write, read ahead, and so on
This commit is contained in:
parent
3b147adafb
commit
7e550edb26
7 changed files with 426 additions and 172 deletions
|
@ -16,6 +16,9 @@
|
|||
|
||||
BOOLEAN CcPfEnablePrefetcher;
|
||||
PFSN_PREFETCHER_GLOBALS CcPfGlobals;
|
||||
MM_SYSTEMSIZE CcCapturedSystemSize;
|
||||
|
||||
static ULONG BugCheckFileId = 0x4 << 16;
|
||||
|
||||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
|
@ -42,15 +45,78 @@ NTAPI
|
|||
INIT_FUNCTION
|
||||
CcInitializeCacheManager(VOID)
|
||||
{
|
||||
return CcInitView();
|
||||
ULONG Thread;
|
||||
|
||||
CcInitView();
|
||||
|
||||
/* Initialize lazy-writer lists */
|
||||
InitializeListHead(&CcIdleWorkerThreadList);
|
||||
InitializeListHead(&CcRegularWorkQueue);
|
||||
|
||||
/* Define lazy writer threshold and the amount of workers,
|
||||
* depending on the system type
|
||||
*/
|
||||
CcCapturedSystemSize = MmQuerySystemSize();
|
||||
switch (CcCapturedSystemSize)
|
||||
{
|
||||
case MmSmallSystem:
|
||||
CcNumberWorkerThreads = ExCriticalWorkerThreads - 1;
|
||||
CcDirtyPageThreshold = MmNumberOfPhysicalPages / 8;
|
||||
break;
|
||||
|
||||
case MmMediumSystem:
|
||||
CcNumberWorkerThreads = ExCriticalWorkerThreads - 1;
|
||||
CcDirtyPageThreshold = MmNumberOfPhysicalPages / 4;
|
||||
break;
|
||||
|
||||
case MmLargeSystem:
|
||||
CcNumberWorkerThreads = ExCriticalWorkerThreads - 2;
|
||||
CcDirtyPageThreshold = MmNumberOfPhysicalPages / 8 + MmNumberOfPhysicalPages / 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
CcNumberWorkerThreads = 1;
|
||||
CcDirtyPageThreshold = MmNumberOfPhysicalPages / 8;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Allocate a work item for all our threads */
|
||||
for (Thread = 0; Thread < CcNumberWorkerThreads; ++Thread)
|
||||
{
|
||||
PWORK_QUEUE_ITEM Item;
|
||||
|
||||
Item = ExAllocatePoolWithTag(NonPagedPool, sizeof(WORK_QUEUE_ITEM), 'qWcC');
|
||||
if (Item == NULL)
|
||||
{
|
||||
CcBugCheck(0, 0, 0);
|
||||
}
|
||||
|
||||
/* By default, it's obviously idle */
|
||||
ExInitializeWorkItem(Item, CcWorkerThread, Item);
|
||||
InsertTailList(&CcIdleWorkerThreadList, &Item->List);
|
||||
}
|
||||
|
||||
/* Initialize our lazy writer */
|
||||
RtlZeroMemory(&LazyWriter, sizeof(LazyWriter));
|
||||
InitializeListHead(&LazyWriter.WorkQueue);
|
||||
/* Delay activation of the lazy writer */
|
||||
KeInitializeDpc(&LazyWriter.ScanDpc, CcScanDpc, NULL);
|
||||
KeInitializeTimer(&LazyWriter.ScanTimer);
|
||||
|
||||
/* Lookaside list for our work items */
|
||||
ExInitializeNPagedLookasideList(&CcTwilightLookasideList, NULL, NULL, 0, sizeof(WORK_QUEUE_ENTRY), 'KWcC', 0);
|
||||
|
||||
/* HACK: for lazy writer watching */
|
||||
KeInitializeEvent(&iLazyWriterNotify, NotificationEvent, FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
CcShutdownSystem(VOID)
|
||||
{
|
||||
/* Inform the lazy writer it has to stop activity */
|
||||
CcShutdownLazyWriter();
|
||||
/* NOTHING TO DO */
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue