Skip to content
Permalink
Browse files

[NTOSKRNL] Simplify (and speedup!) CcCanIWrite() using the dirty page…

…s count in cache map.
  • Loading branch information...
HeisSpiter committed Jan 26, 2018
1 parent 5cc0668 commit dc85171674eaecb386adaf7037b977715b1529f3
Showing with 5 additions and 28 deletions.
  1. +2 −24 ntoskrnl/cc/copy.c
  2. +3 −4 ntoskrnl/cc/view.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,35 +406,16 @@ 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;
}

/* 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;
}
@@ -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;

0 comments on commit dc85171

Please sign in to comment.
You can’t perform that action at this time.