-
Notifications
You must be signed in to change notification settings - Fork 23.5k
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
aligned allocation #8624
base: unstable
Are you sure you want to change the base?
aligned allocation #8624
Conversation
ac1592a
to
145eb52
Compare
@DvirDukhan please try to temporarily copy some of the other platforms CI from the daily.yml to ci.yml (just build is enough, no need to run the tests), so we can see that it builds on all of them. |
cb6b783
to
a323626
Compare
@oranagra What do you think about the other alternative of letting modules do their own custom allocations but have a way to report them so we can track it? |
@yossigo i think there's value in both. some modules would like to report memory usage that's consumed by another allocator entirely, or one that they got by directly using mmap. |
#else | ||
*((size_t*)ptr) = size; | ||
update_zmalloc_stat_alloc(size+PREFIX_SIZE); | ||
if (usable) *usable = size; | ||
return (char*)ptr+PREFIX_SIZE; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how aligned allocation can work with no HAVE_MALLOC_SIZE
, since by definition we're breaking alignment with this pointer manipulation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they can work, if we modify the code to work around that (allocate a bit more extra).
i.e. add max(sizeof(size_t), alignment)
.
note that if the user uses his own allocator, he may have to keep the size somewhere too (there's no support for malloc_size), unless he knows the allocation size implicitly somehow (they're always the same size)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess alignment if often page sized, this means in practice we'd allocate size + page_size
, just to use sizeof(size_t)
bytes in the end of the previous page. I think this is quite a stretch...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't consider such a big alignment request, is that common? i was thinking of 16 bytes and alike.
in that's common, we must fall back to your suggestion and let the module be able to append and deduct from our used_memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DvirDukhan any input on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bringing this PR back from hibernate:
allowing aligned allocation for systems without HAVE_MALLOC_SIZE
will cause problems with releasing the allocation, as there might be padding before the prefix.
so, reiterating the issue, we might need API for modules to expose update_zmalloc_stat_alloc
and update_zmalloc_stat_free
to modules
@MeirShpilraien what is your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding a callback that will be called by Redis when it wants to know the currently used memory of the module (of memory that was allocated with an external allocator)? This way Redis can use it when calculating the currently used memory. I think this is a better approach because sometimes we might use libraries that do not allow us to override the default allocator but do allow us to get used to memory. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so in the case of a system call, like posix_memalign
, the module has to maintain its own counters of the total memory allocated by allocations used outside of Redis, and it reports back to Redis. right?
seems reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think it's a good idea for redis to call a module callback every time it needs to know the memory usage.
it would have been ok if it was just in order to report it in INFO, but if redis needs to take this memory usage as if it was its own memory usage, there are tons of places that get the used memory, and they currently just read from a global variable, i don't want to replace that global variable read with a method with a loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @oranagra. I also don't think it's needed - well mannered libraries will anyway let you provide your own heap functions (which will map to module API heap functions).
Co-authored-by: sundb <sundbcn@gmail.com>
…nto aligned_alloc
@oranagra @yossigo @MeirShpilraien Please fix me if I'm wrong, from the quick research I've made the allocation size is used mostly for long time allocations (replication) and to cap memory. The question: Is it possible to extern some allocation functions that don't save the size of the pointer for allocations which will be freed synchronously (for instance allocation for query execution). The problems with the current solution is:
|
@OfirMos please note that for the vast majority of the target platforms, HAVE_MALLOC_SIZE is true, so redis doesn't allocate any additional bytes to count the memory, so if you allocate 4k, you only allocate 4k). other notes:
|
|
This PR allows modules to use the allocator aligned allocation functionality via Redis modules api