mirror of
https://github.com/reactos/reactos.git
synced 2024-12-30 19:14:31 +00:00
BCB tracing implementation
svn path=/trunk/; revision=17367
This commit is contained in:
parent
a2525f8275
commit
ecb6afadcc
2 changed files with 108 additions and 14 deletions
|
@ -81,12 +81,81 @@ void* _alloca(size_t size);
|
||||||
#error Unknown compiler for alloca intrinsic stack allocation "function"
|
#error Unknown compiler for alloca intrinsic stack allocation "function"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(DBG) || defined(KDBG)
|
||||||
|
static void CcRosCacheSegmentIncRefCount ( PCACHE_SEGMENT cs )
|
||||||
|
{
|
||||||
|
++cs->ReferenceCount;
|
||||||
|
if ( cs->Bcb->Trace )
|
||||||
|
{
|
||||||
|
DPRINT1("CacheSegment %p ++RefCount=%d, Dirty %d, PageOut %d\n",
|
||||||
|
cs, cs->ReferenceCount, cs->Dirty, cs->PageOut );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void CcRosCacheSegmentDecRefCount ( PCACHE_SEGMENT cs )
|
||||||
|
{
|
||||||
|
--cs->ReferenceCount;
|
||||||
|
if ( cs->Bcb->Trace )
|
||||||
|
{
|
||||||
|
DPRINT1("CacheSegment %p --RefCount=%d, Dirty %d, PageOut %d\n",
|
||||||
|
cs, cs->ReferenceCount, cs->Dirty, cs->PageOut );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define CcRosCacheSegmentIncRefCount(cs) (++((cs)->ReferenceCount))
|
||||||
|
#define CcRosCacheSegmentDecRefCount(cs) (--((cs)->ReferenceCount))
|
||||||
|
#endif
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg);
|
CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg);
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
/* FUNCTIONS *****************************************************************/
|
||||||
|
|
||||||
|
VOID
|
||||||
|
STDCALL
|
||||||
|
CcRosTraceCacheMap (
|
||||||
|
PBCB Bcb,
|
||||||
|
BOOLEAN Trace )
|
||||||
|
{
|
||||||
|
#if defined(DBG) || defined(KDBG)
|
||||||
|
KIRQL oldirql;
|
||||||
|
PLIST_ENTRY current_entry;
|
||||||
|
PCACHE_SEGMENT current;
|
||||||
|
|
||||||
|
if ( !Bcb )
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bcb->Trace = Trace;
|
||||||
|
|
||||||
|
if ( Trace )
|
||||||
|
{
|
||||||
|
DPRINT1("Enabling Tracing for CacheMap 0x%p:\n", Bcb );
|
||||||
|
|
||||||
|
ExAcquireFastMutex(&ViewLock);
|
||||||
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
||||||
|
|
||||||
|
current_entry = Bcb->BcbSegmentListHead.Flink;
|
||||||
|
while (current_entry != &Bcb->BcbSegmentListHead)
|
||||||
|
{
|
||||||
|
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
|
||||||
|
current_entry = current_entry->Flink;
|
||||||
|
|
||||||
|
DPRINT1(" CacheSegment 0x%p enabled, RefCount %d, Dirty %d, PageOut %d\n",
|
||||||
|
current, current->ReferenceCount, current->Dirty, current->PageOut );
|
||||||
|
}
|
||||||
|
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
||||||
|
ExReleaseFastMutex(&ViewLock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINT1("Disabling Tracing for CacheMap 0x%p:\n", Bcb );
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
Bcb = Bcb;
|
||||||
|
Trace = Trace;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
|
CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
|
||||||
{
|
{
|
||||||
|
@ -100,7 +169,7 @@ CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
|
||||||
CacheSegment->Dirty = FALSE;
|
CacheSegment->Dirty = FALSE;
|
||||||
RemoveEntryList(&CacheSegment->DirtySegmentListEntry);
|
RemoveEntryList(&CacheSegment->DirtySegmentListEntry);
|
||||||
DirtyPageCount -= CacheSegment->Bcb->CacheSegmentSize / PAGE_SIZE;
|
DirtyPageCount -= CacheSegment->Bcb->CacheSegmentSize / PAGE_SIZE;
|
||||||
CacheSegment->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount ( CacheSegment );
|
||||||
KeReleaseSpinLock(&CacheSegment->Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&CacheSegment->Bcb->BcbLock, oldIrql);
|
||||||
ExReleaseFastMutex(&ViewLock);
|
ExReleaseFastMutex(&ViewLock);
|
||||||
}
|
}
|
||||||
|
@ -243,7 +312,7 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
|
||||||
ULONG i;
|
ULONG i;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
current->ReferenceCount++;
|
CcRosCacheSegmentIncRefCount(current);
|
||||||
last = current;
|
last = current;
|
||||||
current->PageOut = TRUE;
|
current->PageOut = TRUE;
|
||||||
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
|
||||||
|
@ -260,7 +329,7 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
|
||||||
}
|
}
|
||||||
ExAcquireFastMutex(&ViewLock);
|
ExAcquireFastMutex(&ViewLock);
|
||||||
KeAcquireSpinLock(¤t->Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(¤t->Bcb->BcbLock, &oldIrql);
|
||||||
current->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount(current);
|
||||||
current->PageOut = FALSE;
|
current->PageOut = FALSE;
|
||||||
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(¤t->Bcb->BcbLock, oldIrql);
|
||||||
current_entry = ¤t->CacheSegmentLRUListEntry;
|
current_entry = ¤t->CacheSegmentLRUListEntry;
|
||||||
|
@ -315,14 +384,14 @@ CcRosReleaseCacheSegment(PBCB Bcb,
|
||||||
CacheSeg->MappedCount++;
|
CacheSeg->MappedCount++;
|
||||||
}
|
}
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||||
CacheSeg->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount(CacheSeg);
|
||||||
if (Mapped && CacheSeg->MappedCount == 1)
|
if (Mapped && CacheSeg->MappedCount == 1)
|
||||||
{
|
{
|
||||||
CacheSeg->ReferenceCount++;
|
CcRosCacheSegmentIncRefCount(CacheSeg);
|
||||||
}
|
}
|
||||||
if (!WasDirty && CacheSeg->Dirty)
|
if (!WasDirty && CacheSeg->Dirty)
|
||||||
{
|
{
|
||||||
CacheSeg->ReferenceCount++;
|
CcRosCacheSegmentIncRefCount(CacheSeg);
|
||||||
}
|
}
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
ExReleaseFastMutex(&ViewLock);
|
ExReleaseFastMutex(&ViewLock);
|
||||||
|
@ -351,7 +420,7 @@ CcRosLookupCacheSegment(PBCB Bcb, ULONG FileOffset)
|
||||||
if (current->FileOffset <= FileOffset &&
|
if (current->FileOffset <= FileOffset &&
|
||||||
(current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
|
(current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
|
||||||
{
|
{
|
||||||
current->ReferenceCount++;
|
CcRosCacheSegmentIncRefCount(current);
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
ExAcquireFastMutex(¤t->Lock);
|
ExAcquireFastMutex(¤t->Lock);
|
||||||
return(current);
|
return(current);
|
||||||
|
@ -387,7 +456,7 @@ CcRosMarkDirtyCacheSegment(PBCB Bcb, ULONG FileOffset)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||||
CacheSeg->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount(CacheSeg);
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,14 +499,14 @@ CcRosUnmapCacheSegment(PBCB Bcb, ULONG FileOffset, BOOLEAN NowDirty)
|
||||||
}
|
}
|
||||||
|
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||||
CacheSeg->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount(CacheSeg);
|
||||||
if (!WasDirty && NowDirty)
|
if (!WasDirty && NowDirty)
|
||||||
{
|
{
|
||||||
CacheSeg->ReferenceCount++;
|
CcRosCacheSegmentIncRefCount(CacheSeg);
|
||||||
}
|
}
|
||||||
if (CacheSeg->MappedCount == 0)
|
if (CacheSeg->MappedCount == 0)
|
||||||
{
|
{
|
||||||
CacheSeg->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount(CacheSeg);
|
||||||
}
|
}
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
|
|
||||||
|
@ -480,6 +549,12 @@ CcRosCreateCacheSegment(PBCB Bcb,
|
||||||
current->PageOut = FALSE;
|
current->PageOut = FALSE;
|
||||||
current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
|
current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
|
||||||
current->Bcb = Bcb;
|
current->Bcb = Bcb;
|
||||||
|
#if defined(DBG) || defined(KDBG)
|
||||||
|
if ( Bcb->Trace )
|
||||||
|
{
|
||||||
|
DPRINT1("CacheMap 0x%p: new Cache Segment: 0x%p\n", Bcb, current );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
current->MappedCount = 0;
|
current->MappedCount = 0;
|
||||||
current->DirtySegmentListEntry.Flink = NULL;
|
current->DirtySegmentListEntry.Flink = NULL;
|
||||||
current->DirtySegmentListEntry.Blink = NULL;
|
current->DirtySegmentListEntry.Blink = NULL;
|
||||||
|
@ -504,8 +579,17 @@ CcRosCreateCacheSegment(PBCB Bcb,
|
||||||
if (current->FileOffset <= FileOffset &&
|
if (current->FileOffset <= FileOffset &&
|
||||||
(current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
|
(current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
|
||||||
{
|
{
|
||||||
current->ReferenceCount++;
|
CcRosCacheSegmentIncRefCount(current);
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
|
#if defined(DBG) || defined(KDBG)
|
||||||
|
if ( Bcb->Trace )
|
||||||
|
{
|
||||||
|
DPRINT1("CacheMap 0x%p: deleting newly created Cache Segment 0x%p ( found existing one 0x%p )\n",
|
||||||
|
Bcb,
|
||||||
|
(*CacheSeg),
|
||||||
|
current );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
ExReleaseFastMutex(&(*CacheSeg)->Lock);
|
ExReleaseFastMutex(&(*CacheSeg)->Lock);
|
||||||
ExReleaseFastMutex(&ViewLock);
|
ExReleaseFastMutex(&ViewLock);
|
||||||
ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
|
ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
|
||||||
|
@ -761,6 +845,12 @@ CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg)
|
||||||
KIRQL oldIrql;
|
KIRQL oldIrql;
|
||||||
#endif
|
#endif
|
||||||
DPRINT("Freeing cache segment 0x%p\n", CacheSeg);
|
DPRINT("Freeing cache segment 0x%p\n", CacheSeg);
|
||||||
|
#if defined(DBG) || defined(KDBG)
|
||||||
|
if ( CacheSeg->Bcb->Trace )
|
||||||
|
{
|
||||||
|
DPRINT1("CacheMap 0x%p: deleting Cache Segment: 0x%p\n", CacheSeg->Bcb, CacheSeg );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef CACHE_BITMAP
|
#ifdef CACHE_BITMAP
|
||||||
RegionSize = CacheSeg->Bcb->CacheSegmentSize / PAGE_SIZE;
|
RegionSize = CacheSeg->Bcb->CacheSegmentSize / PAGE_SIZE;
|
||||||
|
|
||||||
|
@ -878,7 +968,7 @@ CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointers,
|
||||||
}
|
}
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||||
ExReleaseFastMutex(¤t->Lock);
|
ExReleaseFastMutex(¤t->Lock);
|
||||||
current->ReferenceCount--;
|
CcRosCacheSegmentDecRefCount(current);
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -953,6 +1043,9 @@ CcRosDeleteFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
|
||||||
}
|
}
|
||||||
InsertHeadList(&FreeList, ¤t->BcbSegmentListEntry);
|
InsertHeadList(&FreeList, ¤t->BcbSegmentListEntry);
|
||||||
}
|
}
|
||||||
|
#if defined(DBG) || defined(KDBG)
|
||||||
|
Bcb->Trace = FALSE;
|
||||||
|
#endif
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
|
|
||||||
ExReleaseFastMutex(&ViewLock);
|
ExReleaseFastMutex(&ViewLock);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
EXPORTS
|
EXPORTS
|
||||||
CcRosInitializeFileCache@8
|
CcRosInitializeFileCache@8
|
||||||
CcRosReleaseFileCache@4
|
CcRosReleaseFileCache@4
|
||||||
|
CcRosTraceCacheMap@8
|
||||||
CcCanIWrite@16
|
CcCanIWrite@16
|
||||||
CcCopyRead@24
|
CcCopyRead@24
|
||||||
CcCopyWrite@20
|
CcCopyWrite@20
|
||||||
|
|
Loading…
Reference in a new issue