[NTOSKRNL] Don't mark VACB dirty on unpin
authorPierre Schweitzer <pierre@reactos.org>
Wed, 17 Apr 2019 20:23:57 +0000 (22:23 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Wed, 17 Apr 2019 20:35:19 +0000 (22:35 +0200)
This could happen if BCB was marked dirty previously.
Marking VACB dirty on unpin could lead to a double write of
the VACB, even if clean.
Indeed, now that setting BCB dirty leads to marking VACB
dirty, the VACB can be flushed in between by the lazy-writer.
The BCB state is not reset on VACB flush, contrary to the VACB state.
Thus, on unpin even if the VACB was already flushed, we were
setting back the dirty state, leading the VACB to be flushed again.

This could bring a small performance downgrade. Though it remains
limited since this is mostly used for FS metadata.
Possibly it could lead to metadata corruption, but this is likely
less possible.

CORE-15954

ntoskrnl/cc/pin.c

index 775b105..044458f 100644 (file)
@@ -169,10 +169,15 @@ CcpDereferenceBcb(
         KeReleaseSpinLock(&SharedCacheMap->BcbSpinLock, OldIrql);
 
         ASSERT(Bcb->PinCount == 0);
+        /*
+         * Don't mark dirty, if it was dirty,
+         * the VACB was already marked as such
+         * following the call to CcSetDirtyPinnedData
+         */
         CcRosReleaseVacb(SharedCacheMap,
                          Bcb->Vacb,
                          TRUE,
-                         Bcb->Dirty,
+                         FALSE,
                          FALSE);
 
         ExDeleteResourceLite(&Bcb->Lock);
@@ -682,10 +687,15 @@ CcUnpinRepinnedBcb (
             ASSERT(iBcb->PinCount == 0);
         }
 
+        /*
+         * Don't mark dirty, if it was dirty,
+         * the VACB was already marked as such
+         * following the call to CcSetDirtyPinnedData
+         */
         CcRosReleaseVacb(iBcb->Vacb->SharedCacheMap,
                          iBcb->Vacb,
                          TRUE,
-                         iBcb->Dirty,
+                         FALSE,
                          FALSE);
 
         ExDeleteResourceLite(&iBcb->Lock);