Skip to content

Commit 26742ec

Browse files
authored
Merge pull request #10478 from hoopoepg/topic/oshmem-dynamic-segment-allocation
MEMHEAP/BASE: removed hard segments limit
2 parents 31d719d + 1b26bbd commit 26742ec

File tree

7 files changed

+141
-129
lines changed

7 files changed

+141
-129
lines changed

oshmem/mca/memheap/base/base.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ OSHMEM_DECLSPEC int mca_memheap_base_select(void);
4040

4141
extern int mca_memheap_base_already_opened;
4242
extern int mca_memheap_base_key_exchange;
43+
extern int mca_memheap_num_segments_warn;
4344

44-
#define MCA_MEMHEAP_MAX_SEGMENTS 32
4545
#define HEAP_SEG_INDEX 0
4646
#define MCA_MEMHEAP_SEG_COUNT 2
4747

@@ -54,8 +54,9 @@ typedef struct mca_memheap_base_config {
5454

5555

5656
typedef struct mca_memheap_map {
57-
map_segment_t mem_segs[MCA_MEMHEAP_MAX_SEGMENTS]; /* TODO: change into pointer array */
57+
map_segment_t *mem_segs;
5858
int n_segments;
59+
int capacity;
5960
int num_transports;
6061
} mca_memheap_map_t;
6162

@@ -70,6 +71,7 @@ int mca_memheap_base_reg(mca_memheap_map_t *);
7071
int mca_memheap_base_dereg(mca_memheap_map_t *);
7172
int memheap_oob_init(mca_memheap_map_t *);
7273
void memheap_oob_destruct(void);
74+
map_segment_t *mca_memheap_base_allocate_segment(mca_memheap_map_t *map);
7375

7476
OSHMEM_DECLSPEC int mca_memheap_base_is_symmetric_addr(const void* va);
7577
OSHMEM_DECLSPEC sshmem_mkey_t *mca_memheap_base_get_mkey(void* va,

oshmem/mca/memheap/base/memheap_base_alloc.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "oshmem/mca/memheap/memheap.h"
1919
#include "oshmem/mca/memheap/base/base.h"
2020
#include "ompi/util/timings.h"
21+
#include "opal/util/minmax.h"
2122

2223

2324
int mca_memheap_base_alloc_init(mca_memheap_map_t *map, size_t size, long hint,
@@ -35,7 +36,12 @@ int mca_memheap_base_alloc_init(mca_memheap_map_t *map, size_t size, long hint,
3536
assert(HEAP_SEG_INDEX < map->n_segments);
3637
}
3738

38-
map_segment_t *s = &map->mem_segs[map->n_segments];
39+
map_segment_t *s = mca_memheap_base_allocate_segment(map);
40+
if (NULL == s) {
41+
MEMHEAP_ERROR("failed to allocate segment");
42+
return OSHMEM_ERR_OUT_OF_RESOURCE;
43+
}
44+
3945
seg_filename = oshmem_get_unique_file_name(oshmem_my_proc_id());
4046

4147
OPAL_TIMING_ENV_NEXT(timing, "oshmem_get_unique_file_name()");
@@ -72,6 +78,11 @@ void mca_memheap_base_alloc_exit(mca_memheap_map_t *map)
7278
mca_sshmem_unlink(s);
7379
}
7480
}
81+
82+
free(map->mem_segs);
83+
map->n_segments = 0;
84+
map->capacity = 0;
85+
map->mem_segs = NULL;
7586
}
7687

7788
int mca_memheap_alloc_with_hint(size_t size, long hint, void** ptr)
@@ -90,3 +101,33 @@ int mca_memheap_alloc_with_hint(size_t size, long hint, void** ptr)
90101

91102
return MCA_MEMHEAP_CALL(alloc(size, ptr));
92103
}
104+
105+
map_segment_t *mca_memheap_base_allocate_segment(mca_memheap_map_t *map)
106+
{
107+
static int warned = 0;
108+
map_segment_t *segments;
109+
int capacity;
110+
111+
assert(map->n_segments <= map->capacity);
112+
113+
if (!warned && (map->n_segments > mca_memheap_num_segments_warn)) {
114+
MEMHEAP_WARN("too many segments are registered: %d. This may cause "
115+
"performance degradation. Pls try adding --mca "
116+
"memheap_base_max_segments <NUMBER> to mpirun/oshrun "
117+
"command line to suppress this message", map->n_segments);
118+
warned = 1;
119+
}
120+
121+
if (map->n_segments == map->capacity) {
122+
capacity = opal_max(map->capacity * 2, 4);
123+
segments = realloc(map->mem_segs, capacity * sizeof(*map->mem_segs));
124+
if (segments == NULL) {
125+
return NULL;
126+
}
127+
128+
map->capacity = capacity;
129+
map->mem_segs = segments;
130+
}
131+
132+
return &map->mem_segs[map->n_segments];
133+
}

oshmem/mca/memheap/base/memheap_base_frame.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int mca_memheap_base_key_exchange = 1;
3636
opal_list_t mca_memheap_base_components_opened = {{0}};
3737
int mca_memheap_base_already_opened = 0;
3838
mca_memheap_map_t mca_memheap_base_map = {{{{0}}}};
39+
int mca_memheap_num_segments_warn = 32;
3940

4041
static int mca_memheap_base_register(mca_base_register_flag_t flags)
4142
{
@@ -59,6 +60,14 @@ static int mca_memheap_base_register(mca_base_register_flag_t flags)
5960
MCA_BASE_VAR_SCOPE_LOCAL,
6061
&mca_memheap_base_config.device_nic_mem_seg_size);
6162

63+
mca_base_var_register("oshmem", "memheap", "base", "max_segments",
64+
"Display a warning if the number of segments of the "
65+
"shared memheap exceeds this value",
66+
MCA_BASE_VAR_TYPE_INT, NULL, 0,
67+
MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_3,
68+
MCA_BASE_VAR_SCOPE_LOCAL,
69+
&mca_memheap_num_segments_warn);
70+
6271
return OSHMEM_SUCCESS;
6372
}
6473

oshmem/mca/memheap/base/memheap_base_mkey.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,6 @@ void mkey_segment_init(mkey_segment_t *seg, sshmem_mkey_t *mkey, uint32_t segno)
766766
{
767767
map_segment_t *s;
768768

769-
if (segno >= MCA_MEMHEAP_MAX_SEGMENTS) {
770-
return;
771-
}
772-
773769
s = memheap_find_seg(segno);
774770
assert(NULL != s);
775771
seg->super.va_base = s->super.va_base;

0 commit comments

Comments
 (0)