Skip to content

Commit

Permalink
(re-factor) gc: Remove redundant since_sweep field (#49195)
Browse files Browse the repository at this point in the history
This field is at all times 0 or identical to allocd, so this change
removes it in preference of `gc_num.allocd`. Hopefully this makes the
GC metrics a bit easier to interpret for newcomers.
  • Loading branch information
topolarity committed May 4, 2023
1 parent 724c93d commit ebc6776
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct GC_Num
freecall ::Int64
total_time ::Int64
total_allocd ::Int64 # GC internal
since_sweep ::Int64 # GC internal
collect ::Csize_t # GC internal
pause ::Cint
full_sweep ::Cint
Expand Down
16 changes: 7 additions & 9 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3184,22 +3184,21 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
mark_reset_age = 0;
}

gc_num.since_sweep += gc_num.allocd;
JL_PROBE_GC_MARK_END(scanned_bytes, perm_scanned_bytes);
gc_settime_premark_end();
gc_time_mark_pause(gc_start_time, scanned_bytes, perm_scanned_bytes);
uint64_t end_mark_time = jl_hrtime();
uint64_t mark_time = end_mark_time - start_mark_time;
gc_num.mark_time = mark_time;
gc_num.total_mark_time += mark_time;
int64_t actual_allocd = gc_num.since_sweep;
int64_t allocd = gc_num.allocd;
gc_settime_postmark_end();
// marking is over

// Flush everything in mark cache
gc_sync_all_caches_nolock(ptls);

int64_t live_sz_ub = live_bytes + actual_allocd;
int64_t live_sz_ub = live_bytes + allocd;
int64_t live_sz_est = scanned_bytes + perm_scanned_bytes;
int64_t estimate_freed = live_sz_ub - live_sz_est;

Expand All @@ -3209,11 +3208,11 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
gc_stats_big_obj();
objprofile_printall();
objprofile_reset();
gc_num.total_allocd += gc_num.since_sweep;
gc_num.total_allocd += gc_num.allocd;
if (!prev_sweep_full)
promoted_bytes += perm_scanned_bytes - last_perm_scanned_bytes;
// 5. next collection decision
int not_freed_enough = (collection == JL_GC_AUTO) && estimate_freed < (7*(actual_allocd/10));
int not_freed_enough = (collection == JL_GC_AUTO) && estimate_freed < (7*(allocd/10));
int nptr = 0;
assert(gc_n_threads);
for (int i = 0; i < gc_n_threads; i++) {
Expand Down Expand Up @@ -3334,17 +3333,16 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
_report_gc_finished(pause, gc_num.freed, sweep_full, recollect);

gc_final_pause_end(gc_start_time, gc_end_time);
gc_time_sweep_pause(gc_end_time, actual_allocd, live_bytes,
gc_time_sweep_pause(gc_end_time, allocd, live_bytes,
estimate_freed, sweep_full);
gc_num.full_sweep += sweep_full;
uint64_t max_memory = last_live_bytes + gc_num.allocd;
if (max_memory > gc_num.max_memory) {
gc_num.max_memory = max_memory;
}

gc_num.allocd = 0;
last_live_bytes = live_bytes;
live_bytes += -gc_num.freed + gc_num.since_sweep;
live_bytes += -gc_num.freed + gc_num.allocd;

if (collection == JL_GC_AUTO) {
//If we aren't freeing enough or are seeing lots and lots of pointers let it increase faster
Expand Down Expand Up @@ -3386,7 +3384,7 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
prev_sweep_full = sweep_full;
gc_num.pause += !recollect;
gc_num.total_time += pause;
gc_num.since_sweep = 0;
gc_num.allocd = 0;
gc_num.freed = 0;
if (pause > gc_num.max_pause) {
gc_num.max_pause = pause;
Expand Down
1 change: 0 additions & 1 deletion src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ typedef struct {
uint64_t freecall;
uint64_t total_time;
uint64_t total_allocd;
uint64_t since_sweep;
size_t interval;
int pause;
int full_sweep;
Expand Down

0 comments on commit ebc6776

Please sign in to comment.