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 minor-heap allocation computation in Gc.counters() #12784

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

NickBarnes
Copy link
Contributor

Gc.counters() computes minor-heap allocation incorrectly: it divides the allocation in words since the last collection by the word size.

Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to have been a micro-slip when 4.06.0 was merged into multicore - ocaml-multicore/ocaml-multicore@e8c6908

@@ -111,7 +111,7 @@ CAMLprim value caml_gc_counters(value v)
/* get a copy of these before allocating anything... */
double minwords = Caml_state->stat_minor_words
+ ((double) Wsize_bsize ((uintnat)Caml_state->young_end -
(uintnat) Caml_state->young_ptr)) / sizeof(value);
(uintnat) Caml_state->young_ptr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module currently has inconsistent code, with Wsize_bsize used here and / sizeof(value) used above in caml_gc_minor_words_unboxed. Could you solve this by calling caml_gc_minor_words_unboxed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise for so much discussion over one line, but in the commit I referenced above, the / sizeof(value) was added in both places (erroneously in this second one), where I think the fix really should have been to use Wsize_bsize in caml_gc_minor_words_unboxed rather than / sizeof(value) 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, since both young_ptr and young_end are value *, one could just do the subtraction, without any casts, divisions, or macro applications....

@NickBarnes NickBarnes force-pushed the nick-gc-counters branch 2 times, most recently from 81e84f5 to c6c67b2 Compare November 24, 2023 15:58
@dra27
Copy link
Member

dra27 commented Nov 24, 2023

This also has a user-visible fix to Gc.allocated_bytes (as well as Gc.counters, obviously) - so it should have a Changes entry.

@dra27 dra27 merged commit 9b9868e into ocaml:trunk Nov 24, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants