Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix malloc_increase is not correctly calculated #4860

Merged
merged 1 commit into from Sep 20, 2021

Conversation

peterzhu2118
Copy link
Member

@peterzhu2118 peterzhu2118 commented Sep 17, 2021

Commit 123eeb1 added incremental GC which moved resetting malloc_increase, oldmalloc_increase to before marking. However, during_minor_gc is not set until gc_marks_start. So the value will be from the last GC run, rather than the current one. Before the incremental GC commit, this code was in gc_before_sweep which ran before sweep (after marking) so the value during_minor_gc was correct.

If we run the following script:

arr = []

# Ensure that all objects are promoted to old by triggering GC
3.times do
  GC.start
end

before = GC.stat(:malloc_increase_bytes)
before_old = GC.stat(:oldmalloc_increase_bytes)

# Expand arr so that it reallocates
100.times do
  arr << 0
end

after = GC.stat(:malloc_increase_bytes)
after_old = GC.stat(:oldmalloc_increase_bytes)

# Minor GC
GC.start(full_mark: false)

after_gc = GC.stat(:malloc_increase_bytes)
after_gc_old = GC.stat(:oldmalloc_increase_bytes)

puts before, after, after_gc
puts before_old, after_old, after_gc_old

Before this patch we get this output:

1064
2096
0
1064
2096
0

After this patch we get this output:

272
1304
0
272
1304
1320

A minor GC should not reset oldmalloc_increase_bytes.

Commit 123eeb1 added incremental GC
which moved resetting malloc_increase, oldmalloc_increase to before
marking. However, during_minor_gc is not set until gc_marks_start. So
the value will be from the last GC run, rather than the current one.
Before the incremental GC commit, this code was in gc_before_sweep
which ran before sweep (after marking) so the value during_minor_gc
was correct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant