Author: ion Date: Wed Aug 28 18:57:29 2013 New Revision: 59857
URL: http://svn.reactos.org/svn/reactos?rev=59857&view=rev Log: [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.
Modified: trunk/reactos/dll/ntdll/rtl/libsupp.c trunk/reactos/lib/rtl/heap.c trunk/reactos/lib/rtl/rtlp.h trunk/reactos/ntoskrnl/config/cmdata.c trunk/reactos/ntoskrnl/mm/ARM3/miarm.h trunk/reactos/ntoskrnl/mm/ARM3/mminit.c trunk/reactos/ntoskrnl/mm/ARM3/procsup.c trunk/reactos/ntoskrnl/rtl/libsupp.c
Modified: trunk/reactos/dll/ntdll/rtl/libsupp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/rtl/libsupp.c?rev... ============================================================================== --- trunk/reactos/dll/ntdll/rtl/libsupp.c [iso-8859-1] (original) +++ trunk/reactos/dll/ntdll/rtl/libsupp.c [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -173,6 +173,22 @@ /* meaningless in user mode */ } #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
Modified: trunk/reactos/lib/rtl/heap.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heap.c?rev=59857&am... ============================================================================== --- trunk/reactos/lib/rtl/heap.c [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/heap.c [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -1223,7 +1223,6 @@ 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 @@
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,
Modified: trunk/reactos/lib/rtl/rtlp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/rtlp.h?rev=59857&am... ============================================================================== --- trunk/reactos/lib/rtl/rtlp.h [iso-8859-1] (original) +++ trunk/reactos/lib/rtl/rtlp.h [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -52,6 +52,10 @@
VOID NTAPI +RtlpSetHeapParameters(IN PRTL_HEAP_PARAMETERS Parameters); + +VOID +NTAPI RtlpSetExceptionList(PEXCEPTION_REGISTRATION_RECORD NewExceptionList);
BOOLEAN
Modified: trunk/reactos/ntoskrnl/config/cmdata.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmdata.c?re... ============================================================================== --- trunk/reactos/ntoskrnl/config/cmdata.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/config/cmdata.c [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -523,6 +523,14 @@ },
{ + L"Session Manager\Memory Management", + L"MinimumStackCommitInBytes", + &MmMinimumStackCommitInBytes, + NULL, + NULL + }, + + { L"Session Manager\Executive", L"AdditionalCriticalWorkerThreads", &DummyData, @@ -613,7 +621,7 @@ { L"Session Manager", L"CriticalSectionTimeout", - &DummyData, + &MmCritsectTimeoutSeconds, NULL, NULL }, @@ -621,15 +629,14 @@ { L"Session Manager", L"HeapSegmentReserve", - &DummyData, - NULL, - NULL - }, - + &MmHeapSegmentReserve, + NULL, + NULL + }, { L"Session Manager", L"HeapSegmentCommit", - &DummyData, + &MmHeapSegmentCommit, NULL, NULL }, @@ -637,7 +644,7 @@ { L"Session Manager", L"HeapDeCommitTotalFreeThreshold", - &DummyData, + &MmHeapDeCommitTotalFreeThreshold, NULL, NULL }, @@ -645,7 +652,7 @@ { L"Session Manager", L"HeapDeCommitFreeBlockThreshold", - &DummyData, + &MmHeapDeCommitFreeBlockThreshold, NULL, NULL },
Modified: trunk/reactos/ntoskrnl/mm/ARM3/miarm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/miarm.h?re... ============================================================================== --- trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/ARM3/miarm.h [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -680,11 +680,13 @@ 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;
Modified: trunk/reactos/ntoskrnl/mm/ARM3/mminit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/mminit.c?r... ============================================================================== --- trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/ARM3/mminit.c [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -358,6 +358,16 @@ // FIXME: They should be moved elsewhere since it's not an "init" setting? 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 = @@ -2176,6 +2186,27 @@ 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);
Modified: trunk/reactos/ntoskrnl/mm/ARM3/procsup.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/procsup.c?... ============================================================================== --- trunk/reactos/ntoskrnl/mm/ARM3/procsup.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/mm/ARM3/procsup.c [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -687,13 +687,12 @@ 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);
Modified: trunk/reactos/ntoskrnl/rtl/libsupp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/rtl/libsupp.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/rtl/libsupp.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/rtl/libsupp.c [iso-8859-1] Wed Aug 28 18:57:29 2013 @@ -234,6 +234,17 @@ } } #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