Trim cache

svn path=/trunk/; revision=2443
This commit is contained in:
David Welch 2001-12-29 14:32:22 +00:00
parent 2fbbe48059
commit 3fd3d008eb
17 changed files with 205 additions and 82 deletions

View file

@ -68,7 +68,7 @@ SYS_APPS = services shell winlogon
APPS = args hello test cat bench apc shm lpc thread event file gditest \ APPS = args hello test cat bench apc shm lpc thread event file gditest \
pteb consume dump_shared_data vmtest regtest alive mstest nptest \ pteb consume dump_shared_data vmtest regtest alive mstest nptest \
objdir atomtest winhello partinfo mutex objdir atomtest winhello partinfo mutex readfile
#NET_APPS = ncftp ping roshttpd telnet #NET_APPS = ncftp ping roshttpd telnet
NET_APPS = ncftp ping roshttpd NET_APPS = ncftp ping roshttpd

View file

@ -15,8 +15,10 @@ NTSTATUS STDCALL
CcRosFlushCacheSegment (struct _CACHE_SEGMENT* CacheSeg); CcRosFlushCacheSegment (struct _CACHE_SEGMENT* CacheSeg);
NTSTATUS STDCALL NTSTATUS STDCALL
CcRosReleaseCacheSegment (struct _BCB* Bcb, CcRosReleaseCacheSegment (struct _BCB* Bcb,
struct _CACHE_SEGMENT* CacheSeg, struct _CACHE_SEGMENT* CacheSeg,
BOOLEAN Valid); BOOLEAN Valid,
BOOLEAN Dirty,
BOOLEAN Mapped);
NTSTATUS STDCALL NTSTATUS STDCALL
CcRosRequestCacheSegment (struct _BCB* Bcb, CcRosRequestCacheSegment (struct _BCB* Bcb,
ULONG FileOffset, ULONG FileOffset,

View file

@ -1,4 +1,4 @@
/* $Id: copy.c,v 1.2 2001/12/27 23:56:41 dwelch Exp $ /* $Id: copy.c,v 1.3 2001/12/29 14:32:21 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -47,7 +47,7 @@ NTSTATUS ReadCacheSegment(PCACHE_SEGMENT CacheSeg)
Status = IoPageRead(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, &IoStatus, TRUE); Status = IoPageRead(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, &IoStatus, TRUE);
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE) if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
{ {
CcRosReleaseCacheSegment(CacheSeg->Bcb, CacheSeg, FALSE); CcRosReleaseCacheSegment(CacheSeg->Bcb, CacheSeg, FALSE, FALSE, FALSE);
DPRINT1("IoPageRead failed, Status %x\n", Status); DPRINT1("IoPageRead failed, Status %x\n", Status);
return Status; return Status;
} }
@ -160,7 +160,7 @@ CcCopyRead (
} }
} }
memcpy (Buffer, BaseAddress + ReadOffset % Bcb->CacheSegmentSize, TempLength); memcpy (Buffer, BaseAddress + ReadOffset % Bcb->CacheSegmentSize, TempLength);
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
ReadLength += TempLength; ReadLength += TempLength;
Length -= TempLength; Length -= TempLength;
ReadOffset += TempLength; ReadOffset += TempLength;
@ -190,7 +190,7 @@ CcCopyRead (
} }
} }
memcpy (Buffer, BaseAddress, TempLength); memcpy (Buffer, BaseAddress, TempLength);
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
ReadLength += TempLength; ReadLength += TempLength;
Length -= TempLength; Length -= TempLength;
ReadOffset += TempLength; ReadOffset += TempLength;
@ -273,7 +273,7 @@ CcCopyWrite (
{ {
return FALSE; return FALSE;
} }
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
Length -= TempLength; Length -= TempLength;
WriteOffset += TempLength; WriteOffset += TempLength;
@ -301,7 +301,7 @@ CcCopyWrite (
{ {
return FALSE; return FALSE;
} }
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
Length -= TempLength; Length -= TempLength;
WriteOffset += TempLength; WriteOffset += TempLength;
Buffer += TempLength; Buffer += TempLength;

View file

@ -1,4 +1,4 @@
/* $Id: pin.c,v 1.1 2001/10/10 21:49:15 hbirr Exp $ /* $Id: pin.c,v 1.2 2001/12/29 14:32:21 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -79,7 +79,7 @@ CcMapData (
{ {
if (!Wait) if (!Wait)
{ {
CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE); CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
return FALSE; return FALSE;
} }
if (!NT_SUCCESS(ReadCacheSegment(CacheSeg))) if (!NT_SUCCESS(ReadCacheSegment(CacheSeg)))
@ -91,7 +91,7 @@ CcMapData (
iBcb = ExAllocatePool (NonPagedPool, sizeof(INTERNAL_BCB)); iBcb = ExAllocatePool (NonPagedPool, sizeof(INTERNAL_BCB));
if (iBcb == NULL) if (iBcb == NULL)
{ {
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
return FALSE; return FALSE;
} }
iBcb->CacheSegment = CacheSeg; iBcb->CacheSegment = CacheSeg;
@ -106,7 +106,7 @@ CcUnpinData (
IN PVOID Bcb) IN PVOID Bcb)
{ {
PINTERNAL_BCB iBcb = Bcb; PINTERNAL_BCB iBcb = Bcb;
CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb, iBcb->CacheSegment, TRUE); CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb, iBcb->CacheSegment, TRUE, FALSE, FALSE);
ExFreePool(iBcb); ExFreePool(iBcb);
} }

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.30 2001/12/27 23:56:41 dwelch Exp $ /* $Id: view.c,v 1.31 2001/12/29 14:32:21 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -57,10 +57,19 @@
#include <internal/mm.h> #include <internal/mm.h>
#include <internal/cc.h> #include <internal/cc.h>
#include <internal/pool.h> #include <internal/pool.h>
#include <ntos/minmax.h>
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* TYPES *********************************************************************/
typedef struct _CC_FREE_CONTEXT
{
DWORD Maximum;
PVOID* FreedPages;
} CC_FREE_CONTEXT, *PCC_FREE_CONTEXT;
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S)) #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
@ -71,23 +80,80 @@
static LIST_ENTRY DirtySegmentListHead; static LIST_ENTRY DirtySegmentListHead;
static LIST_ENTRY CacheSegmentListHead; static LIST_ENTRY CacheSegmentListHead;
static LIST_ENTRY CacheSegmentLRUListHead;
static FAST_MUTEX ViewLock; static FAST_MUTEX ViewLock;
NTSTATUS STDCALL
CcRosInternalFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg, PVOID Context);
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS
CcRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed, PVOID* FreedPages)
{
PLIST_ENTRY current_entry;
PCACHE_SEGMENT current;
ULONG PagesPerSegment;
CC_FREE_CONTEXT FreeContext;
ULONG PagesFreed;
DPRINT("CcRosTrimCache(Target %d)\n", Target);
*NrFreed = 0;
ExAcquireFastMutex(&ViewLock);
current_entry = CacheSegmentLRUListHead.Flink;
while (current_entry != &CacheSegmentLRUListHead && Target > 0)
{
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, CacheSegmentLRUListEntry);
current_entry = current_entry->Flink;
ExAcquireFastMutex(&current->Lock);
if (current->MappedCount > 0 || current->Dirty || current->ReferenceCount > 0)
{
ExReleaseFastMutex(&current->Lock);
continue;
}
ExReleaseFastMutex(&current->Lock);
DPRINT("current->Bcb->CacheSegmentSize %d\n", current->Bcb->CacheSegmentSize);
PagesPerSegment = current->Bcb->CacheSegmentSize / PAGESIZE;
FreeContext.Maximum = min(PagesPerSegment, Target);
FreeContext.FreedPages = FreedPages;
CcRosInternalFreeCacheSegment(current->Bcb, current, (PVOID)&FreeContext);
DPRINT("CcRosTrimCache(): Freed %d\n", PagesPerSegment);
PagesFreed = min(PagesPerSegment, Target);
Target = Target - PagesFreed;
FreedPages = FreedPages + PagesFreed;
(*NrFreed) = (*NrFreed) + PagesFreed;
}
ExReleaseFastMutex(&ViewLock);
DPRINT("CcRosTrimCache() finished\n");
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL NTSTATUS STDCALL
CcRosReleaseCacheSegment(PBCB Bcb, CcRosReleaseCacheSegment(PBCB Bcb,
PCACHE_SEGMENT CacheSeg, PCACHE_SEGMENT CacheSeg,
BOOLEAN Valid) BOOLEAN Valid,
BOOLEAN Dirty,
BOOLEAN Mapped)
{ {
DPRINT("CcReleaseCachePage(Bcb %x, CacheSeg %x, Valid %d)\n", DPRINT("CcReleaseCachePage(Bcb %x, CacheSeg %x, Valid %d)\n",
Bcb, CacheSeg, Valid); Bcb, CacheSeg, Valid);
CacheSeg->ReferenceCount--;
CacheSeg->Valid = Valid; CacheSeg->Valid = Valid;
CacheSeg->Dirty = CacheSeg->Dirty || Dirty;
if (Mapped)
{
CacheSeg->MappedCount++;
}
ExReleaseFastMutex(&CacheSeg->Lock); ExReleaseFastMutex(&CacheSeg->Lock);
ExAcquireFastMutex(&ViewLock);
RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry);
InsertTailList(&CacheSegmentLRUListHead, &CacheSeg->CacheSegmentLRUListEntry);
ExReleaseFastMutex(&ViewLock);
InterlockedDecrement(&CacheSeg->ReferenceCount);
DPRINT("CcReleaseCachePage() finished\n"); DPRINT("CcReleaseCachePage() finished\n");
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
@ -165,17 +231,19 @@ CcRosGetCacheSegment(PBCB Bcb,
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());
KeBugCheck(0); KeBugCheck(0);
} }
MmUnlockAddressSpace(MmGetKernelAddressSpace());
current->Valid = FALSE; current->Valid = FALSE;
current->Dirty = FALSE; current->Dirty = FALSE;
current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize); current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
current->Bcb = Bcb; current->Bcb = Bcb;
current->MappedCount = 0;
ExInitializeFastMutex(&current->Lock); ExInitializeFastMutex(&current->Lock);
current->ReferenceCount = 1; current->ReferenceCount = 1;
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql); KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
InsertTailList(&Bcb->BcbSegmentListHead, &current->BcbSegmentListEntry); InsertTailList(&Bcb->BcbSegmentListHead, &current->BcbSegmentListEntry);
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql); KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
InsertTailList(&CacheSegmentListHead, &current->CacheSegmentListEntry); InsertTailList(&CacheSegmentListHead, &current->CacheSegmentListEntry);
InsertTailList(&CacheSegmentLRUListHead, &current->CacheSegmentLRUListEntry);
current->DirtySegmentListEntry.Flink = current->DirtySegmentListEntry.Blink = NULL; current->DirtySegmentListEntry.Flink = current->DirtySegmentListEntry.Blink = NULL;
ExAcquireFastMutex(&current->Lock); ExAcquireFastMutex(&current->Lock);
ExReleaseFastMutex(&ViewLock); ExReleaseFastMutex(&ViewLock);
@ -185,17 +253,24 @@ CcRosGetCacheSegment(PBCB Bcb,
*BaseOffset = current->FileOffset; *BaseOffset = current->FileOffset;
for (i = 0; i < (Bcb->CacheSegmentSize / PAGESIZE); i++) for (i = 0; i < (Bcb->CacheSegmentSize / PAGESIZE); i++)
{ {
Status = MmCreateVirtualMapping(NULL, PVOID Page;
current->BaseAddress + (i * PAGESIZE),
PAGE_READWRITE, Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &Page);
(ULONG)MmAllocPage(0)); if (!NT_SUCCESS(Status))
{
if (!NT_SUCCESS(Status)){ KeBugCheck(0);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
KeBugCheck(0);
}
} }
MmUnlockAddressSpace(MmGetKernelAddressSpace());
Status = MmCreateVirtualMapping(NULL,
current->BaseAddress + (i * PAGESIZE),
PAGE_READWRITE,
(ULONG)Page);
if (!NT_SUCCESS(Status))
{
KeBugCheck(0);
}
}
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -227,31 +302,55 @@ CcRosRequestCacheSegment(PBCB Bcb,
} }
STATIC VOID STATIC VOID
CcFreeCachePage(PVOID Context, PVOID Address, ULONG PhysAddr) CcFreeCachePage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
{ {
PCC_FREE_CONTEXT FreeContext = (PCC_FREE_CONTEXT)Context;
ULONG Offset = (Address - MemoryArea->BaseAddress) / PAGESIZE;
if (PhysAddr != 0) if (PhysAddr != 0)
{ {
MmDereferencePage((PVOID)PhysAddr); if (Context == NULL || Offset >= FreeContext->Maximum)
{
MmReleasePageMemoryConsumer(MC_CACHE, (PVOID)PhysAddr);
}
else
{
DPRINT("Address %X Offset %d PhysAddr %X\n", Address, Offset, PhysAddr);
FreeContext->FreedPages[Offset] = (PVOID)PhysAddr;
}
} }
} }
NTSTATUS STDCALL NTSTATUS STDCALL
CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg) CcRosInternalFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg, PVOID Context)
/* /*
* FUNCTION: Releases a cache segment associated with a BCB * FUNCTION: Releases a cache segment associated with a BCB
*/ */
{ {
DPRINT("Freeing cache segment %x\n", CacheSeg); DPRINT("Freeing cache segment %x\n", CacheSeg);
RemoveEntryList(&CacheSeg->CacheSegmentListEntry); RemoveEntryList(&CacheSeg->CacheSegmentListEntry);
RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry);
RemoveEntryList(&CacheSeg->BcbSegmentListEntry);
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryArea(MmGetKernelAddressSpace(),
CacheSeg->BaseAddress, CacheSeg->BaseAddress,
Bcb->CacheSegmentSize, Bcb->CacheSegmentSize,
CcFreeCachePage, CcFreeCachePage,
NULL); Context);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
ExFreePool(CacheSeg); ExFreePool(CacheSeg);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL
CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg)
{
NTSTATUS Status;
ExAcquireFastMutex(&ViewLock);
Status = CcRosInternalFreeCacheSegment(Bcb, CacheSeg, NULL);
ExReleaseFastMutex(&ViewLock);
return(Status);
}
NTSTATUS STDCALL NTSTATUS STDCALL
CcRosReleaseFileCache(PFILE_OBJECT FileObject, PBCB Bcb) CcRosReleaseFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
/* /*
@ -321,7 +420,9 @@ CcInitView(VOID)
DPRINT1("CcInitView()\n"); DPRINT1("CcInitView()\n");
InitializeListHead(&CacheSegmentListHead); InitializeListHead(&CacheSegmentListHead);
InitializeListHead(&DirtySegmentListHead); InitializeListHead(&DirtySegmentListHead);
InitializeListHead(&CacheSegmentLRUListHead);
ExInitializeFastMutex(&ViewLock); ExInitializeFastMutex(&ViewLock);
MmInitializeMemoryConsumer(MC_CACHE, CcRosTrimCache);
} }
/* EOF */ /* EOF */
@ -332,4 +433,3 @@ CcInitView(VOID)

