Skip to content

Implement umfMemoryProviderAllocation[Split/Merge] #140

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
Jan 22, 2024

Conversation

igchor
Copy link
Member

@igchor igchor commented Jan 13, 2024

That is needed to support jemalloc (avoid leaking memory).

@kswiecicki could you verify if this solves all the memory leaks? On my machine, it seems to work fine after those changes.

@igchor igchor requested a review from ldorau January 13, 2024 02:08
Copy link
Contributor

@pbalcer pbalcer left a comment

Choose a reason for hiding this comment

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

as for concurrency, I think if we don't add a lock we are creating a footgun. I can imagine a scenario where for example, split is called concurrently twice on the same block.

So unless we add some mechanism for exclusive ownerships of ranges of memory, I think we should add a lock.

@ldorau
Copy link
Contributor

ldorau commented Jan 15, 2024

I confirm that the memory leak described in #147 does not occur with this change, because arena_extent_split() succeeds now.

@ldorau ldorau mentioned this pull request Jan 16, 2024
@kswiecicki
Copy link
Contributor

@kswiecicki could you verify if this solves all the memory leaks? On my machine, it seems to work fine after those changes.

It does, ASan no longer reports any leaks in jemalloc.

@igchor
Copy link
Member Author

igchor commented Jan 17, 2024

as for concurrency, I think if we don't add a lock we are creating a footgun. I can imagine a scenario where for example, split is called concurrently twice on the same block.

So unless we add some mechanism for exclusive ownerships of ranges of memory, I think we should add a lock.

Hm, should only add a mutex for split/merge calls or should we also protect trackingFree? I think freeing a memory region that is being split/merged can just be UB, right?

@igchor igchor force-pushed the jemalloc_fixes_and_provider_funcs branch from 37b2184 to bb04c81 Compare January 17, 2024 22:15
@igchor igchor changed the title [WIP] Implement umfMemoryProviderAllocation[Split/Merge] Implement umfMemoryProviderAllocation[Split/Merge] Jan 17, 2024
@igchor igchor marked this pull request as ready for review January 17, 2024 22:16
@igchor igchor requested a review from a team as a code owner January 17, 2024 22:16
@igchor igchor force-pushed the jemalloc_fixes_and_provider_funcs branch 2 times, most recently from 52fbd11 to ab5a5eb Compare January 17, 2024 22:28
@ldorau
Copy link
Contributor

ldorau commented Jan 17, 2024

This PR is required by #153

@igchor
Copy link
Member Author

igchor commented Jan 17, 2024

as for concurrency, I think if we don't add a lock we are creating a footgun. I can imagine a scenario where for example, split is called concurrently twice on the same block.
So unless we add some mechanism for exclusive ownerships of ranges of memory, I think we should add a lock.

Hm, should only add a mutex for split/merge calls or should we also protect trackingFree? I think freeing a memory region that is being split/merged can just be UB, right?

I've added mutex for split/merge only for now.

That is needed to support jemalloc (avoid leaking memory).
@igchor igchor force-pushed the jemalloc_fixes_and_provider_funcs branch from 4633b5c to 3caed7c Compare January 19, 2024 18:13
@bratpiorka bratpiorka requested a review from ldorau January 20, 2024 12:03
@bratpiorka
Copy link
Contributor

@vinser52 @pbalcer @ldorau all I need 2nd approve to merge this PR - could you check if anything is missing here?

@ldorau
Copy link
Contributor

ldorau commented Jan 22, 2024

@vinser52 @pbalcer @ldorau all I need 2nd approve to merge this PR - could you check if anything is missing here?

just checking ...

@ldorau ldorau merged commit e4b8a75 into oneapi-src:main Jan 22, 2024
#ifdef __cplusplus
extern "C" {
#endif

extern umf_memory_provider_ops_t UMF_TRACKING_MEMORY_PROVIDER_OPS;

struct umf_memory_tracker_t {
critnib *map;
os_mutex_t *splitMergeMutex;
Copy link
Contributor

Choose a reason for hiding this comment

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

Global split/merge lock might kill scalability. As I understand the lock is needed only when concurrent split/merge occurs for the same memory buffer.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, mmap is also fully synchronized, so I wouldn't worry that much. This shouldn't be a super common operation. I'd start with a simple mutex and then we can think about locking out ranges of memory if there's a perf problem.

secondSize);
if (ret != UMF_RESULT_SUCCESS) {
fprintf(stderr, "tracking split: umfMemoryTrackerAdd failed\n");
// TODO: what now? should we rollback the split? This can only happen due to ENOMEM
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, preallocation makes sense - should be doable once we have the base allocator.

@igchor igchor deleted the jemalloc_fixes_and_provider_funcs branch January 22, 2024 16:49
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.

6 participants