[NTOSKRNL]
authorCameron Gutman <aicommander@gmail.com>
Fri, 23 Dec 2011 23:20:09 +0000 (23:20 +0000)
committerCameron Gutman <aicommander@gmail.com>
Fri, 23 Dec 2011 23:20:09 +0000 (23:20 +0000)
- Reference the cache segment when flushing to avoid a race between deleting the file cache and the balancer flushing pages to disk which causes random cache segments to be freed while we're holding a lock on it
- Fixes a crash in KeReleaseMutex (used to be a crash in ExReleasePushLock) during periods of high memory load

svn path=/trunk/; revision=54745

reactos/ntoskrnl/cc/view.c

index b75cb56..b6bdab5 100644 (file)
@@ -204,10 +204,13 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
                                     DirtySegmentListEntry);
         current_entry = current_entry->Flink;
 
+        CcRosCacheSegmentIncRefCount(current);
+
         Locked = current->Bcb->Callbacks->AcquireForLazyWrite(
             current->Bcb->LazyWriteContext, Wait);
         if (!Locked)
         {
+            CcRosCacheSegmentDecRefCount(current);
             continue;
         }
 
@@ -220,6 +223,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
         {
             current->Bcb->Callbacks->ReleaseFromLazyWrite(
                 current->Bcb->LazyWriteContext);
+            CcRosCacheSegmentDecRefCount(current);
             continue;
         }
 
@@ -229,6 +233,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
             KeReleaseMutex(&current->Mutex, 0);
             current->Bcb->Callbacks->ReleaseFromLazyWrite(
                 current->Bcb->LazyWriteContext);
+            CcRosCacheSegmentDecRefCount(current);
             continue;
         }
 
@@ -241,6 +246,9 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
         KeReleaseMutex(&current->Mutex, 0);
         current->Bcb->Callbacks->ReleaseFromLazyWrite(
             current->Bcb->LazyWriteContext);
+        
+        KeAcquireGuardedMutex(&ViewLock);
+        CcRosCacheSegmentDecRefCount(current);
 
         if (!NT_SUCCESS(Status) &&  (Status != STATUS_END_OF_FILE))
         {
@@ -251,8 +259,7 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
             (*Count) += PagesPerSegment;
             Target -= PagesPerSegment;
         }
-        
-        KeAcquireGuardedMutex(&ViewLock);
+
         current_entry = DirtySegmentListHead.Flink;
     }