https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e17f61138c60a09969f37…
commit e17f61138c60a09969f37a4022eb315ea19a1828
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Sep 2 14:37:47 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Wed Sep 5 22:06:25 2018 +0200
[NTOSKRNL] When allocating a new BCB, save it in a list
This list is stored in the shared map. Later, this will allow
reusing BCB when appropriate
---
ntoskrnl/cc/pin.c | 22 +++++++++++++++++++++-
ntoskrnl/cc/view.c | 1 +
ntoskrnl/include/internal/cc.h | 3 +++
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/ntoskrnl/cc/pin.c b/ntoskrnl/cc/pin.c
index aba97049f1..07044e23e7 100644
--- a/ntoskrnl/cc/pin.c
+++ b/ntoskrnl/cc/pin.c
@@ -51,6 +51,7 @@ CcMapData (
NTSTATUS Status;
PINTERNAL_BCB iBcb;
LONGLONG ROffset;
+ KIRQL OldIrql;
DPRINT("CcMapData(FileObject 0x%p, FileOffset %I64x, Length %lu, Flags
0x%lx,"
" pBcb 0x%p, pBuffer 0x%p)\n", FileObject, FileOffset->QuadPart,
@@ -156,6 +157,10 @@ CcMapData (
ExInitializeResourceLite(&iBcb->Lock);
*pBcb = (PVOID)iBcb;
+ KeAcquireSpinLock(&SharedCacheMap->BcbSpinLock, &OldIrql);
+ InsertTailList(&SharedCacheMap->BcbList, &iBcb->BcbEntry);
+ KeReleaseSpinLock(&SharedCacheMap->BcbSpinLock, OldIrql);
+
CCTRACE(CC_API_DEBUG, "FileObject=%p FileOffset=%p Length=%lu Flags=0x%lx ->
TRUE Bcb=%p\n",
FileObject, FileOffset, Length, Flags, iBcb);
return TRUE;
@@ -340,12 +345,20 @@ CcUnpinDataForThread (
if (--iBcb->RefCount == 0)
{
- CcRosReleaseVacb(iBcb->Vacb->SharedCacheMap,
+ KIRQL OldIrql;
+ PROS_SHARED_CACHE_MAP SharedCacheMap;
+
+ SharedCacheMap = iBcb->Vacb->SharedCacheMap;
+ CcRosReleaseVacb(SharedCacheMap,
iBcb->Vacb,
TRUE,
iBcb->Dirty,
FALSE);
+ KeAcquireSpinLock(&SharedCacheMap->BcbSpinLock, &OldIrql);
+ RemoveEntryList(&iBcb->BcbEntry);
+ KeReleaseSpinLock(&SharedCacheMap->BcbSpinLock, OldIrql);
+
ExDeleteResourceLite(&iBcb->Lock);
ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
}
@@ -377,6 +390,8 @@ CcUnpinRepinnedBcb (
IN PIO_STATUS_BLOCK IoStatus)
{
PINTERNAL_BCB iBcb = Bcb;
+ KIRQL OldIrql;
+ PROS_SHARED_CACHE_MAP SharedCacheMap;
CCTRACE(CC_API_DEBUG, "Bcb=%p WriteThrough=%d\n", Bcb, WriteThrough);
@@ -408,12 +423,17 @@ CcUnpinRepinnedBcb (
ASSERT(iBcb->Vacb->PinCount == 0);
}
+ SharedCacheMap = iBcb->Vacb->SharedCacheMap;
CcRosReleaseVacb(iBcb->Vacb->SharedCacheMap,
iBcb->Vacb,
TRUE,
iBcb->Dirty,
FALSE);
+ KeAcquireSpinLock(&SharedCacheMap->BcbSpinLock, &OldIrql);
+ RemoveEntryList(&iBcb->BcbEntry);
+ KeReleaseSpinLock(&SharedCacheMap->BcbSpinLock, OldIrql);
+
ExDeleteResourceLite(&iBcb->Lock);
ExFreeToNPagedLookasideList(&iBcbLookasideList, iBcb);
}
diff --git a/ntoskrnl/cc/view.c b/ntoskrnl/cc/view.c
index 6a087e6531..e3c8285254 100644
--- a/ntoskrnl/cc/view.c
+++ b/ntoskrnl/cc/view.c
@@ -1417,6 +1417,7 @@ CcRosInitializeFileCache (
InitializeListHead(&SharedCacheMap->PrivateList);
KeInitializeSpinLock(&SharedCacheMap->CacheMapLock);
InitializeListHead(&SharedCacheMap->CacheMapVacbListHead);
+ InitializeListHead(&SharedCacheMap->BcbList);
}
KeAcquireGuardedMutex(&ViewLock);
diff --git a/ntoskrnl/include/internal/cc.h b/ntoskrnl/include/internal/cc.h
index 0dcea16f43..0c12004326 100644
--- a/ntoskrnl/include/internal/cc.h
+++ b/ntoskrnl/include/internal/cc.h
@@ -172,6 +172,7 @@ typedef struct _ROS_SHARED_CACHE_MAP
CSHORT NodeByteSize;
ULONG OpenCount;
LARGE_INTEGER FileSize;
+ LIST_ENTRY BcbList;
LARGE_INTEGER SectionSize;
PFILE_OBJECT FileObject;
ULONG DirtyPages;
@@ -181,6 +182,7 @@ typedef struct _ROS_SHARED_CACHE_MAP
PVOID LazyWriteContext;
LIST_ENTRY PrivateList;
ULONG DirtyPageThreshold;
+ KSPIN_LOCK BcbSpinLock;
PRIVATE_CACHE_MAP PrivateCacheMap;
/* ROS specific */
@@ -235,6 +237,7 @@ typedef struct _INTERNAL_BCB
BOOLEAN Dirty;
BOOLEAN Pinned;
CSHORT RefCount; /* (At offset 0x34 on WinNT4) */
+ LIST_ENTRY BcbEntry;
} INTERNAL_BCB, *PINTERNAL_BCB;
typedef struct _LAZY_WRITER