From b10383d1ff14b2319aa09f2958c77e1d9ca357d2 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Fri, 24 Feb 2012 11:33:23 +0000 Subject: [PATCH] [NEWCC] Integrate september's speed improvements, which now work. Remove the flush hack when unpinning cache segments. svn path=/trunk/; revision=55839 --- reactos/ntoskrnl/cache/pinsup.c | 11 +++++++--- reactos/ntoskrnl/cache/section/data.c | 13 ++++++----- reactos/ntoskrnl/cache/section/fault.c | 1 + reactos/ntoskrnl/cache/section/swapout.c | 28 +++++++++--------------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/reactos/ntoskrnl/cache/pinsup.c b/reactos/ntoskrnl/cache/pinsup.c index 3d77f69c6ae..b32696f79ee 100644 --- a/reactos/ntoskrnl/cache/pinsup.c +++ b/reactos/ntoskrnl/cache/pinsup.c @@ -130,6 +130,14 @@ VOID CcpDereferenceCache(ULONG Start, BOOLEAN Immediate) DPRINT("Firing work item for %x\n", Bcb->BaseAddress); + if (Dirty) { + CcpUnlock(); + Bcb->RefCount++; + MiFlushMappedSection(ToUnmap, &BaseOffset, &MappedSize, Dirty); + Bcb->RefCount--; + CcpLock(); + } + if (Immediate) { PROS_SECTION_OBJECT ToDeref = Bcb->SectionObject; @@ -143,8 +151,6 @@ VOID CcpDereferenceCache(ULONG Start, BOOLEAN Immediate) RemoveEntryList(&Bcb->ThisFileList); CcpUnlock(); - if (Dirty) - MiFlushMappedSection(ToUnmap, &BaseOffset, &MappedSize, Dirty); MmUnmapCacheViewInSystemSpace(ToUnmap); ObDereferenceObject(ToDeref); CcpLock(); @@ -763,7 +769,6 @@ CcUnpinData(IN PVOID Bcb) CcpUnlock(); if (!Released) { - MiFlushMappedSection(RealBcb->BaseAddress, &RealBcb->FileOffset, &RealBcb->Map->FileSizes.FileSize, RealBcb->Dirty); CcpLock(); CcpUnpinData(RealBcb, TRUE); CcpUnlock(); diff --git a/reactos/ntoskrnl/cache/section/data.c b/reactos/ntoskrnl/cache/section/data.c index 68218453d80..3a8f5a30fd5 100644 --- a/reactos/ntoskrnl/cache/section/data.c +++ b/reactos/ntoskrnl/cache/section/data.c @@ -259,6 +259,7 @@ _MiFlushMappedSection if (NT_SUCCESS(Status)) { MmLockAddressSpace(AddressSpace); MmSetCleanAllRmaps(Page); + MmSetPageProtect(MmGetAddressSpaceOwner(AddressSpace), (PVOID)PageAddress, PAGE_READONLY); MmLockSectionSegment(Segment); Entry = MmGetPageEntrySectionSegment(Segment, &FileOffset); if (Entry && !IS_SWAP_FROM_SSE(Entry) && PFN_FROM_SSE(Entry) == Page) @@ -663,6 +664,11 @@ MmFreeCacheSectionPage Entry = MmGetPageEntrySectionSegment(Segment, &Offset); + if (Page != 0 && PFN_FROM_SSE(Entry) == Page && Dirty) + { + DPRINT("Freeing section page %x:%x -> %x\n", Segment, Offset.LowPart, Entry); + MmSetPageEntrySectionSegment(Segment, &Offset, DIRTY_SSE(Entry)); + } if (Page) { DPRINT("Removing page %x:%x -> %x\n", Segment, Offset.LowPart, Entry); @@ -671,12 +677,7 @@ MmFreeCacheSectionPage MmDeleteVirtualMapping(Process, Address, FALSE, NULL, NULL); MmReleasePageMemoryConsumer(MC_CACHE, Page); } - if (Page != 0 && PFN_FROM_SSE(Entry) == Page && Dirty) - { - DPRINT("Freeing section page %x:%x -> %x\n", Segment, Offset.LowPart, Entry); - MmSetPageEntrySectionSegment(Segment, &Offset, DIRTY_SSE(Entry)); - } - else if (SwapEntry != 0) + if (SwapEntry != 0) { MmFreeSwapPage(SwapEntry); } diff --git a/reactos/ntoskrnl/cache/section/fault.c b/reactos/ntoskrnl/cache/section/fault.c index f0a1a7f629e..583714e317b 100644 --- a/reactos/ntoskrnl/cache/section/fault.c +++ b/reactos/ntoskrnl/cache/section/fault.c @@ -296,6 +296,7 @@ MiCowCacheSectionPage MmSetPageEntrySectionSegment(Segment, &Offset, DIRTY_SSE(Entry)); } MmSetPageProtect(Process, PAddress, PAGE_READWRITE); + MmSetDirtyPage(Process, PAddress); MmUnlockSectionSegment(Segment); DPRINT("Done\n"); return STATUS_SUCCESS; diff --git a/reactos/ntoskrnl/cache/section/swapout.c b/reactos/ntoskrnl/cache/section/swapout.c index a56bd4641d7..7fae9b835be 100644 --- a/reactos/ntoskrnl/cache/section/swapout.c +++ b/reactos/ntoskrnl/cache/section/swapout.c @@ -184,11 +184,12 @@ MmPageOutCacheSection (PMMSUPPORT AddressSpace, MEMORY_AREA* MemoryArea, PVOID Address, + BOOLEAN Dirty, PMM_REQUIRED_RESOURCES Required) { NTSTATUS Status = STATUS_SUCCESS; ULONG Entry; - BOOLEAN Dirty = FALSE; + PFN_NUMBER OurPage; PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace); LARGE_INTEGER TotalOffset; PMM_SECTION_SEGMENT Segment; @@ -202,24 +203,16 @@ MmPageOutCacheSection MmLockSectionSegment(Segment); ASSERT(KeGetCurrentIrql() <= APC_LEVEL); - Dirty = MmIsDirtyPageRmap(Required->Page[0]); Entry = MmGetPageEntrySectionSegment(Segment, &TotalOffset); - if (Dirty) - { - PFN_NUMBER OurPage; + if (Dirty) { + DPRINT("Dirty page: %p:%p segment %p offset %08x%08x\n", Process, Address, Segment, TotalOffset.HighPart, TotalOffset.LowPart); MmSetPageEntrySectionSegment(Segment, &TotalOffset, DIRTY_SSE(Entry)); - MmDeleteRmap(Required->Page[0], Process, Address); - MmDeleteVirtualMapping(Process, Address, FALSE, &Dirty, &OurPage); - ASSERT(OurPage == Required->Page[0]); - } else { - /* Just unmap if the page wasn't dirty */ - PFN_NUMBER OurPage; - MmDeleteRmap(Required->Page[0], Process, Address); - MmDeleteVirtualMapping(Process, Address, FALSE, &Dirty, &OurPage); - DPRINT("OurPage %x ThePage %x\n", OurPage, Required->Page[0]); - ASSERT(OurPage == Required->Page[0]); - } + } + + MmDeleteRmap(Required->Page[0], Process, Address); + MmDeleteVirtualMapping(Process, Address, FALSE, NULL, &OurPage); + ASSERT(OurPage == Required->Page[0]); if (NT_SUCCESS(Status)) { @@ -368,7 +361,7 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page) DPRINT("%x:%x, page %x %x\n", Process, Address, Page, Resources.Page[0]); Status = MmPageOutCacheSection - (AddressSpace, MemoryArea, Address, &Resources); + (AddressSpace, MemoryArea, Address, Dirty, &Resources); DPRINT("%x\n", Status); ASSERT(KeGetCurrentIrql() <= APC_LEVEL); @@ -398,7 +391,6 @@ MmpPageOutPhysicalAddress(PFN_NUMBER Page) MmLockAddressSpace(AddressSpace); } while (Status == STATUS_MM_RESTART_OPERATION); - Dirty |= Resources.State & 1; // Accumulate dirty MmUnlockAddressSpace(AddressSpace);