[NTOSKRNL] Simplify (and speedup!) CcCanIWrite() using the dirty pages count in cache...
authorPierre Schweitzer <pierre@reactos.org>
Fri, 26 Jan 2018 09:50:13 +0000 (10:50 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Fri, 26 Jan 2018 09:50:13 +0000 (10:50 +0100)
ntoskrnl/cc/copy.c
ntoskrnl/cc/view.c

index db6f0f4..e194074 100644 (file)
@@ -376,9 +376,6 @@ CcCanIWrite (
     IN BOOLEAN Wait,
     IN BOOLEAN Retrying)
 {
     IN BOOLEAN Wait,
     IN BOOLEAN Retrying)
 {
-    KIRQL OldIrql;
-    ULONG DirtyPages;
-    PLIST_ENTRY ListEntry;
     PFSRTL_COMMON_FCB_HEADER Fcb;
     PROS_SHARED_CACHE_MAP SharedCacheMap;
 
     PFSRTL_COMMON_FCB_HEADER Fcb;
     PROS_SHARED_CACHE_MAP SharedCacheMap;
 
@@ -409,27 +406,8 @@ CcCanIWrite (
         return TRUE;
     }
 
         return TRUE;
     }
 
-    /* There's a limit, start counting dirty pages */
-    DirtyPages = 0;
-    KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql);
-    for (ListEntry = SharedCacheMap->CacheMapVacbListHead.Flink;
-         ListEntry != &SharedCacheMap->CacheMapVacbListHead;
-         ListEntry = ListEntry->Flink)
-    {
-        PROS_VACB Vacb;
-
-        Vacb = CONTAINING_RECORD(ListEntry,
-                                 ROS_VACB,
-                                 CacheMapVacbListEntry);
-        if (Vacb->Dirty)
-        {
-            DirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
-        }
-    }
-    KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql);
-
     /* Is dirty page count above local threshold? */
     /* Is dirty page count above local threshold? */
-    if (DirtyPages > SharedCacheMap->DirtyPageThreshold)
+    if (SharedCacheMap->DirtyPages > SharedCacheMap->DirtyPageThreshold)
     {
         return FALSE;
     }
     {
         return FALSE;
     }
@@ -437,7 +415,7 @@ CcCanIWrite (
     /* We cannot write if dirty pages count will bring use above
      * XXX: Might not be accurate
      */
     /* We cannot write if dirty pages count will bring use above
      * XXX: Might not be accurate
      */
-    if (DirtyPages + (BytesToWrite / PAGE_SIZE) > SharedCacheMap->DirtyPageThreshold)
+    if (SharedCacheMap->DirtyPages + (BytesToWrite / PAGE_SIZE) > SharedCacheMap->DirtyPageThreshold)
     {
         return FALSE;
     }
     {
         return FALSE;
     }
index b08210c..0340c68 100644 (file)
@@ -1521,6 +1521,9 @@ ExpKdbgExtFileCache(ULONG Argc, PCHAR Argv[])
 
         SharedCacheMap = CONTAINING_RECORD(ListEntry, ROS_SHARED_CACHE_MAP, SharedCacheMapLinks);
 
 
         SharedCacheMap = CONTAINING_RECORD(ListEntry, ROS_SHARED_CACHE_MAP, SharedCacheMapLinks);
 
+        /* Dirty size */
+        Dirty = (SharedCacheMap->DirtyPages * PAGE_SIZE) / 1024;
+
         /* First, count for all the associated VACB */
         for (Vacbs = SharedCacheMap->CacheMapVacbListHead.Flink;
              Vacbs != &SharedCacheMap->CacheMapVacbListHead;
         /* First, count for all the associated VACB */
         for (Vacbs = SharedCacheMap->CacheMapVacbListHead.Flink;
              Vacbs != &SharedCacheMap->CacheMapVacbListHead;
@@ -1529,10 +1532,6 @@ ExpKdbgExtFileCache(ULONG Argc, PCHAR Argv[])
             PROS_VACB Vacb;
 
             Vacb = CONTAINING_RECORD(Vacbs, ROS_VACB, CacheMapVacbListEntry);
             PROS_VACB Vacb;
 
             Vacb = CONTAINING_RECORD(Vacbs, ROS_VACB, CacheMapVacbListEntry);
-            if (Vacb->Dirty)
-            {
-                Dirty += VACB_MAPPING_GRANULARITY / 1024;
-            }
             if (Vacb->Valid)
             {
                 Valid += VACB_MAPPING_GRANULARITY / 1024;
             if (Vacb->Valid)
             {
                 Valid += VACB_MAPPING_GRANULARITY / 1024;