+/* FIXME: Someday this could somewhat implement write-behind/read-ahead */
+VOID
+NTAPI
+CciLazyWriter(PVOID Unused)
+{
+ LARGE_INTEGER OneSecond;
+
+ OneSecond.QuadPart = (LONGLONG)-1*1000*1000*10;
+
+ while (TRUE)
+ {
+ NTSTATUS Status;
+ ULONG Target, Count = 0;
+
+ /* One per second or until we have to stop */
+ Status = KeWaitForSingleObject(&iLazyWriterShutdown,
+ Executive,
+ KernelMode,
+ FALSE,
+ &OneSecond);
+
+ /* If we succeeed, we've to stop running! */
+ if (Status == STATUS_SUCCESS)
+ {
+ break;
+ }
+
+ /* We're not sleeping anymore */
+ KeClearEvent(&iLazyWriterNotify);
+
+ /* Only start operations if above threshold */
+ DPRINT("TS: %lu, Count: %lu\n", CcDirtyPageThreshold, CcTotalDirtyPages);
+ if (CcTotalDirtyPages > CcDirtyPageThreshold)
+ {
+ /* Our target is one-eighth of the dirty pages */
+ Target = CcTotalDirtyPages / 8;
+ if (Target != 0)
+ {
+ /* Flush! */
+ DPRINT("Lazy writer starting (%d)\n", Target);
+ CcRosFlushDirtyPages(Target, &Count, FALSE, TRUE);
+
+ /* And update stats */
+ CcLazyWritePages += Count;
+ ++CcLazyWriteIos;
+ DPRINT("Lazy writer done (%d)\n", Count);
+ }
+ }
+
+ /* Inform people waiting on us that we're done */
+ KeSetEvent(&iLazyWriterNotify, IO_DISK_INCREMENT, FALSE);
+ }
+}
+