mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
- Allocate a separate memory area for the kmap area.
- Changed the free block list for the non paged pool from a double linked list to an avl tree which is sorted by sizes. svn path=/trunk/; revision=5002
This commit is contained in:
parent
4ac70b6bbb
commit
89b0516273
5 changed files with 906 additions and 337 deletions
|
@ -198,7 +198,7 @@ NTSTATUS MmCreateMemoryArea(struct _EPROCESS* Process,
|
||||||
MEMORY_AREA* MmOpenMemoryAreaByAddress(PMADDRESS_SPACE AddressSpace,
|
MEMORY_AREA* MmOpenMemoryAreaByAddress(PMADDRESS_SPACE AddressSpace,
|
||||||
PVOID Address);
|
PVOID Address);
|
||||||
NTSTATUS MmInitMemoryAreas(VOID);
|
NTSTATUS MmInitMemoryAreas(VOID);
|
||||||
VOID ExInitNonPagedPool(ULONG BaseAddress);
|
VOID MiInitializeNonPagedPool(VOID);
|
||||||
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
|
||||||
PVOID BaseAddress,
|
PVOID BaseAddress,
|
||||||
ULONG Length,
|
ULONG Length,
|
||||||
|
@ -333,7 +333,7 @@ VOID MmInit2(VOID);
|
||||||
VOID MmInit3(VOID);
|
VOID MmInit3(VOID);
|
||||||
NTSTATUS MmInitPagerThread(VOID);
|
NTSTATUS MmInitPagerThread(VOID);
|
||||||
|
|
||||||
VOID MmInitKernelMap(PVOID BaseAddress);
|
VOID MiInitKernelMap(VOID);
|
||||||
NTSTATUS MmCreatePageTable(PVOID PAddress);
|
NTSTATUS MmCreatePageTable(PVOID PAddress);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
@ -18,11 +18,13 @@ VOID MmInitializePagedPool(VOID);
|
||||||
extern PVOID MmPagedPoolBase;
|
extern PVOID MmPagedPoolBase;
|
||||||
extern ULONG MmPagedPoolSize;
|
extern ULONG MmPagedPoolSize;
|
||||||
|
|
||||||
#define MM_PAGED_POOL_SIZE (100*1024*1024)
|
#define MM_PAGED_POOL_SIZE (100*1024*1024)
|
||||||
|
#define MM_NONPAGED_POOL_SIZE (100*1024*1024)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Maximum size of the kmalloc area (this is totally arbitary)
|
* Maximum size of the kmalloc area (this is totally arbitary)
|
||||||
*/
|
*/
|
||||||
#define NONPAGED_POOL_SIZE (100*1024*1024)
|
#define MM_KERNEL_MAP_SIZE (16*1024*1024)
|
||||||
|
|
||||||
|
|
||||||
#endif /* __INTERNAL_POOL_H */
|
#endif /* __INTERNAL_POOL_H */
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: kmap.c,v 1.24 2003/06/19 19:01:01 gvg Exp $
|
/* $Id: kmap.c,v 1.25 2003/07/05 18:10:50 hbirr Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -20,18 +20,19 @@
|
||||||
|
|
||||||
/* GLOBALS *****************************************************************/
|
/* GLOBALS *****************************************************************/
|
||||||
|
|
||||||
#define ALLOC_MAP_SIZE (NONPAGED_POOL_SIZE / PAGE_SIZE)
|
#define ALLOC_MAP_SIZE (MM_KERNEL_MAP_SIZE / PAGE_SIZE)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* One bit for each page in the kmalloc region
|
* One bit for each page in the kmalloc region
|
||||||
* If set then the page is used by a kmalloc block
|
* If set then the page is used by a kmalloc block
|
||||||
*/
|
*/
|
||||||
static UCHAR AllocMapBuffer[ROUND_UP(ALLOC_MAP_SIZE, 8) / 8];
|
static UCHAR AllocMapBuffer[ROUND_UP(ALLOC_MAP_SIZE, 32) / 8];
|
||||||
static RTL_BITMAP AllocMap;
|
static RTL_BITMAP AllocMap;
|
||||||
static KSPIN_LOCK AllocMapLock;
|
static KSPIN_LOCK AllocMapLock;
|
||||||
static ULONG AllocMapHint = 0;
|
static ULONG AllocMapHint = 0;
|
||||||
|
|
||||||
static PVOID NonPagedPoolBase;
|
extern PVOID MiKernelMapStart;
|
||||||
|
extern ULONG MiKernelMapLength;
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ VOID
|
||||||
ExUnmapPage(PVOID Addr)
|
ExUnmapPage(PVOID Addr)
|
||||||
{
|
{
|
||||||
KIRQL oldIrql;
|
KIRQL oldIrql;
|
||||||
ULONG Base = (Addr - NonPagedPoolBase) / PAGE_SIZE;
|
ULONG Base = (Addr - MiKernelMapStart) / PAGE_SIZE;
|
||||||
|
|
||||||
DPRINT("ExUnmapPage(Addr %x)\n",Addr);
|
DPRINT("ExUnmapPage(Addr %x)\n",Addr);
|
||||||
|
|
||||||
|
@ -109,12 +110,12 @@ ExAllocatePageWithPhysPage(PHYSICAL_ADDRESS PhysPage)
|
||||||
{
|
{
|
||||||
AllocMapHint = Base + 1;
|
AllocMapHint = Base + 1;
|
||||||
KeReleaseSpinLock(&AllocMapLock, oldlvl);
|
KeReleaseSpinLock(&AllocMapLock, oldlvl);
|
||||||
Addr = NonPagedPoolBase + Base * PAGE_SIZE;
|
Addr = MiKernelMapStart + Base * PAGE_SIZE;
|
||||||
Status = MmCreateVirtualMapping(NULL,
|
Status = MmCreateVirtualMapping(NULL,
|
||||||
Addr,
|
Addr,
|
||||||
PAGE_READWRITE | PAGE_SYSTEM,
|
PAGE_READWRITE | PAGE_SYSTEM,
|
||||||
PhysPage,
|
PhysPage,
|
||||||
FALSE);
|
TRUE);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DbgPrint("Unable to create virtual mapping\n");
|
DbgPrint("Unable to create virtual mapping\n");
|
||||||
|
@ -127,19 +128,18 @@ ExAllocatePageWithPhysPage(PHYSICAL_ADDRESS PhysPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
MmInitKernelMap(PVOID BaseAddress)
|
MiInitKernelMap(VOID)
|
||||||
{
|
{
|
||||||
NonPagedPoolBase = BaseAddress;
|
|
||||||
KeInitializeSpinLock(&AllocMapLock);
|
KeInitializeSpinLock(&AllocMapLock);
|
||||||
RtlInitializeBitMap(&AllocMap, (PVOID)&AllocMapBuffer, ALLOC_MAP_SIZE);
|
RtlInitializeBitMap(&AllocMap, (PVOID)&AllocMapBuffer, ALLOC_MAP_SIZE);
|
||||||
RtlClearAllBits(&AllocMap);
|
RtlClearAllBits(&AllocMap);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
VOID
|
VOID
|
||||||
MiFreeNonPagedPoolRegion(PVOID Addr, ULONG Count, BOOLEAN Free)
|
MiFreeNonPagedPoolRegion(PVOID Addr, ULONG Count, BOOLEAN Free)
|
||||||
{
|
{
|
||||||
ULONG i;
|
ULONG i;
|
||||||
ULONG Base = (Addr - NonPagedPoolBase) / PAGE_SIZE;
|
ULONG Base = (Addr - MiKernelMapStart) / PAGE_SIZE;
|
||||||
KIRQL oldlvl;
|
KIRQL oldlvl;
|
||||||
|
|
||||||
for (i = 0; i < Count; i++)
|
for (i = 0; i < Count; i++)
|
||||||
|
@ -178,5 +178,7 @@ MiAllocNonPagedPoolRegion(ULONG nr_pages)
|
||||||
}
|
}
|
||||||
KeReleaseSpinLock(&AllocMapLock, oldlvl);
|
KeReleaseSpinLock(&AllocMapLock, oldlvl);
|
||||||
DPRINT("returning %x\n",NonPagedPoolBase + Base * PAGE_SIZE);
|
DPRINT("returning %x\n",NonPagedPoolBase + Base * PAGE_SIZE);
|
||||||
return NonPagedPoolBase + Base * PAGE_SIZE;
|
return MiKernelMapStart + Base * PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: mminit.c,v 1.49 2003/06/19 19:01:01 gvg Exp $
|
/* $Id: mminit.c,v 1.50 2003/07/05 18:10:50 hbirr Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top directory
|
* COPYRIGHT: See COPYING in the top directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -42,14 +42,21 @@ static MM_SYSTEM_SIZE MmSystemSize = MmSmallSystem;
|
||||||
extern unsigned int _bss_end__;
|
extern unsigned int _bss_end__;
|
||||||
|
|
||||||
static MEMORY_AREA* kernel_text_desc = NULL;
|
static MEMORY_AREA* kernel_text_desc = NULL;
|
||||||
|
static MEMORY_AREA* kernel_map_desc = NULL;
|
||||||
static MEMORY_AREA* kernel_data_desc = NULL;
|
static MEMORY_AREA* kernel_data_desc = NULL;
|
||||||
static MEMORY_AREA* kernel_param_desc = NULL;
|
static MEMORY_AREA* kernel_param_desc = NULL;
|
||||||
static MEMORY_AREA* kernel_pool_desc = NULL;
|
static MEMORY_AREA* kernel_pool_desc = NULL;
|
||||||
static MEMORY_AREA* kernel_shared_data_desc = NULL;
|
static MEMORY_AREA* kernel_shared_data_desc = NULL;
|
||||||
|
static MEMORY_AREA* MiKernelMapDescriptor = NULL;
|
||||||
static MEMORY_AREA* MiPagedPoolDescriptor = NULL;
|
static MEMORY_AREA* MiPagedPoolDescriptor = NULL;
|
||||||
|
|
||||||
PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
|
PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
|
||||||
|
|
||||||
|
PVOID MiNonPagedPoolStart;
|
||||||
|
ULONG MiNonPagedPoolLength;
|
||||||
|
PVOID MiKernelMapStart;
|
||||||
|
ULONG MiKernelMapLength;
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
BOOLEAN STDCALL MmIsThisAnNtAsSystem(VOID)
|
BOOLEAN STDCALL MmIsThisAnNtAsSystem(VOID)
|
||||||
|
@ -84,13 +91,37 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
|
||||||
DPRINT("MmInitVirtualMemory(%x, %x)\n",LastKernelAddress, KernelLength);
|
DPRINT("MmInitVirtualMemory(%x, %x)\n",LastKernelAddress, KernelLength);
|
||||||
|
|
||||||
LastKernelAddress = PAGE_ROUND_UP(LastKernelAddress);
|
LastKernelAddress = PAGE_ROUND_UP(LastKernelAddress);
|
||||||
|
|
||||||
MmInitMemoryAreas();
|
MmInitMemoryAreas();
|
||||||
ExInitNonPagedPool(LastKernelAddress + PAGE_SIZE);
|
|
||||||
|
/* Don't change the start of kernel map. Pte's must always exist for this region. */
|
||||||
|
MiKernelMapStart = (PVOID)LastKernelAddress + PAGE_SIZE;
|
||||||
|
MiKernelMapLength = MM_KERNEL_MAP_SIZE;
|
||||||
|
|
||||||
|
MiNonPagedPoolStart = MiKernelMapStart + MiKernelMapLength + PAGE_SIZE;
|
||||||
|
MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
|
||||||
|
|
||||||
|
MmPagedPoolBase = MiNonPagedPoolStart + MiNonPagedPoolLength + PAGE_SIZE;
|
||||||
|
MmPagedPoolSize = MM_PAGED_POOL_SIZE;
|
||||||
|
|
||||||
|
|
||||||
|
MiInitKernelMap();
|
||||||
|
MiInitializeNonPagedPool();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup the system area descriptor list
|
* Setup the system area descriptor list
|
||||||
*/
|
*/
|
||||||
|
BaseAddress = (PVOID)0xf0000000;
|
||||||
|
MmCreateMemoryArea(NULL,
|
||||||
|
MmGetKernelAddressSpace(),
|
||||||
|
MEMORY_AREA_SYSTEM,
|
||||||
|
&BaseAddress,
|
||||||
|
0x400000,
|
||||||
|
0,
|
||||||
|
&kernel_map_desc,
|
||||||
|
FALSE,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
BaseAddress = (PVOID)KERNEL_BASE;
|
BaseAddress = (PVOID)KERNEL_BASE;
|
||||||
Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE;
|
Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE;
|
||||||
ParamLength = ParamLength - Length;
|
ParamLength = ParamLength - Length;
|
||||||
|
@ -108,7 +139,6 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
|
||||||
&kernel_text_desc,
|
&kernel_text_desc,
|
||||||
FALSE,
|
FALSE,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) -
|
Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) -
|
||||||
PAGE_ROUND_UP(((ULONG)&_text_end__));
|
PAGE_ROUND_UP(((ULONG)&_text_end__));
|
||||||
ParamLength = ParamLength - Length;
|
ParamLength = ParamLength - Length;
|
||||||
|
@ -129,9 +159,8 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
|
||||||
&kernel_data_desc,
|
&kernel_data_desc,
|
||||||
FALSE,
|
FALSE,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_bss_end__));
|
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_bss_end__));
|
||||||
// Length = ParamLength;
|
|
||||||
Length = LastKernelAddress - (ULONG)BaseAddress;
|
Length = LastKernelAddress - (ULONG)BaseAddress;
|
||||||
MmCreateMemoryArea(NULL,
|
MmCreateMemoryArea(NULL,
|
||||||
MmGetKernelAddressSpace(),
|
MmGetKernelAddressSpace(),
|
||||||
|
@ -142,33 +171,40 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
|
||||||
&kernel_param_desc,
|
&kernel_param_desc,
|
||||||
FALSE,
|
FALSE,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
BaseAddress = (PVOID)(LastKernelAddress + PAGE_SIZE);
|
BaseAddress = MiNonPagedPoolStart;
|
||||||
Length = NONPAGED_POOL_SIZE;
|
|
||||||
MmCreateMemoryArea(NULL,
|
MmCreateMemoryArea(NULL,
|
||||||
MmGetKernelAddressSpace(),
|
MmGetKernelAddressSpace(),
|
||||||
MEMORY_AREA_SYSTEM,
|
MEMORY_AREA_SYSTEM,
|
||||||
&BaseAddress,
|
&BaseAddress,
|
||||||
Length,
|
MiNonPagedPoolLength,
|
||||||
0,
|
0,
|
||||||
&kernel_pool_desc,
|
&kernel_pool_desc,
|
||||||
FALSE,
|
FALSE,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
MmPagedPoolSize = MM_PAGED_POOL_SIZE;
|
BaseAddress = MiKernelMapStart;
|
||||||
BaseAddress = (PVOID)(LastKernelAddress + PAGE_SIZE + NONPAGED_POOL_SIZE +
|
Status = MmCreateMemoryArea(NULL,
|
||||||
PAGE_SIZE);
|
MmGetKernelAddressSpace(),
|
||||||
MmPagedPoolBase = BaseAddress;
|
MEMORY_AREA_SYSTEM,
|
||||||
Length = MM_PAGED_POOL_SIZE;
|
&BaseAddress,
|
||||||
MmCreateMemoryArea(NULL,
|
MiKernelMapLength,
|
||||||
|
0,
|
||||||
|
&MiKernelMapDescriptor,
|
||||||
|
FALSE,
|
||||||
|
FALSE);
|
||||||
|
|
||||||
|
BaseAddress = MmPagedPoolBase;
|
||||||
|
Status = MmCreateMemoryArea(NULL,
|
||||||
MmGetKernelAddressSpace(),
|
MmGetKernelAddressSpace(),
|
||||||
MEMORY_AREA_PAGED_POOL,
|
MEMORY_AREA_PAGED_POOL,
|
||||||
&BaseAddress,
|
&BaseAddress,
|
||||||
Length,
|
MmPagedPoolSize,
|
||||||
0,
|
0,
|
||||||
&MiPagedPoolDescriptor,
|
&MiPagedPoolDescriptor,
|
||||||
FALSE,
|
FALSE,
|
||||||
FALSE);
|
FALSE);
|
||||||
|
|
||||||
MmInitializePagedPool();
|
MmInitializePagedPool();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue