Skip to content

Commit 636d038

Browse files
committed
Update DevDax provider config API
1 parent 61f02ef commit 636d038

11 files changed

+415
-121
lines changed

include/umf/providers/provider_devdax_memory.h

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,41 @@ extern "C" {
1818
#define UMF_DEVDAX_RESULTS_START_FROM 2000
1919
/// @endcond
2020

21-
/// @brief Memory provider settings struct
22-
typedef struct umf_devdax_memory_provider_params_t {
23-
/// path of the device DAX
24-
char *path;
25-
/// size of the device DAX in bytes
26-
size_t size;
27-
/// combination of 'umf_mem_protection_flags_t' flags
28-
unsigned protection;
29-
} umf_devdax_memory_provider_params_t;
21+
struct umf_devdax_memory_provider_params_t;
22+
23+
typedef struct umf_devdax_memory_provider_params_t
24+
*umf_devdax_memory_provider_params_handle_t;
25+
26+
/// @brief Create a struct to store parameters of the Devdax Memory Provider.
27+
/// @param hParams [out] handle to the newly created parameters struct.
28+
/// @param path [in] path of the device DAX.
29+
/// @param size [in] size of the device DAX in bytes.
30+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
31+
umf_result_t umfDevDaxMemoryProviderParamsCreate(
32+
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
33+
size_t size);
34+
35+
/// @brief Destroy parameters struct.
36+
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
37+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
38+
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
39+
umf_devdax_memory_provider_params_handle_t hParams);
40+
41+
/// @brief Set device DAX in the parameters struct.
42+
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
43+
/// @param path [in] path of the device DAX.
44+
/// @param size [in] size of the device DAX in bytes.
45+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
46+
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
47+
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
48+
size_t size);
49+
50+
/// @brief Set the protection flags in the parameters struct.
51+
/// @param hParams [in] handle to the parameters of the Devdax Memory Provider.
52+
/// @param protection [in] combination of 'umf_mem_protection_flags_t' flags.
53+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
54+
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
55+
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection);
3056

3157
/// @brief Devdax Memory Provider operation results
3258
typedef enum umf_devdax_memory_provider_native_error {
@@ -39,18 +65,6 @@ typedef enum umf_devdax_memory_provider_native_error {
3965

4066
umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void);
4167

42-
/// @brief Create default params for the devdax memory provider
43-
static inline umf_devdax_memory_provider_params_t
44-
umfDevDaxMemoryProviderParamsDefault(char *path, size_t size) {
45-
umf_devdax_memory_provider_params_t params = {
46-
path, /* path of the device DAX */
47-
size, /* size of the device DAX in bytes */
48-
UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */
49-
};
50-
51-
return params;
52-
}
53-
5468
#ifdef __cplusplus
5569
}
5670
#endif

src/libumf.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ EXPORTS
2323
umfCUDAMemoryProviderParamsSetDevice
2424
umfCUDAMemoryProviderParamsSetMemoryType
2525
umfDevDaxMemoryProviderOps
26+
umfDevDaxMemoryProviderParamsCreate
27+
umfDevDaxMemoryProviderParamsDestroy
28+
umfDevDaxMemoryProviderParamsSetDeviceDax
29+
umfDevDaxMemoryProviderParamsSetProtection
2630
umfFree
2731
umfFileMemoryProviderOps
2832
umfGetIPCHandle

src/libumf.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ UMF_1.0 {
1717
umfCUDAMemoryProviderParamsSetDevice;
1818
umfCUDAMemoryProviderParamsSetMemoryType;
1919
umfDevDaxMemoryProviderOps;
20+
umfDevDaxMemoryProviderParamsCreate;
21+
umfDevDaxMemoryProviderParamsDestroy;
22+
umfDevDaxMemoryProviderParamsSetDeviceDax;
23+
umfDevDaxMemoryProviderParamsSetProtection;
2024
umfFree;
2125
umfFileMemoryProviderOps;
2226
umfGetIPCHandle;

src/provider/provider_devdax_memory.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,37 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
2424
return NULL;
2525
}
2626

27+
umf_result_t umfDevDaxMemoryProviderParamsCreate(
28+
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
29+
size_t size) {
30+
(void)hParams;
31+
(void)path;
32+
(void)size;
33+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
34+
}
35+
36+
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
37+
umf_devdax_memory_provider_params_handle_t hParams) {
38+
(void)hParams;
39+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
40+
}
41+
42+
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
43+
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
44+
size_t size) {
45+
(void)hParams;
46+
(void)path;
47+
(void)size;
48+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
49+
}
50+
51+
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
52+
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection) {
53+
(void)hParams;
54+
(void)protection;
55+
return UMF_RESULT_ERROR_NOT_SUPPORTED;
56+
}
57+
2758
#else // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
2859

2960
#include "base_alloc_global.h"
@@ -44,6 +75,13 @@ typedef struct devdax_memory_provider_t {
4475
unsigned protection; // combination of OS-specific protection flags
4576
} devdax_memory_provider_t;
4677

78+
// DevDax Memory provider settings struct
79+
typedef struct umf_devdax_memory_provider_params_t {
80+
char *path;
81+
size_t size;
82+
unsigned protection;
83+
} umf_devdax_memory_provider_params_t;
84+
4785
typedef struct devdax_last_native_error_t {
4886
int32_t native_error;
4987
int errno_value;
@@ -511,4 +549,99 @@ umf_memory_provider_ops_t *umfDevDaxMemoryProviderOps(void) {
511549
return &UMF_DEVDAX_MEMORY_PROVIDER_OPS;
512550
}
513551

552+
umf_result_t umfDevDaxMemoryProviderParamsCreate(
553+
umf_devdax_memory_provider_params_handle_t *hParams, const char *path,
554+
size_t size) {
555+
if (hParams == NULL) {
556+
LOG_ERR("DevDax Memory Provider params handle is NULL");
557+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
558+
}
559+
560+
if (path == NULL) {
561+
LOG_ERR("DevDax path is NULL");
562+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
563+
}
564+
565+
umf_devdax_memory_provider_params_handle_t params =
566+
umf_ba_global_alloc(sizeof(*params));
567+
if (params == NULL) {
568+
LOG_ERR(
569+
"Allocating memory for the DevDax Memory Provider params failed");
570+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
571+
}
572+
573+
params->path = NULL;
574+
params->size = 0;
575+
params->protection = UMF_PROTECTION_READ | UMF_PROTECTION_WRITE;
576+
577+
umf_result_t res =
578+
umfDevDaxMemoryProviderParamsSetDeviceDax(params, path, size);
579+
if (res != UMF_RESULT_SUCCESS) {
580+
umf_ba_global_free(params);
581+
return res;
582+
}
583+
584+
*hParams = params;
585+
586+
return UMF_RESULT_SUCCESS;
587+
}
588+
589+
umf_result_t umfDevDaxMemoryProviderParamsDestroy(
590+
umf_devdax_memory_provider_params_handle_t hParams) {
591+
if (hParams != NULL) {
592+
umf_ba_global_free(hParams->path);
593+
umf_ba_global_free(hParams);
594+
}
595+
596+
return UMF_RESULT_SUCCESS;
597+
}
598+
599+
umf_result_t umfDevDaxMemoryProviderParamsSetDeviceDax(
600+
umf_devdax_memory_provider_params_handle_t hParams, const char *path,
601+
size_t size) {
602+
if (hParams == NULL) {
603+
LOG_ERR("DevDax Memory Provider params handle is NULL");
604+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
605+
}
606+
607+
if (path == NULL) {
608+
LOG_ERR("DevDax path is NULL");
609+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
610+
}
611+
612+
size_t path_len = strlen(path);
613+
if (path_len == 0) {
614+
LOG_ERR("DevDax path is empty");
615+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
616+
}
617+
618+
path_len += 1; // for the null terminator
619+
char *new_path = umf_ba_global_alloc(path_len);
620+
if (new_path == NULL) {
621+
LOG_ERR("Allocating memory for the DevDax path failed");
622+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
623+
}
624+
625+
strncpy(new_path, path, path_len);
626+
627+
umf_ba_global_free(hParams->path);
628+
629+
hParams->path = new_path;
630+
hParams->size = size;
631+
632+
return UMF_RESULT_SUCCESS;
633+
}
634+
635+
umf_result_t umfDevDaxMemoryProviderParamsSetProtection(
636+
umf_devdax_memory_provider_params_handle_t hParams, unsigned protection) {
637+
if (hParams == NULL) {
638+
LOG_ERR("DevDax Memory Provider params handle is NULL");
639+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
640+
}
641+
642+
hParams->protection = protection;
643+
644+
return UMF_RESULT_SUCCESS;
645+
}
646+
514647
#endif // !defined(_WIN32) && !defined(UMF_NO_HWLOC)

test/ipc_devdax_prov_consumer.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
1919
return -1;
2020
}
2121

22+
int ret = 0;
2223
int port = atoi(argv[1]);
2324

2425
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
@@ -33,12 +34,22 @@ int main(int argc, char *argv[]) {
3334
return 0;
3435
}
3536

36-
umf_devdax_memory_provider_params_t devdax_params =
37-
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
37+
umf_devdax_memory_provider_params_handle_t devdax_params = NULL;
38+
umf_result_t umf_result =
39+
umfDevDaxMemoryProviderParamsCreate(&devdax_params, path, atol(size));
40+
if (umf_result != UMF_RESULT_SUCCESS) {
41+
fprintf(stderr, "[consumer] ERROR: creating DevDax Memory Provider "
42+
"params failed\n");
43+
return -1;
44+
}
3845

3946
void *pool_params = NULL;
4047

41-
return run_consumer(port, umfScalablePoolOps(), pool_params,
42-
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
43-
NULL);
48+
ret = run_consumer(port, umfScalablePoolOps(), pool_params,
49+
umfDevDaxMemoryProviderOps(), devdax_params, memcopy,
50+
NULL);
51+
52+
umfDevDaxMemoryProviderParamsDestroy(devdax_params);
53+
54+
return ret;
4455
}

