Skip to content

Commit 7af549e

Browse files
committed
Batch other big allocations as well
1 parent 2ab7f95 commit 7af549e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/gc.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,13 @@ STATIC_INLINE jl_value_t *jl_gc_big_alloc_inner(jl_ptls_t ptls, size_t sz)
10101010
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + allocsz);
10111011
jl_atomic_store_relaxed(&ptls->gc_num.bigalloc,
10121012
jl_atomic_load_relaxed(&ptls->gc_num.bigalloc) + 1);
1013-
jl_atomic_fetch_add_relaxed(&gc_heap_stats.heap_size, allocsz);
1013+
uint64_t alloc_acc = jl_atomic_load_relaxed(&ptls->gc_num.alloc_acc);
1014+
if (alloc_acc + allocsz < 16*1024)
1015+
jl_atomic_store_relaxed(&ptls->gc_num.alloc_acc, alloc_acc + allocsz);
1016+
else {
1017+
jl_atomic_fetch_add_relaxed(&gc_heap_stats.heap_size, alloc_acc + allocsz);
1018+
jl_atomic_store_relaxed(&ptls->gc_num.alloc_acc, 0);
1019+
}
10141020
#ifdef MEMDEBUG
10151021
memset(v, 0xee, allocsz);
10161022
#endif
@@ -1117,7 +1123,13 @@ void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT
11171123
jl_ptls_t ptls = jl_current_task->ptls;
11181124
jl_atomic_store_relaxed(&ptls->gc_num.allocd,
11191125
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + sz);
1120-
jl_atomic_fetch_add_relaxed(&gc_heap_stats.heap_size, sz);
1126+
uint64_t alloc_acc = jl_atomic_load_relaxed(&ptls->gc_num.alloc_acc);
1127+
if (alloc_acc + sz < 16*1024)
1128+
jl_atomic_store_relaxed(&ptls->gc_num.alloc_acc, alloc_acc + sz);
1129+
else {
1130+
jl_atomic_fetch_add_relaxed(&gc_heap_stats.heap_size, alloc_acc + sz);
1131+
jl_atomic_store_relaxed(&ptls->gc_num.alloc_acc, 0);
1132+
}
11211133
}
11221134

11231135
static void combine_thread_gc_counts(jl_gc_num_t *dest) JL_NOTSAFEPOINT
@@ -3739,7 +3751,13 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz)
37393751
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + allocsz);
37403752
jl_atomic_store_relaxed(&ptls->gc_num.malloc,
37413753
jl_atomic_load_relaxed(&ptls->gc_num.malloc) + 1);
3742-
jl_atomic_fetch_add_relaxed(&gc_heap_stats.heap_size, allocsz);
3754+
uint64_t alloc_acc = jl_atomic_load_relaxed(&ptls->gc_num.alloc_acc);
3755+
if (alloc_acc + allocsz < 16*1024)
3756+
jl_atomic_store_relaxed(&ptls->gc_num.alloc_acc, alloc_acc + allocsz);
3757+
else {
3758+
jl_atomic_fetch_add_relaxed(&gc_heap_stats.heap_size, alloc_acc + allocsz);
3759+
jl_atomic_store_relaxed(&ptls->gc_num.alloc_acc, 0);
3760+
}
37433761
int last_errno = errno;
37443762
#ifdef _OS_WINDOWS_
37453763
DWORD last_error = GetLastError();

0 commit comments

Comments
 (0)