Skip to content

Implement arena_extent_dalloc in pool_jemalloc #141

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 1 commit into from
Jan 19, 2024

Conversation

igchor
Copy link
Member

@igchor igchor commented Jan 13, 2024

@pbalcer why this function wasn't implemented in memkind? My understanding is that without this function extent deallocation is deferred to when the arena is destroyed. Is that true? Is there any reason we should implement it?

@igchor igchor requested a review from a team as a code owner January 13, 2024 02:13
@igchor
Copy link
Member Author

igchor commented Jan 13, 2024

Interestingly, when I run this with older version of jemalloc (installed using apt) I get a few umfMemoryProviderFree failed in dalloc messages (tests still pass). With the newest version, I don't see this message anymore. It looks like older version of jemalloc called arena_extent_dalloc with an address that was not coming from any previous arena_extend_alloc for some reason.

@pbalcer
Copy link
Contributor

pbalcer commented Jan 15, 2024

There are two implementations in memkind: one that "hogs memory", and one that releases it back to the system: https://github.com/memkind/memkind/blob/master/src/memkind_pmem.c#L88.
Hog memory was introduced for performance reasons.

@bratpiorka bratpiorka requested a review from pbalcer January 15, 2024 10:10
@ldorau
Copy link
Contributor

ldorau commented Jan 15, 2024

Interestingly, when I run this with older version of jemalloc (installed using apt) I get a few umfMemoryProviderFree failed in dalloc messages (tests still pass)....

The #146 PR will make those messages not appear.

@ldorau
Copy link
Contributor

ldorau commented Jan 15, 2024

My understanding is that without this function extent deallocation is deferred to when the arena is destroyed. Is that true?

@igchor No, or not always at least - I have debugged it and arena_extent_dalloc() was called when the arena was destroyed, not earlier ....

@vinser52
Copy link
Contributor

Interestingly, when I run this with older version of jemalloc (installed using apt) I get a few umfMemoryProviderFree failed in dalloc messages (tests still pass). With the newest version, I don't see this message anymore. It looks like older version of jemalloc called arena_extent_dalloc with an address that was not coming from any previous arena_extend_alloc for some reason.

@igchor could you please clarify this case? When you say "jemalloc called arena_extent_dalloc with an address that was not coming from any previous arena_extend_alloc" is it just a sub-range of previously allocated buffer or completely different memory region?

@ldorau
Copy link
Contributor

ldorau commented Jan 16, 2024

@igchor could you please clarify this case? When you say "jemalloc called arena_extent_dalloc with an address that was not coming from any previous arena_extend_alloc" is it just a sub-range of previously allocated buffer or completely different memory region?

@vinser52 it seems to be a completely different memory region - see: log.txt

@vinser52
Copy link
Contributor

I found that the memory region deallocated with arena_extent_dalloc was allocated during pool creation by je_initialize function when the following mallctl is called:

unsigned arena_index;
    err =
        mallctl("arenas.create", (void *)&arena_index, &unsigned_size, NULL, 0);
    if (err) {
        fprintf(stderr, "Could not create arena.\n");
        goto err_free_pool;
    }

@bratpiorka
Copy link
Contributor

@vinser52 so some memory is allocated using arena_extent_alloc and some using other functions? if so, can we use tracking functionality and handle the memory that was allocated only by us?

@bratpiorka
Copy link
Contributor

@igchor I think we should wait with this PR until we merge split/merge

@ldorau
Copy link
Contributor

ldorau commented Jan 17, 2024

This PR is required by #153

@vinser52
Copy link
Contributor

@vinser52 so some memory is allocated using arena_extent_alloc and some using other functions? if so, can we use tracking functionality and handle the memory that was allocated only by us?

I am not sure what do mean with that statement: "can we use tracking functionality and handle the memory that was allocated only by us?". This is what UMF tracking is supposed to do - track all allocations by memory providers. But case with jemalloc looks like a bug in jemalloc. Furthermore, Igor mentioned that this issue gone away with the new version of jemalloc that Igor built manually.

@ldorau
Copy link
Contributor

ldorau commented Jan 18, 2024

@vinser52 so some memory is allocated using arena_extent_alloc and some using other functions? if so, can we use tracking functionality and handle the memory that was allocated only by us?

I am not sure what do mean with that statement: "can we use tracking functionality and handle the memory that was allocated only by us?". This is what UMF tracking is supposed to do - track all allocations by memory providers. But case with jemalloc looks like a bug in jemalloc.

The #140 PR makes this bug not occur any more
See also: #155 (all CI builds pass)

@bratpiorka bratpiorka merged commit 379a785 into oneapi-src:main Jan 19, 2024
@igchor igchor deleted the arena_dalloc branch January 19, 2024 17:33
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.

5 participants