View file

@ -1,6 +1,6 @@
#ifndef __INCLUDE_INTERNAL_CC_H #ifndef __INCLUDE_INTERNAL_CC_H
#define __INCLUDE_INTERNAL_CC_H #define __INCLUDE_INTERNAL_CC_H
/* $Id: cc.h,v 1.7 2001/12/27 23:56:42 dwelch Exp $ */ /* $Id: cc.h,v 1.8 2001/12/29 14:32:22 dwelch Exp $ */
#include <ddk/ntifs.h> #include <ddk/ntifs.h>
typedef struct _BCB typedef struct _BCB
@ -23,12 +23,14 @@ typedef struct _CACHE_SEGMENT
BOOLEAN Valid; BOOLEAN Valid;
/* Are the contents of the cache segment data newer than those on disk. */ /* Are the contents of the cache segment data newer than those on disk. */
BOOLEAN Dirty; BOOLEAN Dirty;
ULONG MappedCount;
/* Entry in the list of segments for this BCB. */ /* Entry in the list of segments for this BCB. */
LIST_ENTRY BcbSegmentListEntry; LIST_ENTRY BcbSegmentListEntry;
/* Entry in the list of segments which are dirty. */ /* Entry in the list of segments which are dirty. */
LIST_ENTRY DirtySegmentListEntry; LIST_ENTRY DirtySegmentListEntry;
/* Entry in the list of segments. */ /* Entry in the list of segments. */
LIST_ENTRY CacheSegmentListEntry; LIST_ENTRY CacheSegmentListEntry;
LIST_ENTRY CacheSegmentLRUListEntry;
/* Offset in the file which this cache segment maps. */ /* Offset in the file which this cache segment maps. */
ULONG FileOffset; ULONG FileOffset;
/* Lock. */ /* Lock. */