test/ipc_devdax_prov_producer.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int main(int argc, char *argv[]) {
1919
return -1;
2020
}
2121

22+
int ret = 0;
2223
int port = atoi(argv[1]);
2324

2425
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
@@ -33,12 +34,22 @@ int main(int argc, char *argv[]) {
3334
return 0;
3435
}
3536

36-
umf_devdax_memory_provider_params_t devdax_params =
37-
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
37+
umf_devdax_memory_provider_params_handle_t devdax_params = NULL;
38+
umf_result_t umf_result =
39+
umfDevDaxMemoryProviderParamsCreate(&devdax_params, path, atol(size));
40+
if (umf_result != UMF_RESULT_SUCCESS) {
41+
fprintf(stderr, "[producer] ERROR: creating DevDax Memory Provider "
42+
"params failed\n");
43+
return -1;
44+
}
3845

3946
void *pool_params = NULL;
4047

41-
return run_producer(port, umfScalablePoolOps(), pool_params,
42-
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
43-
NULL);
48+
ret = run_producer(port, umfScalablePoolOps(), pool_params,
49+
umfDevDaxMemoryProviderOps(), devdax_params, memcopy,
50+
NULL);
51+
52+
umfDevDaxMemoryProviderParamsDestroy(devdax_params);
53+
54+
return ret;
4455
}

test/poolFixtures.hpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,6 @@ struct umfPoolTest : umf_test::test,
6969
void SetUp() override {
7070
test::SetUp();
7171

72-
auto [pool_ops, pool_params, provider_ops, provider_params,
73-
coarse_params] = this->GetParam();
74-
(void)pool_ops;
75-
(void)pool_params;
76-
(void)provider_params;
77-
(void)coarse_params;
78-
79-
if (provider_ops == umfDevDaxMemoryProviderOps()) {
80-
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
81-
if (path == nullptr || path[0] == 0) {
82-
GTEST_SKIP()
83-
<< "Test skipped, UMF_TESTS_DEVDAX_PATH is not set";
84-
}
85-
86-
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
87-
if (size == nullptr || size[0] == 0) {
88-
GTEST_SKIP()
89-
<< "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set";
90-
}
91-
}
92-
9372
pool = poolCreateExtUnique(this->GetParam());
9473
}
9574

test/pools/jemalloc_coarse_devdax.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,39 @@
77

88
#include "pool_coarse.hpp"
99

10+
using devdax_params_unique_handle_t =
11+
std::unique_ptr<umf_devdax_memory_provider_params_t,
12+
decltype(&umfDevDaxMemoryProviderParamsDestroy)>;
13+
14+
devdax_params_unique_handle_t create_devdax_params() {
15+
char *path = getenv("UMF_TESTS_DEVDAX_PATH");
16+
char *size = getenv("UMF_TESTS_DEVDAX_SIZE");
17+
if (path == nullptr || path[0] == 0 || size == nullptr || size[0] == 0) {
18+
return devdax_params_unique_handle_t(
19+
nullptr, &umfDevDaxMemoryProviderParamsDestroy);
20+
}
21+
22+
umf_devdax_memory_provider_params_handle_t params = NULL;
23+
umf_result_t res =
24+
umfDevDaxMemoryProviderParamsCreate(&params, path, atol(size));
25+
if (res != UMF_RESULT_SUCCESS) {
26+
throw std::runtime_error(
27+
"Failed to create DevDax Memory Provider params");
28+
}
29+
30+
return devdax_params_unique_handle_t(params,
31+
&umfDevDaxMemoryProviderParamsDestroy);
32+
}
33+
1034
auto coarseParams = umfCoarseMemoryProviderParamsDefault();
11-
auto devdaxParams = umfDevDaxMemoryProviderParamsDefault(
12-
getenv("UMF_TESTS_DEVDAX_PATH"), getenv("UMF_TESTS_DEVDAX_SIZE")
13-
? atol(getenv("UMF_TESTS_DEVDAX_SIZE"))
14-
: 0);
35+
auto devdaxParams = create_devdax_params();
36+
37+
static std::vector<poolCreateExtParams> poolParamsList =
38+
devdaxParams.get()
39+
? std::vector<poolCreateExtParams>{poolCreateExtParams{
40+
umfJemallocPoolOps(), nullptr, umfDevDaxMemoryProviderOps(),
41+
devdaxParams.get(), &coarseParams}}
42+
: std::vector<poolCreateExtParams>{};
1543

1644
INSTANTIATE_TEST_SUITE_P(jemallocCoarseDevDaxTest, umfPoolTest,
17-
::testing::Values(poolCreateExtParams{
18-
umfJemallocPoolOps(), nullptr,
19-
umfDevDaxMemoryProviderOps(), &devdaxParams,
20-
&coarseParams}));
45+
::testing::ValuesIn(poolParamsList));

0 commit comments

Comments
 (0)