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

Stub implementation of new custom memory API #3437

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

Conversation

stedolan
Copy link
Contributor

@stedolan stedolan commented Jan 8, 2025

This is a stub implementation of @damiendoligez's new custom memory allocation API. The new API tracks both allocation and deallocation of dependent memory using caml_alloc_dependent_mem / caml_free_dependent_mem, and provides a convenience function caml_alloc_custom_dep which combines a custom block allocation and a call to caml_alloc_dependent_mem.

The difference from caml_alloc_custom_mem is that a user of caml_alloc_custom_dep must be sure to call caml_free_depedent_mem when the custom block is finalised.

In this PR, the new API is added so that we can port code to it, but under the hood it just calls caml_alloc_custom_mem and the alloc_dependent / free_dependent functions are no-ops.

(The changes to the existing API functions caml_alloc/free_dependent_mem are not backwards compatible. However, I'm not aware of any actual users of these functions, and if we find one someday it's easy to adapt)

@stedolan stedolan force-pushed the stub-custom-alloc-dep branch from 93e52c4 to 90f16ac Compare January 8, 2025 11:56
@stedolan stedolan force-pushed the stub-custom-alloc-dep branch from 90f16ac to 4f574f6 Compare January 8, 2025 11:59
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.

Broadly this is OK, and we should probably merge it as-is. Three minor points which we could address when we put the implementation in:

  • I'm unclear why bigarray.c is so different between runtime 4 and runtime 5;
  • I would find this stuff easier to navigate with a clearer distinction in variable names and comments between custom block sizes and dependent memory sizes. Maybe consistently using dep_size?
  • Moar comments plzkthxbai.

reclaimed.
*/
CAMLextern value caml_alloc_custom_dep(struct custom_operations * ops,
uintnat size, /*size in bytes*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like a clearer distinction in the comments between size and mem.

@@ -251,7 +251,7 @@ caml_ba_alloc(int flags, int num_dims, void * data, intnat * dim)
uses_resources =
((flags & CAML_BA_MANAGED_MASK) == CAML_BA_MANAGED)
&& !(flags & CAML_BA_SUBARRAY);
res = caml_alloc_custom_mem(&caml_ba_ops, asize, uses_resources ? size : 0);
res = caml_alloc_custom_dep(&caml_ba_ops, asize, uses_resources ? size : 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unclear to me why this is different in runtime4.

CAMLexport value caml_alloc_custom_dep(const struct custom_operations * ops,
uintnat size, mlsize_t mem)
{
return caml_alloc_custom_mem(ops, size, mem);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment indicating what else will go in here in future.

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.

3 participants