Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KFilipek
Copy link
Contributor

Description

Checklist

  • Code compiles without errors locally
  • All tests pass locally
  • CI workflows execute properly
  • CI workflows, not executed per PR (e.g. Nightly), execute properly
  • New tests added, especially if they will fail without my changes
  • Added/extended example(s) to cover this functionality
  • Extended the README/documentation
  • All newly added source files have a license
  • All newly added source files are referenced in CMake files
  • Logger (with debug/info/... messages) is used
  • All API changes are reflected in docs and def/map files, and are tested

@KFilipek KFilipek self-assigned this Jul 25, 2025
@KFilipek KFilipek requested a review from a team as a code owner July 25, 2025 09:25
@bratpiorka bratpiorka marked this pull request as draft July 28, 2025 09:22
@KFilipek KFilipek force-pushed the post_initialize branch 17 times, most recently from 54df467 to 40c6dfc Compare August 1, 2025 08:46
@KFilipek KFilipek marked this pull request as ready for review August 1, 2025 10:14
@KFilipek KFilipek requested review from lplewa and bratpiorka August 1, 2025 10:15
Comment on lines 171 to 176
/// @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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write better documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 38 to 53
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';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf?

Copy link
Contributor Author

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.

(void)source, (void)indexes, (void)size;
disjoint_pool_t *pool = (disjoint_pool_t *)ctx;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito

Copy link
Contributor Author

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

@@ -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);
Copy link
Contributor

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

Comment on lines 841 to 844

err_free_disjoint_pool:
umf_ba_global_free(disjoint_pool);

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted, thanks

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

????

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// @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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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 "
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - rebased.

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 "
Copy link
Contributor

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?

Copy link
Contributor

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 :)

Copy link
Contributor

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 ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased.

@@ -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.
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor

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

@KFilipek KFilipek force-pushed the post_initialize branch 2 times, most recently from a5f6195 to 7aca774 Compare August 4, 2025 11:53
@@ -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
Copy link
Contributor

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

@@ -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.
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// @brief Post-initializes and set up memory pool.
///
/// \details
/// * This function *must* be called before any other memory pool operation.
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

///
/// @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
Copy link
Contributor

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};
Copy link
Contributor

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

Copy link
Contributor Author

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.

/// @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,
Copy link
Contributor

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
Copy link
Contributor

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

void *provider) {
(void)params;
(void)provider;
return UMF_RESULT_SUCCESS;
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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.

@KFilipek KFilipek force-pushed the post_initialize branch 3 times, most recently from 7af81de to e3b372c Compare August 5, 2025 11:14
@@ -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);

///
Copy link
Contributor

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"

Copy link
Contributor Author

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);

///
Copy link
Contributor

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@KFilipek KFilipek force-pushed the post_initialize branch 3 times, most recently from 4675e67 to fdf2ac3 Compare August 5, 2025 16:42
Split between initialize and post-initialize function is necessary
for properly handling CTL defaults.
@KFilipek KFilipek force-pushed the post_initialize branch 3 times, most recently from dcb8c16 to 172429a Compare August 5, 2025 17:15
/// \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
Copy link
Contributor

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.
Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy