[RTL]: Correctly read PEB or Kernel Variables for Heap Tuning.

[NTOSKRNL]: MmCreatePeb should correctly fill out the Heap PEB parameters.
[NTOSKRNL]: MmInitSystem and mminit.c should correctly initialize and hold the Heap Tuning Parameters.
[NTOSKRNL]: CmControlVector should read the registry Heap Tuning Parameters into the real Mm variables, instaed of "Dummy".
This removes heap hacks and makes Windows NTDLL happy.

svn path=/trunk/; revision=59857
This commit is contained in:
Alex Ionescu 2013-08-28 18:57:29 +00:00
parent c268c87586
commit 4ca622a65d
8 changed files with 84 additions and 37 deletions

View file

@ -174,6 +174,22 @@ CHECK_PAGED_CODE_RTL(char *file, int line)
}
#endif
VOID
NTAPI
RtlpSetHeapParameters(IN PRTL_HEAP_PARAMETERS Parameters)
{
PPEB Peb;
/* Get PEB */
Peb = RtlGetCurrentPeb();
/* Apply defaults for non-set parameters */
if (!Parameters->SegmentCommit) Parameters->SegmentCommit = Peb->HeapSegmentCommit;
if (!Parameters->SegmentReserve) Parameters->SegmentReserve = Peb->HeapSegmentReserve;
if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = Peb->HeapDeCommitFreeBlockThreshold;
if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = Peb->HeapDeCommitTotalFreeThreshold;
}
BOOLEAN
NTAPI
RtlpHandleDpcStackException(IN PEXCEPTION_REGISTRATION_RECORD RegistrationFrame,

View file

@ -1223,7 +1223,6 @@ RtlCreateHeap(ULONG Flags,
PVOID CommittedAddress = NULL, UncommittedAddress = NULL;
PHEAP Heap = NULL;
RTL_HEAP_PARAMETERS SafeParams = {0};
PPEB Peb;
ULONG_PTR MaximumUserModeAddress;
SYSTEM_BASIC_INFORMATION SystemInformation;
MEMORY_BASIC_INFORMATION MemoryInfo;
@ -1276,32 +1275,10 @@ RtlCreateHeap(ULONG Flags,
if (NtGlobalFlags & FLG_USER_STACK_TRACE_DB)
Flags |= HEAP_CAPTURE_STACK_BACKTRACES;
/* Get PEB */
Peb = RtlGetCurrentPeb();
/* Apply defaults for non-set parameters */
if (!Parameters->SegmentCommit) Parameters->SegmentCommit = Peb->HeapSegmentCommit;
if (!Parameters->SegmentReserve) Parameters->SegmentReserve = Peb->HeapSegmentReserve;
if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = Peb->HeapDeCommitFreeBlockThreshold;
if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = Peb->HeapDeCommitTotalFreeThreshold;
}
else
{
/* Apply defaults for non-set parameters */
#if 0
if (!Parameters->SegmentCommit) Parameters->SegmentCommit = MmHeapSegmentCommit;
if (!Parameters->SegmentReserve) Parameters->SegmentReserve = MmHeapSegmentReserve;
if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;
if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
#endif
}
// FIXME: Move to memory manager
if (!Parameters->SegmentCommit) Parameters->SegmentCommit = PAGE_SIZE * 2;
if (!Parameters->SegmentReserve) Parameters->SegmentReserve = 1048576;
if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = PAGE_SIZE;
if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = 65536;
/* Set tunable parameters */
RtlpSetHeapParameters(Parameters);
/* Get the max um address */
Status = ZwQuerySystemInformation(SystemBasicInformation,

View file

@ -50,6 +50,10 @@ PEXCEPTION_REGISTRATION_RECORD
NTAPI
RtlpGetExceptionList(VOID);
VOID
NTAPI
RtlpSetHeapParameters(IN PRTL_HEAP_PARAMETERS Parameters);
VOID
NTAPI
RtlpSetExceptionList(PEXCEPTION_REGISTRATION_RECORD NewExceptionList);

View file

@ -522,6 +522,14 @@ INIT_FUNCTION CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
NULL
},
{
L"Session Manager\\Memory Management",
L"MinimumStackCommitInBytes",
&MmMinimumStackCommitInBytes,
NULL,
NULL
},
{
L"Session Manager\\Executive",
L"AdditionalCriticalWorkerThreads",
@ -613,7 +621,7 @@ INIT_FUNCTION CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
{
L"Session Manager",
L"CriticalSectionTimeout",
&DummyData,
&MmCritsectTimeoutSeconds,
NULL,
NULL
},
@ -621,15 +629,14 @@ INIT_FUNCTION CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
{
L"Session Manager",
L"HeapSegmentReserve",
&DummyData,
&MmHeapSegmentReserve,
NULL,
NULL
},
{
L"Session Manager",
L"HeapSegmentCommit",
&DummyData,
&MmHeapSegmentCommit,
NULL,
NULL
},
@ -637,7 +644,7 @@ INIT_FUNCTION CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
{
L"Session Manager",
L"HeapDeCommitTotalFreeThreshold",
&DummyData,
&MmHeapDeCommitTotalFreeThreshold,
NULL,
NULL
},
@ -645,7 +652,7 @@ INIT_FUNCTION CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
{
L"Session Manager",
L"HeapDeCommitFreeBlockThreshold",
&DummyData,
&MmHeapDeCommitFreeBlockThreshold,
NULL,
NULL
},

View file

@ -680,11 +680,13 @@ extern PFN_NUMBER MiLowNonPagedPoolThreshold;
extern PFN_NUMBER MiHighNonPagedPoolThreshold;
extern PFN_NUMBER MmMinimumFreePages;
extern PFN_NUMBER MmPlentyFreePages;
extern SIZE_T MmMinimumStackCommitInBytes;
extern PFN_COUNT MiExpansionPoolPagesInitialCharge;
extern PFN_NUMBER MmResidentAvailablePages;
extern PFN_NUMBER MmResidentAvailableAtInit;
extern ULONG MmTotalFreeSystemPtes[MaximumPtePoolTypes];
extern PFN_NUMBER MmTotalSystemDriverPages;
extern ULONG MmCritsectTimeoutSeconds;
extern PVOID MiSessionImageStart;
extern PVOID MiSessionImageEnd;
extern PMMPTE MiHighestUserPte;

View file

@ -359,6 +359,16 @@ SIZE_T MmAllocationFragment;
SIZE_T MmTotalCommitLimit;
SIZE_T MmTotalCommitLimitMaximum;
/*
* These value tune certain user parameters. They have default values set here,
* as well as in the code, and can be overwritten by registry settings.
*/
SIZE_T MmHeapSegmentReserve = 1 * _1MB;
SIZE_T MmHeapSegmentCommit = 2 * PAGE_SIZE;
SIZE_T MmHeapDeCommitTotalFreeThreshold = 64 * _1KB;
SIZE_T MmHeapDeCommitFreeBlockThreshold = PAGE_SIZE;
SIZE_T MmMinimumStackCommitInBytes = 0;
/* Internal setting used for debugging memory descriptors */
BOOLEAN MiDbgEnableMdDump =
#ifdef _ARM_
@ -2176,6 +2186,27 @@ MmArmInitSystem(IN ULONG Phase,
DPRINT("System PTE count has been tuned to %d (%d bytes)\n",
MmNumberOfSystemPtes, MmNumberOfSystemPtes * PAGE_SIZE);
/* Check if no values are set for the heap limits */
if (MmHeapSegmentReserve == 0)
{
MmHeapSegmentReserve = 2 * _1MB;
}
if (MmHeapSegmentCommit == 0)
{
MmHeapSegmentCommit = 2 * PAGE_SIZE;
}
if (MmHeapDeCommitTotalFreeThreshold == 0)
{
MmHeapDeCommitTotalFreeThreshold = 64 * _1KB;
}
if (MmHeapDeCommitFreeBlockThreshold == 0)
{
MmHeapDeCommitFreeBlockThreshold = PAGE_SIZE;
}
/* Initialize the working set lock */
ExInitializePushLock(&MmSystemCacheWs.WorkingSetMutex);

View file

@ -687,13 +687,12 @@ MmCreatePeb(IN PEPROCESS Process,
Peb->NumberOfProcessors = KeNumberProcessors;
Peb->BeingDebugged = (BOOLEAN)(Process->DebugPort != NULL);
Peb->NtGlobalFlag = NtGlobalFlag;
/*Peb->HeapSegmentReserve = MmHeapSegmentReserve;
Peb->HeapSegmentCommit = MmHeapSegmentCommit;
Peb->HeapDeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
Peb->HeapDeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;*/
Peb->HeapSegmentReserve = MmHeapSegmentReserve;
Peb->HeapSegmentCommit = MmHeapSegmentCommit;
Peb->HeapDeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
Peb->HeapDeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;
Peb->CriticalSectionTimeout = MmCriticalSectionTimeout;
/*Peb->MinimumStackCommit = MmMinimumStackCommitInBytes;
*/
Peb->MinimumStackCommit = MmMinimumStackCommitInBytes;
Peb->MaximumNumberOfHeaps = (PAGE_SIZE - sizeof(PEB)) / sizeof(PVOID);
Peb->ProcessHeaps = (PVOID*)(Peb + 1);

View file

@ -235,6 +235,17 @@ CHECK_PAGED_CODE_RTL(char *file, int line)
}
#endif
VOID
NTAPI
RtlpSetHeapParameters(IN PRTL_HEAP_PARAMETERS Parameters)
{
/* Apply defaults for non-set parameters */
if (!Parameters->SegmentCommit) Parameters->SegmentCommit = MmHeapSegmentCommit;
if (!Parameters->SegmentReserve) Parameters->SegmentReserve = MmHeapSegmentReserve;
if (!Parameters->DeCommitFreeBlockThreshold) Parameters->DeCommitFreeBlockThreshold = MmHeapDeCommitFreeBlockThreshold;
if (!Parameters->DeCommitTotalFreeThreshold) Parameters->DeCommitTotalFreeThreshold = MmHeapDeCommitTotalFreeThreshold;
}
VOID
NTAPI
RtlpCheckLogException(IN PEXCEPTION_RECORD ExceptionRecord,