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

Function large_ralloc_no_move

deps/jemalloc/src/large.c:218–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216}
217
218bool
219large_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, size_t usize_min,
220 size_t usize_max, bool zero) {
221 size_t oldusize = extent_usize_get(extent);
222
223 /* The following should have been caught by callers. */
224 assert(usize_min > 0 && usize_max <= SC_LARGE_MAXCLASS);
225 /* Both allocation sizes must be large to avoid a move. */
226 assert(oldusize >= SC_LARGE_MINCLASS
227 && usize_max >= SC_LARGE_MINCLASS);
228
229 if (usize_max > oldusize) {
230 /* Attempt to expand the allocation in-place. */
231 if (!large_ralloc_no_move_expand(tsdn, extent, usize_max,
232 zero)) {
233 arena_decay_tick(tsdn, extent_arena_get(extent));
234 return false;
235 }
236 /* Try again, this time with usize_min. */
237 if (usize_min < usize_max && usize_min > oldusize &&
238 large_ralloc_no_move_expand(tsdn, extent, usize_min,
239 zero)) {
240 arena_decay_tick(tsdn, extent_arena_get(extent));
241 return false;
242 }
243 }
244
245 /*
246 * Avoid moving the allocation if the existing extent size accommodates
247 * the new size.
248 */
249 if (oldusize >= usize_min && oldusize <= usize_max) {
250 arena_decay_tick(tsdn, extent_arena_get(extent));
251 return false;
252 }
253
254 /* Attempt to shrink the allocation in-place. */
255 if (oldusize > usize_max) {
256 if (!large_ralloc_no_move_shrink(tsdn, extent, usize_max)) {
257 arena_decay_tick(tsdn, extent_arena_get(extent));
258 return false;
259 }
260 }
261 return true;
262}
263
264static void *
265large_ralloc_move_helper(tsdn_t *tsdn, arena_t *arena, size_t usize,

Callers 2

large_rallocFunction · 0.70
arena_ralloc_no_moveFunction · 0.70

Calls 5

extent_usize_getFunction · 0.50
arena_decay_tickFunction · 0.50
extent_arena_getFunction · 0.50

Tested by

no test coverage detected