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

[NEW] Defrag - Global handling for reallocations during defrag cycle #1366

Open
zvi-code opened this issue Nov 27, 2024 · 0 comments
Open

[NEW] Defrag - Global handling for reallocations during defrag cycle #1366

zvi-code opened this issue Nov 27, 2024 · 0 comments

Comments

@zvi-code
Copy link
Contributor

The problem/use-case that the feature addresses
Current defrag implementation uses explicit allocatorDefragAlloc/allocatorDefragFree functions that bypass tcache. The motivation to bypass tcache is so that when we free a memory ptr because of defrag we want to avoid reallocating it from tcache in next allocation, bypassing the tcache frees the ptr directly to the arena.

The dedicated API for defrag alloc introduce a challange for modules where we do not have full control over the memory allocations (and we might not want to have this control).

In these cases we would want, ideally, to defrag by just reallocating the object(if that's required).

raised in the context of the discussion #1210 (comment)

Description of the feature

The proposal is to achieve this by embedding the special defrag specific allocatorDefragAlloc/allocatorDefragFree API into the zmalloc zmalloc\zfree api for the defragging thread(s).

To achieve this we would need to introduce zmalloc_thread_start_defrag() and zmalloc_thread_stop_defrag(). These would be called on begin\end of defrag cycle and when started, the zmalloc\zfree of the defrag thread would use the allocatorDefragAlloc/allocatorDefragFree instead of the normal alloc.

Alternatives you've considered

Other alternative is to give modules access to allocatorDefragAlloc/allocatorDefragFree

Additional information

This feature can be combined with additional improvement to utilize user defined tcache, to keep some of the performance benefit of tcache during defrag while keeping the alloc-free separation (force ptrs recycle through the arena before realloc)

@zvi-code zvi-code changed the title [NEW] Global handling for reallocations during defrag cycle [NEW] Defrag - Global handling for reallocations during defrag cycle Nov 27, 2024
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

No branches or pull requests

1 participant