Skip to content

Make arenas_lookup_ctl triable #2424

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

Merged
merged 2 commits into from
May 11, 2023
Merged

Make arenas_lookup_ctl triable #2424

merged 2 commits into from
May 11, 2023

Conversation

auxten
Copy link
Contributor

@auxten auxten commented May 3, 2023

See #2425

arena_t *arena;

ptr = NULL;
ret = EINVAL;
malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx);
WRITE(ptr, void *);
edata = emap_edata_lookup(tsd_tsdn(tsd), &arena_emap_global, ptr);
if (edata == NULL) {
ptr_not_present = emap_full_alloc_ctx_try_lookup(tsd_tsdn(tsd), &arena_emap_global, 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 sounds like a good idea given that we got rid of ivsalloc. I'll wait a bit to merge in case @guangli-dai or @davidtgoldblatt have any concerns.

One thing to note is that emap_full_alloc_ctx_try_lookup is slightly slower since it cannot assume the lookup won't fail, so has a few more branches down the path.

Another way to make the entire call more efficient from the application side, is to do mallctlnametomib when initialize, and call mallctlbymib afterwards, instead of doing mallctl every time (which walks the namespace tree).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe calling rtree_read_independent here is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good to me. If we are worried about the efficiency of using emap_full_alloc_ctx_try_lookup here (although I don't think it should bother anyone), we can create another function, i.e., arenas_lookup_triable_ctl, which allows a triable lookup and keep arenas_lookup_ctl as it was in case anyone is using it in any efficiency-critical scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think from the pure user side, calling mallctl("arenas.lookup", ...) is expecting just lookup and triable. It may not be good to add arenas_lookup_triable_ctl here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I'm hoping we don't have to add another API specifically for the triage. After all the added overhead is a few branches, so only would be noticeable if calling very frequently (e.g. millions per second). Also there's one trick we have not done on the rtree look up path -- for potentially fail-able lookups, we can make all invalid / null nodes in the rtree point to a special node (which then points to itself) to indicate look up failure. That way the lookup will always go through the fixed levels and only need to check for failure last. Since the frequent lookups are all dependent ones, that optimization hasn't been necessary yet.

maybe calling rtree_read_independent here is better?

No need to change really. rtree accesses should go through the emap (which is a wrapper in this case) anyway.

I'll merge in a couple of days if no other concerns here.

@interwq interwq merged commit 5bac384 into jemalloc:dev May 11, 2023
@interwq
Copy link
Member

interwq commented May 11, 2023

Thanks again for the patch and discussion @auxten !

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.

3 participants