mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-30 12:23:28 +00:00
It seems unclear as to what the point of the Page Reference Count Table in the React Addres Space structure really was. It seems an over-engineered approach that actually causes more problems
then it attempts to solve. The idea is to be able to unmap PDEs when they are not required anymore (a noble idea), which saves you 4KB of non-paged pool whenever a process frees a chunk of 4MB memory (oversimplification). The problem is that to keep track of this, an extremly expensive series of branches, comparisons, masks and shifts is applied every single time that a page is mapped or unmapped. It also adds 8KB of non-paged pool to keep track of the references, which in some cases can be more wasteful than keeping the page tables around. Finally, if the process quickly allocates and de-allocates memory in the same PDE range, we will effectively map and unmap the PDE continously, fragmenting hyperspace and slowing down perf. This patch removes this functionality from the system and re-uses the code that was already present in Mmi386ReleaseMmInfo (with some optimizations and changes) to do this unmapping when the process exists. This should make things faster, with a very small amount of increased memory footprint (we're talking about less than 100kb of non paged pool, in worse-case scenarios). svn path=/trunk/; revision=34865
This commit is contained in:
@@ -255,7 +255,6 @@ typedef struct _MADDRESS_SPACE
|
||||
PMEMORY_AREA MemoryAreaRoot;
|
||||
PVOID LowestAddress;
|
||||
PEPROCESS Process;
|
||||
PUSHORT PageTableRefCountTable;
|
||||
PEX_PUSH_LOCK Lock;
|
||||
} MADDRESS_SPACE, *PMADDRESS_SPACE;
|
||||
|
||||
|
||||
@@ -39,8 +39,6 @@ NTAPI
|
||||
MmInitializeAddressSpace(PEPROCESS Process,
|
||||
PMADDRESS_SPACE AddressSpace)
|
||||
{
|
||||
ULONG Count;
|
||||
|
||||
AddressSpace->MemoryAreaRoot = NULL;
|
||||
|
||||
if (Process != NULL)
|
||||
@@ -48,19 +46,12 @@ MmInitializeAddressSpace(PEPROCESS Process,
|
||||
AddressSpace->LowestAddress = MM_LOWEST_USER_ADDRESS;
|
||||
AddressSpace->Process = Process;
|
||||
AddressSpace->Lock = (PEX_PUSH_LOCK)&Process->AddressCreationLock;
|
||||
ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);
|
||||
Count = MiGetUserPageDirectoryCount();
|
||||
AddressSpace->PageTableRefCountTable = ExAllocatePoolWithTag(NonPagedPool,
|
||||
Count * sizeof(USHORT),
|
||||
TAG_PTRC);
|
||||
RtlZeroMemory(AddressSpace->PageTableRefCountTable, Count * sizeof(USHORT));
|
||||
|
||||
ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddressSpace->LowestAddress = MmSystemRangeStart;
|
||||
AddressSpace->Process = NULL;
|
||||
AddressSpace->PageTableRefCountTable = NULL;
|
||||
AddressSpace->Lock = (PEX_PUSH_LOCK)&PsGetCurrentProcess()->AddressCreationLock;
|
||||
ExInitializePushLock((PULONG_PTR)AddressSpace->Lock);
|
||||
}
|
||||
@@ -72,11 +63,6 @@ NTSTATUS
|
||||
NTAPI
|
||||
MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
|
||||
{
|
||||
if (AddressSpace->PageTableRefCountTable)
|
||||
{
|
||||
ExFreePool(AddressSpace->PageTableRefCountTable);
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -145,9 +145,8 @@ Mmi386ReleaseMmInfo(PEPROCESS Process)
|
||||
{
|
||||
PUSHORT LdtDescriptor;
|
||||
ULONG LdtBase;
|
||||
PULONG Pde;
|
||||
PULONG PageDir;
|
||||
ULONG i, j;
|
||||
ULONG i;
|
||||
|
||||
DPRINT("Mmi386ReleaseMmInfo(Process %x)\n",Process);
|
||||
|
||||
@@ -168,28 +167,7 @@ Mmi386ReleaseMmInfo(PEPROCESS Process)
|
||||
{
|
||||
if (PageDir[i] != 0)
|
||||
{
|
||||
DPRINT1("Pde for %08x - %08x is not freed, RefCount %d\n",
|
||||
i * 4 * 1024 * 1024, (i + 1) * 4 * 1024 * 1024 - 1,
|
||||
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable[i]);
|
||||
Pde = MmCreateHyperspaceMapping(PTE_TO_PFN(PageDir[i]));
|
||||
for (j = 0; j < 1024; j++)
|
||||
{
|
||||
if(Pde[j] != 0)
|
||||
{
|
||||
if (Pde[j] & PA_PRESENT)
|
||||
{
|
||||
DPRINT1("Page at %08x is not freed\n",
|
||||
i * 4 * 1024 * 1024 + j * PAGE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DPRINT1("Swapentry %x at %x is not freed\n",
|
||||
Pde[j], i * 4 * 1024 * 1024 + j * PAGE_SIZE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
MmDeleteHyperspaceMapping(Pde);
|
||||
MiZeroPage(PTE_TO_PFN(PageDir[i]));
|
||||
MmReleasePageMemoryConsumer(MC_NPPOOL, PTE_TO_PFN(PageDir[i]));
|
||||
}
|
||||
}
|
||||
@@ -604,25 +582,6 @@ MmDeleteVirtualMapping(PEPROCESS Process, PVOID Address, BOOLEAN FreePage,
|
||||
{
|
||||
*Page = Pfn;
|
||||
}
|
||||
/*
|
||||
* Decrement the reference count for this page table.
|
||||
*/
|
||||
if (Process != NULL && WasValid &&
|
||||
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
|
||||
Address < MmSystemRangeStart)
|
||||
{
|
||||
PUSHORT Ptrc;
|
||||
ULONG Idx;
|
||||
|
||||
Ptrc = ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable;
|
||||
Idx = ADDR_TO_PAGE_TABLE(Address);
|
||||
|
||||
Ptrc[Idx]--;
|
||||
if (Ptrc[Idx] == 0)
|
||||
{
|
||||
MmFreePageTable(Process, Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
@@ -651,25 +610,6 @@ MmDeletePageFileMapping(PEPROCESS Process, PVOID Address,
|
||||
|
||||
MiFlushTlb(Pt, Address);
|
||||
|
||||
/*
|
||||
* Decrement the reference count for this page table.
|
||||
*/
|
||||
if (Process != NULL && Pte &&
|
||||
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
|
||||
Address < MmSystemRangeStart)
|
||||
{
|
||||
PUSHORT Ptrc;
|
||||
|
||||
Ptrc = ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable;
|
||||
|
||||
Ptrc[ADDR_TO_PAGE_TABLE(Address)]--;
|
||||
if (Ptrc[ADDR_TO_PAGE_TABLE(Address)] == 0)
|
||||
{
|
||||
MmFreePageTable(Process, Address);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return some information to the caller
|
||||
*/
|
||||
@@ -971,17 +911,6 @@ MmCreatePageFileMapping(PEPROCESS Process,
|
||||
MmUnmapPageTable(Pt);
|
||||
}
|
||||
|
||||
if (Process != NULL &&
|
||||
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
|
||||
Address < MmSystemRangeStart)
|
||||
{
|
||||
PUSHORT Ptrc;
|
||||
ULONG Idx;
|
||||
|
||||
Ptrc = ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable;
|
||||
Idx = ADDR_TO_PAGE_TABLE(Address);
|
||||
Ptrc[Idx]++;
|
||||
}
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1092,16 +1021,6 @@ MmCreateVirtualMappingUnsafe(PEPROCESS Process,
|
||||
MmMarkPageUnmapped(PTE_TO_PFN((Pte)));
|
||||
}
|
||||
(void)InterlockedExchangeUL(Pt, PFN_TO_PTE(Pages[i]) | Attributes);
|
||||
if (Address < MmSystemRangeStart &&
|
||||
((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable != NULL &&
|
||||
Attributes & PA_PRESENT)
|
||||
{
|
||||
PUSHORT Ptrc;
|
||||
|
||||
Ptrc = ((PMADDRESS_SPACE)&Process->VadRoot)->PageTableRefCountTable;
|
||||
|
||||
Ptrc[ADDR_TO_PAGE_TABLE(Addr)]++;
|
||||
}
|
||||
if (Pte != 0)
|
||||
{
|
||||
if (Address > MmSystemRangeStart ||
|
||||
@@ -1411,13 +1330,6 @@ MmInitGlobalKernelPageDirectory(VOID)
|
||||
}
|
||||
}
|
||||
|
||||
ULONG
|
||||
NTAPI
|
||||
MiGetUserPageDirectoryCount(VOID)
|
||||
{
|
||||
return ADDR_TO_PDE_OFFSET(MmSystemRangeStart);
|
||||
}
|
||||
|
||||
VOID
|
||||
INIT_FUNCTION
|
||||
NTAPI
|
||||
|
||||
Reference in New Issue
Block a user