[NTOSKRNL]

- Add a wait parameter to CcRosFlushDirtyPages and only block on the segment locks of it is safe

svn path=/trunk/; revision=54730
This commit is contained in:
Cameron Gutman 2011-12-21 19:46:07 +00:00
parent 80ee75c141
commit 274217e861
4 changed files with 20 additions and 38 deletions

View file

@ -175,43 +175,23 @@ CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
NTSTATUS
NTAPI
CcRosFlushDirtyPages(ULONG Target, PULONG Count)
CcRosFlushDirtyPages(ULONG Target, PULONG Count, BOOLEAN Wait)
{
PLIST_ENTRY current_entry;
PCACHE_SEGMENT current;
ULONG PagesPerSegment;
BOOLEAN Locked;
NTSTATUS Status;
static ULONG WriteCount[4] = {0, 0, 0, 0};
ULONG NewTarget;
LARGE_INTEGER ZeroTimeout;
DPRINT("CcRosFlushDirtyPages(Target %d)\n", Target);
(*Count) = 0;
ZeroTimeout.QuadPart = 0;
KeEnterCriticalRegion();
KeAcquireGuardedMutex(&ViewLock);
WriteCount[0] = WriteCount[1];
WriteCount[1] = WriteCount[2];
WriteCount[2] = WriteCount[3];
WriteCount[3] = 0;
NewTarget = WriteCount[0] + WriteCount[1] + WriteCount[2];
if (NewTarget < DirtyPageCount)
{
NewTarget = (DirtyPageCount - NewTarget + 3) / 4;
WriteCount[0] += NewTarget;
WriteCount[1] += NewTarget;
WriteCount[2] += NewTarget;
WriteCount[3] += NewTarget;
}
NewTarget = WriteCount[0];
Target = max(NewTarget, Target);
current_entry = DirtySegmentListHead.Flink;
if (current_entry == &DirtySegmentListHead)
{
@ -225,17 +205,23 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
current_entry = current_entry->Flink;
Locked = current->Bcb->Callbacks->AcquireForLazyWrite(
current->Bcb->LazyWriteContext, TRUE);
current->Bcb->LazyWriteContext, Wait);
if (!Locked)
{
continue;
}
KeWaitForSingleObject(&current->Mutex,
Executive,
KernelMode,
FALSE,
NULL);
Status = KeWaitForSingleObject(&current->Mutex,
Executive,
KernelMode,
FALSE,
Wait ? NULL : &ZeroTimeout);
if (Status != STATUS_SUCCESS)
{
current->Bcb->Callbacks->ReleaseFromLazyWrite(
current->Bcb->LazyWriteContext);
continue;
}
ASSERT(current->Dirty);
if (current->ReferenceCount > 1)
@ -270,11 +256,6 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
current_entry = DirtySegmentListHead.Flink;
}
if (*Count < NewTarget)
{
WriteCount[1] += (NewTarget - *Count);
}
KeReleaseGuardedMutex(&ViewLock);
KeLeaveCriticalRegion();
@ -374,7 +355,7 @@ retry:
if (Target > 0 && !FlushedPages)
{
/* Flush dirty pages to disk */
CcRosFlushDirtyPages(Target, &PagesFreed);
CcRosFlushDirtyPages(Target, &PagesFreed, FALSE);
FlushedPages = TRUE;
/* We can only swap as many pages as we flushed */

View file

@ -261,7 +261,8 @@ NTSTATUS
NTAPI
CcRosFlushDirtyPages(
ULONG Target,
PULONG Count
PULONG Count,
BOOLEAN Wait
);
VOID

View file

@ -306,7 +306,7 @@ MmMpwThreadMain(PVOID Ignored)
#ifndef NEWCC
// XXX arty -- we flush when evicting pages or destorying cache
// sections.
CcRosFlushDirtyPages(128, &PagesWritten);
CcRosFlushDirtyPages(128, &PagesWritten, FALSE);
#endif
}
}

View file

@ -902,7 +902,7 @@ NtSetSystemPowerState(IN POWER_ACTION SystemAction,
#ifndef NEWCC
/* Flush dirty cache pages */
CcRosFlushDirtyPages(-1, &Dummy);
CcRosFlushDirtyPages(-1, &Dummy, TRUE);
#else
Dummy = 0;
#endif