diff --git a/reactos/Makefile b/reactos/Makefile index 84ce9ae82f0..3823556cd3a 100644 --- a/reactos/Makefile +++ b/reactos/Makefile @@ -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 diff --git a/reactos/include/ddk/ntifs.h b/reactos/include/ddk/ntifs.h index de25705715c..30aaea1b553 100644 --- a/reactos/include/ddk/ntifs.h +++ b/reactos/include/ddk/ntifs.h @@ -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, diff --git a/reactos/ntoskrnl/cc/copy.c b/reactos/ntoskrnl/cc/copy.c index bd803d8bc7d..5cfa30c06cf 100644 --- a/reactos/ntoskrnl/cc/copy.c +++ b/reactos/ntoskrnl/cc/copy.c @@ -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; diff --git a/reactos/ntoskrnl/cc/pin.c b/reactos/ntoskrnl/cc/pin.c index f1b3f672f80..921f8fadd3e 100644 --- a/reactos/ntoskrnl/cc/pin.c +++ b/reactos/ntoskrnl/cc/pin.c @@ -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); } diff --git a/reactos/ntoskrnl/cc/view.c b/reactos/ntoskrnl/cc/view.c index 2bde154eac8..129cd1544aa 100644 --- a/reactos/ntoskrnl/cc/view.c +++ b/reactos/ntoskrnl/cc/view.c @@ -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 #include #include +#include #define NDEBUG #include +/* 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) - diff --git a/reactos/ntoskrnl/include/internal/cc.h b/reactos/ntoskrnl/include/internal/cc.h index c44b30fef30..05b8afc329d 100644 --- a/reactos/ntoskrnl/include/internal/cc.h +++ b/reactos/ntoskrnl/include/internal/cc.h @@ -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 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. */ diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index 8d2cc184794..f699e12f086 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -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 diff --git a/reactos/ntoskrnl/include/internal/ntoskrnl.h b/reactos/ntoskrnl/include/internal/ntoskrnl.h index 712de53d110..2bdad2df848 100644 --- a/reactos/ntoskrnl/include/internal/ntoskrnl.h +++ b/reactos/ntoskrnl/include/internal/ntoskrnl.h @@ -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 */ diff --git a/reactos/ntoskrnl/include/internal/pool.h b/reactos/ntoskrnl/include/internal/pool.h index 0248baf46a7..a3bcedfaa80 100644 --- a/reactos/ntoskrnl/include/internal/pool.h +++ b/reactos/ntoskrnl/include/internal/pool.h @@ -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 */ diff --git a/reactos/ntoskrnl/ke/kthread.c b/reactos/ntoskrnl/ke/kthread.c index 93c15a1d3d0..e0df2468580 100644 --- a/reactos/ntoskrnl/ke/kthread.c +++ b/reactos/ntoskrnl/ke/kthread.c @@ -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) { diff --git a/reactos/ntoskrnl/mm/balance.c b/reactos/ntoskrnl/mm/balance.c index 1c46f7b9da0..f950e851b1a 100644 --- a/reactos/ntoskrnl/mm/balance.c +++ b/reactos/ntoskrnl/mm/balance.c @@ -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]); } } diff --git a/reactos/ntoskrnl/mm/cont.c b/reactos/ntoskrnl/mm/cont.c index f1a0397468b..cc2d5cb9ef0 100644 --- a/reactos/ntoskrnl/mm/cont.c +++ b/reactos/ntoskrnl/mm/cont.c @@ -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) { diff --git a/reactos/ntoskrnl/mm/freelist.c b/reactos/ntoskrnl/mm/freelist.c index 42a6cb2d13c..74fd88c0671 100644 --- a/reactos/ntoskrnl/mm/freelist.c +++ b/reactos/ntoskrnl/mm/freelist.c @@ -382,6 +382,7 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress, MmStats.NrTotalPages = MmStats.NrFreePages + MmStats.NrSystemPages + MmStats.NrReservedPages + MmStats.NrUserPages; + MmInitializeBalancer(MmStats.NrFreePages); return((PVOID)LastKernelAddress); } diff --git a/reactos/ntoskrnl/mm/marea.c b/reactos/ntoskrnl/mm/marea.c index 5be02b0ad36..5f2503afcc1 100644 --- a/reactos/ntoskrnl/mm/marea.c +++ b/reactos/ntoskrnl/mm/marea.c @@ -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); } } diff --git a/reactos/ntoskrnl/mm/ncache.c b/reactos/ntoskrnl/mm/ncache.c index 51008a41db3..68e727c7034 100644 --- a/reactos/ntoskrnl/mm/ncache.c +++ b/reactos/ntoskrnl/mm/ncache.c @@ -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) { diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index 92a2fff8161..9d51c93a967 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -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); } diff --git a/reactos/ntoskrnl/mm/virtual.c b/reactos/ntoskrnl/mm/virtual.c index 5631058b2f3..a27bfc378b0 100644 --- a/reactos/ntoskrnl/mm/virtual.c +++ b/reactos/ntoskrnl/mm/virtual.c @@ -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) {