https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dc85171674eaecb386adaf7037b977715b1529f3

commit dc85171674eaecb386adaf7037b977715b1529f3
Author:     Pierre Schweitzer <[email protected]>
AuthorDate: Fri Jan 26 10:50:13 2018 +0100
Commit:     Pierre Schweitzer <[email protected]>
CommitDate: Fri Jan 26 10:50:13 2018 +0100

    [NTOSKRNL] Simplify (and speedup!) CcCanIWrite() using the dirty pages 
count in cache map.
---
 ntoskrnl/cc/copy.c | 26 ++------------------------
 ntoskrnl/cc/view.c |  7 +++----
 2 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/ntoskrnl/cc/copy.c b/ntoskrnl/cc/copy.c
index db6f0f4920..e194074d59 100644
--- a/ntoskrnl/cc/copy.c
+++ b/ntoskrnl/cc/copy.c
@@ -376,9 +376,6 @@ CcCanIWrite (
     IN BOOLEAN Wait,
     IN BOOLEAN Retrying)
 {
-    KIRQL OldIrql;
-    ULONG DirtyPages;
-    PLIST_ENTRY ListEntry;
     PFSRTL_COMMON_FCB_HEADER Fcb;
     PROS_SHARED_CACHE_MAP SharedCacheMap;
 
@@ -409,27 +406,8 @@ CcCanIWrite (
         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? */
-    if (DirtyPages > SharedCacheMap->DirtyPageThreshold)
+    if (SharedCacheMap->DirtyPages > SharedCacheMap->DirtyPageThreshold)
     {
         return FALSE;
     }
@@ -437,7 +415,7 @@ CcCanIWrite (
     /* 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;
     }
diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c
index b08210c241..0340c68407 100644
--- a/ntoskrnl/cc/view.c
+++ b/ntoskrnl/cc/view.c
@@ -1521,6 +1521,9 @@ ExpKdbgExtFileCache(ULONG Argc, PCHAR Argv[])
 
         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;
@@ -1529,10 +1532,6 @@ ExpKdbgExtFileCache(ULONG Argc, PCHAR Argv[])
             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;

Reply via email to