mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 09:34:43 +00:00
Trim cache
svn path=/trunk/; revision=2443
This commit is contained in:
parent
2fbbe48059
commit
3fd3d008eb
17 changed files with 205 additions and 82 deletions
|
@ -68,7 +68,7 @@ SYS_APPS = services shell winlogon
|
|||
|
||||
APPS = args hello test cat bench apc shm lpc thread event file gditest \
|
||||
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
|
||||
|
|
|
@ -15,8 +15,10 @@ NTSTATUS STDCALL
|
|||
CcRosFlushCacheSegment (struct _CACHE_SEGMENT* CacheSeg);
|
||||
NTSTATUS STDCALL
|
||||
CcRosReleaseCacheSegment (struct _BCB* Bcb,
|
||||
struct _CACHE_SEGMENT* CacheSeg,
|
||||
BOOLEAN Valid);
|
||||
struct _CACHE_SEGMENT* CacheSeg,
|
||||
BOOLEAN Valid,
|
||||
BOOLEAN Dirty,
|
||||
BOOLEAN Mapped);
|
||||
NTSTATUS STDCALL
|
||||
CcRosRequestCacheSegment (struct _BCB* Bcb,
|
||||
ULONG FileOffset,
|
||||
|
|
|
@ -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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -47,7 +47,7 @@ NTSTATUS ReadCacheSegment(PCACHE_SEGMENT CacheSeg)
|
|||
Status = IoPageRead(CacheSeg->Bcb->FileObject, Mdl, &SegOffset, &IoStatus, TRUE);
|
||||
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);
|
||||
return Status;
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ CcCopyRead (
|
|||
}
|
||||
}
|
||||
memcpy (Buffer, BaseAddress + ReadOffset % Bcb->CacheSegmentSize, TempLength);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
|
||||
ReadLength += TempLength;
|
||||
Length -= TempLength;
|
||||
ReadOffset += TempLength;
|
||||
|
@ -190,7 +190,7 @@ CcCopyRead (
|
|||
}
|
||||
}
|
||||
memcpy (Buffer, BaseAddress, TempLength);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
|
||||
ReadLength += TempLength;
|
||||
Length -= TempLength;
|
||||
ReadOffset += TempLength;
|
||||
|
@ -273,7 +273,7 @@ CcCopyWrite (
|
|||
{
|
||||
return FALSE;
|
||||
}
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
|
||||
|
||||
Length -= TempLength;
|
||||
WriteOffset += TempLength;
|
||||
|
@ -301,7 +301,7 @@ CcCopyWrite (
|
|||
{
|
||||
return FALSE;
|
||||
}
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
|
||||
Length -= TempLength;
|
||||
WriteOffset += TempLength;
|
||||
Buffer += TempLength;
|
||||
|
|
|
@ -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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -79,7 +79,7 @@ CcMapData (
|
|||
{
|
||||
if (!Wait)
|
||||
{
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, FALSE, FALSE, FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
if (!NT_SUCCESS(ReadCacheSegment(CacheSeg)))
|
||||
|
@ -91,7 +91,7 @@ CcMapData (
|
|||
iBcb = ExAllocatePool (NonPagedPool, sizeof(INTERNAL_BCB));
|
||||
if (iBcb == NULL)
|
||||
{
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE);
|
||||
CcRosReleaseCacheSegment(Bcb, CacheSeg, TRUE, FALSE, FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
iBcb->CacheSegment = CacheSeg;
|
||||
|
@ -106,7 +106,7 @@ CcUnpinData (
|
|||
IN PVOID Bcb)
|
||||
{
|
||||
PINTERNAL_BCB iBcb = Bcb;
|
||||
CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb, iBcb->CacheSegment, TRUE);
|
||||
CcRosReleaseCacheSegment(iBcb->CacheSegment->Bcb, iBcb->CacheSegment, TRUE, FALSE, FALSE);
|
||||
ExFreePool(iBcb);
|
||||
}
|
||||
|
||||
|
|
|
@ -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: 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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -57,10 +57,19 @@
|
|||
#include <internal/mm.h>
|
||||
#include <internal/cc.h>
|
||||
#include <internal/pool.h>
|
||||
#include <ntos/minmax.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <internal/debug.h>
|
||||
|
||||
/* TYPES *********************************************************************/
|
||||
|
||||
typedef struct _CC_FREE_CONTEXT
|
||||
{
|
||||
DWORD Maximum;
|
||||
PVOID* FreedPages;
|
||||
} CC_FREE_CONTEXT, *PCC_FREE_CONTEXT;
|
||||
|
||||
/* GLOBALS *******************************************************************/
|
||||
|
||||
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
|
||||
|
@ -71,23 +80,80 @@
|
|||
|
||||
static LIST_ENTRY DirtySegmentListHead;
|
||||
static LIST_ENTRY CacheSegmentListHead;
|
||||
static LIST_ENTRY CacheSegmentLRUListHead;
|
||||
|
||||
static FAST_MUTEX ViewLock;
|
||||
|
||||
NTSTATUS STDCALL
|
||||
CcRosInternalFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg, PVOID Context);
|
||||
|
||||
/* 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(¤t->Lock);
|
||||
if (current->MappedCount > 0 || current->Dirty || current->ReferenceCount > 0)
|
||||
{
|
||||
ExReleaseFastMutex(¤t->Lock);
|
||||
continue;
|
||||
}
|
||||
ExReleaseFastMutex(¤t->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
|
||||
CcRosReleaseCacheSegment(PBCB Bcb,
|
||||
PCACHE_SEGMENT CacheSeg,
|
||||
BOOLEAN Valid)
|
||||
PCACHE_SEGMENT CacheSeg,
|
||||
BOOLEAN Valid,
|
||||
BOOLEAN Dirty,
|
||||
BOOLEAN Mapped)
|
||||
{
|
||||
DPRINT("CcReleaseCachePage(Bcb %x, CacheSeg %x, Valid %d)\n",
|
||||
Bcb, CacheSeg, Valid);
|
||||
|
||||
CacheSeg->ReferenceCount--;
|
||||
CacheSeg->Valid = Valid;
|
||||
CacheSeg->Dirty = CacheSeg->Dirty || Dirty;
|
||||
if (Mapped)
|
||||
{
|
||||
CacheSeg->MappedCount++;
|
||||
}
|
||||
ExReleaseFastMutex(&CacheSeg->Lock);
|
||||
|
||||
ExAcquireFastMutex(&ViewLock);
|
||||
RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry);
|
||||
InsertTailList(&CacheSegmentLRUListHead, &CacheSeg->CacheSegmentLRUListEntry);
|
||||
ExReleaseFastMutex(&ViewLock);
|
||||
InterlockedDecrement(&CacheSeg->ReferenceCount);
|
||||
|
||||
DPRINT("CcReleaseCachePage() finished\n");
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
|
@ -165,17 +231,19 @@ CcRosGetCacheSegment(PBCB Bcb,
|
|||
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
||||
KeBugCheck(0);
|
||||
}
|
||||
|
||||
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
||||
current->Valid = FALSE;
|
||||
current->Dirty = FALSE;
|
||||
current->FileOffset = ROUND_DOWN(FileOffset, Bcb->CacheSegmentSize);
|
||||
current->Bcb = Bcb;
|
||||
current->MappedCount = 0;
|
||||
ExInitializeFastMutex(¤t->Lock);
|
||||
current->ReferenceCount = 1;
|
||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||
InsertTailList(&Bcb->BcbSegmentListHead, ¤t->BcbSegmentListEntry);
|
||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||
InsertTailList(&CacheSegmentListHead, ¤t->CacheSegmentListEntry);
|
||||
InsertTailList(&CacheSegmentLRUListHead, ¤t->CacheSegmentLRUListEntry);
|
||||
current->DirtySegmentListEntry.Flink = current->DirtySegmentListEntry.Blink = NULL;
|
||||
ExAcquireFastMutex(¤t->Lock);
|
||||
ExReleaseFastMutex(&ViewLock);
|
||||
|
@ -185,17 +253,24 @@ CcRosGetCacheSegment(PBCB Bcb,
|
|||
*BaseOffset = current->FileOffset;
|
||||
for (i = 0; i < (Bcb->CacheSegmentSize / PAGESIZE); i++)
|
||||
{
|
||||
Status = MmCreateVirtualMapping(NULL,
|
||||
current->BaseAddress + (i * PAGESIZE),
|
||||
PAGE_READWRITE,
|
||||
(ULONG)MmAllocPage(0));
|
||||
|
||||
if (!NT_SUCCESS(Status)){
|
||||
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
||||
KeBugCheck(0);
|
||||
}
|
||||
PVOID Page;
|
||||
|
||||
Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &Page);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
KeBugCheck(0);
|
||||
}
|
||||
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
||||
|
||||
Status = MmCreateVirtualMapping(NULL,
|
||||
current->BaseAddress + (i * PAGESIZE),
|
||||
PAGE_READWRITE,
|
||||
(ULONG)Page);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
KeBugCheck(0);
|
||||
}
|
||||
}
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -227,31 +302,55 @@ CcRosRequestCacheSegment(PBCB Bcb,
|
|||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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
|
||||
CcRosFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg)
|
||||
CcRosInternalFreeCacheSegment(PBCB Bcb, PCACHE_SEGMENT CacheSeg, PVOID Context)
|
||||
/*
|
||||
* FUNCTION: Releases a cache segment associated with a BCB
|
||||
*/
|
||||
{
|
||||
DPRINT("Freeing cache segment %x\n", CacheSeg);
|
||||
RemoveEntryList(&CacheSeg->CacheSegmentListEntry);
|
||||
RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry);
|
||||
RemoveEntryList(&CacheSeg->BcbSegmentListEntry);
|
||||
MmLockAddressSpace(MmGetKernelAddressSpace());
|
||||
MmFreeMemoryArea(MmGetKernelAddressSpace(),
|
||||
CacheSeg->BaseAddress,
|
||||
Bcb->CacheSegmentSize,
|
||||
CcFreeCachePage,
|
||||
NULL);
|
||||
Context);
|
||||
MmUnlockAddressSpace(MmGetKernelAddressSpace());
|
||||
ExFreePool(CacheSeg);
|
||||
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
|
||||
CcRosReleaseFileCache(PFILE_OBJECT FileObject, PBCB Bcb)
|
||||
/*
|
||||
|
@ -321,7 +420,9 @@ CcInitView(VOID)
|
|||
DPRINT1("CcInitView()\n");
|
||||
InitializeListHead(&CacheSegmentListHead);
|
||||
InitializeListHead(&DirtySegmentListHead);
|
||||
InitializeListHead(&CacheSegmentLRUListHead);
|
||||
ExInitializeFastMutex(&ViewLock);
|
||||
MmInitializeMemoryConsumer(MC_CACHE, CcRosTrimCache);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
@ -332,4 +433,3 @@ CcInitView(VOID)
|
|||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef __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>
|
||||
|
||||
typedef struct _BCB
|
||||
|
@ -23,12 +23,14 @@ typedef struct _CACHE_SEGMENT
|
|||
BOOLEAN Valid;
|
||||
/* Are the contents of the cache segment data newer than those on disk. */
|
||||
BOOLEAN Dirty;
|
||||
ULONG MappedCount;
|
||||
/* Entry in the list of segments for this BCB. */
|
||||
LIST_ENTRY BcbSegmentListEntry;
|
||||
/* Entry in the list of segments which are dirty. */
|
||||
LIST_ENTRY DirtySegmentListEntry;
|
||||
/* Entry in the list of segments. */
|
||||
LIST_ENTRY CacheSegmentListEntry;
|
||||
LIST_ENTRY CacheSegmentLRUListEntry;
|
||||
/* Offset in the file which this cache segment maps. */
|
||||
ULONG FileOffset;
|
||||
/* Lock. */
|
||||
|
|
|
@ -185,8 +185,8 @@ VOID ExInitNonPagedPool(ULONG BaseAddress);
|
|||
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
||||
PVOID BaseAddress,
|
||||
ULONG Length,
|
||||
VOID (*FreePage)(PVOID Context, PVOID Address,
|
||||
ULONG PhysAddr),
|
||||
VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea,
|
||||
PVOID Address, ULONG PhysAddr),
|
||||
PVOID FreePageContext);
|
||||
VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead);
|
||||
NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea);
|
||||
|
@ -473,4 +473,22 @@ MmCreateVirtualMappingForKernel(PVOID Address,
|
|||
ULONG PhysicalAddress);
|
||||
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
|
||||
|
|
|
@ -19,11 +19,6 @@
|
|||
#define PAGE_LOCKED_FUNCTION (PLACE_IN_SECTION("pagelk"))
|
||||
#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
|
||||
*/
|
||||
|
|
|
@ -20,4 +20,9 @@ extern ULONG MmPagedPoolSize;
|
|||
|
||||
#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 */
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
VOID
|
||||
KeFreeStackPage(PVOID Context, PVOID Address, ULONG PhysAddr)
|
||||
KeFreeStackPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
|
||||
{
|
||||
if (PhysAddr != 0)
|
||||
{
|
||||
|
|
|
@ -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.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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -44,12 +44,6 @@ typedef struct _MM_MEMORY_CONSUMER
|
|||
NTSTATUS (*Trim)(ULONG Target, ULONG Priority, PULONG NrFreed, PVOID* FreedPages);
|
||||
} 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 ******************************************************************/
|
||||
|
||||
static MM_MEMORY_CONSUMER MiMemoryConsumers[MC_MAXIMUM];
|
||||
|
@ -116,6 +110,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
|
|||
PVOID* FreedPages;
|
||||
ULONG NrFreedPages;
|
||||
ULONG TotalFreedPages;
|
||||
PVOID* OrigFreedPages;
|
||||
|
||||
Target = MiMinimumAvailablePages - MiNrAvailablePages;
|
||||
if (Target < 0)
|
||||
|
@ -123,7 +118,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
|
|||
Target = 1;
|
||||
}
|
||||
|
||||
FreedPages = alloca(sizeof(PVOID) * Target);
|
||||
OrigFreedPages = FreedPages = alloca(sizeof(PVOID) * Target);
|
||||
TotalFreedPages = 0;
|
||||
|
||||
for (i = 0; i < MC_MAXIMUM && Target > 0; i++)
|
||||
|
@ -142,7 +137,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
|
|||
}
|
||||
if (Page != NULL)
|
||||
{
|
||||
*Page = FreedPages[0];
|
||||
*Page = OrigFreedPages[0];
|
||||
i = 1;
|
||||
}
|
||||
else
|
||||
|
@ -151,7 +146,7 @@ MiRebalanceMemoryConsumers(PVOID* Page)
|
|||
}
|
||||
for (; i < TotalFreedPages; i++)
|
||||
{
|
||||
MmDereferencePage(FreedPages[i]);
|
||||
MmDereferencePage(OrigFreedPages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -20,7 +20,7 @@
|
|||
/* FUNCTIONS *****************************************************************/
|
||||
|
||||
VOID STATIC
|
||||
MmFreeContinuousPage(PVOID Context, PVOID Address, ULONG PhysAddr)
|
||||
MmFreeContinuousPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
|
||||
{
|
||||
if (PhysAddr != 0)
|
||||
{
|
||||
|
|
|
@ -382,6 +382,7 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
|
|||
|
||||
MmStats.NrTotalPages = MmStats.NrFreePages + MmStats.NrSystemPages +
|
||||
MmStats.NrReservedPages + MmStats.NrUserPages;
|
||||
MmInitializeBalancer(MmStats.NrFreePages);
|
||||
return((PVOID)LastKernelAddress);
|
||||
}
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ NTSTATUS
|
|||
MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
||||
PVOID BaseAddress,
|
||||
ULONG Length,
|
||||
VOID (*FreePage)(PVOID Context, PVOID Address,
|
||||
VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
|
||||
ULONG PhysAddr),
|
||||
PVOID FreePageContext)
|
||||
{
|
||||
|
@ -307,10 +307,7 @@ MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
|||
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
|
||||
BaseAddress);
|
||||
if (MemoryArea == NULL)
|
||||
{
|
||||
|
||||
DPRINT1("AddressSpace 0x%X - KASpace 0x%X\n", AddressSpace, MmGetKernelAddressSpace());
|
||||
DPRINT1("Memory area is NULL\n");
|
||||
{
|
||||
KeBugCheck(0);
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
@ -320,14 +317,14 @@ MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
|||
|
||||
PhysAddr =
|
||||
MmGetPhysicalAddressForProcess(AddressSpace->Process,
|
||||
MemoryArea->BaseAddress + (i*PAGESIZE));
|
||||
MmDeleteVirtualMapping(AddressSpace->Process,
|
||||
MemoryArea->BaseAddress + (i*PAGESIZE));
|
||||
MmDeleteVirtualMapping(AddressSpace->Process,
|
||||
MemoryArea->BaseAddress + (i*PAGESIZE),
|
||||
FALSE, NULL, NULL);
|
||||
if (FreePage != NULL)
|
||||
{
|
||||
FreePage(FreePageContext,
|
||||
MemoryArea->BaseAddress + (i * PAGESIZE), PhysAddr);
|
||||
FreePage(FreePageContext, MemoryArea,
|
||||
MemoryArea->BaseAddress + (i * PAGESIZE), PhysAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -85,7 +85,7 @@ MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
|
|||
}
|
||||
|
||||
VOID STATIC
|
||||
MmFreeNonCachedPage(PVOID Context, PVOID Address, ULONG PhysAddr)
|
||||
MmFreeNonCachedPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
|
||||
{
|
||||
if (PhysAddr != 0)
|
||||
{
|
||||
|
|
|
@ -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.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
|
||||
* FILE: ntoskrnl/mm/section.c
|
||||
|
@ -315,7 +315,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
|
|||
TRUE);
|
||||
if (!NT_SUCCESS(Status) && Status != STATUS_END_OF_FILE)
|
||||
{
|
||||
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, FALSE);
|
||||
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, FALSE, FALSE, FALSE);
|
||||
return(Status);
|
||||
}
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ MiReadPage(PMEMORY_AREA MemoryArea,
|
|||
(*Page) = (PVOID)(ULONG)Addr.QuadPart;
|
||||
MmReferencePage((*Page));
|
||||
|
||||
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, TRUE);
|
||||
CcRosReleaseCacheSegment(Fcb->Bcb, CacheSeg, TRUE, FALSE, TRUE);
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
else
|
||||
|
@ -1852,7 +1852,7 @@ NtMapViewOfSection(HANDLE SectionHandle,
|
|||
}
|
||||
|
||||
VOID STATIC
|
||||
MmFreeSectionPage(PVOID Context, PVOID Address, ULONG PhysAddr)
|
||||
MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address, ULONG PhysAddr)
|
||||
{
|
||||
PMEMORY_AREA MArea;
|
||||
ULONG Entry;
|
||||
|
@ -2135,21 +2135,28 @@ MmAllocateSection (IN ULONG Length)
|
|||
MmUnlockAddressSpace(AddressSpace);
|
||||
return (NULL);
|
||||
}
|
||||
MmUnlockAddressSpace(AddressSpace);
|
||||
DPRINT("Result %p\n",Result);
|
||||
for (i = 0; (i <= (Length / PAGESIZE)); i++)
|
||||
{
|
||||
Status = MmCreateVirtualMapping (NULL,
|
||||
(Result + (i * PAGESIZE)),
|
||||
PAGE_READWRITE,
|
||||
(ULONG)MmAllocPage(0));
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DbgPrint("Unable to create virtual mapping\n");
|
||||
MmUnlockAddressSpace(AddressSpace);
|
||||
KeBugCheck(0);
|
||||
}
|
||||
PVOID Page;
|
||||
|
||||
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Page);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DbgPrint("Unable to allocate page\n");
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -1023,6 +1023,7 @@ NtFlushVirtualMemory(IN HANDLE ProcessHandle,
|
|||
|
||||
VOID STATIC
|
||||
MmFreeVirtualMemoryPage(PVOID Context,
|
||||
MEMORY_AREA* MemoryArea,
|
||||
PVOID Address,
|
||||
ULONG PhysicalAddr)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue