Author: arty
Date: Thu Jan 7 00:35:55 2010
New Revision: 44984
URL:
http://svn.reactos.org/svn/reactos?rev=44984&view=rev
Log:
We now actually write a page (which make require evicting a cache stripe) after fixing
up the accompanying segment (which could be the one evicted).
We bail early if a process is being killed.
Silence a lot of printing.
Modified:
branches/arty-newcc/ntoskrnl/include/internal/ps.h
branches/arty-newcc/ntoskrnl/mm/anonmem.c
branches/arty-newcc/ntoskrnl/mm/balance.c
branches/arty-newcc/ntoskrnl/mm/freelist.c
branches/arty-newcc/ntoskrnl/mm/mmfault.c
branches/arty-newcc/ntoskrnl/mm/rmap.c
branches/arty-newcc/ntoskrnl/mm/section/data.c
branches/arty-newcc/ntoskrnl/mm/section/fault.c
branches/arty-newcc/ntoskrnl/mm/section/pagefile.c
branches/arty-newcc/ntoskrnl/ps/kill.c
Modified: branches/arty-newcc/ntoskrnl/include/internal/ps.h
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/include/int…
==============================================================================
--- branches/arty-newcc/ntoskrnl/include/internal/ps.h [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/include/internal/ps.h [iso-8859-1] Thu Jan 7 00:35:55
2010
@@ -110,6 +110,12 @@
NTAPI
PsGetNextProcess(
IN PEPROCESS OldProcess OPTIONAL
+);
+
+BOOLEAN
+NTAPI
+PsIsProcessExiting(
+ IN PEPROCESS Process
);
NTSTATUS
Modified: branches/arty-newcc/ntoskrnl/mm/anonmem.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/anonmem.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/anonmem.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/anonmem.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -225,7 +225,7 @@
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
KIRQL OldIrql;
- DPRINT1("Not Present %x in (%x-%x)\n", Address,
MemoryArea->StartingAddress, MemoryArea->EndingAddress);
+ DPRINT("Not Present %x in (%x-%x)\n", Address,
MemoryArea->StartingAddress, MemoryArea->EndingAddress);
/*
* There is a window between taking the page fault and locking the
@@ -291,11 +291,11 @@
Required->Consumer = MC_USER;
Required->Amount = 1;
Required->DoAcquisition = MiGetOnePage;
- DPRINT1("Allocate\n");
+ DPRINT("Allocate\n");
return STATUS_MORE_PROCESSING_REQUIRED;
}
- DPRINT1("Using page %x\n", Required->Page[0]);
+ DPRINT("Using page %x\n", Required->Page[0]);
/*
* Set the page. If we fail because we are out of memory then
@@ -330,7 +330,7 @@
KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
}
- DPRINT1("Success!\n");
+ DPRINT("Success!\n");
return(STATUS_SUCCESS);
}
Modified: branches/arty-newcc/ntoskrnl/mm/balance.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/balance.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/balance.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/balance.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -33,7 +33,7 @@
BOOLEAN MiBalancerInitialized = FALSE;
MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
-/*static*/ ULONG MiMinimumAvailablePages = 128;
+/*static*/ ULONG MiMinimumAvailablePages = 0x3000;
static ULONG MiNrTotalPages;
static LIST_ENTRY AllocationListHead;
static KSPIN_LOCK AllocationListLock;
@@ -270,7 +270,7 @@
if(BALANCER_CAN_EVICT(Consumer))
MmInsertLRULastUserPage(Page);
- DPRINT1("Successful alloc %x after balancer (consumer %d)\n", Page,
Consumer);
+ DPRINT("Successful alloc %x after balancer (consumer %d)\n", Page,
Consumer);
*AllocatedPage = Page;
return(STATUS_SUCCESS);
Modified: branches/arty-newcc/ntoskrnl/mm/freelist.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/freelist…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/freelist.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/freelist.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -867,7 +867,7 @@
Page = MiGetPfnEntry(Pfn);
ASSERT(Page);
- DPRINT1("MmReferencePage(PysicalAddress %x,%s:%d,%d)\n", Pfn <<
PAGE_SHIFT, file, line, Page->ReferenceCount);
+ DPRINT("MmReferencePage(PysicalAddress %x,%s:%d,%d)\n", Pfn <<
PAGE_SHIFT, file, line, Page->ReferenceCount);
if (Page->Flags.Type != MM_PHYSICAL_PAGE_USED)
{
Modified: branches/arty-newcc/ntoskrnl/mm/mmfault.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/mmfault.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/mmfault.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/mmfault.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -136,7 +136,7 @@
{
MmUnlockAddressSpace(AddressSpace);
}
- DPRINT1("Address: %x\n", Address);
+ DPRINT("Address: %x\n", Address);
return (STATUS_ACCESS_VIOLATION);
}
@@ -161,7 +161,7 @@
if (Status == STATUS_SUCCESS + 1)
{
// Wait page ...
- DPRINT1("Waiting for %x\n", Address);
+ DPRINT("Waiting for %x\n", Address);
if (!NT_SUCCESS
(KeWaitForSingleObject
(&MmWaitPageEvent,
@@ -170,7 +170,7 @@
FALSE,
NULL)))
ASSERT(FALSE);
- DPRINT1("Restarting fault %x\n", Address);
+ DPRINT("Restarting fault %x\n", Address);
Status = STATUS_MM_RESTART_OPERATION;
}
else if (Status == STATUS_MORE_PROCESSING_REQUIRED)
@@ -211,8 +211,8 @@
if (!NT_SUCCESS(Status))
{
- DPRINT1("Completed page fault handling %x %x\n", Address, Status);
- DPRINT1
+ DPRINT("Completed page fault handling %x %x\n", Address, Status);
+ DPRINT
("Type %x (%x -> %x)\n",
MemoryArea->Type,
MemoryArea->StartingAddress,
@@ -316,7 +316,7 @@
break;
}
- DPRINT1
+ DPRINT
("Type %x (%x -> %x)\n",
MemoryArea->Type,
MemoryArea->StartingAddress,
@@ -343,7 +343,7 @@
if (Status == STATUS_SUCCESS + 1)
{
// Wait page ...
- DPRINT1("Waiting for %x\n", Address);
+ DPRINT("Waiting for %x\n", Address);
if (!NT_SUCCESS
(KeWaitForSingleObject
(&MmWaitPageEvent,
@@ -352,7 +352,7 @@
FALSE,
NULL)))
ASSERT(FALSE);
- DPRINT1("Done waiting for %x\n", Address);
+ DPRINT("Done waiting for %x\n", Address);
Status = STATUS_MM_RESTART_OPERATION;
}
else if (Status == STATUS_MORE_PROCESSING_REQUIRED)
Modified: branches/arty-newcc/ntoskrnl/mm/rmap.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/rmap.c?r…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/rmap.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/rmap.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -221,7 +221,14 @@
if (Process && Address < MmSystemRangeStart)
{
+ // Make sure we don't try to page out part of an exiting process
Status = ObReferenceObject(Process);
+ if (PsIsProcessExiting(Process))
+ {
+ ObDereferenceObject(Process);
+ ExReleaseFastMutex(&RmapListLock);
+ goto bail;
+ }
if (!NT_SUCCESS(Status))
{
DPRINT("bail\n");
@@ -355,7 +362,10 @@
Evicted =
NT_SUCCESS(Status) &&
NT_SUCCESS(MmFinalizeSectionPageOut(Segment, &FileOffset, Page, Dirty));
-
+
+ /* Note: on success, segment might not exist anymore, due to cache segment
+ * replacement in cc */
+
if (!Evicted && SectionPage)
{
DPRINT1
Modified: branches/arty-newcc/ntoskrnl/mm/section/data.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section/…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section/data.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section/data.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -90,7 +90,7 @@
NTAPI
_MmLockSectionSegment(PMM_SECTION_SEGMENT Segment, const char *file, int line)
{
- DPRINT1("MmLockSectionSegment(%p,%s:%d)\n", Segment, file, line);
+ DPRINT("MmLockSectionSegment(%p,%s:%d)\n", Segment, file, line);
ExAcquireFastMutex(&Segment->Lock);
}
@@ -99,7 +99,7 @@
_MmUnlockSectionSegment(PMM_SECTION_SEGMENT Segment, const char *file, int line)
{
ExReleaseFastMutex(&Segment->Lock);
- DPRINT1("MmUnlockSectionSegment(%p,%s:%d)\n", Segment, file, line);
+ DPRINT("MmUnlockSectionSegment(%p,%s:%d)\n", Segment, file, line);
}
VOID
@@ -260,7 +260,7 @@
if (!NT_SUCCESS(Status))
{
- DPRINT1
+ DPRINT
("Writeback from section flush %08x%08x (%x) %x@%x (%08x%08x:%wZ) failed
%x\n",
FileOffset.u.HighPart, FileOffset.u.LowPart,
(ULONG)(FileSize->QuadPart - FileOffset.QuadPart),
@@ -894,7 +894,7 @@
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
- DPRINT1("Mapping between 0x%.8X and 0x%.8X failed (%X).\n",
+ DPRINT("Mapping between 0x%.8X and 0x%.8X failed (%X).\n",
(*BaseAddress), (char*)(*BaseAddress) + ViewSize, Status);
return(Status);
}
@@ -1170,7 +1170,7 @@
if (IS_DIRTY_SSE(Entry) && FileObject)
{
- DPRINT1("MiWriteBackPage(%wZ,%08x%08x)\n", &FileObject->FileName,
FileOffset->u.HighPart, FileOffset->u.LowPart);
+ DPRINT("MiWriteBackPage(%wZ,%08x%08x)\n", &FileObject->FileName,
FileOffset->u.HighPart, FileOffset->u.LowPart);
MiWriteBackPage(FileObject, FileOffset, PAGE_SIZE, OldPage);
DPRINT("Dereference page %x\n", OldPage);
}
Modified: branches/arty-newcc/ntoskrnl/mm/section/fault.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section/…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section/fault.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section/fault.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -46,7 +46,7 @@
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
-//#define NDEBUG
+#define NDEBUG
#include <debug.h>
extern KEVENT MmWaitPageEvent;
@@ -164,7 +164,7 @@
MmUnlockSectionSegment(Segment);
DPRINT("XXX Set Event %x\n", Status);
KeSetEvent(&MmWaitPageEvent, IO_NO_INCREMENT, FALSE);
- DPRINT1("Status %x\n", Status);
+ DPRINT("Status %x\n", Status);
return Status;
}
else if (MmIsPageSwapEntry(Process, Address))
@@ -173,7 +173,7 @@
MmGetPageFileMapping(Process, Address, &SwapEntry);
if (SwapEntry == MM_WAIT_ENTRY)
{
- DPRINT1("Wait for page entry in section\n");
+ DPRINT("Wait for page entry in section\n");
MmUnlockSectionSegment(Segment);
return STATUS_SUCCESS + 1;
}
@@ -194,7 +194,7 @@
SWAPENTRY SwapEntry = SWAPENTRY_FROM_SSE(Entry);
if (SwapEntry == MM_WAIT_ENTRY)
{
- DPRINT1("Wait for page entry in section\n");
+ DPRINT("Wait for page entry in section\n");
MmUnlockSectionSegment(Segment);
return STATUS_SUCCESS + 1;
}
@@ -225,7 +225,7 @@
DPRINT("XXX Set Event %x\n", Status);
KeSetEvent(&MmWaitPageEvent, IO_NO_INCREMENT, FALSE);
MmUnlockSectionSegment(Segment);
- DPRINT1("Status %x\n", Status);
+ DPRINT("Status %x\n", Status);
return Status;
}
else
@@ -286,7 +286,7 @@
BoundaryAddressMultiple.QuadPart = 0;
- DPRINT1("Not Present: %p %p (%p-%p)\n", AddressSpace, Address,
MemoryArea->StartingAddress, MemoryArea->EndingAddress);
+ DPRINT("Not Present: %p %p (%p-%p)\n", AddressSpace, Address,
MemoryArea->StartingAddress, MemoryArea->EndingAddress);
/*
* There is a window between taking the page fault and locking the
@@ -706,7 +706,7 @@
if (!Private)
{
ASSERT(SwapEntry == 0);
- DPRINT1("MiWriteBackPage(%wZ,%08x%08x)\n", &FileObject->FileName,
Offset.u.HighPart, Offset.u.LowPart);
+ DPRINT("MiWriteBackPage(%wZ,%08x%08x)\n", &FileObject->FileName,
Offset.u.HighPart, Offset.u.LowPart);
Status = MiWriteBackPage(FileObject, &Offset, PAGE_SIZE, Page);
MmSetCleanAllRmaps(Page);
MmUnlockSectionSegment(Segment);
@@ -730,7 +730,7 @@
/*
* Write the page to the pagefile
*/
- DPRINT1("Writing swap entry: %x %x\n", SwapEntry, Page);
+ DPRINT("Writing swap entry: %x %x\n", SwapEntry, Page);
Status = MmWriteToSwapPage(SwapEntry, Page);
if (!NT_SUCCESS(Status))
{
@@ -790,7 +790,7 @@
ASSERT(KeGetCurrentIrql() <= APC_LEVEL);
if (SwapEntry == MM_WAIT_ENTRY)
{
- DPRINT1
+ DPRINT
("SwapEntry is a WAIT, our swap to is %x, State is %x for (%x:%x) on page
%x\n",
Required->SwapEntry,
Required->State,
@@ -833,7 +833,7 @@
MmUnlockSectionSegment(Segment);
return STATUS_PAGEFILE_QUOTA;
}
- DPRINT1("MiWriteSwapPage (%x -> %x)\n", OurPage,
Required->SwapEntry);
+ DPRINT("MiWriteSwapPage (%x -> %x)\n", OurPage, Required->SwapEntry);
Required->DoAcquisition = MiWriteSwapPage;
MmCreatePageFileMapping(Process, Address, MM_WAIT_ENTRY);
MmUnlockSectionSegment(Segment);
@@ -841,7 +841,7 @@
}
else
{
- DPRINT1("Out of swap space for page %x\n", OurPage);
+ DPRINT("Out of swap space for page %x\n", OurPage);
MmUnlockSectionSegment(Segment);
return STATUS_PAGEFILE_QUOTA;
}
Modified: branches/arty-newcc/ntoskrnl/mm/section/pagefile.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section/…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section/pagefile.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section/pagefile.c [iso-8859-1] Thu Jan 7 00:35:55
2010
@@ -153,20 +153,20 @@
BOOLEAN Dirty)
{
NTSTATUS Status = STATUS_SUCCESS;
- BOOLEAN WriteZero = FALSE;
+ BOOLEAN WriteZero = FALSE, WritePage = FALSE;
SWAPENTRY Swap = MmGetSavedSwapEntryPage(Page);
MmLockSectionSegment(Segment);
+
if (Dirty)
{
- DPRINT1("Finalize (dirty) Segment %x Page %x\n", Segment, Page);
+ DPRINT("Finalize (dirty) Segment %x Page %x\n", Segment, Page);
DPRINT("Segment->FileObject %x\n", Segment->FileObject);
DPRINT("Segment->Flags %x\n", Segment->Flags);
if (Segment->FileObject && !(Segment->Flags & MM_IMAGE_SEGMENT))
{
- DPRINT1("Segment %x FileObject %x Offset %x\n", Segment,
Segment->FileObject, FileOffset->LowPart);
- Status = MiWriteBackPage(Segment->FileObject, FileOffset, PAGE_SIZE, Page);
- WriteZero = NT_SUCCESS(Status);
+ WriteZero = TRUE;
+ WritePage = TRUE;
}
else
{
@@ -193,24 +193,32 @@
if (WriteZero)
{
- DPRINT1("Setting page entry in segment %x:%x to swap %x\n", Segment,
FileOffset->LowPart, Swap);
+ DPRINT("Setting page entry in segment %x:%x to swap %x\n", Segment,
FileOffset->LowPart, Swap);
MiSetPageEntrySectionSegment(Segment, FileOffset, Swap ? MAKE_SWAP_SSE(Swap) : 0);
}
else
{
- DPRINT1("Setting page entry in segment %x:%x to page %x\n", Segment,
FileOffset->LowPart, Page);
+ DPRINT("Setting page entry in segment %x:%x to page %x\n", Segment,
FileOffset->LowPart, Page);
MiSetPageEntrySectionSegment
(Segment, FileOffset, Page ? (Dirty ? DIRTY_SSE(MAKE_PFN_SSE(Page)) :
MAKE_PFN_SSE(Page)) : 0);
}
+ MmUnlockSectionSegment(Segment);
+
+ if (WritePage)
+ {
+ DPRINT("Segment %x FileObject %x Offset %x\n", Segment,
Segment->FileObject, FileOffset->LowPart);
+ Status = MiWriteBackPage(Segment->FileObject, FileOffset, PAGE_SIZE, Page);
+ }
+
if (NT_SUCCESS(Status))
{
- DPRINT1("Removing page %x for real\n", Page);
+ DPRINT("Removing page %x for real\n", Page);
MmSetSavedSwapEntryPage(Page, 0);
MmDereferencePage(Page);
}
- MmUnlockSectionSegment(Segment);
+ /* Note: Writing may evict the segment... Nothing is guaranteed from here down */
KeSetEvent(&MmWaitPageEvent, IO_NO_INCREMENT, FALSE);
Modified: branches/arty-newcc/ntoskrnl/ps/kill.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/ps/kill.c?r…
==============================================================================
--- branches/arty-newcc/ntoskrnl/ps/kill.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/ps/kill.c [iso-8859-1] Thu Jan 7 00:35:55 2010
@@ -605,6 +605,7 @@
if (TerminationPort)
{
/* Setup the message header */
+ TerminationMsg.h.u2.ZeroInit = 0;
TerminationMsg.h.u2.s2.Type = LPC_CLIENT_DIED;
TerminationMsg.h.u1.s1.TotalLength = sizeof(TerminationMsg);
TerminationMsg.h.u1.s1.DataLength = sizeof(TerminationMsg) -
@@ -1020,6 +1021,13 @@
return Status;
}
+BOOLEAN
+NTAPI
+PsIsProcessExiting(IN PEPROCESS Process)
+{
+ return Process->Flags & PSF_PROCESS_EXITING_BIT;
+}
+
VOID
NTAPI
PspExitProcess(IN BOOLEAN LastThread,