From 65e29b4b1f3ba0360c2fb30b5c3a38d1ffb784e2 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Wed, 2 May 2018 23:30:10 +0200 Subject: [PATCH] [NTOSKRNL] Optimize a bit deferred writes. In the lazy writer run, first post items that are queued for this. Only then, start executing deferred writes if any. If there were any, reschedule immediately a lazy writer run, to keep Cc warm and to make it unqueue write faster in case of high IOs situation. To make second lazy writer run happen faster, we keep our state active to use short delay (1s) instead of standard idle (3s). --- ntoskrnl/cc/lazywrite.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ntoskrnl/cc/lazywrite.c b/ntoskrnl/cc/lazywrite.c index ddb7bc42c3f..8cb5adb2e71 100644 --- a/ntoskrnl/cc/lazywrite.c +++ b/ntoskrnl/cc/lazywrite.c @@ -152,12 +152,6 @@ CcLazyWriteScan(VOID) DPRINT("Lazy writer done (%d)\n", Count); } - /* If we have deferred writes, try them now! */ - if (!IsListEmpty(&CcDeferredWrites)) - { - CcPostDeferredWrites(); - } - /* Post items that were due for end of run */ while (!IsListEmpty(&ToPost)) { @@ -166,10 +160,22 @@ CcLazyWriteScan(VOID) CcPostWorkQueue(WorkItem, &CcRegularWorkQueue); } - /* We're no longer active */ - OldIrql = KeAcquireQueuedSpinLock(LockQueueMasterLock); - LazyWriter.ScanActive = FALSE; - KeReleaseQueuedSpinLock(LockQueueMasterLock, OldIrql); + /* If we have deferred writes, try them now! */ + if (!IsListEmpty(&CcDeferredWrites)) + { + CcPostDeferredWrites(); + /* Reschedule immediately a lazy writer run + * Keep us active to have short idle delay + */ + CcScheduleLazyWriteScan(FALSE); + } + else + { + /* We're no longer active */ + OldIrql = KeAcquireQueuedSpinLock(LockQueueMasterLock); + LazyWriter.ScanActive = FALSE; + KeReleaseQueuedSpinLock(LockQueueMasterLock, OldIrql); + } } VOID CcScheduleLazyWriteScan(