ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
malloc.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
8 #ifdef ABT_CONFIG_USE_MEM_POOL
9 /* Currently the total memory allocated for stacks and task block pages is not
10  * shrunk to avoid the thrashing overhead except that ESs are terminated or
11  * ABT_finalize is called. When an ES terminates its execution, stacks and
12  * empty pages that it holds are deallocated. Non-empty pages are added to the
13  * global data. When ABTI_finalize is called, all memory objects that we have
14  * allocated are returned to the higher-level memory allocator. */
15 
16 void ABTI_mem_init(ABTI_global *p_global)
17 {
18  int num_requested_types = 0;
19  ABTU_MEM_LARGEPAGE_TYPE requested_types[3];
20  switch (gp_ABTI_global->mem_lp_alloc) {
22  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MMAP;
23  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MALLOC;
24  break;
26  requested_types[num_requested_types++] =
28  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MMAP;
29  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MALLOC;
30  break;
32  requested_types[num_requested_types++] =
34  requested_types[num_requested_types++] =
36  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MALLOC;
37  break;
38  case ABTI_MEM_LP_THP:
39  requested_types[num_requested_types++] =
41  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MALLOC;
42  break;
43  default:
44  requested_types[num_requested_types++] = ABTU_MEM_LARGEPAGE_MALLOC;
45  break;
46  }
47  size_t thread_stacksize = p_global->thread_stacksize;
48  ABTI_ASSERT((thread_stacksize & (ABT_CONFIG_STATIC_CACHELINE_SIZE - 1)) ==
49  0);
50  size_t stacksize = (thread_stacksize + sizeof(ABTI_ythread) +
53  if ((stacksize & (2 * ABT_CONFIG_STATIC_CACHELINE_SIZE - 1)) == 0) {
54  /* Avoid a multiple of 2 * cacheline size to avoid cache bank conflict.
55  */
57  }
59  p_global->mem_max_stacks /
61  stacksize, thread_stacksize,
62  p_global->mem_sp_size, requested_types,
63  num_requested_types,
65  /* The last four bytes will be used to store a mempool flag */
69  p_global->mem_max_descs /
72  p_global->mem_page_size, requested_types,
73  num_requested_types,
75 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
78  &p_global->mem_pool_stack);
81  &p_global->mem_pool_desc);
82 #endif
83 }
84 
85 void ABTI_mem_init_local(ABTI_xstream *p_local_xstream)
86 {
91 }
92 
93 void ABTI_mem_finalize(ABTI_global *p_global)
94 {
95 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD
98 #endif
101 }
102 
103 void ABTI_mem_finalize_local(ABTI_xstream *p_local_xstream)
104 {
107 }
108 
109 int ABTI_mem_check_lp_alloc(int lp_alloc)
110 {
111  size_t sp_size = gp_ABTI_global->mem_sp_size;
112  size_t pg_size = gp_ABTI_global->mem_page_size;
113  size_t alignment = ABT_CONFIG_STATIC_CACHELINE_SIZE;
114  switch (lp_alloc) {
115  case ABTI_MEM_LP_MMAP_RP:
116  if (ABTU_is_supported_largepage_type(pg_size, alignment,
118  return ABTI_MEM_LP_MMAP_RP;
119  } else {
120  return ABTI_MEM_LP_MALLOC;
121  }
124  sp_size, alignment, ABTU_MEM_LARGEPAGE_MMAP_HUGEPAGE)) {
125  return ABTI_MEM_LP_MMAP_HP_RP;
126  } else if (
127  ABTU_is_supported_largepage_type(pg_size, alignment,
129  return ABTI_MEM_LP_MMAP_RP;
130  } else {
131  return ABTI_MEM_LP_MALLOC;
132  }
135  sp_size, alignment, ABTU_MEM_LARGEPAGE_MMAP_HUGEPAGE)) {
137  } else if (
141  return ABTI_MEM_LP_THP;
142  } else {
143  return ABTI_MEM_LP_MALLOC;
144  }
145  case ABTI_MEM_LP_THP:
149  return ABTI_MEM_LP_THP;
150  } else {
151  return ABTI_MEM_LP_MALLOC;
152  }
153  default:
154  return ABTI_MEM_LP_MALLOC;
155  }
156 }
157 
158 #else /* !ABT_CONFIG_USE_MEM_POOL */
159 
160 void ABTI_mem_init(ABTI_global *p_global)
161 {
162 }
163 
164 void ABTI_mem_init_local(ABTI_xstream *p_local_xstream)
165 {
166 }
167 
169 {
170 }
171 
172 void ABTI_mem_finalize_local(ABTI_xstream *p_local_xstream)
173 {
174 }
175 
176 #endif /* !ABT_CONFIG_USE_MEM_POOL */
ABTI_spinlock mem_pool_stack_lock
Definition: abti.h:204
int mem_lp_alloc
Definition: abti.h:197
void ABTI_mem_init(ABTI_global *p_global)
Definition: malloc.c:160
#define ABT_MEM_POOL_MAX_LOCAL_BUCKETS
Definition: abti_mem_pool.h:9
void ABTI_mem_pool_init_local_pool(ABTI_mem_pool_local_pool *p_local_pool, ABTI_mem_pool_global_pool *p_global_pool)
Definition: mem_pool.c:128
struct ABTI_ythread ABTI_ythread
Definition: abti.h:113
int ABTI_mem_check_lp_alloc(int lp_alloc)
static void ABTI_spinlock_clear(ABTI_spinlock *p_lock)
Definition: abti_spinlock.h:18
ABTI_mem_pool_global_pool mem_pool_stack
Definition: abti.h:199
#define ABT_CONFIG_STATIC_CACHELINE_SIZE
Definition: abt_config.h:57
uint32_t mem_page_size
Definition: abti.h:193
int ABTU_is_supported_largepage_type(size_t size, size_t alignment_hint, ABTU_MEM_LARGEPAGE_TYPE requested)
Definition: largepage.c:59
void ABTI_mem_pool_destroy_local_pool(ABTI_mem_pool_local_pool *p_local_pool)
Definition: mem_pool.c:142
ABTI_global * gp_ABTI_global
Definition: global.c:18
uint32_t huge_page_size
Definition: abti.h:191
void ABTI_mem_finalize_local(ABTI_xstream *p_local_xstream)
Definition: malloc.c:172
void ABTI_mem_pool_destroy_global_pool(ABTI_mem_pool_global_pool *p_global_pool)
Definition: mem_pool.c:105
void ABTI_mem_init_local(ABTI_xstream *p_local_xstream)
Definition: malloc.c:164
void ABTI_mem_finalize(ABTI_global *p_global)
Definition: malloc.c:168
ABTI_mem_pool_local_pool mem_pool_desc_ext
Definition: abti.h:207
ABTI_mem_pool_local_pool mem_pool_desc
Definition: abti.h:255
ABTI_mem_pool_local_pool mem_pool_stack_ext
Definition: abti.h:205
void ABTI_mem_pool_init_global_pool(ABTI_mem_pool_global_pool *p_global_pool, int num_headers_per_bucket, size_t header_size, size_t header_offset, size_t page_size, const ABTU_MEM_LARGEPAGE_TYPE *lp_type_requests, int num_lp_type_requests, size_t alignment_hint)
Definition: mem_pool.c:77
ABTU_MEM_LARGEPAGE_TYPE
Definition: abtu.h:218
ABTI_spinlock mem_pool_desc_lock
Definition: abti.h:206
uint32_t mem_max_descs
Definition: abti.h:196
#define ABTI_ASSERT(cond)
Definition: abti_error.h:12
uint32_t mem_max_stacks
Definition: abti.h:195
uint32_t mem_sp_size
Definition: abti.h:194
#define ABTI_STATIC_ASSERT(cond)
Definition: abti_error.h:19
#define ABTI_MEM_POOL_DESC_ELEM_SIZE
Definition: abti_mem.h:14
size_t thread_stacksize
Definition: abti.h:182
ABTI_mem_pool_global_pool mem_pool_desc
Definition: abti.h:200
ABTI_mem_pool_local_pool mem_pool_stack
Definition: abti.h:254