[NTOSKRNL]
authorCameron Gutman <aicommander@gmail.com>
Wed, 21 Dec 2011 19:46:07 +0000 (19:46 +0000)
committerCameron Gutman <aicommander@gmail.com>
Wed, 21 Dec 2011 19:46:07 +0000 (19:46 +0000)
- Add a wait parameter to CcRosFlushDirtyPages and only block on the segment locks of it is safe

svn path=/trunk/; revision=54730

reactos/ntoskrnl/cc/view.c
reactos/ntoskrnl/include/internal/cc.h
reactos/ntoskrnl/mm/mminit.c
reactos/ntoskrnl/po/power.c

index 7c29a6f..b75cb56 100644 (file)
@@ -175,43 +175,23 @@ CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
 
 NTSTATUS
 NTAPI
-CcRosFlushDirtyPages(ULONG Target, PULONG Count)
+CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
 {
     PLIST_ENTRY current_entry;
     PCACHE_SEGMENT current;
     ULONG PagesPerSegment;
     BOOLEAN Locked;
     NTSTATUS Status;
-    static ULONG WriteCount[4] = {0, 0, 0, 0};
-    ULONG NewTarget;
+    LARGE_INTEGER ZeroTimeout;
     
     DPRINT("CcRosFlushDirtyPages(Target %d)\n", Target);
     
     (*Count) = 0;
+    ZeroTimeout.QuadPart = 0;
     
     KeEnterCriticalRegion();
     KeAcquireGuardedMutex(&ViewLock);
     
-    WriteCount[0] = WriteCount[1];
-    WriteCount[1] = WriteCount[2];
-    WriteCount[2] = WriteCount[3];
-    WriteCount[3] = 0;
-    
-    NewTarget = WriteCount[0] + WriteCount[1] + WriteCount[2];
-    
-    if (NewTarget < DirtyPageCount)
-    {
-        NewTarget = (DirtyPageCount - NewTarget + 3) / 4;
-        WriteCount[0] += NewTarget;
-        WriteCount[1] += NewTarget;
-        WriteCount[2] += NewTarget;
-        WriteCount[3] += NewTarget;
-    }
-    
-    NewTarget = WriteCount[0];
-    
-    Target = max(NewTarget, Target);
-    
     current_entry = DirtySegmentListHead.Flink;
     if (current_entry == &DirtySegmentListHead)
     {
@@ -225,17 +205,23 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
         current_entry = current_entry->Flink;
 
         Locked = current->Bcb->Callbacks->AcquireForLazyWrite(
-            current->Bcb->LazyWriteContext, TRUE);
+            current->Bcb->LazyWriteContext, Wait);
         if (!Locked)
         {
             continue;
         }
 
-        KeWaitForSingleObject(&current->Mutex,
-                              Executive,
-                              KernelMode,
-                              FALSE,
-                              NULL);
+        Status = KeWaitForSingleObject(&current->Mutex,
+                                       Executive,
+                                       KernelMode,
+                                       FALSE,
+                                       Wait ? NULL : &ZeroTimeout);
+        if (Status != STATUS_SUCCESS)
+        {
+            current->Bcb->Callbacks->ReleaseFromLazyWrite(
+                current->Bcb->LazyWriteContext);
+            continue;
+        }
 
         ASSERT(current->Dirty);
         if (current->ReferenceCount > 1)
@@ -270,11 +256,6 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
         current_entry = DirtySegmentListHead.Flink;
     }
     
-    if (*Count < NewTarget)
-    {
-        WriteCount[1] += (NewTarget - *Count);
-    }
-    
     KeReleaseGuardedMutex(&ViewLock);
     KeLeaveCriticalRegion();
     
@@ -374,7 +355,7 @@ retry:
     if (Target > 0 && !FlushedPages)
     {
         /* Flush dirty pages to disk */
-        CcRosFlushDirtyPages(Target, &PagesFreed);
+        CcRosFlushDirtyPages(Target, &PagesFreed, FALSE);
         FlushedPages = TRUE;
 
         /* We can only swap as many pages as we flushed */
index 141e202..de71f28 100644 (file)
@@ -261,7 +261,8 @@ NTSTATUS
 NTAPI
 CcRosFlushDirtyPages(
     ULONG Target,
-    PULONG Count
+    PULONG Count,
+    BOOLEAN Wait
 );
 
 VOID
index 1ad5b5c..8d4e864 100644 (file)
@@ -306,7 +306,7 @@ MmMpwThreadMain(PVOID Ignored)
 #ifndef NEWCC
          // XXX arty -- we flush when evicting pages or destorying cache
          // sections.
-      CcRosFlushDirtyPages(128, &PagesWritten);
+      CcRosFlushDirtyPages(128, &PagesWritten, FALSE);
 #endif
    }
 }
index f249309..d044330 100644 (file)
@@ -902,7 +902,7 @@ NtSetSystemPowerState(IN POWER_ACTION SystemAction,
         
 #ifndef NEWCC
         /* Flush dirty cache pages */
-        CcRosFlushDirtyPages(-1, &Dummy);
+        CcRosFlushDirtyPages(-1, &Dummy, TRUE);
 #else
         Dummy = 0;
 #endif