-
Notifications
You must be signed in to change notification settings - Fork 40
Split initialize function and add post-initialize phase #1467
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
base: main
Are you sure you want to change the base?
Conversation
54df467
to
40c6dfc
Compare
40c6dfc
to
1f76309
Compare
include/umf/memory_pool_ops.h
Outdated
/// @param provider memory provider that will be used for coarse-grain allocations. | ||
/// Should contain at least one memory provider. | ||
/// @param numProvider number of elements in the providers array | ||
/// @param params pool-specific params, or NULL for defaults | ||
/// @param pool [out] returns pointer to the pool | ||
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure. |
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.
Write better documentation
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/memory_provider.c
Outdated
@@ -250,6 +276,16 @@ umf_result_t umfMemoryProviderCreate(const umf_memory_provider_ops_t *ops, | |||
|
|||
provider->provider_priv = provider_priv; | |||
|
|||
if (provider->ops.ext_post_initialize != NULL) { |
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.
this if is not needed
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/pool/pool_disjoint.c
Outdated
static umf_result_t CTL_READ_HANDLER(name)(void *ctx, | ||
umf_ctl_query_source_t source, | ||
void *arg, size_t size, | ||
umf_ctl_index_utlist_t *indexes) { | ||
static umf_result_t CTL_READ_HANDLER(name)(void* ctx, | ||
umf_ctl_query_source_t source, | ||
void* arg, size_t size, | ||
umf_ctl_index_utlist_t* indexes) { | ||
(void)source, (void)indexes; | ||
|
||
disjoint_pool_t *pool = (disjoint_pool_t *)ctx; | ||
disjoint_pool_t* pool = (disjoint_pool_t*)ctx; | ||
|
||
if (arg == NULL) { | ||
return UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
if (size > 0) { | ||
strncpy((char *)arg, pool->params.name, size - 1); | ||
((char *)arg)[size - 1] = '\0'; | ||
strncpy((char*)arg, pool->params.name, size - 1); | ||
((char*)arg)[size - 1] = '\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.
wtf?
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.
Corrected. Funny fact is that this is ignored by code check, I suppose that #if 0
is here a perpetrator.
src/pool/pool_disjoint.c
Outdated
(void)source, (void)indexes, (void)size; | ||
disjoint_pool_t *pool = (disjoint_pool_t *)ctx; |
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.
dito
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 suppose it's fixed
src/memory_pool.c
Outdated
@@ -261,7 +276,16 @@ static umf_result_t umfPoolCreateInternal(const umf_memory_pool_ops_t *ops, | |||
} | |||
} | |||
|
|||
if (ops->ext_post_initialize != NULL) { | |||
ret = ops->ext_post_initialize(pool->provider, params, pool->pool_priv); |
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.
document what happens if post initialize fails. Who is responsible for clearing things initialized in initialize bunction
src/pool/pool_disjoint.c
Outdated
|
||
err_free_disjoint_pool: | ||
umf_ba_global_free(disjoint_pool); | ||
|
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.
is it memleak? Who is respoinsible for this free?
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.
Reverted, thanks
test/pools/jemalloc_pool.cpp
Outdated
@@ -161,7 +161,7 @@ TEST_F(test, jemallocPoolParams) { | |||
EXPECT_EQ(ret, UMF_RESULT_SUCCESS); | |||
} | |||
|
|||
TEST_F(test, jemallocPoolParamsInvalid) { | |||
TEST_F(test, jemallocPoolParamsInvalid) { // TODO FIX 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.
????
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.
include/umf/memory_pool_ops.h
Outdated
/// @brief Post-initializes memory pool. | ||
/// @param provider memory provider that will be used for coarse-grain allocations. | ||
/// Should contain at least one memory provider. | ||
/// @param numProvider number of elements in the providers array |
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.
rm numProvider
+ Should contain at least one memory provider.
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/memory_pool.c
Outdated
memcpy(&compatible_ops, ops, | ||
offsetof(umf_memory_pool_ops_t, ext_post_initialize)); | ||
} else { | ||
LOG_ERR("Memory Pool ops unknown version, which \"%d\" is not " |
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.
\"%d\"
should be moved right after unknown version
, I guess
e.g. Memory Pool ops unknown version (%d) - it is not supported
or Unsupported Memory Pool ops version: %d
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 - rebased.
src/memory_pool.c
Outdated
memcpy(&compatible_ops, ops, | ||
offsetof(umf_memory_pool_ops_t, ext_post_initialize)); | ||
} else { | ||
LOG_ERR("Memory Pool ops unknown version, which \"%d\" is not " |
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 if we have new version 1.2 - it won't be supported?
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 need to keep backward compatibility, not future :)
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.
soo, I gues it will just fail whenever someone bumps the version, which is not ideal - just saying ;)
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.
Rebased.
include/umf/memory_pool_ops.h
Outdated
@@ -166,6 +166,18 @@ typedef struct umf_memory_pool_ops_t { | |||
const char *name, void *arg, size_t size, | |||
umf_ctl_query_type_t queryType, va_list args); | |||
|
|||
/// | |||
/// @brief Post-initializes memory pool. |
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 please describe it a little more, what does it mean "post-init"? Reading the code I can see something for CTL is set up between init and post-init, but that's really not obvious reading the docs.
@@ -98,7 +98,7 @@ jobs: | |||
run: > | |||
UMF_LOG="level:warning;flush:debug;output:stderr;pid:no" | |||
LD_LIBRARY_PATH=${{github.workspace}}/latest_version/build/lib/ | |||
ctest --verbose |
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.
whole test file should be excluded? At least add a TODO info why it's disabled.
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.
+1. Also, if only specific test cases fail, please use gtest to test the rest
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.
Comment added and splited in two steps
void *provider) { | ||
(void)params; | ||
(void)provider; | ||
// For initial version, just return success |
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.
since this is ext function, can't we just omit it, when not needed?
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.
+1 - this would be replaced by "default" handler during provider creation
a5f6195
to
7aca774
Compare
@@ -98,7 +98,7 @@ jobs: | |||
run: > | |||
UMF_LOG="level:warning;flush:debug;output:stderr;pid:no" | |||
LD_LIBRARY_PATH=${{github.workspace}}/latest_version/build/lib/ | |||
ctest --verbose |
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.
+1. Also, if only specific test cases fail, please use gtest to test the rest
include/umf/memory_pool_ops.h
Outdated
@@ -36,6 +36,10 @@ typedef struct umf_memory_pool_ops_t { | |||
|
|||
/// | |||
/// @brief Initializes memory pool. | |||
/// /details | |||
/// * This function *must* be called before any other memory pool operation. |
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 remove this. This API is not intended to be called by the user; it is only used by the internal UMF functions
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.
include/umf/memory_pool_ops.h
Outdated
/// @brief Post-initializes and set up memory pool. | ||
/// | ||
/// \details | ||
/// * This function *must* be called before any other memory pool operation. |
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 remove notes about calling this func. This API is not intended to be called by the user; it is only used by the internal UMF functions
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.
include/umf/memory_pool_ops.h
Outdated
/// | ||
/// @param provider memory provider that will be used for coarse-grain allocations | ||
/// @param params pool-specific params, or NULL for defaults | ||
/// @param pool returns pointer to the pool |
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.
This function doesn't set the "pool" param - this is the in not out. Next, the "pool" param should go first, as this is the operation on an existing object. Finally, why do we need provider and params args? What if they are different from args used in initialize()?
@@ -1146,7 +1152,7 @@ static umf_memory_pool_ops_t UMF_DISJOINT_POOL_OPS = { | |||
.get_last_allocation_error = disjoint_pool_get_last_allocation_error, | |||
.get_name = disjoint_pool_get_name, | |||
.ext_ctl = disjoint_pool_ctl, | |||
}; | |||
.ext_post_initialize = disjoint_pool_post_initialize}; |
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.
nit: add ',' after the last member
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.
Initializer list doesn't require it; it's not a struct declaration. Sometimes ends with ,
, sometimes not (vide defaults structure in the same file). I will leave it as is, if it's not a problem.
include/umf/memory_pool_ops.h
Outdated
/// @param pool returns pointer to the pool | ||
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure | ||
/// | ||
umf_result_t (*ext_post_initialize)(umf_memory_provider_handle_t provider, |
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 remove params and provider - they should be stored in the pool already
void *provider) { | ||
(void)params; | ||
(void)provider; | ||
// For initial version, just return success |
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.
+1 - this would be replaced by "default" handler during provider creation
src/memory_provider.c
Outdated
void *provider) { | ||
(void)params; | ||
(void)provider; | ||
return UMF_RESULT_SUCCESS; |
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 return UMF_RESULT_ERROR_NOT_SUPPORTED here
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.
@@ -166,6 +170,24 @@ typedef struct umf_memory_pool_ops_t { | |||
const char *name, void *arg, size_t size, | |||
umf_ctl_query_type_t queryType, va_list args); | |||
|
|||
/// | |||
/// @brief Post-initializes and set up memory pool. |
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.
add "this function must be implemented if the pool/provider supports CTL that overrides defaults"
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.
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.
Even with this clarification, for me it is not clear why we need a separate function.
7af81de
to
e3b372c
Compare
@@ -166,6 +169,24 @@ typedef struct umf_memory_pool_ops_t { | |||
const char *name, void *arg, size_t size, | |||
umf_ctl_query_type_t queryType, va_list args); | |||
|
|||
/// |
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.
add a comment above "The following operations were added in ops version 1.1"
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.
Rebased.
@@ -278,6 +278,14 @@ typedef struct umf_memory_provider_ops_t { | |||
const char *name, void *arg, size_t size, | |||
umf_ctl_query_type_t queryType, va_list args); | |||
|
|||
/// |
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.
add a comment above "The following operations were added in ops version 1.1"
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.
4675e67
to
fdf2ac3
Compare
Split between initialize and post-initialize function is necessary for properly handling CTL defaults.
dcb8c16
to
172429a
Compare
172429a
to
1fcad79
Compare
/// \details | ||
/// * This function *must* be implemented if the pool/provider supports CTL that overrides defaults. | ||
/// * This function *must* free any resources allocated in the function. | ||
/// * This function *must* be called after the memory pool has been allocated in initialize function |
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.
This function *must* be called after the memory pool has been allocated in initialize function
Must be called by whom? If UMF calls it, then the comment is missleading.
@@ -166,6 +170,24 @@ typedef struct umf_memory_pool_ops_t { | |||
const char *name, void *arg, size_t size, | |||
umf_ctl_query_type_t queryType, va_list args); | |||
|
|||
/// | |||
/// @brief Post-initializes and set up memory pool. |
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.
Even with this clarification, for me it is not clear why we need a separate function.
Description
Checklist