Skip to content

Conversation

@NickBarnes
Copy link
Contributor

Statmemprof needs to be called when allocations are made, and at the start and end of each GC (at the start for scanning roots, at the end for cleaning up weak roots pointing to any tracked blocks which have been collected). This PR adds an appropriate interface, with stub implementation, to the memprof module, and adds calls to those stubs from the GC and memory modules.

This is the latest in a series of small PRs working towards multicore statmemprof. See #12379 for a monolithic (unreviewable) PR with a more complete implementation.

@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch from 4fd0bb6 to 5c60ad9 Compare July 18, 2023 16:19
@kayceesrk kayceesrk added the statmemprof PRs and issues related to statmemprof label Jul 18, 2023
{
uintnat num_domains_in_stw;

/* TODO: Not clear this memprof work is really part of the "cycle"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sadiqj I'd appreciate your input on this block. As the comment describes, I had a version in which this was separated out into its own function, which I called on all participating domains, but it failed because caml_try_run_on_all_domains() would push domains back into mark/sweep. See this commit which fails numerous tests such as tests/memory-model/forbidden.ml

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 just trying to understand what needs to be done at caml_memprof_after_major_gc so I can figure out where it's best placed.

I was looking at 4.14.1 and I only see caml_memprof_update_clean_phase being called from the major_gc. Is that the intention for this hook, that it should be called at the point where ephemerons need cleaning? That's a different place from where it is 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.

It needs to be called after marking is complete, for a similar purpose to cleaning ephemerons - memprof needs to walk its internal data structures, to update all entries for blocks which have not survived collection. Originally I put the call in major_collection_slice, close to the ephemerons stuff, but that didn't work as previously noted. It's ended up here as a placeholder, really.

@NickBarnes
Copy link
Contributor Author

Note: this PR now incorporates #12398 (a small change to the test suite which I made to get this to pass).

Copy link
Contributor

@jhjourdan jhjourdan left a comment

Choose a reason for hiding this comment

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

These changes are small, and not really arguable. The one thing I'm not sure about is the call to caml_memprof_after_major_gc, because I'm not an expert on functionning of multicore's GC. It seems like it's indeed not at the right place, but @sadiqj will know better than me.

Appart from that, the changes to lib-runtime-event/test_caml.ml does not seem to be related, so it should be submitted as a separated PR.

(Other minor comments, see details of review.)

@jhjourdan
Copy link
Contributor

Yet another comment: when #12193 will be merged, this will have to be adapted to take into account memprof's roots.

@NickBarnes
Copy link
Contributor Author

Yet another comment: when #12193 will be merged, this will have to be adapted to take into account memprof's roots.

Yes. Happily this should be doable by simply calling caml_memprof_scan_roots with a suitable scanning_action f.

@jhjourdan
Copy link
Contributor

Well, that's not that easy, because the weaknesses of the roots are different, so you don't traverse the same roots when doing mark&sweep and when doing compaction (where you need to traverse al the roots, including weak ones).

@NickBarnes
Copy link
Contributor Author

Well, that's not that easy, because the weaknesses of the roots are different, so you don't traverse the same roots when doing mark&sweep and when doing compaction (where you need to traverse al the roots, including weak ones).

You are quite right. I think the strong roots should be done in that way, and the weak roots by adding something akin to caml_memprof_after_major_gc. Possibly we could extend the caml_memprof_scan_roots interface for this, though (add another boolean flag). The difference with compaction is that compaction per se does not "deallocate" anything (so in a sense all the "weak roots" are actually strong here).

@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch 2 times, most recently from fb80ad4 to f119bbc Compare August 21, 2023 16:07
@NickBarnes
Copy link
Contributor Author

This force-push is rebased on trunk and also removes the #12398 changes. As a result, this PR fails on lib-runtime-events/test_caml.ml (which is then fixed by #12398).

@NickBarnes
Copy link
Contributor Author

#12398 is merged now so this now passes that test.

@kayceesrk
Copy link
Contributor

@NickBarnes can you resolve the conflicts on the Changes file, please?

This PR was approved in July. Are we ok to merge?

@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch from 7260532 to 0c33306 Compare October 17, 2023 11:27
@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch from 0c33306 to e1621da Compare November 7, 2023 12:57
@NickBarnes
Copy link
Contributor Author

rebased.

@sadiqj sadiqj self-assigned this Nov 7, 2023
@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch from e1621da to 43c9b44 Compare November 24, 2023 17:31
@NickBarnes
Copy link
Contributor Author

Rebased.

@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch from 43c9b44 to 639ccad Compare November 24, 2023 23:37
@NickBarnes NickBarnes force-pushed the nick-statmemprof-tracking-gc-api branch from 639ccad to 7e0616a Compare November 24, 2023 23:43
@NickBarnes NickBarnes marked this pull request as draft January 18, 2024 12:13
@NickBarnes
Copy link
Contributor Author

This PR is wholly subsumed by the forthcoming main statmemprof PR, so should not be merged. Converting to draft.

@NickBarnes
Copy link
Contributor Author

Closing as wholly included (and improved!) in #12923.

@NickBarnes NickBarnes closed this Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

statmemprof PRs and issues related to statmemprof

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants