diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c index f35d5c227c2..e4397200b2f 100644 --- a/ntoskrnl/cc/view.c +++ b/ntoskrnl/cc/view.c @@ -164,33 +164,20 @@ CcRosFlushVacb ( _Out_opt_ PIO_STATUS_BLOCK Iosb) { NTSTATUS Status; - BOOLEAN HaveLock = FALSE; PROS_SHARED_CACHE_MAP SharedCacheMap = Vacb->SharedCacheMap; + /* Unmark dirty first, and then write. This will avoid trying to flush + * twice a dirty VACB under high IOs pressure. */ CcRosUnmarkDirtyVacb(Vacb, TRUE); - /* Lock for flush, if we are not already the top-level */ - if (IoGetTopLevelIrp() != (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP) - { - Status = FsRtlAcquireFileForCcFlushEx(Vacb->SharedCacheMap->FileObject); - if (!NT_SUCCESS(Status)) - goto quit; - HaveLock = TRUE; - } - Status = MmFlushSegment(SharedCacheMap->FileObject->SectionObjectPointer, &Vacb->FileOffset, VACB_MAPPING_GRANULARITY, Iosb); - - if (HaveLock) - { - FsRtlReleaseFileForCcFlush(Vacb->SharedCacheMap->FileObject); - } - -quit: if (!NT_SUCCESS(Status)) + { CcRosMarkDirtyVacb(Vacb); + } else { /* Update VDL */ @@ -1108,6 +1095,7 @@ CcFlushCache ( PROS_SHARED_CACHE_MAP SharedCacheMap; LONGLONG FlushStart, FlushEnd; NTSTATUS Status; + BOOLEAN HaveFileLock = FALSE; CCTRACE(CC_API_DEBUG, "SectionObjectPointers=%p FileOffset=0x%I64X Length=%lu\n", SectionObjectPointers, FileOffset ? FileOffset->QuadPart : 0LL, Length); @@ -1146,7 +1134,15 @@ CcFlushCache ( IoStatus->Information = 0; } - KeAcquireGuardedMutex(&SharedCacheMap->FlushCacheLock); + /* Lock for flush, if we are not already the top-level */ + if (IoGetTopLevelIrp() != (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP) + { + Status = FsRtlAcquireFileForCcFlushEx(SharedCacheMap->FileObject); + if (!NT_SUCCESS(Status)) + goto quit; + + HaveFileLock = TRUE; + } /* * We flush the VACBs that we find here. @@ -1217,7 +1213,8 @@ CcFlushCache ( FlushStart -= FlushStart % VACB_MAPPING_GRANULARITY; } - KeReleaseGuardedMutex(&SharedCacheMap->FlushCacheLock); + if (HaveFileLock) + FsRtlReleaseFileForCcFlush(SharedCacheMap->FileObject); quit: if (IoStatus) @@ -1327,7 +1324,6 @@ CcRosInitializeFileCache ( KeInitializeSpinLock(&SharedCacheMap->CacheMapLock); InitializeListHead(&SharedCacheMap->CacheMapVacbListHead); InitializeListHead(&SharedCacheMap->BcbList); - KeInitializeGuardedMutex(&SharedCacheMap->FlushCacheLock); SharedCacheMap->Flags = SHARED_CACHE_MAP_IN_CREATION; diff --git a/ntoskrnl/include/internal/cc.h b/ntoskrnl/include/internal/cc.h index b37c5478f05..90c315901d1 100644 --- a/ntoskrnl/include/internal/cc.h +++ b/ntoskrnl/include/internal/cc.h @@ -193,7 +193,6 @@ typedef struct _ROS_SHARED_CACHE_MAP LIST_ENTRY CacheMapVacbListHead; BOOLEAN PinAccess; KSPIN_LOCK CacheMapLock; - KGUARDED_MUTEX FlushCacheLock; #if DBG BOOLEAN Trace; /* enable extra trace output for this cache map and it's VACBs */ #endif