xref: /netbsd-src/external/bsd/jemalloc/dist/include/jemalloc/internal/exp_grow.h (revision 32d1c65c71fbdb65a012e8392a62a757dd6853e9)
1 #ifndef JEMALLOC_INTERNAL_EXP_GROW_H
2 #define JEMALLOC_INTERNAL_EXP_GROW_H
3 
4 typedef struct exp_grow_s exp_grow_t;
5 struct exp_grow_s {
6 	/*
7 	 * Next extent size class in a growing series to use when satisfying a
8 	 * request via the extent hooks (only if opt_retain).  This limits the
9 	 * number of disjoint virtual memory ranges so that extent merging can
10 	 * be effective even if multiple arenas' extent allocation requests are
11 	 * highly interleaved.
12 	 *
13 	 * retain_grow_limit is the max allowed size ind to expand (unless the
14 	 * required size is greater).  Default is no limit, and controlled
15 	 * through mallctl only.
16 	 */
17 	pszind_t next;
18 	pszind_t limit;
19 };
20 
21 static inline bool
22 exp_grow_size_prepare(exp_grow_t *exp_grow, size_t alloc_size_min,
23     size_t *r_alloc_size, pszind_t *r_skip) {
24 	*r_skip = 0;
25 	*r_alloc_size = sz_pind2sz(exp_grow->next + *r_skip);
26 	while (*r_alloc_size < alloc_size_min) {
27 		(*r_skip)++;
28 		if (exp_grow->next + *r_skip  >=
29 		    sz_psz2ind(SC_LARGE_MAXCLASS)) {
30 			/* Outside legal range. */
31 			return true;
32 		}
33 		*r_alloc_size = sz_pind2sz(exp_grow->next + *r_skip);
34 	}
35 	return false;
36 }
37 
38 static inline void
39 exp_grow_size_commit(exp_grow_t *exp_grow, pszind_t skip) {
40 	if (exp_grow->next + skip + 1 <= exp_grow->limit) {
41 		exp_grow->next += skip + 1;
42 	} else {
43 		exp_grow->next = exp_grow->limit;
44 	}
45 
46 }
47 
48 void exp_grow_init(exp_grow_t *exp_grow);
49 
50 #endif /* JEMALLOC_INTERNAL_EXP_GROW_H */
51