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

Separate the mechanisms and APIs for dependent memory and custom blocks #3597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stedolan
Copy link
Contributor

Previously, allocating a block with caml_alloc_custom or caml_alloc_custom_mem would both register a custom block finaliser and accelerate the GC.

Now, caml_alloc_custom(_mem) has no effect on GC, and the functions caml_adjust_gc_speed and caml_adjust_minor_gc_speed become noops. The GC speed increase for dependent memory happens only through caml_alloc_dependent_memory and caml_free_dependent_memory.

The function caml_alloc_custom_dep is available to call both caml_alloc_custom and caml_alloc_dependent_memory. However, the user must ensure to call caml_free_dependent_memory in their finaliser. (Bigarrays have already been updated to use this API in a previous patch)

This is to pave the way for a new GC pacing policy. However, no change to pacing is made by this patch - the GC should perform as previously on e.g. bigarray values, which have been ported to use the new API.

(Most of the code in this patch was written by @damiendoligez )

Previously, allocating a block with caml_alloc_custom or caml_alloc_custom_mem
would both register a custom block finaliser and accelerate the GC.

Now, caml_alloc_custom(_mem) has no effect on GC, and the functions
caml_adjust_gc_speed and caml_adjust_minor_gc_speed become noops. The GC speed
increase for dependent memory happens only through caml_alloc_dependent_memory
and caml_free_dependent_memory.

The function caml_alloc_custom_dep is available to call both
caml_alloc_custom and caml_alloc_dependent_memory. However, the user must ensure
to call caml_free_dependent_memory in their finaliser. (Bigarrays have already
been updated to use this API in a previous patch)

This is to pave the way for a new GC pacing policy. However, no change to pacing
is made by this patch - the GC should perform as previously on e.g. bigarray values,
which have been ported to use the new API.

(Most of the code in this patch was written by @damiendoligez)
Copy link
Contributor

@NickBarnes NickBarnes left a comment

Choose a reason for hiding this comment

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

LGTM, modulo the pacing code which is about to change. One comment is just plain wrong, and the FIXME asks the important question (which I'm sure will be answered by the next PR).

static value alloc_custom_gen (const struct custom_operations * ops,
uintnat bsz,
mlsize_t mem,
mlsize_t max_major,
mlsize_t max_minor,
int minor_ok,
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance of making these bool while we're here?

CAMLexport value caml_alloc_custom(const struct custom_operations * ops,
uintnat bsz,
mlsize_t mem,
mlsize_t max)
{
return caml_alloc_custom0(ops, bsz, mem, max, 0);
return alloc_custom_gen(ops, bsz, /* minor_ok: */ 1, /* local: */ 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this call caml_memprof_sample_block?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, no. The proxy block is already sampled, and this is now the path for custom blocks without foreign memory.


DOMAIN_STATE(uintnat, dependent_size)
DOMAIN_STATE(uintnat, dependent_allocated)
/* How much external memory is currenty held by the minor and major heap. */
Copy link
Contributor

Choose a reason for hiding this comment

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

s/and major//

intnat alloc_work, dependent_work, extra_work, new_work;
intnat my_alloc_count, my_alloc_direct_count, my_dependent_count;
intnat alloc_work, extra_work, new_work;
intnat my_alloc_count, my_alloc_direct_count;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm only skimming this function as I review this PR because I know it's about to change radically (in the next week or so).

/ 100 * caml_custom_minor_ratio){
caml_request_minor_gc ();
}
}else{
Copy link
Contributor

Choose a reason for hiding this comment

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

horrible whitespace in this function.

}else{
caml_add_dependent_bytes (Caml_state->shared_heap, nbytes);
Caml_state->allocated_dependent_bytes += nbytes;
/* FIXME sdolan: what's the right condition here? */
Copy link
Contributor

Choose a reason for hiding this comment

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

An excellent question. I don't really believe in any of this caml_custom_get_max_major() stuff. "2/3 of 44% of the heap size, divided by 5". I keep expecting to subtract the number I first thought of and tada: it's the playing card hidden in the orange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants