mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 22:06:53 +00:00
[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:
parent
80ee75c141
commit
274217e861
4 changed files with 20 additions and 38 deletions
|
@ -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(¤t->Mutex,
|
||||
Executive,
|
||||
KernelMode,
|
||||
FALSE,
|
||||
NULL);
|
||||
Status = KeWaitForSingleObject(¤t->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 */
|
||||
|
|
|
@ -261,7 +261,8 @@ NTSTATUS
|
|||
NTAPI
|
||||
CcRosFlushDirtyPages(
|
||||
ULONG Target,
|
||||
PULONG Count
|
||||
PULONG Count,
|
||||
BOOLEAN Wait
|
||||
);
|
||||
|
||||
VOID
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue