Skip to content

Fix error handling in OS provider #211

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

Merged
Merged
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
1 change: 1 addition & 0 deletions include/umf/providers/provider_os_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef enum umf_os_memory_provider_native_error {
UMF_OS_RESULT_ERROR_FREE_FAILED,
UMF_OS_RESULT_ERROR_PURGE_LAZY_FAILED,
UMF_OS_RESULT_ERROR_PURGE_FORCE_FAILED,
UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED,
} umf_os_memory_provider_native_error_t;

umf_memory_provider_ops_t *umfOsMemoryProviderOps(void);
Expand Down
23 changes: 17 additions & 6 deletions src/provider/provider_os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ static __TLS os_last_native_error_t TLS_last_native_error;
(UMF_OS_RESULT_ERROR_PURGE_LAZY_FAILED - UMF_OS_RESULT_SUCCESS)
#define _UMF_OS_RESULT_ERROR_PURGE_FORCE_FAILED \
(UMF_OS_RESULT_ERROR_PURGE_FORCE_FAILED - UMF_OS_RESULT_SUCCESS)
#define _UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED \
(UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED - UMF_OS_RESULT_SUCCESS)

static const char *Native_error_str[] = {
[_UMF_OS_RESULT_SUCCESS] = "success",
Expand All @@ -86,6 +88,8 @@ static const char *Native_error_str[] = {
[_UMF_OS_RESULT_ERROR_FREE_FAILED] = "memory deallocation failed",
[_UMF_OS_RESULT_ERROR_PURGE_LAZY_FAILED] = "lazy purging failed",
[_UMF_OS_RESULT_ERROR_PURGE_FORCE_FAILED] = "force purging failed",
[_UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED] =
"HWLOC topology discovery failed",
};

static void os_store_last_native_error(int32_t native_error, int errno_value) {
Expand Down Expand Up @@ -291,23 +295,24 @@ static umf_result_t os_initialize(void *params, void **provider) {
if (os_provider->traces) {
fprintf(stderr, "HWLOC topology init failed\n");
}
umf_ba_free(base_allocator, os_provider);
ret = UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
goto err_free_os_provider;
}

r = hwloc_topology_load(os_provider->topo);
if (r) {
os_store_last_native_error(UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED,
0);
if (os_provider->traces) {
fprintf(stderr, "HWLOC topology discovery failed\n");
}
hwloc_topology_destroy(os_provider->topo);
umf_ba_free(base_allocator, os_provider);
ret = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC;
goto err_destroy_hwloc_topology;
}

ret = translate_params(in_params, os_provider);
if (ret != UMF_RESULT_SUCCESS) {
hwloc_topology_destroy(os_provider->topo);
umf_ba_free(base_allocator, os_provider);
return ret;
goto err_destroy_hwloc_topology;
}

if (os_provider->traces) {
Expand All @@ -324,6 +329,12 @@ static umf_result_t os_initialize(void *params, void **provider) {
*provider = os_provider;

return UMF_RESULT_SUCCESS;

err_destroy_hwloc_topology:
hwloc_topology_destroy(os_provider->topo);
err_free_os_provider:
umf_ba_free(base_allocator, os_provider);
return ret;
}

static void os_finalize(void *provider) {
Expand Down
5 changes: 3 additions & 2 deletions test/provider_os_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ static const char *Native_error_str[] = {
"allocated address is not aligned", // UMF_OS_RESULT_ERROR_ADDRESS_NOT_ALIGNED
"binding memory to NUMA node failed", // UMF_OS_RESULT_ERROR_BIND_FAILED
"memory deallocation failed", // UMF_OS_RESULT_ERROR_FREE_FAILED
"lazy purging failed", // UMF_OS_RESULT_ERROR_PURGE_LAZY_FAILED
"force purging failed", // UMF_OS_RESULT_ERROR_PURGE_FORCE_FAILED
"lazy purging failed", // UMF_OS_RESULT_ERROR_PURGE_LAZY_FAILED
"force purging failed", // UMF_OS_RESULT_ERROR_PURGE_FORCE_FAILED
"HWLOC topology discovery failed", // UMF_OS_RESULT_ERROR_TOPO_DISCOVERY_FAILED
};

// test helpers
Expand Down