Skip to content
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

Update OS provider config API #925

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions benchmark/multithread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ static void mt_alloc_free(poolCreateExtParams params,
}

int main() {
auto osParams = umfOsMemoryProviderParamsDefault();
umf_os_memory_provider_params_handle_t osParams = nullptr;
umf_result_t res = umfOsMemoryProviderParamsCreate(&osParams);
if (res != UMF_RESULT_SUCCESS) {
std::cerr << "os memory provider params create failed" << std::endl;
return -1;
}

#if defined(UMF_POOL_SCALABLE_ENABLED)

Expand All @@ -102,7 +107,7 @@ int main() {

std::cout << "scalable_pool mt_alloc_free: ";
mt_alloc_free(poolCreateExtParams{umfScalablePoolOps(), nullptr,
umfOsMemoryProviderOps(), &osParams},
umfOsMemoryProviderOps(), osParams},
params);
#else
std::cout << "skipping scalable_pool mt_alloc_free" << std::endl;
Expand All @@ -111,7 +116,7 @@ int main() {
#if defined(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
std::cout << "jemalloc_pool mt_alloc_free: ";
mt_alloc_free(poolCreateExtParams{umfJemallocPoolOps(), nullptr,
umfOsMemoryProviderOps(), &osParams});
umfOsMemoryProviderOps(), osParams});
#else
std::cout << "skipping jemalloc_pool mt_alloc_free" << std::endl;
#endif
Expand All @@ -126,7 +131,7 @@ int main() {

std::cout << "disjoint_pool mt_alloc_free: ";
mt_alloc_free(poolCreateExtParams{umfDisjointPoolOps(), hDisjointParams,
umfOsMemoryProviderOps(), &osParams});
umfOsMemoryProviderOps(), osParams});
#else
std::cout << "skipping disjoint_pool mt_alloc_free" << std::endl;
#endif
Expand Down
76 changes: 50 additions & 26 deletions benchmark/ubench.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,6 @@ UBENCH_EX(simple, glibc_malloc) {

////////////////// OS MEMORY PROVIDER

static umf_os_memory_provider_params_t UMF_OS_MEMORY_PROVIDER_PARAMS = {
/* .protection = */ UMF_PROTECTION_READ | UMF_PROTECTION_WRITE,
/* .visibility = */ UMF_MEM_MAP_PRIVATE,
/* .shm_name = */ NULL,

// NUMA config
/* .numa_list = */ NULL,
/* .numa_list_len = */ 0,

/* .numa_mode = */ UMF_NUMA_MODE_DEFAULT,
/* .part_size = */ 0,

/* .partitions = */ NULL,
/* .partitions_len = */ 0,
};

static void *w_umfMemoryProviderAlloc(void *provider, size_t size,
size_t alignment) {
void *ptr = NULL;
Expand Down Expand Up @@ -171,9 +155,17 @@ UBENCH_EX(simple, os_memory_provider) {

umf_result_t umf_result;
umf_memory_provider_handle_t os_memory_provider = NULL;
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(),
&UMF_OS_MEMORY_PROVIDER_PARAMS,
umf_os_memory_provider_params_handle_t os_params = NULL;

umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfOsMemoryProviderParamsCreate() failed\n");
exit(-1);
}

umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&os_memory_provider);
umfOsMemoryProviderParamsDestroy(os_params);
Copy link
Contributor

Choose a reason for hiding this comment

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

we could also check return value of this func

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, but what we should do with that? It does not impact the benchamrk. As you can see below we also do not check the return of the umfMemoryProviderDestroy

if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfMemoryProviderCreate() failed\n");
exit(-1);
Expand Down Expand Up @@ -215,9 +207,17 @@ UBENCH_EX(simple, proxy_pool_with_os_memory_provider) {

umf_result_t umf_result;
umf_memory_provider_handle_t os_memory_provider = NULL;
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(),
&UMF_OS_MEMORY_PROVIDER_PARAMS,
umf_os_memory_provider_params_handle_t os_params = NULL;

umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfOsMemoryProviderParamsCreate() failed\n");
exit(-1);
}

umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&os_memory_provider);
umfOsMemoryProviderParamsDestroy(os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfMemoryProviderCreate() failed\n");
exit(-1);
Expand Down Expand Up @@ -252,9 +252,17 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {

umf_result_t umf_result;
umf_memory_provider_handle_t os_memory_provider = NULL;
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(),
&UMF_OS_MEMORY_PROVIDER_PARAMS,
umf_os_memory_provider_params_handle_t os_params = NULL;

umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfOsMemoryProviderParamsCreate() failed\n");
exit(-1);
}

umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&os_memory_provider);
umfOsMemoryProviderParamsDestroy(os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfMemoryProviderCreate() failed\n");
exit(-1);
Expand Down Expand Up @@ -329,9 +337,17 @@ UBENCH_EX(simple, jemalloc_pool_with_os_memory_provider) {

umf_result_t umf_result;
umf_memory_provider_handle_t os_memory_provider = NULL;
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(),
&UMF_OS_MEMORY_PROVIDER_PARAMS,
umf_os_memory_provider_params_handle_t os_params = NULL;

umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfOsMemoryProviderParamsCreate() failed\n");
exit(-1);
}

umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&os_memory_provider);
umfOsMemoryProviderParamsDestroy(os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfMemoryProviderCreate() failed\n");
exit(-1);
Expand Down Expand Up @@ -367,9 +383,17 @@ UBENCH_EX(simple, scalable_pool_with_os_memory_provider) {

umf_result_t umf_result;
umf_memory_provider_handle_t os_memory_provider = NULL;
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(),
&UMF_OS_MEMORY_PROVIDER_PARAMS,
umf_os_memory_provider_params_handle_t os_params = NULL;

umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfOsMemoryProviderParamsCreate() failed\n");
exit(-1);
}

umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&os_memory_provider);
umfOsMemoryProviderParamsDestroy(os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfMemoryProviderCreate() failed\n");
exit(-1);
Expand Down
11 changes: 9 additions & 2 deletions examples/basic/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ int main(void) {
// in an mmap call like this:
// mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)
umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps();
umf_os_memory_provider_params_t params = umfOsMemoryProviderParamsDefault();
umf_os_memory_provider_params_handle_t params = NULL;
umf_memory_provider_handle_t provider;

res = umfMemoryProviderCreate(provider_ops, &params, &provider);
res = umfOsMemoryProviderParamsCreate(&params);
if (res != UMF_RESULT_SUCCESS) {
printf("Failed to create OS memory provider params!\n");
return -1;
}

res = umfMemoryProviderCreate(provider_ops, params, &provider);
umfOsMemoryProviderParamsDestroy(params);
if (res != UMF_RESULT_SUCCESS) {
printf("Failed to create a memory provider!\n");
return -1;
Expand Down
11 changes: 8 additions & 3 deletions examples/dram_and_fsdax/dram_and_fsdax.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ static umf_memory_pool_handle_t create_dram_pool(void) {
umf_memory_pool_handle_t pool_dram;
umf_result_t umf_result;

umf_os_memory_provider_params_t params_dram =
umfOsMemoryProviderParamsDefault();
umf_os_memory_provider_params_handle_t params_dram = NULL;
umf_result = umfOsMemoryProviderParamsCreate(&params_dram);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create OS memory provider params!\n");
return NULL;
}

umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), &params_dram,
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), params_dram,
&provider_dram);
umfOsMemoryProviderParamsDestroy(params_dram);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Creation of the OS memory provider failed");
return NULL;
Expand Down
29 changes: 24 additions & 5 deletions examples/ipc_ipcapi/ipc_ipcapi_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,33 @@ int main(int argc, char *argv[]) {
int port = atoi(argv[1]);

umf_memory_provider_handle_t OS_memory_provider = NULL;
umf_os_memory_provider_params_t os_params;
umf_os_memory_provider_params_handle_t os_params = NULL;
enum umf_result_t umf_result;

os_params = umfOsMemoryProviderParamsDefault();
os_params.visibility = UMF_MEM_MAP_SHARED;
umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(
stderr,
"[consumer] ERROR: creating OS memory provider params failed\n");
return -1;
}
umf_result =
umfOsMemoryProviderParamsSetVisibility(os_params, UMF_MEM_MAP_SHARED);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "[consumer] ERROR: setting visibility mode failed\n");
goto err_destroy_OS_params;
}
if (argc >= 3) {
os_params.shm_name = argv[2];
umf_result = umfOsMemoryProviderParamsSetShmName(os_params, argv[2]);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"[consumer] ERROR: setting shared memory name failed\n");
goto err_destroy_OS_params;
}
}

// create OS memory provider
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), &os_params,
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&OS_memory_provider);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
Expand Down Expand Up @@ -267,6 +283,9 @@ int main(int argc, char *argv[]) {
err_destroy_OS_memory_provider:
umfMemoryProviderDestroy(OS_memory_provider);

err_destroy_OS_params:
umfOsMemoryProviderParamsDestroy(os_params);

if (ret == 0) {
fprintf(stderr, "[consumer] Shutting down (status OK) ...\n");
} else if (ret == 1) {
Expand Down
29 changes: 24 additions & 5 deletions examples/ipc_ipcapi/ipc_ipcapi_producer.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,33 @@ int main(int argc, char *argv[]) {
int port = atoi(argv[1]);

umf_memory_provider_handle_t OS_memory_provider = NULL;
umf_os_memory_provider_params_t os_params;
umf_os_memory_provider_params_handle_t os_params = NULL;
enum umf_result_t umf_result;

os_params = umfOsMemoryProviderParamsDefault();
os_params.visibility = UMF_MEM_MAP_SHARED;
umf_result = umfOsMemoryProviderParamsCreate(&os_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(
stderr,
"[producer] ERROR: creating OS memory provider params failed\n");
return -1;
}
umf_result =
umfOsMemoryProviderParamsSetVisibility(os_params, UMF_MEM_MAP_SHARED);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "[producer] ERROR: setting visibility mode failed\n");
goto err_destroy_OS_params;
}
if (argc >= 3) {
os_params.shm_name = argv[2];
umf_result = umfOsMemoryProviderParamsSetShmName(os_params, argv[2]);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"[producer] ERROR: setting shared memory name failed\n");
goto err_destroy_OS_params;
}
}

// create OS memory provider
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), &os_params,
umf_result = umfMemoryProviderCreate(umfOsMemoryProviderOps(), os_params,
&OS_memory_provider);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
Expand Down Expand Up @@ -240,6 +256,9 @@ int main(int argc, char *argv[]) {
err_destroy_OS_memory_provider:
umfMemoryProviderDestroy(OS_memory_provider);

err_destroy_OS_params:
umfOsMemoryProviderParamsDestroy(os_params);

if (ret == 0) {
fprintf(stderr, "[producer] Shutting down (status OK) ...\n");
} else if (ret == 1) {
Expand Down
Loading
Loading