Navigation Menu

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

Simplify minor heaps configuration logic and masking #422

Conversation

abbysmal
Copy link
Collaborator

@abbysmal abbysmal commented Oct 22, 2020

This PR is a first step toward Domain local allocation buffers. (see also #398).
This first step aimed to rewrite the previous bit-twiddling logic of Minor_heap_sel_bits and Minor_heap_align_bits with a scheme closer to trunk.
The commits are split by duty, starting with the first one is likely the best.

The first commit introduce Minor_heap_max, and used this potential maximum size to reserve the minor heaps area.
The minor heaps area is reserved for Max_domains (so Max_domains * Minor_heap_max).
Further refactoring is done by removing Is_minor and only relying on Is_young, which is now a simple bound check (minor_heaps_base < v < minor_heaps_end). In parallel minor I believe such distinction is not required anymore.
This specific transition is done in the second commit however.

The third commit introduces a way to override the Minor_heap_max setting using OCAMLRUNPARAM=s.
This may not be the prettiest solution, and does not align with trunk (Minor_heap_max should not be exceeded by the user-configured minor heap.)

Sandmark run:

minor_heap_re2

minor_heap_re1

Copy link
Collaborator

@ctk21 ctk21 left a comment

Choose a reason for hiding this comment

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

There is a bug with Is_block_and_is_young that will need fixing.

Having looked at the trunk setting for Minor_heap_max which is (1 << 28); that is 268M words or 2GB per domain minor heap on a 64bit platform. I'm wondering if we need the commit that allows overriding of the minor heap limit with OCAMLRUNPARAM:
9494796

Wouldn't it be easier to drop that override commit and settle with (1 << 28)? I'm thinking if people want to experiment with larger than (1<<28) they can change that setting in the header fairly easily and recompile.

Dropping the override commit, it makes us a bit closer to trunk. I'm in favour of dropping the override commit.


/* An entire minor heap must fit inside one region
of size 1 << Minor_heap_align_bits, which determines
the maximum size of the heap */
#if SIZEOF_PTR <= 4
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trunk has

/* Maximum size of the minor zone (words).
   Must be greater than or equal to [Minor_heap_min].
*/
#define Minor_heap_max (1 << 28)

(1<<28) words is ~2GB per minor heap on a 64bit machine, I think we should just take that.

#define Is_minor(val) \
((((uintnat)(val) ^ (uintnat)Caml_state) & Minor_val_bitmask) == 0)
#define Is_young(val) \
((char *)(val) < (char *)caml_minor_heaps_end && \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add CAMLassert (Is_block (val)) to the assert?
This will mirror ocaml/ocaml:

#define Is_young(val) \
  (CAMLassert (Is_block (val)), \
   (char *)(val) < (char *)Caml_state_field(young_end) && \
   (char *)(val) > (char *)Caml_state_field(young_start))

((((uintnat)(val) ^ (uintnat)Caml_state) & Minor_val_bitmask) == 0)
#define Is_young(val) \
((char *)(val) < (char *)caml_minor_heaps_end && \
(char *)(val) > (char *)caml_minor_heaps_base)

#define Is_block_and_young(val) Is_young(val)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This macro needs updating to:
Is_block(val) && Is_young(val)
previously with the bit twiddling Is_young(val) would also tell you if val was a block, but with the lo/hi we need to explicitly check the block as well.

@abbysmal abbysmal force-pushed the engil/refactor_minor_heaps_allocation branch from b1a8b09 to 365efb1 Compare October 23, 2020 12:07
@abbysmal abbysmal force-pushed the engil/refactor_minor_heaps_allocation branch from 3c20ec8 to 70c65bd Compare October 30, 2020 11:07
@abbysmal
Copy link
Collaborator Author

I think this PR is ready to be merged if everyone agrees with it.
I will need to squash it before though, this history is needlessly messy.

Here are the current results, comparing a few different version (stock, stock+256M, multicore, multicore+default (this patch + default minor heap size), and multicore+256M.)
There is now obvious slowdown, and I will gather notes and notebooks to discuss further the entry cost of bigger minor heaps in multicore in another issue.

Normalized (stock)

sequential_normalized_stock

Non normalized

sequential_defaut_stock

@ctk21
Copy link
Collaborator

ctk21 commented Nov 27, 2020

I think this one is good to go.
You mention wanting to squash the history. There is also a merge conflict that needs patching up.

This commit refactor the minor heaps allocation process by first rewriting the logic to not
rely on bitmasks and instead move it to a model closer to trunk, introducing a Minor_heap_max configuration variable.
Some bits are removed: the arm64 backend used to expose Minor_heap_align_bits in config.h to the emitter, which is removed for now.
The Is_minor/Is_young changes are now unified as only Is_young (is the value in *any* minor heap at all?) matters.
In a follow up commit, Is_minor will be renamed definitely to Is_yound to follow suit.
@abbysmal abbysmal force-pushed the engil/refactor_minor_heaps_allocation branch from 70c65bd to d38cfb8 Compare November 27, 2020 15:51
@ctk21 ctk21 merged commit a89a0a6 into ocaml-multicore:parallel_minor_gc Nov 28, 2020
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Jan 10, 2022
…il/refactor_minor_heaps_allocation

Simplify minor heaps configuration logic and masking
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

2 participants