This source file includes following definitions.
- mca_memheap_base_alloc_init
- mca_memheap_base_alloc_exit
- mca_memheap_alloc_with_hint
1
2
3
4
5
6
7
8
9
10
11
12
13 #include "oshmem_config.h"
14
15 #include "oshmem/util/oshmem_util.h"
16 #include "oshmem/mca/sshmem/sshmem.h"
17 #include "oshmem/mca/sshmem/base/base.h"
18 #include "oshmem/mca/memheap/memheap.h"
19 #include "oshmem/mca/memheap/base/base.h"
20
21
22 int mca_memheap_base_alloc_init(mca_memheap_map_t *map, size_t size, long hint)
23 {
24 int ret = OSHMEM_SUCCESS;
25 char * seg_filename = NULL;
26
27 assert(map);
28 if (hint == 0) {
29 assert(HEAP_SEG_INDEX == map->n_segments);
30 } else {
31 assert(HEAP_SEG_INDEX < map->n_segments);
32 }
33
34 map_segment_t *s = &map->mem_segs[map->n_segments];
35 seg_filename = oshmem_get_unique_file_name(oshmem_my_proc_id());
36 ret = mca_sshmem_segment_create(s, seg_filename, size, hint);
37
38 if (OSHMEM_SUCCESS == ret) {
39 map->n_segments++;
40 MEMHEAP_VERBOSE(1,
41 "Memheap alloc memory: %llu byte(s), %d segments by method: %d",
42 (unsigned long long)size, map->n_segments, s->type);
43 }
44
45 free(seg_filename);
46
47 return ret;
48 }
49
50 void mca_memheap_base_alloc_exit(mca_memheap_map_t *map)
51 {
52 int i;
53
54 if (!map) {
55 return;
56 }
57
58 for (i = 0; i < map->n_segments; ++i) {
59 map_segment_t *s = &map->mem_segs[i];
60 if (s->type != MAP_SEGMENT_STATIC) {
61 mca_sshmem_segment_detach(s, NULL);
62 mca_sshmem_unlink(s);
63 }
64 }
65 }
66
67 int mca_memheap_alloc_with_hint(size_t size, long hint, void** ptr)
68 {
69 int i;
70
71 for (i = 0; i < mca_memheap_base_map.n_segments; i++) {
72 map_segment_t *s = &mca_memheap_base_map.mem_segs[i];
73 if (s->allocator && (hint && s->alloc_hints)) {
74
75
76
77 return s->allocator->realloc(s, size, NULL, ptr);
78 }
79 }
80
81 return MCA_MEMHEAP_CALL(alloc(size, ptr));
82 }