1 #ifndef JEMALLOC_INTERNAL_EXTENT_STRUCTS_H
2 #define JEMALLOC_INTERNAL_EXTENT_STRUCTS_H
4 #include "jemalloc/internal/atomic.h"
5 #include "jemalloc/internal/bit_util.h"
6 #include "jemalloc/internal/bitmap.h"
7 #include "jemalloc/internal/mutex.h"
8 #include "jemalloc/internal/ql.h"
9 #include "jemalloc/internal/ph.h"
10 #include "jemalloc/internal/sc.h"
13 extent_state_active = 0,
14 extent_state_dirty = 1,
15 extent_state_muzzy = 2,
16 extent_state_retained = 3
19 /* Extent (span of pages). Use accessor functions for e_* fields. */
22 * Bitfield containing several fields:
35 * nnnnnnnn ... nnnnnnss ssssffff ffffffii iiiiiitt zdcbaaaa aaaaaaaa
37 * arena_ind: Arena from which this extent came, or all 1 bits if
40 * slab: The slab flag indicates whether the extent is used for a slab
41 * of small regions. This helps differentiate small size classes,
42 * and it indicates whether interior pointers can be looked up via
45 * committed: The committed flag indicates whether physical memory is
46 * committed to the extent, whether explicitly or implicitly
47 * as on a system that overcommits and satisfies physical
48 * memory needs on demand via soft page faults.
50 * dumpable: The dumpable flag indicates whether or not we've set the
51 * memory in question to be dumpable. Note that this
52 * interacts somewhat subtly with user-specified extent hooks,
53 * since we don't know if *they* are fiddling with
54 * dumpability (in which case, we don't want to undo whatever
55 * they're doing). To deal with this scenario, we:
56 * - Make dumpable false only for memory allocated with the
58 * - Only allow memory to go from non-dumpable to dumpable,
60 * - Never make the OS call to allow dumping when the
61 * dumpable bit is already set.
62 * These three constraints mean that we will never
63 * accidentally dump user memory that the user meant to set
64 * nondumpable with their extent hooks.
67 * zeroed: The zeroed flag is used by extent recycling code to track
68 * whether memory is zero-filled.
70 * state: The state flag is an extent_state_t.
72 * szind: The szind flag indicates usable size class index for
73 * allocations residing in this extent, regardless of whether the
74 * extent is a slab. Extent size and usable size often differ
75 * even for non-slabs, either due to sz_large_pad or promotion of
76 * sampled small regions.
78 * nfree: Number of free regions in slab.
80 * bin_shard: the shard of the bin from which this extent came.
82 * sn: Serial number (potentially non-unique).
84 * Serial numbers may wrap around if !opt_retain, but as long as
85 * comparison functions fall back on address comparison for equal
86 * serial numbers, stable (if imperfect) ordering is maintained.
88 * Serial numbers may not be unique even in the absence of
89 * wrap-around, e.g. when splitting an extent and assigning the same
90 * serial number to both resulting adjacent extents.
93 #define MASK(CURRENT_FIELD_WIDTH, CURRENT_FIELD_SHIFT) ((((((uint64_t)0x1U) << (CURRENT_FIELD_WIDTH)) - 1)) << (CURRENT_FIELD_SHIFT))
95 #define EXTENT_BITS_ARENA_WIDTH MALLOCX_ARENA_BITS
96 #define EXTENT_BITS_ARENA_SHIFT 0
97 #define EXTENT_BITS_ARENA_MASK MASK(EXTENT_BITS_ARENA_WIDTH, EXTENT_BITS_ARENA_SHIFT)
99 #define EXTENT_BITS_SLAB_WIDTH 1
100 #define EXTENT_BITS_SLAB_SHIFT (EXTENT_BITS_ARENA_WIDTH + EXTENT_BITS_ARENA_SHIFT)
101 #define EXTENT_BITS_SLAB_MASK MASK(EXTENT_BITS_SLAB_WIDTH, EXTENT_BITS_SLAB_SHIFT)
103 #define EXTENT_BITS_COMMITTED_WIDTH 1
104 #define EXTENT_BITS_COMMITTED_SHIFT (EXTENT_BITS_SLAB_WIDTH + EXTENT_BITS_SLAB_SHIFT)
105 #define EXTENT_BITS_COMMITTED_MASK MASK(EXTENT_BITS_COMMITTED_WIDTH, EXTENT_BITS_COMMITTED_SHIFT)
107 #define EXTENT_BITS_DUMPABLE_WIDTH 1
108 #define EXTENT_BITS_DUMPABLE_SHIFT (EXTENT_BITS_COMMITTED_WIDTH + EXTENT_BITS_COMMITTED_SHIFT)
109 #define EXTENT_BITS_DUMPABLE_MASK MASK(EXTENT_BITS_DUMPABLE_WIDTH, EXTENT_BITS_DUMPABLE_SHIFT)
111 #define EXTENT_BITS_ZEROED_WIDTH 1
112 #define EXTENT_BITS_ZEROED_SHIFT (EXTENT_BITS_DUMPABLE_WIDTH + EXTENT_BITS_DUMPABLE_SHIFT)
113 #define EXTENT_BITS_ZEROED_MASK MASK(EXTENT_BITS_ZEROED_WIDTH, EXTENT_BITS_ZEROED_SHIFT)
115 #define EXTENT_BITS_STATE_WIDTH 2
116 #define EXTENT_BITS_STATE_SHIFT (EXTENT_BITS_ZEROED_WIDTH + EXTENT_BITS_ZEROED_SHIFT)
117 #define EXTENT_BITS_STATE_MASK MASK(EXTENT_BITS_STATE_WIDTH, EXTENT_BITS_STATE_SHIFT)
119 #define EXTENT_BITS_SZIND_WIDTH LG_CEIL(SC_NSIZES)
120 #define EXTENT_BITS_SZIND_SHIFT (EXTENT_BITS_STATE_WIDTH + EXTENT_BITS_STATE_SHIFT)
121 #define EXTENT_BITS_SZIND_MASK MASK(EXTENT_BITS_SZIND_WIDTH, EXTENT_BITS_SZIND_SHIFT)
123 #define EXTENT_BITS_NFREE_WIDTH (LG_SLAB_MAXREGS + 1)
124 #define EXTENT_BITS_NFREE_SHIFT (EXTENT_BITS_SZIND_WIDTH + EXTENT_BITS_SZIND_SHIFT)
125 #define EXTENT_BITS_NFREE_MASK MASK(EXTENT_BITS_NFREE_WIDTH, EXTENT_BITS_NFREE_SHIFT)
127 #define EXTENT_BITS_BINSHARD_WIDTH 6
128 #define EXTENT_BITS_BINSHARD_SHIFT (EXTENT_BITS_NFREE_WIDTH + EXTENT_BITS_NFREE_SHIFT)
129 #define EXTENT_BITS_BINSHARD_MASK MASK(EXTENT_BITS_BINSHARD_WIDTH, EXTENT_BITS_BINSHARD_SHIFT)
131 #define EXTENT_BITS_IS_HEAD_WIDTH 1
132 #define EXTENT_BITS_IS_HEAD_SHIFT (EXTENT_BITS_BINSHARD_WIDTH + EXTENT_BITS_BINSHARD_SHIFT)
133 #define EXTENT_BITS_IS_HEAD_MASK MASK(EXTENT_BITS_IS_HEAD_WIDTH, EXTENT_BITS_IS_HEAD_SHIFT)
135 #define EXTENT_BITS_SN_SHIFT (EXTENT_BITS_IS_HEAD_WIDTH + EXTENT_BITS_IS_HEAD_SHIFT)
136 #define EXTENT_BITS_SN_MASK (UINT64_MAX << EXTENT_BITS_SN_SHIFT)
138 /* Pointer to the extent that this structure is responsible for. */
143 * Extent size and serial number associated with the extent
144 * structure (different than the serial number for the extent at
147 * ssssssss [...] ssssssss ssssnnnn nnnnnnnn
150 #define EXTENT_SIZE_MASK ((size_t)~(PAGE-1))
151 #define EXTENT_ESN_MASK ((size_t)PAGE-1)
152 /* Base extent size, which may not be a multiple of PAGE. */
157 * List linkage, used by a variety of lists:
158 * - bin_t's slabs_full
160 * - stashed dirty extents
161 * - arena's large allocations
163 ql_elm(extent_t) ql_link;
166 * Linkage for per size class sn/address-ordered heaps, and
169 phn(extent_t) ph_link;
172 /* Small region slab metadata. */
173 arena_slab_data_t e_slab_data;
175 /* Profiling data, used for large objects. */
177 /* Time when this was allocated. */
178 nstime_t e_alloc_time;
179 /* Points to a prof_tctx_t. */
180 atomic_p_t e_prof_tctx;
184 typedef ql_head(extent_t) extent_list_t;
185 typedef ph(extent_t) extent_tree_t;
186 typedef ph(extent_t) extent_heap_t;
188 /* Quantized collection of extents, with built-in LRU queue. */
193 * Quantized per size class heaps of extents.
195 * Synchronization: mtx.
197 extent_heap_t heaps[SC_NPSIZES + 1];
198 atomic_zu_t nextents[SC_NPSIZES + 1];
199 atomic_zu_t nbytes[SC_NPSIZES + 1];
202 * Bitmap for which set bits correspond to non-empty heaps.
204 * Synchronization: mtx.
206 bitmap_t bitmap[BITMAP_GROUPS(SC_NPSIZES + 1)];
209 * LRU of all extents in heaps.
211 * Synchronization: mtx.
216 * Page sum for all extents in heaps.
218 * The synchronization here is a little tricky. Modifications to npages
219 * must hold mtx, but reads need not (though, a reader who sees npages
220 * without holding the mutex can't assume anything about the rest of the
221 * state of the extents_t).
225 /* All stored extents must be in the same state. */
226 extent_state_t state;
229 * If true, delay coalescing until eviction; otherwise coalesce during
236 * The following two structs are for experimental purposes. See
237 * experimental_utilization_query_ctl and
238 * experimental_utilization_batch_query_ctl in src/ctl.c.
241 struct extent_util_stats_s {
247 struct extent_util_stats_verbose_s {
256 #endif /* JEMALLOC_INTERNAL_EXTENT_STRUCTS_H */