- Acquire always the segmemt lock in CcRosLookupCacheSegment/CcRosCreateCacheSegment.

- Try to remove mapped section pages from a cache segment in CcRosTrimCache.

svn path=/trunk/; revision=5134
This commit is contained in:
Hartmut Birr 2003-07-15 19:30:33 +00:00
parent 4610a1b077
commit e6d3e40053

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: view.c,v 1.66 2003/07/11 01:23:14 royce Exp $ /* $Id: view.c,v 1.67 2003/07/15 19:30:33 hbirr Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/cc/view.c * FILE: ntoskrnl/cc/view.c
@ -132,9 +132,6 @@ CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment)
return(Status); return(Status);
} }
VOID CcRosRemoveUnusedFiles(VOID);
NTSTATUS NTSTATUS
CcRosFlushDirtyPages(ULONG Target, PULONG Count) CcRosFlushDirtyPages(ULONG Target, PULONG Count)
{ {
@ -231,7 +228,7 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
*/ */
{ {
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
PCACHE_SEGMENT current; PCACHE_SEGMENT current, last = NULL;
ULONG PagesPerSegment; ULONG PagesPerSegment;
ULONG PagesFreed; ULONG PagesFreed;
KIRQL oldIrql; KIRQL oldIrql;
@ -266,7 +263,33 @@ CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
} }
else else
{ {
KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql); if (last != current && current->MappedCount > 0 && !current->Dirty)
{
ULONG i;
NTSTATUS Status;
current->ReferenceCount++;
last = current;
KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql);
ExReleaseFastMutex(&ViewLock);
for (i = 0; i < current->Bcb->CacheSegmentSize / PAGE_SIZE; i++)
{
PHYSICAL_ADDRESS Page;
Page = MmGetPhysicalAddress(current->BaseAddress + i * PAGE_SIZE);
Status = MmPageOutPhysicalAddress(Page);
if (!NT_SUCCESS(Status))
{
break;
}
}
ExAcquireFastMutex(&ViewLock);
KeAcquireSpinLock(&current->Bcb->BcbLock, &oldIrql);
current->ReferenceCount--;
KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql);
current_entry = &current->CacheSegmentLRUListEntry;
continue;
}
KeReleaseSpinLock(&current->Bcb->BcbLock, oldIrql);
} }
} }
ExReleaseFastMutex(&ViewLock); ExReleaseFastMutex(&ViewLock);
@ -353,6 +376,7 @@ CcRosLookupCacheSegment(PBCB Bcb, ULONG FileOffset)
{ {
current->ReferenceCount++; current->ReferenceCount++;
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
ExAcquireFastMutex(&current->Lock);
return(current); return(current);
} }
current_entry = current_entry->Flink; current_entry = current_entry->Flink;
@ -376,7 +400,6 @@ CcRosMarkDirtyCacheSegment(PBCB Bcb, ULONG FileOffset)
{ {
KeBugCheck(0); KeBugCheck(0);
} }
ExAcquireFastMutex(&CacheSeg->Lock);
if (!CacheSeg->Dirty) if (!CacheSeg->Dirty)
{ {
ExAcquireFastMutex(&ViewLock); ExAcquireFastMutex(&ViewLock);
@ -415,7 +438,6 @@ CcRosUnmapCacheSegment(PBCB Bcb, ULONG FileOffset, BOOLEAN NowDirty)
{ {
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
ExAcquireFastMutex(&CacheSeg->Lock);
WasDirty = CacheSeg->Dirty; WasDirty = CacheSeg->Dirty;
CacheSeg->Dirty = CacheSeg->Dirty || NowDirty; CacheSeg->Dirty = CacheSeg->Dirty || NowDirty;
@ -449,8 +471,7 @@ CcRosUnmapCacheSegment(PBCB Bcb, ULONG FileOffset, BOOLEAN NowDirty)
NTSTATUS STATIC NTSTATUS STATIC
CcRosCreateCacheSegment(PBCB Bcb, CcRosCreateCacheSegment(PBCB Bcb,
ULONG FileOffset, ULONG FileOffset,
PCACHE_SEGMENT* CacheSeg, PCACHE_SEGMENT* CacheSeg)
BOOLEAN Lock)
{ {
ULONG i; ULONG i;
PCACHE_SEGMENT current; PCACHE_SEGMENT current;
@ -507,10 +528,7 @@ CcRosCreateCacheSegment(PBCB Bcb,
ExReleaseFastMutex(&ViewLock); ExReleaseFastMutex(&ViewLock);
ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg); ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
*CacheSeg = current; *CacheSeg = current;
if (Lock) ExAcquireFastMutex(&current->Lock);
{
ExAcquireFastMutex(&current->Lock);
}
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if (current->FileOffset < FileOffset) if (current->FileOffset < FileOffset)
@ -600,11 +618,6 @@ CcRosCreateCacheSegment(PBCB Bcb,
KeBugCheck(0); KeBugCheck(0);
} }
} }
if (!Lock)
{
ExReleaseFastMutex(&current->Lock);
}
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -641,14 +654,13 @@ CcRosGetCacheSegmentChain(PBCB Bcb,
} }
else else
{ {
CcRosCreateCacheSegment(Bcb, CurrentOffset, &current, FALSE); CcRosCreateCacheSegment(Bcb, CurrentOffset, &current);
CacheSegList[i] = current; CacheSegList[i] = current;
} }
} }
for (i = 0; i < (Length / Bcb->CacheSegmentSize); i++) for (i = 0; i < (Length / Bcb->CacheSegmentSize); i++)
{ {
ExAcquireFastMutex(&CacheSegList[i]->Lock);
if (i == 0) if (i == 0)
{ {
*CacheSeg = CacheSegList[i]; *CacheSeg = CacheSegList[i];
@ -684,16 +696,12 @@ CcRosGetCacheSegment(PBCB Bcb,
* Look for a cache segment already mapping the same data. * Look for a cache segment already mapping the same data.
*/ */
current = CcRosLookupCacheSegment(Bcb, FileOffset); current = CcRosLookupCacheSegment(Bcb, FileOffset);
if (current != NULL) if (current == NULL)
{
ExAcquireFastMutex(&current->Lock);
}
else
{ {
/* /*
* Otherwise create a new segment. * Otherwise create a new segment.
*/ */
Status = CcRosCreateCacheSegment(Bcb, FileOffset, &current, TRUE); Status = CcRosCreateCacheSegment(Bcb, FileOffset, &current);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return Status; return Status;
@ -873,7 +881,6 @@ CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointers,
current = CcRosLookupCacheSegment (Bcb, Offset.u.LowPart); current = CcRosLookupCacheSegment (Bcb, Offset.u.LowPart);
if (current != NULL) if (current != NULL)
{ {
ExAcquireFastMutex(&current->Lock);
if (current->Dirty) if (current->Dirty)
{ {
Status = CcRosFlushCacheSegment(current); Status = CcRosFlushCacheSegment(current);
@ -1000,7 +1007,7 @@ VOID CcRosReferenceCache(PFILE_OBJECT FileObject)
VOID CcRosSetRemoveOnClose(PSECTION_OBJECT_POINTERS SectionObjectPointer) VOID CcRosSetRemoveOnClose(PSECTION_OBJECT_POINTERS SectionObjectPointer)
{ {
PBCB Bcb; PBCB Bcb;
// DPRINT1("CcRosSetRemoveOnClose()\n"); DPRINT("CcRosSetRemoveOnClose()\n");
ExAcquireFastMutex(&ViewLock); ExAcquireFastMutex(&ViewLock);
Bcb = (PBCB)SectionObjectPointer->SharedCacheMap; Bcb = (PBCB)SectionObjectPointer->SharedCacheMap;
if (Bcb) if (Bcb)