-
Notifications
You must be signed in to change notification settings - Fork 653
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
Rax size tracking #688
Rax size tracking #688
Conversation
To resolve DCO complaints, you can sign-off the previous commits.
|
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #688 +/- ##
============================================
+ Coverage 70.47% 70.60% +0.13%
============================================
Files 114 114
Lines 61695 61710 +15
============================================
+ Hits 43479 43572 +93
+ Misses 18216 18138 -78
|
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.
In general LGTM. The test needs to be ported to the new kind of unit tests.
Is is possible to test the calculation of the alloc size by comparing it to the stats we can get from the allocator? If we run a fuzz test and it does no other allocations, then it could work I think.
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Great Idea. I wanted also to check that after every element from the rax was removed, memory goes back to 0. Turns out there is an issue right now that needs further investigation, ie
|
Just an idea: If it's a problem with zmalloc, you can create another rax_test_malloc.h to instead of rax_malloc.h just for the rax test. If the test defines RAX_MALLOC_INCLUDE before it includes rax.c, then rax.c will use it. It's already like this in rax.c: #ifndef RAX_MALLOC_INCLUDE
#define RAX_MALLOC_INCLUDE "rax_malloc.h"
#endif
#include RAX_MALLOC_INCLUDE |
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Thanks for the tip @zuiderkwast . I think it wasn't a problem with zmalloc, see the latest two commits. There was a zfree missing which was the cause of valkey-unit-tests --large-memory failing. However you gave me another idea: what if instead of manually tracking rax->alloc_size in the main code body, we made rax_alloc_size and friends do it, as in |
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
Please check clang-format and spellcheck. You can change "ba" to "by" (etc.) in the rax_test, or if this actually affects the test, it's OK to add this file to |
I see. I had a quick exchange with @touitou-dan who was suggesting a 2% degradation in pipeline only can be ignored. After all pipeline is not the standard mode of benchmark. In light of that, do we know the degradation of the memory tracking for the other pieces? If similar, maybe it's worth not making it configurable. Thoughts @zuiderkwast? |
This will have to wait until |
@knggk Did we consider ways to avoid calling zmalloc_size on each rax operation? IIRC these can be expensive and we should aim to avoid them. For example It might be messy but we could try and use the jemalloc *_usable API when allocating memory and retrieve the allocation size. |
But it only happens on rax mutations right?
What are those? Are you saying they are less expensive than zmalloc_size? What's the context behind zmalloc_size being expensive?
Agree, good idea if this new used_memory_thread is updated during allocation calls and would capture a diff when called right before allocating eg a raxNode, and again right after. Is this how used_memory_thread behaves? |
yes
I mean for example there is the 'oid *zmalloc_usable(size_t size, size_t *usable)' which both allocate memory and return the allocation size, so it can be used in a single call instead of later calling 'zmalloc_size'
Basically since we are taking the diff without being preempted and doing "something else" I think we can count of this diff to reflect the exact amount of memory we allocated/freed during the rax operation. |
Good idea. If it's not too complicated, it would be better to use it, but I'm not sure
I think this can work, but note that IMO, we can also accept this PR with |
Can we open an issue for that then? |
Not sure there is a problem. we only take a diff of the thread local variable, so even if it was negative the diff calculation will still be fine. |
@ranshid 🤔 You're probably right. Another problem is that we only track a certain number of threads. If a module creates a lot of threads and they use the rax (e.g. using I don't know how to solve that. Do you have an idea? The per-thread size tracking was not designed for what we're discussing here. It was only designed to speed up the total size tracking. Letting the rax track its own allocations seems more robust to me somehow.
Sure. @knggk, will you merge latest unstable to this branch? |
I tried just now but am getting:
Edit: Nvm, this also happens on clean unstable. Might be a problem with my local toolchain? |
Seems to be, because the build works in the CI. Did you try |
Signed-off-by: Guillaume Koenig <knggk@amazon.com>
28951d3
to
fee849d
Compare
I tried with distclean but still getting the same issue on link. I am on Mac Sonoma if that's any useful info. Could is be because of missing pkg-config? I get:
PS pushed commit to fix formatting |
Great, thanks.
Possibly. I'm running Fedora on my macbook. It seemed better for programmers. :D pkg-config is used in the Makefile and maybe it just exits if it's not available. Why don't you have it? And why don't you have |
@knggk There was a build failure with undefined-santitizer in Daily:
I have a fix for it in #1122. |
Thanks Viktor for the turn around, I hadn't seen the issue. |
Fix the warning introduced in #688: ``` unit/test_rax.c:168:15: runtime error: left shift of 36625 by 16 places cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior unit/test_rax.c:168:15 in Fuzz test in mode 1 [7504]: ``` Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Introduce a `size_t` field into the rax struct to track allocation size. Update the allocation size on rax insert and deletes. Return the allocation size when `raxAllocSize` is called. This size tracking is now used in MEMORY USAGE and MEMORY STATS in place of the previous method based on sampling. The module API allows to create sorted dictionaries, which are backed by rax. Users now also get precise memory allocation for them (through `ValkeyModule_MallocSizeDict`). Fixes valkey-io#677. For the release notes: * MEMORY USAGE and MEMORY STATS are now exact for streams, rather than based on sampling. --------- Signed-off-by: Guillaume Koenig <knggk@amazon.com> Signed-off-by: Guillaume Koenig <106696198+knggk@users.noreply.github.com> Co-authored-by: Joey <yzhaon@amazon.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech> Signed-off-by: naglera <anagler123@gmail.com>
Fix the warning introduced in valkey-io#688: ``` unit/test_rax.c:168:15: runtime error: left shift of 36625 by 16 places cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior unit/test_rax.c:168:15 in Fuzz test in mode 1 [7504]: ``` Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech> Signed-off-by: naglera <anagler123@gmail.com>
Introduce a `size_t` field into the rax struct to track allocation size. Update the allocation size on rax insert and deletes. Return the allocation size when `raxAllocSize` is called. This size tracking is now used in MEMORY USAGE and MEMORY STATS in place of the previous method based on sampling. The module API allows to create sorted dictionaries, which are backed by rax. Users now also get precise memory allocation for them (through `ValkeyModule_MallocSizeDict`). Fixes valkey-io#677. For the release notes: * MEMORY USAGE and MEMORY STATS are now exact for streams, rather than based on sampling. --------- Signed-off-by: Guillaume Koenig <knggk@amazon.com> Signed-off-by: Guillaume Koenig <106696198+knggk@users.noreply.github.com> Co-authored-by: Joey <yzhaon@amazon.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Fix the warning introduced in valkey-io#688: ``` unit/test_rax.c:168:15: runtime error: left shift of 36625 by 16 places cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior unit/test_rax.c:168:15 in Fuzz test in mode 1 [7504]: ``` Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Introduce a `size_t` field into the rax struct to track allocation size. Update the allocation size on rax insert and deletes. Return the allocation size when `raxAllocSize` is called. This size tracking is now used in MEMORY USAGE and MEMORY STATS in place of the previous method based on sampling. The module API allows to create sorted dictionaries, which are backed by rax. Users now also get precise memory allocation for them (through `ValkeyModule_MallocSizeDict`). Fixes valkey-io#677. For the release notes: * MEMORY USAGE and MEMORY STATS are now exact for streams, rather than based on sampling. --------- Signed-off-by: Guillaume Koenig <knggk@amazon.com> Signed-off-by: Guillaume Koenig <106696198+knggk@users.noreply.github.com> Co-authored-by: Joey <yzhaon@amazon.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Fix the warning introduced in valkey-io#688: ``` unit/test_rax.c:168:15: runtime error: left shift of 36625 by 16 places cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior unit/test_rax.c:168:15 in Fuzz test in mode 1 [7504]: ``` Signed-off-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
Introduce a
size_t
field into the rax struct to track allocation size.Update the allocation size on rax insert and deletes.
Return the allocation size when
raxAllocSize
is called.This size tracking is now used in MEMORY USAGE and MEMORY STATS in place of the previous method based on sampling.
The module API allows to create sorted dictionaries, which are backed by rax. Users now also get precise memory allocation for them (through
ValkeyModule_MallocSizeDict
).Fixes #677.
For the release notes: