Replaced all calls to MmDereferencePage with MmReleasePageMemoryConsumer.

Added handling for multiple referenced pages in MmReleasePageMemoryConsumer.

svn path=/trunk/; revision=3041
This commit is contained in:
Hartmut Birr 2002-06-10 21:34:38 +00:00
parent a64eec7e49
commit 16068960f0
7 changed files with 44 additions and 27 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: kthread.c,v 1.26 2002/06/04 15:26:56 dwelch Exp $
/* $Id: kthread.c,v 1.27 2002/06/10 21:34:36 hbirr Exp $
*
* FILE: ntoskrnl/ke/kthread.c
* PURPOSE: Microkernel thread support
@ -50,7 +50,7 @@ KeFreeStackPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
assert(SwapEntry == 0);
if (PhysAddr.QuadPart != 0)
{
MmDereferencePage(PhysAddr);
MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
}
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: balance.c,v 1.9 2002/06/04 15:26:56 dwelch Exp $
/* $Id: balance.c,v 1.10 2002/06/10 21:34:37 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -67,6 +67,13 @@ static ULONG MiMinimumPagesPerRun = 1;
/* FUNCTIONS ****************************************************************/
VOID MmPrintMemoryStatistic(VOID)
{
DbgPrint("MC_CACHE %d, MC_USER %d, MC_PPOOL %d, MC_NPPOOL %d\n",
MiMemoryConsumers[MC_CACHE].PagesUsed, MiMemoryConsumers[MC_USER].PagesUsed,
MiMemoryConsumers[MC_PPOOL].PagesUsed, MiMemoryConsumers[MC_NPPOOL].PagesUsed);
}
VOID
MmInitializeBalancer(ULONG NrAvailablePages)
{
@ -105,10 +112,12 @@ MmReleasePageMemoryConsumer(ULONG Consumer, PHYSICAL_ADDRESS Page)
KeBugCheck(0);
}
KeAcquireSpinLock(&AllocationListLock, &oldIrql);
if (MmGetReferenceCountPage(Page) == 1)
{
InterlockedDecrement(&MiMemoryConsumers[Consumer].PagesUsed);
InterlockedIncrement(&MiNrAvailablePages);
InterlockedDecrement(&MiPagesRequired);
KeAcquireSpinLock(&AllocationListLock, &oldIrql);
if (IsListEmpty(&AllocationListHead))
{
KeReleaseSpinLock(&AllocationListLock, oldIrql);
@ -122,6 +131,13 @@ MmReleasePageMemoryConsumer(ULONG Consumer, PHYSICAL_ADDRESS Page)
Request->Page = Page;
KeSetEvent(&Request->Event, IO_NO_INCREMENT, FALSE);
}
}
else
{
KeReleaseSpinLock(&AllocationListLock, oldIrql);
MmDereferencePage(Page);
}
return(STATUS_SUCCESS);
}
@ -129,6 +145,7 @@ VOID
MiTrimMemoryConsumer(ULONG Consumer)
{
LONG Target;
ULONG NrFreedPages;
Target = MiMemoryConsumers[Consumer].PagesUsed -
MiMemoryConsumers[Consumer].PagesTarget;
@ -139,7 +156,7 @@ MiTrimMemoryConsumer(ULONG Consumer)
if (MiMemoryConsumers[Consumer].Trim != NULL)
{
MiMemoryConsumers[Consumer].Trim(Target, 0, NULL);
MiMemoryConsumers[Consumer].Trim(Target, 0, &NrFreedPages);
}
}

View file

