Skip to content

Commit ac1a5fa

Browse files
Pace a cycle against the space the allocator can use
The reserve counted the free rows in every block. A fragmented heap has many of those in holes too small to use, so the allocator ran out long before a cycle reached its start point, and every collection was a full stop: with one object in eight surviving, 1001 stops and no slices. The reserve is now the free list's bytes and the room to grow, what the stop-the-world collector really spends before it collects.
1 parent 4ad33f5 commit ac1a5fa

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

‎src/hx/gc/Immix.cpp‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6918,17 +6918,6 @@ class GlobalAllocator
69186918
mTotalAfterLastCollect = MemUsage();
69196919

69206920
#ifdef HXCPP_GC_INCREMENTAL
6921-
// The stop-the-world collector spends every free block, and grows the heap
6922-
// up to its target, before it collects. Pacing against less than that
6923-
// runs a cycle more often than it would collect.
6924-
{
6925-
size_t heap = std::max(sWorkingMemorySize, GetWorkingMemory());
6926-
size_t reserve = std::max(targetFree, heap>mem ? heap-mem : 0);
6927-
size_t startAt, pressureAt;
6928-
hx::IncrementalData().plan(reserve, startAt, pressureAt);
6929-
mIncrementalStartAt.store(startAt,std::memory_order_relaxed);
6930-
mIncrementalPressureAt.store(pressureAt,std::memory_order_relaxed);
6931-
}
69326921
mIncrementalAllocated.store(0,std::memory_order_relaxed);
69336922
#endif
69346923

@@ -6986,6 +6975,22 @@ class GlobalAllocator
69866975

69876976
createFreeList();
69886977

6978+
#ifdef HXCPP_GC_INCREMENTAL
6979+
// The stop-the-world collector spends the free list, and grows the heap up
6980+
// to its target, before it collects. Pacing against less runs a cycle more
6981+
// often than it would collect. Pacing against more, by counting free rows
6982+
// in holes too small to use, lets the allocator run out before a cycle starts.
6983+
{
6984+
size_t reserve = mFreeListBytes;
6985+
if (sWorkingMemorySize>GetWorkingMemory())
6986+
reserve += sWorkingMemorySize-GetWorkingMemory();
6987+
size_t startAt, pressureAt;
6988+
hx::IncrementalData().plan(reserve, startAt, pressureAt);
6989+
mIncrementalStartAt.store(startAt,std::memory_order_relaxed);
6990+
mIncrementalPressureAt.store(pressureAt,std::memory_order_relaxed);
6991+
}
6992+
#endif
6993+
69896994
// This saves some running/stall time, but increases the total CPU usage
69906995
// Delaying it until just before the block is used to improve the cache locality
69916996
backgroundProcessFreeList(true);
@@ -7245,13 +7250,19 @@ class GlobalAllocator
72457250
place[i] += place[i-1];
72467251

72477252
mFreeBlocks.setSize(place[IMMIX_LINES]);
7253+
#ifdef HXCPP_GC_INCREMENTAL
7254+
mFreeListBytes = 0;
7255+
#endif
72487256
for(int i=0;i<mAllBlocks.size();i++)
72497257
{
72507258
BlockDataInfo *info = mAllBlocks[i];
72517259
if (info->GetFreeRows() > 0 && info->mMaxHoleSize>256)
72527260
{
72537261
info->mOwned = false;
72547262
mFreeBlocks[place[info->mMaxHoleSize>>IMMIX_LINE_BITS]++] = info;
7263+
#ifdef HXCPP_GC_INCREMENTAL
7264+
mFreeListBytes += info->GetFreeData();
7265+
#endif
72557266
}
72567267
}
72577268

@@ -7494,6 +7505,7 @@ class GlobalAllocator
74947505
std::atomic_size_t mIncrementalStartAt{hx::sgMinimumWorkingMemory/2};
74957506
std::atomic_size_t mIncrementalPressureAt{hx::sgMinimumWorkingMemory*3/4};
74967507
bool mZeroingLeft = false;
7508+
size_t mFreeListBytes = 0;
74977509
size_t mReclaimAhead = 0;
74987510
std::atomic_size_t mIncrementalAllocated{0};
74997511
#endif

0 commit comments

Comments
 (0)