@@ -505,10 +505,11 @@ HeapInfo::Initialize(Recycler * recycler
505505 if (pageheapmode == PageHeapMode::PageHeapModeOff)
506506 {
507507#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
508- isPageHeapEnabled = recycler->GetRecyclerFlagsTable ().PageHeap != PageHeapMode::PageHeapModeOff;
509- pageheapmode = (PageHeapMode)recycler->GetRecyclerFlagsTable ().PageHeap ;
510- blockTypeFilter = (PageHeapBlockTypeFilter)recycler->GetRecyclerFlagsTable ().PageHeapBlockType ;
511- pBucketNumberRange = &recycler->GetRecyclerFlagsTable ().PageHeapBucketNumber ;
508+ auto & flags = recycler->GetRecyclerFlagsTable ();
509+ isPageHeapEnabled = flags.PageHeap != PageHeapMode::PageHeapModeOff;
510+ pageheapmode = (PageHeapMode)flags.PageHeap ;
511+ blockTypeFilter = (PageHeapBlockTypeFilter)flags.PageHeapBlockType ;
512+ pBucketNumberRange = &flags.PageHeapBucketNumber ;
512513
513514#else
514515 // @TODO in free build, use environment var or other way to enable page heap
@@ -1767,12 +1768,60 @@ BOOL SmallAllocationBlockAttributes::IsAlignedObjectSize(size_t sizeCat)
17671768{
17681769 return HeapInfo::IsAlignedSmallObjectSize (sizeCat);
17691770}
1771+ /* static */
1772+ uint SmallAllocationBlockAttributes::GetUnusablePageCount (size_t sizeCat)
1773+ {
1774+ UNREFERENCED_PARAMETER (sizeCat);
1775+ return 0 ;
1776+ }
1777+ /* static */
1778+ void SmallAllocationBlockAttributes::DecommitUnusablePages (HeapBlock* heapBlock)
1779+ {
1780+ UNREFERENCED_PARAMETER (heapBlock);
1781+ }
1782+ /* static */
1783+ BOOL SmallAllocationBlockAttributes::RecommitUnusablePages (HeapBlock* heapBlock)
1784+ {
1785+ UNREFERENCED_PARAMETER (heapBlock);
1786+ return TRUE ;
1787+ }
17701788
17711789/* static */
17721790BOOL MediumAllocationBlockAttributes::IsAlignedObjectSize (size_t sizeCat)
17731791{
17741792 return HeapInfo::IsAlignedMediumObjectSize (sizeCat);
17751793}
1794+ /* static */
1795+ uint MediumAllocationBlockAttributes::GetUnusablePageCount (size_t sizeCat)
1796+ {
1797+ return ((MediumAllocationBlockAttributes::PageCount*AutoSystemInfo::PageSize) % sizeCat) / AutoSystemInfo::PageSize;
1798+ }
1799+ /* static */
1800+ void MediumAllocationBlockAttributes::DecommitUnusablePages (HeapBlock* heapBlock)
1801+ {
1802+ size_t count = MediumAllocationBlockAttributes::GetUnusablePageCount (heapBlock->GetObjectSize (nullptr ));
1803+ if (count > 0 )
1804+ {
1805+ char * startPage = (char *)heapBlock->address + (MediumAllocationBlockAttributes::PageCount - count)*AutoSystemInfo::PageSize;
1806+ #pragma warning(suppress: 6250)
1807+ ::VirtualFree (startPage, count*AutoSystemInfo::PageSize, MEM_DECOMMIT);
1808+ ::ResetWriteWatch (startPage, count*AutoSystemInfo::PageSize);
1809+ }
1810+ }
1811+ /* static */
1812+ BOOL MediumAllocationBlockAttributes::RecommitUnusablePages (HeapBlock* heapBlock)
1813+ {
1814+ size_t count = MediumAllocationBlockAttributes::GetUnusablePageCount (heapBlock->GetObjectSize (nullptr ));
1815+ if (count > 0 )
1816+ {
1817+ FAULTINJECT_MEMORY_NOTHROW_RET (_u (" recommit unusable pages" ), count*AutoSystemInfo::PageSize, FALSE );
1818+
1819+ char * startPage = (char *)heapBlock->address + (MediumAllocationBlockAttributes::PageCount - count)*AutoSystemInfo::PageSize;
1820+ #pragma warning(suppress: 6250)
1821+ return startPage==::VirtualAlloc (startPage, count*AutoSystemInfo::PageSize, MEM_COMMIT, PAGE_READWRITE);
1822+ }
1823+ return TRUE ;
1824+ }
17761825
17771826template class HeapInfo ::ValidPointersMap<SmallAllocationBlockAttributes>;
17781827template class ValidPointers <SmallAllocationBlockAttributes>;
0 commit comments