@ -1,4 +1,4 @@
/* $Id: cont.c,v 1.20 2002/06/04 15:26:56 dwelch Exp $
/* $Id: cont.c,v 1.21 2002/06/10 21:34:37 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -27,7 +27,7 @@ MmFreeContinuousPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
assert(SwapEntry == 0);
if (PhysAddr.QuadPart != 0)
{
MmDereferencePage(PhysAddr);
MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
}
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: page.c,v 1.37 2002/06/04 15:26:57 dwelch Exp $
/* $Id: page.c,v 1.38 2002/06/10 21:34:38 hbirr Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/i386/page.c
@ -124,7 +124,7 @@ NTSTATUS Mmi386ReleaseMmInfo(PEPROCESS Process)
{
DPRINT("Mmi386ReleaseMmInfo(Process %x)\n",Process);
MmDereferencePage(Process->Pcb.DirectoryTableBase);
MmReleasePageMemoryConsumer(MC_NPPOOL, Process->Pcb.DirectoryTableBase);
Process->Pcb.DirectoryTableBase.QuadPart = 0LL;
DPRINT("Finished Mmi386ReleaseMmInfo()\n");
@ -216,7 +216,7 @@ VOID MmFreePageTable(PEPROCESS Process, PVOID Address)
{
MmGlobalKernelPageDirectory[ADDR_TO_PDE_OFFSET(Address)] = 0;
}
MmDereferencePage(PTE_TO_PAGE(npage));
MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PAGE(npage));
FLUSH_TLB;
if (Process != NULL && Process != CurrentProcess)
{
@ -474,7 +474,7 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOL FreePage,
}
if (FreePage && WasValid)
{
MmDereferencePage(PTE_TO_PAGE(Pte));
MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PAGE(Pte));
}
/*

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.18 2002/06/04 15:26:57 dwelch Exp $
/* $Id: ncache.c,v 1.19 2002/06/10 21:34:37 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -93,7 +93,7 @@ MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
assert(SwapEntry == 0);
if (PhysAddr.QuadPart != 0)
{
MmDereferencePage(PhysAddr);
MmReleasePageMemoryConsumer(MC_NPPOOL, PhysAddr);
}
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: section.c,v 1.85 2002/06/04 15:26:57 dwelch Exp $
/* $Id: section.c,v 1.86 2002/06/10 21:34:37 hbirr Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c
@ -1115,7 +1115,7 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
MmUnsharePageEntrySectionSegment(Section, Segment, Offset.QuadPart, FALSE);
MmDeleteRmap(OldPage, PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(Address));
MmDereferencePage(OldPage);
MmReleasePageMemoryConsumer(MC_USER, OldPage);
PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
@ -1147,7 +1147,7 @@ MmPageOutDeleteMapping(PVOID Context, PEPROCESS Process, PVOID Address)
PageOutContext->Offset.u.LowPart,
PageOutContext->WasDirty);
}
MmDereferencePage(PhysicalAddress);
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress);
}
NTSTATUS
@ -1360,7 +1360,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
if (DirectMapped && !Private)
{
assert(SwapEntry == 0);
MmDereferencePage(PhysicalAddress);
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddress);
PageOp->Status = STATUS_SUCCESS;
KeSetEvent(&PageOp->CompletionEvent, IO_NO_INCREMENT, FALSE);
MmReleasePageOp(PageOp);
@ -1535,7 +1535,7 @@ MmpCreateSection(PVOID ObjectBody,
PWSTR RemainingPath,
POBJECT_ATTRIBUTES ObjectAttributes)
{
DPRINT("MmpCreateDevice(ObjectBody %x, Parent %x, RemainingPath %S)\n",
DPRINT("MmpCreateSection(ObjectBody %x, Parent %x, RemainingPath %S)\n",
ObjectBody, Parent, RemainingPath);
if (RemainingPath == NULL)
@ -2588,7 +2588,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
* Just dereference private pages
*/
MmDeleteRmap(PhysAddr, MArea->Process, Address);
MmDereferencePage(PhysAddr);
MmReleasePageMemoryConsumer(MC_USER, PhysAddr);
}
else
{
@ -2597,7 +2597,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
Offset,
Dirty);
MmDeleteRmap(PhysAddr, MArea->Process, Address);
MmDereferencePage(PhysAddr);
MmReleasePageMemoryConsumer(MC_USER, PhysAddr);
}
}
}

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.59 2002/06/04 15:26:57 dwelch Exp $
/* $Id: virtual.c,v 1.60 2002/06/10 21:34:37 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -436,7 +436,7 @@ MmModifyAttributes(PMADDRESS_SPACE AddressSpace,
{
MmDeleteRmap(PhysicalAddr, AddressSpace->Process,
BaseAddress + (i * PAGESIZE));
MmDereferencePage(PhysicalAddr);
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddr);
}
}
}
@ -1062,7 +1062,7 @@ MmFreeVirtualMemoryPage(PVOID Context,
if (PhysicalAddr.QuadPart != 0)
{
MmDeleteRmap(PhysicalAddr, Process, Address);
MmDereferencePage(PhysicalAddr);
MmReleasePageMemoryConsumer(MC_USER, PhysicalAddr);
}
else if (SwapEntry != 0)
{