Skip to content

Commit 7904c64

Browse files
committed
Remove umf_mem_visibility_t
Right now, only PRIVATE memory is supported. Additional research is needed to decide how to expose SHARED memory.
1 parent f2b784a commit 7904c64

File tree

6 files changed

+6
-98
lines changed

6 files changed

+6
-98
lines changed

benchmark/ubench.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ UBENCH_EX(simple, glibc_malloc) {
9999

100100
static umf_os_memory_provider_params_t UMF_OS_MEMORY_PROVIDER_PARAMS = {
101101
/* .protection = */ UMF_PROTECTION_READ | UMF_PROTECTION_WRITE,
102-
/* .visibility = */ UMF_VISIBILITY_PRIVATE,
103102

104103
// NUMA config
105104
/* .nodemask = */ NULL,

include/umf/providers/provider_os_memory.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ typedef enum umf_mem_protection_flags_t {
2626
UMF_PROTECTION_MAX // must be the last one
2727
} umf_mem_protection_flags_t;
2828

29-
/// @brief Visibility of the memory allocations
30-
typedef enum umf_mem_visibility_t {
31-
UMF_VISIBILITY_SHARED, ///< Updates to the memory allocated using OS provider are visible to other processes.
32-
/// TODO: need to expose functionality to share open the mapping in other process and explicit sync?
33-
UMF_VISIBILITY_PRIVATE, ///< Updates to the memory allocated using OS provider are not visible to other processes.
34-
} umf_mem_visibility_t;
35-
3629
/// @brief Memory binding mode
3730
///
3831
/// Specifies how memory is bound to NUMA nodes on systems that support NUMA.
@@ -57,9 +50,6 @@ typedef struct umf_os_memory_provider_params_t {
5750
/// combination of 'umf_mem_protection_flags_t' flags
5851
unsigned protection;
5952

60-
/// shared or private visibility of memory mapped by a provider
61-
umf_mem_visibility_t visibility;
62-
6353
// NUMA config
6454
/// points to a bit mask of nodes containing up to maxnode bits, depending on
6555
/// selected numa_mode newly allocated memory will be bound to those nodes
@@ -92,7 +82,6 @@ static inline umf_os_memory_provider_params_t
9282
umfOsMemoryProviderParamsDefault(void) {
9383
umf_os_memory_provider_params_t params = {
9484
UMF_PROTECTION_READ | UMF_PROTECTION_WRITE, /* protection */
95-
UMF_VISIBILITY_PRIVATE, /* visibility */
9685
NULL, /* nodemask */
9786
0, /* maxnode */
9887
UMF_NUMA_MODE_DEFAULT, /* numa_mode */

src/provider/provider_os_memory.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
typedef struct umf_os_memory_provider_config_t {
2424
unsigned protection; // combination of OS-specific protection flags
25-
unsigned visibility;
2625

2726
// NUMA config
2827
unsigned long *nodemask;
@@ -35,7 +34,6 @@ typedef struct umf_os_memory_provider_config_t {
3534

3635
typedef struct os_memory_provider_t {
3736
unsigned protection; // combination of OS-specific protection flags
38-
unsigned visibility;
3937

4038
// NUMA config
4139
hwloc_bitmap_t nodeset;
@@ -204,16 +202,6 @@ static umf_result_t translate_params(umf_os_memory_provider_params_t *in_params,
204202
}
205203
provider->protection = ret;
206204

207-
ret = os_translate_mem_visibility(in_params->visibility);
208-
if (ret < 0) {
209-
if (in_params->traces) {
210-
fprintf(stderr, "error: incorrect memory visibility mode: %u\n",
211-
in_params->visibility);
212-
}
213-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
214-
}
215-
provider->visibility = ret;
216-
217205
// NUMA config
218206
int emptyNodeset = (!in_params->maxnode || !in_params->nodemask);
219207
ret = translate_numa_mode(in_params->numa_mode, emptyNodeset);
@@ -241,18 +229,6 @@ static umf_result_t os_initialize(void *params, void **provider) {
241229
umf_os_memory_provider_params_t *in_params =
242230
(umf_os_memory_provider_params_t *)params;
243231

244-
if (in_params->visibility == UMF_VISIBILITY_SHARED &&
245-
in_params->numa_mode != UMF_NUMA_MODE_DEFAULT) {
246-
// TODO: add support for that
247-
if (in_params->traces) {
248-
fprintf(stderr,
249-
"NUMA binding mode (%i) not supported for "
250-
"UMF_VISIBILITY_SHARED\n",
251-
in_params->numa_mode);
252-
}
253-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
254-
}
255-
256232
umf_ba_pool_t *base_allocator =
257233
umf_ba_get_pool(sizeof(os_memory_provider_t));
258234
if (!base_allocator) {
@@ -387,13 +363,12 @@ static umf_result_t os_alloc(void *provider, size_t size, size_t alignment,
387363
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
388364
}
389365

390-
int flags = os_provider->visibility;
391366
int protection = os_provider->protection;
392367

393368
void *addr = NULL;
394369
errno = 0;
395-
ret = os_mmap_aligned(NULL, size, alignment, page_size, protection, flags,
396-
-1, 0, &addr);
370+
ret = os_mmap_aligned(NULL, size, alignment, page_size, protection, -1, 0,
371+
&addr);
397372
if (ret) {
398373
os_store_last_native_error(UMF_OS_RESULT_ERROR_ALLOC_FAILED, errno);
399374
if (os_provider->traces) {

src/provider/provider_os_memory_internal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ int os_translate_flags(unsigned in_flags, unsigned max,
2525

2626
int os_translate_mem_protection_flags(unsigned protection);
2727

28-
int os_translate_mem_visibility(umf_mem_visibility_t visibility);
29-
3028
int os_mmap_aligned(void *hint_addr, size_t length, size_t alignment,
31-
size_t page_size, int prot, int flags, int fd, long offset,
29+
size_t page_size, int prot, int fd, long offset,
3230
void **out_addr);
3331

3432
int os_munmap(void *addr, size_t length);

src/provider/provider_os_memory_linux.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ int os_translate_mem_protection_flags(unsigned protection_flags) {
3434
os_translate_mem_protection_one_flag);
3535
}
3636

37-
int os_translate_mem_visibility(umf_mem_visibility_t visibility) {
38-
switch (visibility) {
39-
case UMF_VISIBILITY_SHARED:
40-
return MAP_SHARED;
41-
case UMF_VISIBILITY_PRIVATE:
42-
return MAP_PRIVATE;
43-
}
44-
assert(0);
45-
return -1;
46-
}
47-
4837
static int os_translate_purge_advise(umf_purge_advise_t advise) {
4938
switch (advise) {
5039
case UMF_PURGE_LAZY:
@@ -63,7 +52,7 @@ static inline void assert_is_page_aligned(uintptr_t ptr, size_t page_size) {
6352
}
6453

6554
int os_mmap_aligned(void *hint_addr, size_t length, size_t alignment,
66-
size_t page_size, int prot, int flags, int fd, long offset,
55+
size_t page_size, int prot, int fd, long offset,
6756
void **out_addr) {
6857
assert(out_addr);
6958

@@ -78,8 +67,8 @@ int os_mmap_aligned(void *hint_addr, size_t length, size_t alignment,
7867
}
7968

8069
// MAP_ANONYMOUS - the mapping is not backed by any file
81-
void *ptr = mmap(hint_addr, extended_length, prot, MAP_ANONYMOUS | flags,
82-
fd, offset);
70+
void *ptr = mmap(hint_addr, extended_length, prot,
71+
MAP_ANONYMOUS | MAP_PRIVATE, fd, offset);
8372
if (ptr == MAP_FAILED) {
8473
return -1;
8574
}

test/provider_os_memory_config.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -188,45 +188,3 @@ TEST_P(providerConfigTestNumaMode, numa_modes) {
188188
}
189189
}
190190
}
191-
192-
struct providerConfigTestVisibility
193-
: providerConfigTest,
194-
testing::WithParamInterface<umf_mem_visibility_t> {
195-
std::string primary_str = "primary";
196-
std::string new_str = "new";
197-
std::string expected_str;
198-
umf_os_memory_provider_params_t params = umfOsMemoryProviderParamsDefault();
199-
200-
void SetUp() override {
201-
providerConfigTest::SetUp();
202-
params.visibility = GetParam();
203-
if (params.visibility == UMF_VISIBILITY_PRIVATE) {
204-
expected_str = primary_str;
205-
} else if (params.visibility == UMF_VISIBILITY_SHARED) {
206-
expected_str = new_str;
207-
}
208-
}
209-
};
210-
211-
INSTANTIATE_TEST_SUITE_P(visibility, providerConfigTestVisibility,
212-
testing::Values(UMF_VISIBILITY_PRIVATE,
213-
UMF_VISIBILITY_SHARED));
214-
215-
TEST_P(providerConfigTestVisibility, visibility) {
216-
create_provider(&params);
217-
allocate_memory();
218-
write_memory(primary_str);
219-
220-
int pid = fork();
221-
if (pid == 0) {
222-
// child process
223-
write_memory(new_str);
224-
} else if (pid > 0) {
225-
// main process
226-
int status;
227-
while (-1 == waitpid(0, &status, 0)) {
228-
// wait for the child process to complete
229-
}
230-
EXPECT_EQ(static_cast<char *>(ptr), expected_str);
231-
}
232-
}

0 commit comments

Comments
 (0)