Author: arty Date: Fri Aug 29 05:24:38 2008 New Revision: 35749
URL: http://svn.reactos.org/svn/reactos?rev=35749&view=rev Log: Remove page cleaning in section.c -- not needed. Page replacement will take care of it.
Add refcount for SharedCacheMap ... it appears that CcInitializeCacheMap and CcUninitializeCacheMap are expected to be paired and refcounted.
Modified: branches/arty-newcc/ntoskrnl/cache/cachesub.c branches/arty-newcc/ntoskrnl/cache/fssup.c branches/arty-newcc/ntoskrnl/cache/pinsup.c branches/arty-newcc/ntoskrnl/include/internal/cc.h branches/arty-newcc/ntoskrnl/mm/section.c
Modified: branches/arty-newcc/ntoskrnl/cache/cachesub.c URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/caches... ============================================================================== --- branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] (original) +++ branches/arty-newcc/ntoskrnl/cache/cachesub.c [iso-8859-1] Fri Aug 29 05:24:38 2008 @@ -36,7 +36,9 @@ PDEVICE_OBJECT DeviceObject; PIO_STACK_LOCATION IrpSp; KIRQL OldIrql; - + PHYSICAL_ADDRESS Page; + + ASSERT(Length <= PAGE_SIZE); KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
if (MmIsDirtyPage(PsInitialSystemProcess, Buffer)) @@ -93,7 +95,9 @@ return Status; } } - + + Page = MmGetPhysicalAddress(Buffer); + MmSetCleanAllRmaps((PFN_TYPE)(Page.QuadPart >> PAGE_SHIFT)); ObDereferenceObject(FileObject);
DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
Modified: branches/arty-newcc/ntoskrnl/cache/fssup.c URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/fssup.... ============================================================================== --- branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] (original) +++ branches/arty-newcc/ntoskrnl/cache/fssup.c [iso-8859-1] Fri Aug 29 05:24:38 2008 @@ -104,13 +104,25 @@ IN PVOID LazyWriteContext) { DPRINT("Initializing file object for %wZ\n", &FileObject->FileName); - PNOCC_CACHE_MAP Map = ExAllocatePool(NonPagedPool, sizeof(NOCC_CACHE_MAP)); - FileObject->SectionObjectPointer->SharedCacheMap = Map; - Map->FileObject = FileObject; - Map->NumberOfMaps = 0; - Map->FileSizes = *FileSizes; - DPRINT("FileSizes->ValidDataLength %x\n", FileSizes->ValidDataLength.LowPart); - InitializeListHead(&Map->AssociatedBcb); + CcpLock(); + if (FileObject->SectionObjectPointer->SharedCacheMap) + { + PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap; + InterlockedIncrement((PLONG)&Map->RefCount); + } + else + { + PNOCC_CACHE_MAP Map = ExAllocatePool(NonPagedPool, sizeof(NOCC_CACHE_MAP)); + FileObject->SectionObjectPointer->SharedCacheMap = Map; + Map->RefCount = 1; + Map->FileObject = FileObject; + Map->NumberOfMaps = 0; + Map->FileSizes = *FileSizes; + ASSERT(Map->FileSizes.ValidDataLength.HighPart != 0xcccccccc); + DPRINT("FileSizes->ValidDataLength %x\n", FileSizes->ValidDataLength.LowPart); + InitializeListHead(&Map->AssociatedBcb); + } + CcpUnlock(); }
BOOLEAN @@ -124,10 +136,10 @@ PLIST_ENTRY Entry; IO_STATUS_BLOCK IOSB;
- DPRINT("Uninitializing file object for %wZ\n", &FileObject->FileName); + DPRINT("Uninitializing file object for %wZ SectionObjectPointer %x\n", &FileObject->FileName, FileObject->SectionObjectPointer);
ASSERT(UninitializeEvent == NULL); - + for (Entry = Map->AssociatedBcb.Flink; Entry != &Map->AssociatedBcb; Entry = Entry->Flink) @@ -148,25 +160,28 @@ }
CcpLock(); - - for (Entry = Map->AssociatedBcb.Flink; - Entry != &Map->AssociatedBcb; - Entry = Entry->Flink) - { - Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList); - if (Bcb->RefCount == 1) - { - DPRINT("Unmapping #%x\n", Bcb - CcCacheSections); - CcpDereferenceCache(Bcb - CcCacheSections); - } + + if (InterlockedDecrement((PLONG)&Map->RefCount) == 1) + { + for (Entry = Map->AssociatedBcb.Flink; + Entry != &Map->AssociatedBcb; + Entry = Entry->Flink) + { + Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList); + if (Bcb->RefCount == 1) + { + DPRINT("Unmapping #%x\n", Bcb - CcCacheSections); + CcpDereferenceCache(Bcb - CcCacheSections); + } + } + + ExFreePool(Map); + + /* Clear the cache map */ + FileObject->SectionObjectPointer->SharedCacheMap = NULL; }
CcpUnlock(); - - ExFreePool(Map); - - /* Clear the cache map */ - FileObject->SectionObjectPointer->SharedCacheMap = NULL; return TRUE; } @@ -200,7 +215,10 @@ IN BOOLEAN UninitializeCacheMaps) { IO_STATUS_BLOCK IOSB; + PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)SectionObjectPointer->SharedCacheMap; CcFlushCache(SectionObjectPointer, FileOffset, Length, &IOSB); + if (UninitializeCacheMaps) + CcUninitializeCacheMap(Map->FileObject, NULL, NULL); return NT_SUCCESS(IOSB.Status); }
Modified: branches/arty-newcc/ntoskrnl/cache/pinsup.c URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/cache/pinsup... ============================================================================== --- branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] (original) +++ branches/arty-newcc/ntoskrnl/cache/pinsup.c [iso-8859-1] Fri Aug 29 05:24:38 2008 @@ -455,10 +455,23 @@ if (!SectionObject) { PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap; - LONG SectionSize = min(CACHE_STRIPE, Map->FileSizes.ValidDataLength.QuadPart - Target.QuadPart); - ASSERT(SectionSize > 0 && SectionSize <= CACHE_STRIPE); + ULONG SectionSize; + + DPRINT("%08x: File size %x%x\n", FileObject->SectionObjectPointer, Map->FileSizes.ValidDataLength.HighPart, Map->FileSizes.ValidDataLength.LowPart); + + if (Map->FileSizes.ValidDataLength.QuadPart) + { + SectionSize = min(CACHE_STRIPE, Map->FileSizes.ValidDataLength.QuadPart - Target.QuadPart); + } + else + { + SectionSize = CACHE_STRIPE; + } + DPRINT("Allocating a cache stripe at %x:%d\n", Target.LowPart, SectionSize); + ASSERT(SectionSize <= CACHE_STRIPE); + Status = CcpAllocateSection (FileObject, SectionSize,
Modified: branches/arty-newcc/ntoskrnl/include/internal/cc.h URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/include/inte... ============================================================================== --- branches/arty-newcc/ntoskrnl/include/internal/cc.h [iso-8859-1] (original) +++ branches/arty-newcc/ntoskrnl/include/internal/cc.h [iso-8859-1] Fri Aug 29 05:24:38 2008 @@ -132,6 +132,7 @@ LIST_ENTRY AssociatedBcb; PFILE_OBJECT FileObject; ULONG NumberOfMaps; + ULONG RefCount; CC_FILE_SIZES FileSizes; } NOCC_CACHE_MAP, *PNOCC_CACHE_MAP;
Modified: branches/arty-newcc/ntoskrnl/mm/section.c URL: http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section.c... ============================================================================== --- branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] (original) +++ branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] Fri Aug 29 05:24:38 2008 @@ -159,8 +159,6 @@ PIRP Irp = NULL; KEVENT ReadWait; PDEVICE_OBJECT DeviceObject = MmGetDeviceObjectForFile(FileObject); - PCHAR BufferWalk; - PHYSICAL_ADDRESS Page; PIO_STACK_LOCATION IrpSp;
DPRINT1 @@ -220,13 +218,6 @@ ((PCHAR)Buffer)[2] & 0xff, ((PCHAR)Buffer)[3] & 0xff);
- for (BufferWalk = (PCHAR)Buffer; BufferWalk < (PCHAR)Buffer + Length; BufferWalk += PAGE_SIZE) - { - Page = MmGetPhysicalAddress((PVOID)BufferWalk); - DPRINT("Setting page clean: %x\n", Page.u.LowPart); - //MmSetCleanAllRmaps((PFN_TYPE)(Page.QuadPart >> PAGE_SHIFT)); - } - return ReadStatus->Status; }
@@ -243,8 +234,6 @@ PIRP Irp = NULL; KEVENT ReadWait; PDEVICE_OBJECT DeviceObject; - PCHAR BufferWalk; - PHYSICAL_ADDRESS Page; PIO_STACK_LOCATION IrpSp;
ASSERT(FileObject); @@ -308,12 +297,6 @@ ObDereferenceObject(FileObject);
DPRINT("Paging IO Done: %08x\n", ReadStatus->Status); - for (BufferWalk = (PCHAR)Buffer; BufferWalk < (PCHAR)Buffer + Length; BufferWalk += PAGE_SIZE) - { - Page = MmGetPhysicalAddress((PVOID)BufferWalk); - //MmSetCleanAllRmaps((PFN_TYPE)(Page.QuadPart >> PAGE_SHIFT)); - } - return ReadStatus->Status; }