-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add threshold to proxy lib to call system allocator #883
base: main
Are you sure you want to change the base?
Add threshold to proxy lib to call system allocator #883
Conversation
8bfade2
to
2a5fb9e
Compare
2a5fb9e
to
4cdba02
Compare
0d3f0c7
to
7c781ef
Compare
UMF_PROXY="size.threshold=128" | ||
UMF_LOG="level:debug;flush:debug;output:stderr;pid:yes" | ||
LD_PRELOAD=./lib/libumf_proxy.so | ||
ctest --output-on-failure -E provider_file_memory_ipc |
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.
we should have a test where you use umfPoolByPtr() to check allocs smaller than threshold were not registered in the tracker
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 will add a test for that
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.
@bratpiorka tests added
Done
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.
@bratpiorka ping
7c781ef
to
db760b2
Compare
src/proxy_lib/proxy_lib.c
Outdated
if (Proxy_pool) { | ||
if (!was_called_from_umfPool && Proxy_pool && | ||
(umfPoolByPtr(ptr) == Proxy_pool)) { | ||
was_called_from_umfPool = 1; | ||
void *new_ptr = umfPoolRealloc(Proxy_pool, ptr, size); | ||
was_called_from_umfPool = 0; | ||
return new_ptr; | ||
} | ||
|
||
assert(0); | ||
if (threshold_value) { | ||
return system_realloc(ptr, 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.
Please add test
ptr = Malloc(threshold_value + 1)
realloc(ptr, threshold_value - 1)
and vice versa.
ptr = Malloc(threshold_value - 1)
realloc(ptr, threshold_value + 1)
Both cases check then umfPoolByPtr if it returns expected value.
(atm in this PR we are not supporting this correctly - if we increasing or decrease size of allocation thru realoc we should "realloc this allocation" to correct allocator.
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.
@lplewa Tests added.
Done
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.
@lplewa If you would like to change an allocator in realloc() depending on a size of an allocation, where do you get from the size of the current allocation coming from glibc ? You have to know the original size to do memcopy() inside realloc() ...
db760b2
to
4ac6b3e
Compare
src/libumf.c
Outdated
if (utils_is_running_in_proxy_lib_with_size_threshold()) { | ||
// We cannot destroy the TRACKER nor the base allocator | ||
// when we are running in the proxy library with a size threshold, | ||
// because it could lead to calling the system free() with an invalid pointer |
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.
to call
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 meant "It could lead to something", so "calling ..." , not "call ..."
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 believe lead to
should be followed by either something or to <verb>
you could write it somehow differently e.g. it could result in calling
, or lead to system free call with ...
that's my understanding, but you know... I'm not native ;)
I'd re-phrase with it could result in calling ... and a segfault.
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.
Replaced with it could result in calling ...
Done.
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.
now the last part as a result
is redundant.
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.
Done
src/proxy_lib/proxy_lib.c
Outdated
*end = '\0'; | ||
} | ||
|
||
size_t int_threshold = (size_t)atoi(str_threshold); |
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.
won't coverity complain about int -> size_t conversion?
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.
Can you check that? I cannot. We will see ...
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.
heh, ok, let me re-phrase the question - should we worry if the user pass size.threshold=-1
(e.g. by mistake)
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.
Fixed.
Done.
// replace ';' with '\0' to mark end of the string | ||
*end = '\0'; | ||
} | ||
|
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.
we could have a test for checking this parsing
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 would have to move this function to utils, it cannot be tested here as a part of proxy lib.
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.
we could have a script or part of CI, that will run multiple configurations, like:
UMF_PROXY="size.threshold=XYZ;<other var>" LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure
UMF_PROXY="<other var>;size.threshold=ABC" LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure
etc...
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.
we could have a script or part of CI, that will run multiple configurations, like:
UMF_PROXY="size.threshold=XYZ;<other var>" LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure UMF_PROXY="<other var>;size.threshold=ABC" LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure etc...
I am afraid it would take too much time ...
test/test_proxy_lib.cpp
Outdated
#endif | ||
} | ||
|
||
TEST_F(test, proxyLib_size_threshold_malloc) { |
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.
we could have a test with multiple allocs, not just 2
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.
What would it change?
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.
we would have more tests 😄
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.
Only 2 are needed in tests of the size threshold: one for the default system allocator (size < threshold) and another one for the proxy library pool UMF pool allocator (size >= threshold). There is no need for an extra one.
4ac6b3e
to
846f30b
Compare
Signed-off-by: Lukasz Dorau <[email protected]>
Signed-off-by: Lukasz Dorau <[email protected]>
Do not assert(ptr) in umfMemoryTrackerGetAllocInfo(), return UMF_RESULT_ERROR_INVALID_ARGUMENT instead. Replace LOG_WARN() with LOG_DEBUG().
Add utils_env_var_get_str() to utils_common. Use utils_env_var_get_str() inside utils_env_var_has_str() and utils_is_running_in_proxy_lib(). Signed-off-by: Lukasz Dorau <[email protected]>
Signed-off-by: Lukasz Dorau <[email protected]>
Add a size threshold to proxy lib to call system allocator when the size is less than the given threshold (Linux only yet). Signed-off-by: Lukasz Dorau <[email protected]>
846f30b
to
653bd3d
Compare
This WA for the issue: oneapi-src#894 It protects us from a recursion in malloc_usable_size() when the JEMALLOC proxy_lib_pool is used. TODO: remove this WA when the issue is fixed. Signed-off-by: Lukasz Dorau <[email protected]>
The proxyLib_size_threshold_* tests test the size threshold of the proxy library (Linux only yet). The size threshold is set to 64 bytes in this test, so all allocations of: 1) size < 64 go through the default system allocator and (umfPoolByPtr(ptr_size < 64) == nullptr) 2) size >= 64 go through the proxy lib allocator and (umfPoolByPtr(ptr_size >= 64) != nullptr). Ref: oneapi-src#894 Signed-off-by: Lukasz Dorau <[email protected]>
653bd3d
to
ec89615
Compare
Description
Add threshold to proxy lib to call system allocator
when a size is less than the given threshold (Linux only yet).
Ref: #894
Requires:
Checklist