MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / base_auto_thp_switch

Function base_auto_thp_switch

deps/jemalloc/src/base.c:143–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143static void
144base_auto_thp_switch(tsdn_t *tsdn, base_t *base) {
145 assert(opt_metadata_thp == metadata_thp_auto);
146 malloc_mutex_assert_owner(tsdn, &base->mtx);
147 if (base->auto_thp_switched) {
148 return;
149 }
150 /* Called when adding a new block. */
151 bool should_switch;
152 if (base_ind_get(base) != 0) {
153 should_switch = (base_get_num_blocks(base, true) ==
154 BASE_AUTO_THP_THRESHOLD);
155 } else {
156 should_switch = (base_get_num_blocks(base, true) ==
157 BASE_AUTO_THP_THRESHOLD_A0);
158 }
159 if (!should_switch) {
160 return;
161 }
162
163 base->auto_thp_switched = true;
164 assert(!config_stats || base->n_thp == 0);
165 /* Make the initial blocks THP lazily. */
166 base_block_t *block = base->blocks;
167 while (block != NULL) {
168 assert((block->size & HUGEPAGE_MASK) == 0);
169 pages_huge(block, block->size);
170 if (config_stats) {
171 base->n_thp += HUGEPAGE_CEILING(block->size -
172 extent_bsize_get(&block->extent)) >> LG_HUGEPAGE;
173 }
174 block = block->next;
175 assert(block == NULL || (base_ind_get(base) == 0));
176 }
177}
178
179static void *
180base_extent_bump_alloc_helper(extent_t *extent, size_t *gap_size, size_t size,

Callers 1

base_block_allocFunction · 0.85

Calls 5

base_get_num_blocksFunction · 0.85
pages_hugeFunction · 0.70
base_ind_getFunction · 0.50
extent_bsize_getFunction · 0.50

Tested by

no test coverage detected