|
8 | 8 | #include "jemalloc/internal/witness.h" |
9 | 9 | #include "jemalloc/internal/jemalloc_probe.h" |
10 | 10 |
|
11 | | -#define HPA_EDEN_SIZE (128 * HUGEPAGE) |
12 | | - |
13 | 11 | static edata_t *hpa_alloc(tsdn_t *tsdn, pai_t *self, size_t size, |
14 | 12 | size_t alignment, bool zero, bool guarded, bool frequent_reuse, |
15 | 13 | bool *deferred_work_generated); |
@@ -74,119 +72,6 @@ hpa_do_consistency_checks(hpa_shard_t *shard) { |
74 | 72 | assert(shard->base != NULL); |
75 | 73 | } |
76 | 74 |
|
77 | | -bool |
78 | | -hpa_central_init( |
79 | | - hpa_central_t *central, base_t *base, const hpa_hooks_t *hooks) { |
80 | | - /* malloc_conf processing should have filtered out these cases. */ |
81 | | - assert(hpa_supported()); |
82 | | - bool err; |
83 | | - err = malloc_mutex_init(¢ral->grow_mtx, "hpa_central_grow", |
84 | | - WITNESS_RANK_HPA_CENTRAL_GROW, malloc_mutex_rank_exclusive); |
85 | | - if (err) { |
86 | | - return true; |
87 | | - } |
88 | | - |
89 | | - central->base = base; |
90 | | - central->eden = NULL; |
91 | | - central->eden_len = 0; |
92 | | - central->hooks = *hooks; |
93 | | - return false; |
94 | | -} |
95 | | - |
96 | | -static hpdata_t * |
97 | | -hpa_alloc_ps(tsdn_t *tsdn, hpa_central_t *central) { |
98 | | - return (hpdata_t *)base_alloc( |
99 | | - tsdn, central->base, sizeof(hpdata_t), CACHELINE); |
100 | | -} |
101 | | - |
102 | | -static hpdata_t * |
103 | | -hpa_central_extract(tsdn_t *tsdn, hpa_central_t *central, size_t size, |
104 | | - uint64_t age, bool hugify_eager, bool *oom) { |
105 | | - /* Don't yet support big allocations; these should get filtered out. */ |
106 | | - assert(size <= HUGEPAGE); |
107 | | - /* |
108 | | - * Should only try to extract from the central allocator if the local |
109 | | - * shard is exhausted. We should hold the grow_mtx on that shard. |
110 | | - */ |
111 | | - witness_assert_positive_depth_to_rank( |
112 | | - tsdn_witness_tsdp_get(tsdn), WITNESS_RANK_HPA_SHARD_GROW); |
113 | | - |
114 | | - malloc_mutex_lock(tsdn, ¢ral->grow_mtx); |
115 | | - *oom = false; |
116 | | - |
117 | | - hpdata_t *ps = NULL; |
118 | | - bool start_as_huge = hugify_eager |
119 | | - || (init_system_thp_mode == system_thp_mode_always |
120 | | - && opt_experimental_hpa_start_huge_if_thp_always); |
121 | | - |
122 | | - /* Is eden a perfect fit? */ |
123 | | - if (central->eden != NULL && central->eden_len == HUGEPAGE) { |
124 | | - ps = hpa_alloc_ps(tsdn, central); |
125 | | - if (ps == NULL) { |
126 | | - *oom = true; |
127 | | - malloc_mutex_unlock(tsdn, ¢ral->grow_mtx); |
128 | | - return NULL; |
129 | | - } |
130 | | - hpdata_init(ps, central->eden, age, start_as_huge); |
131 | | - central->eden = NULL; |
132 | | - central->eden_len = 0; |
133 | | - malloc_mutex_unlock(tsdn, ¢ral->grow_mtx); |
134 | | - return ps; |
135 | | - } |
136 | | - |
137 | | - /* |
138 | | - * We're about to try to allocate from eden by splitting. If eden is |
139 | | - * NULL, we have to allocate it too. Otherwise, we just have to |
140 | | - * allocate an edata_t for the new psset. |
141 | | - */ |
142 | | - if (central->eden == NULL) { |
143 | | - /* Allocate address space, bailing if we fail. */ |
144 | | - void *new_eden = central->hooks.map(HPA_EDEN_SIZE); |
145 | | - if (new_eden == NULL) { |
146 | | - *oom = true; |
147 | | - malloc_mutex_unlock(tsdn, ¢ral->grow_mtx); |
148 | | - return NULL; |
149 | | - } |
150 | | - if (hugify_eager) { |
151 | | - central->hooks.hugify( |
152 | | - new_eden, HPA_EDEN_SIZE, /* sync */ false); |
153 | | - } |
154 | | - ps = hpa_alloc_ps(tsdn, central); |
155 | | - if (ps == NULL) { |
156 | | - central->hooks.unmap(new_eden, HPA_EDEN_SIZE); |
157 | | - *oom = true; |
158 | | - malloc_mutex_unlock(tsdn, ¢ral->grow_mtx); |
159 | | - return NULL; |
160 | | - } |
161 | | - central->eden = new_eden; |
162 | | - central->eden_len = HPA_EDEN_SIZE; |
163 | | - } else { |
164 | | - /* Eden is already nonempty; only need an edata for ps. */ |
165 | | - ps = hpa_alloc_ps(tsdn, central); |
166 | | - if (ps == NULL) { |
167 | | - *oom = true; |
168 | | - malloc_mutex_unlock(tsdn, ¢ral->grow_mtx); |
169 | | - return NULL; |
170 | | - } |
171 | | - } |
172 | | - assert(ps != NULL); |
173 | | - assert(central->eden != NULL); |
174 | | - assert(central->eden_len > HUGEPAGE); |
175 | | - assert(central->eden_len % HUGEPAGE == 0); |
176 | | - assert(HUGEPAGE_ADDR2BASE(central->eden) == central->eden); |
177 | | - |
178 | | - hpdata_init(ps, central->eden, age, start_as_huge); |
179 | | - |
180 | | - char *eden_char = (char *)central->eden; |
181 | | - eden_char += HUGEPAGE; |
182 | | - central->eden = (void *)eden_char; |
183 | | - central->eden_len -= HUGEPAGE; |
184 | | - |
185 | | - malloc_mutex_unlock(tsdn, ¢ral->grow_mtx); |
186 | | - |
187 | | - return ps; |
188 | | -} |
189 | | - |
190 | 75 | bool |
191 | 76 | hpa_shard_init(hpa_shard_t *shard, hpa_central_t *central, emap_t *emap, |
192 | 77 | base_t *base, edata_cache_t *edata_cache, unsigned ind, |
|
0 commit comments