diff --git a/NTOSKRNL/CC/cclazywriter.cpp b/NTOSKRNL/CC/cclazywriter.cpp index d46f8ec..62fbd49 100644 --- a/NTOSKRNL/CC/cclazywriter.cpp +++ b/NTOSKRNL/CC/cclazywriter.cpp @@ -1175,44 +1175,7 @@ NTAPI CcLazyWriteScan() CcScheduleLazyWriteScan(FALSE); } } -NTSTATUS CcWaitForCurrentLazyWriterActivity() -{ - NTSTATUS result; - PWORK_QUEUE_ENTRY WorkQueueEntry = nullptr; - KEVENT Event = {0}; - KIRQL irql = {0}; - result = CcAllocateWorkQueueEntry(&WorkQueueEntry); - if (NT_SUCCESS(result)) - { - WorkQueueEntry->Function = SetDone; - KeInitializeEvent(&Event, NotificationEvent, FALSE); - WorkQueueEntry->Parameters.Notification.Reason = (ULONG_PTR)&Event; - - if ((PerfGlobalGroupMask.Masks[4] & 0x20000) != 0) - CcPerfLogWorkItemEnqueue(&CcPostTickWorkQueue, WorkQueueEntry, 0, 0); - - irql = KeAcquireQueuedSpinLock(LockQueueMasterLock); - - WorkQueueEntry->WorkQueueLinks.Flink = &CcPostTickWorkQueue; - WorkQueueEntry->WorkQueueLinks.Blink = CcPostTickWorkQueue.Blink; - CcPostTickWorkQueue.Blink->Flink = &WorkQueueEntry->WorkQueueLinks; - CcPostTickWorkQueue.Blink = &WorkQueueEntry->WorkQueueLinks; - - LazyWriter.OtherWork = 1; - _InterlockedIncrement(&CcPostTickWorkItemCount); - - CcScheduleLazyWriteScan(1, 1); - - KeReleaseQueuedSpinLock(LockQueueMasterLock, irql); - - result = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); - - _InterlockedDecrement(&CcPostTickWorkItemCount); - } - - return result; -} VOID VECTORCALL CcReEngageWorkerThreads( ULONG NormalThreadsToActivate, ULONG ExtraWriteBehindThreadsToActivate @@ -1281,6 +1244,62 @@ VOID VECTORCALL CcReEngageWorkerThreads( ExQueueWorkItem(currentExtraThreadEntry, CriticalWorkQueue); } } + +VOID +NTAPI +CcAdjustWriteBehindThreadPool( + IN BOOLEAN IsThreadPriorityLow) +{ + if (IsThreadPriorityLow) + { + CcMaxNumberOfWriteBehindThreads = 1; + if (CcAddExtraWriteBehindThreads) + { + CcAddExtraWriteBehindThreads = false; + } + } + else + { + CcMaxNumberOfWriteBehindThreads = (ULONG)-1; + if (!IsListEmpty(&CcRegularWorkQueue) && !CcQueueThrottle) + { + CcReEngageWorkerThreads(CcNumberofWorkerThreads, 0); + } + } +} +VOID +NTAPI +CcAdjustWriteBehindThreadPoolIfNeeded( + IN BOOLEAN NeedAdjustment) +{ + BOOLEAN NeedBoost = false; + KSPIN_LOCK_QUEUE_NUMBER queueNumber = LockQueueMasterLock; + SpinLockGuard guard(queueNumber); + + if (CcPostTickWorkItemCount != 0) + { + if (CcIsWriteBehindThreadpoolAtLowPriority()) + { + CcAdjustWriteBehindThreadPool(false); + } + } + else + { + if (CcGlobalDirtyPageStatistics.DirtyPages > 0x2000 || NeedAdjustment) + { + if (CcIsWriteBehindThreadpoolAtLowPriority()) + { + CcAdjustWriteBehindThreadPool(false); + + } + } + else if (!CcExecutingWriteBehindWorkItems && IsListEmpty(&CcRegularWorkQueue)) + { + CcAdjustWriteBehindThreadPool(true); + } + } + +} VOID NTAPI CcWorkerThread(PVOID Parameter)