View file

@ -185,8 +185,8 @@ VOID ExInitNonPagedPool(ULONG BaseAddress);
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace, NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress, PVOID BaseAddress,
ULONG Length, ULONG Length,
VOID (*FreePage)(PVOID Context, PVOID Address, VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea,
ULONG PhysAddr), PVOID Address, ULONG PhysAddr),
PVOID FreePageContext); PVOID FreePageContext);
VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead); VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead);
NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea); NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea);
@ -473,4 +473,22 @@ MmCreateVirtualMappingForKernel(PVOID Address,
ULONG PhysicalAddress); ULONG PhysicalAddress);
NTSTATUS MmCommitPagedPoolAddress(PVOID Address); NTSTATUS MmCommitPagedPoolAddress(PVOID Address);
/* Memory balancing. */
VOID
MmInitializeMemoryConsumer(ULONG Consumer,
NTSTATUS (*Trim)(ULONG Target, ULONG Priority,
PULONG NrFreed, PVOID* FreedPages));
VOID
MmInitializeBalancer(ULONG NrAvailablePages);
NTSTATUS
MmReleasePageMemoryConsumer(ULONG Consumer, PVOID Page);
NTSTATUS
MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN CanWait, PVOID* AllocatedPage);
#define MC_CACHE (0)
#define MC_USER (1)
#define MC_PPOOL (2)
#define MC_NPPOOL (3)
#define MC_MAXIMUM (4)
#endif #endif

View file

@ -19,11 +19,6 @@
#define PAGE_LOCKED_FUNCTION (PLACE_IN_SECTION("pagelk")) #define PAGE_LOCKED_FUNCTION (PLACE_IN_SECTION("pagelk"))
#define PAGE_UNLOCKED_FUNCTION (PLACE_IN_SECTION("pagepo")) #define PAGE_UNLOCKED_FUNCTION (PLACE_IN_SECTION("pagepo"))
/*
* Maximum size of the kmalloc area (this is totally arbitary)
*/
#define NONPAGED_POOL_SIZE (4*1024*1024)
/* /*
* Defines a descriptor as it appears in the processor tables * Defines a descriptor as it appears in the processor tables
*/ */

View file

@ -20,4 +20,9 @@ extern ULONG MmPagedPoolSize;
#define MM_PAGED_POOL_SIZE (4*1024*1024) #define MM_PAGED_POOL_SIZE (4*1024*1024)
/*
* Maximum size of the kmalloc area (this is totally arbitary)
*/
#define NONPAGED_POOL_SIZE (4*1024*1024)
#endif /* __INTERNAL_POOL_H */ #endif /* __INTERNAL_POOL_H */

View file

@ -43,7 +43,7 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID VOID
KeFreeStackPage(PVOID Context, PVOID Address, ULONG PhysAddr) KeFreeStackPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
{ {
if (PhysAddr != 0) if (PhysAddr != 0)
{ {

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: balance.c,v 1.1 2001/12/28 00:04:45 dwelch Exp $ /* $Id: balance.c,v 1.2 2001/12/29 14:32:22 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -44,12 +44,6 @@ typedef struct _MM_MEMORY_CONSUMER
NTSTATUS (*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed, PVOID* FreedPages); NTSTATUS (*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed, PVOID* FreedPages);
} MM_MEMORY_CONSUMER, *PMM_MEMORY_CONSUMER; } MM_MEMORY_CONSUMER, *PMM_MEMORY_CONSUMER;
#define MC_CACHE (0)
#define MC_USER (1)
#define MC_PPOOL (2)
#define MC_NPPOOL (3)
#define MC_MAXIMUM (4)
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
static MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM]; static MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
@ -116,6 +110,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
PVOID* FreedPages; PVOID* FreedPages;
ULONG NrFreedPages; ULONG NrFreedPages;
ULONG TotalFreedPages; ULONG TotalFreedPages;
PVOID* OrigFreedPages;
Target = MiMinimumAvailablePages - MiNrAvailablePages; Target = MiMinimumAvailablePages - MiNrAvailablePages;
if (Target < 0) if (Target < 0)
@ -123,7 +118,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
Target = 1; Target = 1;
} }
FreedPages = alloca(sizeof(PVOID) * Target); OrigFreedPages = FreedPages = alloca(sizeof(PVOID) * Target);
TotalFreedPages = 0; TotalFreedPages = 0;
for (i = 0; i < MC_MAXIMUM && Target > 0; i++) for (i = 0; i < MC_MAXIMUM && Target > 0; i++)
@ -142,7 +137,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
} }
if (Page != NULL) if (Page != NULL)
{ {
*Page = FreedPages[0]; *Page = OrigFreedPages[0];
i = 1; i = 1;
} }
else else
@ -151,7 +146,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
} }
for (; i < TotalFreedPages; i++) for (; i < TotalFreedPages; i++)
{ {
MmDereferencePage(FreedPages[i]); MmDereferencePage(OrigFreedPages[i]);
} }
} }

View file

@ -1,4 +1,4 @@
/* $Id: cont.c,v 1.13 2001/08/03 09:36:18 ei Exp $ /* $Id: cont.c,v 1.14 2001/12/29 14:32:22 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -20,7 +20,7 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID STATIC VOID STATIC
MmFreeContinuousPage(PVOID Context, PVOID Address, ULONG PhysAddr) MmFreeContinuousPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
{ {
if (PhysAddr != 0) if (PhysAddr != 0)
{ {

View file

@ -382,6 +382,7 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
MmStats.NrTotalPages = MmStats.NrFreePages + MmStats.NrSystemPages + MmStats.NrTotalPages = MmStats.NrFreePages + MmStats.NrSystemPages +
MmStats.NrReservedPages + MmStats.NrUserPages; MmStats.NrReservedPages + MmStats.NrUserPages;
MmInitializeBalancer(MmStats.NrFreePages);
return((PVOID)LastKernelAddress); return((PVOID)LastKernelAddress);
} }

View file

@ -294,7 +294,7 @@ NTSTATUS
MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace, MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress, PVOID BaseAddress,
ULONG Length, ULONG Length,
VOID (*FreePage)(PVOID Context, PVOID Address, VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
ULONG PhysAddr), ULONG PhysAddr),
PVOID FreePageContext) PVOID FreePageContext)
{ {
@ -307,10 +307,7 @@ MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace, MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
BaseAddress); BaseAddress);
if (MemoryArea == NULL) if (MemoryArea == NULL)
{ {
DPRINT1("AddressSpace 0x%X - KASpace 0x%X\n", AddressSpace, MmGetKernelAddressSpace());
DPRINT1("Memory area is NULL\n");
KeBugCheck(0); KeBugCheck(0);
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
@ -320,14 +317,14 @@ MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PhysAddr = PhysAddr =
MmGetPhysicalAddressForProcess(AddressSpace->Process, MmGetPhysicalAddressForProcess(AddressSpace->Process,
MemoryArea->BaseAddress + (i*PAGESIZE)); MemoryArea->BaseAddress + (i*PAGESIZE));
MmDeleteVirtualMapping(AddressSpace->Process, MmDeleteVirtualMapping(AddressSpace->Process,
MemoryArea->BaseAddress + (i*PAGESIZE), MemoryArea->BaseAddress + (i*PAGESIZE),
FALSE, NULL, NULL); FALSE, NULL, NULL);
if (FreePage != NULL) if (FreePage != NULL)
{ {
FreePage(FreePageContext, FreePage(FreePageContext, MemoryArea,
MemoryArea->BaseAddress + (i * PAGESIZE), PhysAddr); MemoryArea->BaseAddress + (i * PAGESIZE), PhysAddr);
} }
} }

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.11 2001/08/03 09:36:18 ei Exp $ /* $Id: ncache.c,v 1.12 2001/12/29 14:32:22 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -85,7 +85,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
} }
VOID STATIC VOID STATIC
MmFreeNonCachedPage(PVOID Context, PVOID Address, ULONG PhysAddr) MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
{ {
if (PhysAddr != 0) if (PhysAddr != 0)
{ {

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: section.c,v 1.68 2001/12/05 01:40:25 dwelch Exp $ /* $Id: section.c,v 1.69 2001/12/29 14:32:22 dwelch Exp $
* *
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/section.c * FILE: ntoskrnl/mm/section.c
@ -315,7 +315,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
TRUE); TRUE);
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE) if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
{ {
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, FALSE); CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, FALSE, FALSE, FALSE);
return(Status); return(Status);
} }
} }
@ -327,7 +327,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
(*Page) = (PVOID)(ULONG)Addr.QuadPart; (*Page) = (PVOID)(ULONG)Addr.QuadPart;
MmReferencePage((*Page)); MmReferencePage((*Page));
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, TRUE, FALSE, TRUE);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
else else
@ -1852,7 +1852,7 @@ NtMapViewOfSection(HANDLE SectionHandle,
} }
VOID STATIC VOID STATIC
MmFreeSectionPage(PVOID Context, PVOID Address, ULONG PhysAddr) MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
{ {
PMEMORY_AREA MArea; PMEMORY_AREA MArea;
ULONG Entry; ULONG Entry;
@ -2135,21 +2135,28 @@ MmAllocateSection (IN ULONG Length)
MmUnlockAddressSpace(AddressSpace); MmUnlockAddressSpace(AddressSpace);
return (NULL); return (NULL);
} }
MmUnlockAddressSpace(AddressSpace);
DPRINT("Result %p\n",Result); DPRINT("Result %p\n",Result);
for (i = 0; (i <= (Length / PAGESIZE)); i++) for (i = 0; (i <= (Length / PAGESIZE)); i++)
{ {
Status = MmCreateVirtualMapping (NULL, PVOID Page;
(Result + (i * PAGESIZE)),
PAGE_READWRITE, Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Page);
(ULONG)MmAllocPage(0)); if (!NT_SUCCESS(Status))
if (!NT_SUCCESS(Status)) {
{ DbgPrint("Unable to allocate page\n");
DbgPrint("Unable to create virtual mapping\n"); KeBugCheck(0);
MmUnlockAddressSpace(AddressSpace); }
KeBugCheck(0); Status = MmCreateVirtualMapping (NULL,
} (Result + (i * PAGESIZE)),
PAGE_READWRITE,
(ULONG)Page);
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
KeBugCheck(0);
}
} }
MmUnlockAddressSpace(AddressSpace);
return ((PVOID)Result); return ((PVOID)Result);
} }

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.49 2001/09/27 02:14:35 dwelch Exp $ /* $Id: virtual.c,v 1.50 2001/12/29 14:32:22 dwelch Exp $
* *
* COPYRIGHT: See COPYING in the top directory * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -1023,6 +1023,7 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
VOID STATIC VOID STATIC
MmFreeVirtualMemoryPage(PVOID Context, MmFreeVirtualMemoryPage(PVOID Context,
MEMORY_AREA* MemoryArea,
PVOID Address, PVOID Address,
ULONG PhysicalAddr) ULONG PhysicalAddr)
{ {