[NTOSKRNL] Misc fixes to Cc:

- CcUnpinDataForThread() only release VACB when the last BCB reference is gone. This avoids having a valid BCB with an invalid VACB
- CcRosMarkDirtyVacb() will only accept non-dirty VACB now. This avoids a major bug where a an already dirty VACB was over-dereferenced
- Thanks to previous point, simplify CcRosUnmapVacb(), CcRosReleaseVacb() implementation
- And only set VACB dirty once in CcSetDirtyPinnedData()
- Add a few sanity checks

With that I can again install ReactOS with 128MB RAM :-).

CORE-14263
CORE-14268
This commit is contained in:
Pierre Schweitzer 2018-01-28 11:09:21 +01:00
parent d3e0eb2026
commit 52287be9a9
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
2 changed files with 25 additions and 49 deletions

View file

@ -247,7 +247,10 @@ CcSetDirtyPinnedData (
Bcb, Lsn);
iBcb->Dirty = TRUE;
CcRosMarkDirtyVacb(iBcb->Vacb);
if (!iBcb->Vacb->Dirty)
{
CcRosMarkDirtyVacb(iBcb->Vacb);
}
}
@ -284,14 +287,14 @@ CcUnpinDataForThread (
iBcb->Vacb->PinCount--;
}
CcRosReleaseVacb(iBcb->Vacb->SharedCacheMap,
iBcb->Vacb,
TRUE,
iBcb->Dirty,
FALSE);
if (--iBcb->RefCount == 0)
{
CcRosReleaseVacb(iBcb->Vacb->SharedCacheMap,
iBcb->Vacb,
TRUE,
iBcb->Dirty,
FALSE);
ExDeleteResourceLite(&iBcb->Lock);
ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
}

View file

@ -99,6 +99,7 @@ static void CcRosVacbIncRefCount_(PROS_VACB vacb, const char* file, int line)
static void CcRosVacbDecRefCount_(PROS_VACB vacb, const char* file, int line)
{
--vacb->ReferenceCount;
ASSERT(!(vacb->ReferenceCount == 0 && vacb->Dirty));
if (vacb->SharedCacheMap->Trace)
{
DbgPrint("(%s:%i) VACB %p --RefCount=%lu, Dirty %u, PageOut %lu\n",
@ -518,8 +519,6 @@ CcRosReleaseVacb (
BOOLEAN Dirty,
BOOLEAN Mapped)
{
BOOLEAN WasDirty;
ASSERT(SharedCacheMap);
DPRINT("CcRosReleaseVacb(SharedCacheMap 0x%p, Vacb 0x%p, Valid %u)\n",
@ -527,17 +526,9 @@ CcRosReleaseVacb (
Vacb->Valid = Valid;
WasDirty = FALSE;
if (Dirty)
if (Dirty && !Vacb->Dirty)
{
if (!Vacb->Dirty)
{
CcRosMarkDirtyVacb(Vacb);
}
else
{
WasDirty = TRUE;
}
CcRosMarkDirtyVacb(Vacb);
}
if (Mapped)
@ -549,10 +540,6 @@ CcRosReleaseVacb (
{
CcRosVacbIncRefCount(Vacb);
}
if (!WasDirty && Vacb->Dirty)
{
CcRosVacbIncRefCount(Vacb);
}
CcRosReleaseVacbLock(Vacb);
@ -618,16 +605,12 @@ CcRosMarkDirtyVacb (
KeAcquireGuardedMutex(&ViewLock);
KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &oldIrql);
if (!Vacb->Dirty)
{
InsertTailList(&DirtyVacbListHead, &Vacb->DirtyVacbListEntry);
CcTotalDirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
Vacb->SharedCacheMap->DirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
}
else
{
CcRosVacbDecRefCount(Vacb);
}
ASSERT(!Vacb->Dirty);
InsertTailList(&DirtyVacbListHead, &Vacb->DirtyVacbListEntry);
CcTotalDirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
Vacb->SharedCacheMap->DirtyPages += VACB_MAPPING_GRANULARITY / PAGE_SIZE;
CcRosVacbIncRefCount(Vacb);
/* Move to the tail of the LRU list */
RemoveEntryList(&Vacb->VacbLruListEntry);
@ -658,7 +641,10 @@ CcRosMarkDirtyFile (
KeBugCheck(CACHE_MANAGER);
}
CcRosMarkDirtyVacb(Vacb);
if (!Vacb->Dirty)
{
CcRosMarkDirtyVacb(Vacb);
}
CcRosReleaseVacbLock(Vacb);
@ -673,7 +659,6 @@ CcRosUnmapVacb (
BOOLEAN NowDirty)
{
PROS_VACB Vacb;
BOOLEAN WasDirty;
ASSERT(SharedCacheMap);
@ -686,26 +671,14 @@ CcRosUnmapVacb (
return STATUS_UNSUCCESSFUL;
}
WasDirty = FALSE;
if (NowDirty)
if (NowDirty && !Vacb->Dirty)
{
if (!Vacb->Dirty)
{
CcRosMarkDirtyVacb(Vacb);
}
else
{
WasDirty = TRUE;
}
CcRosMarkDirtyVacb(Vacb);
}
Vacb->MappedCount--;
CcRosVacbDecRefCount(Vacb);
if (!WasDirty && NowDirty)
{
CcRosVacbIncRefCount(Vacb);
}
if (Vacb->MappedCount == 0)
{
CcRosVacbDecRefCount(Vacb);