blob: 2f99debf7477659ff8f0e807c5ce9bfcd38efaf7 [file] [log] [blame]
Jason Evanse476f8a2010-01-16 09:53:50 -08001/******************************************************************************/
2#ifdef JEMALLOC_H_TYPES
3
4typedef struct extent_node_s extent_node_t;
5
6#endif /* JEMALLOC_H_TYPES */
7/******************************************************************************/
8#ifdef JEMALLOC_H_STRUCTS
9
Jason Evansee41ad42015-02-15 18:04:46 -080010/* Tree of extents. Use accessor functions for en_* fields. */
Jason Evanse476f8a2010-01-16 09:53:50 -080011struct extent_node_s {
Jason Evanscbf3a6d2015-02-11 12:24:27 -080012 /* Arena from which this extent came, if any. */
Jason Evansee41ad42015-02-15 18:04:46 -080013 arena_t *en_arena;
Jason Evans6109fe02010-02-10 10:37:56 -080014
Jason Evanse476f8a2010-01-16 09:53:50 -080015 /* Pointer to the extent that this tree node is responsible for. */
Jason Evansee41ad42015-02-15 18:04:46 -080016 void *en_addr;
17
18 /* Total region size. */
19 size_t en_size;
Jason Evanse476f8a2010-01-16 09:53:50 -080020
Jason Evanscbf3a6d2015-02-11 12:24:27 -080021 /*
Jason Evansee41ad42015-02-15 18:04:46 -080022 * The zeroed flag is used by chunk recycling code to track whether
23 * memory is zero-filled.
Jason Evanscbf3a6d2015-02-11 12:24:27 -080024 */
Jason Evansee41ad42015-02-15 18:04:46 -080025 bool en_zeroed;
Jason Evans7de92762012-10-08 17:56:11 -070026
Jason Evans918a1a52015-01-30 21:21:16 -080027 /*
Jason Evansee41ad42015-02-15 18:04:46 -080028 * The achunk flag is used to validate that huge allocation lookups
29 * don't return arena chunks.
Jason Evans918a1a52015-01-30 21:21:16 -080030 */
Jason Evansee41ad42015-02-15 18:04:46 -080031 bool en_achunk;
32
Jason Evansa4e18882015-02-17 15:13:52 -080033 /* Profile counters, used for huge objects. */
34 prof_tctx_t *en_prof_tctx;
Jason Evans918a1a52015-01-30 21:21:16 -080035
Jason Evansa4e18882015-02-17 15:13:52 -080036 /* Linkage for arena's runs_dirty and chunks_dirty rings. */
37 qr(extent_node_t) cd_link;
38 arena_chunk_map_misc_t runs_dirty;
Jason Evanscbf3a6d2015-02-11 12:24:27 -080039
40 union {
41 /* Linkage for the size/address-ordered tree. */
Jason Evans2195ba42015-02-15 16:43:52 -080042 rb_node(extent_node_t) szad_link;
Jason Evanscbf3a6d2015-02-11 12:24:27 -080043
Jason Evansee41ad42015-02-15 18:04:46 -080044 /* Linkage for arena's huge and node_cache lists. */
Jason Evans2195ba42015-02-15 16:43:52 -080045 ql_elm(extent_node_t) ql_link;
Jason Evanscbf3a6d2015-02-11 12:24:27 -080046 };
47
48 /* Linkage for the address-ordered tree. */
Jason Evans2195ba42015-02-15 16:43:52 -080049 rb_node(extent_node_t) ad_link;
Jason Evanse476f8a2010-01-16 09:53:50 -080050};
51typedef rb_tree(extent_node_t) extent_tree_t;
52
53#endif /* JEMALLOC_H_STRUCTS */
54/******************************************************************************/
55#ifdef JEMALLOC_H_EXTERNS
56
Jason Evanse476f8a2010-01-16 09:53:50 -080057rb_proto(, extent_tree_szad_, extent_tree_t, extent_node_t)
Jason Evanse476f8a2010-01-16 09:53:50 -080058
59rb_proto(, extent_tree_ad_, extent_tree_t, extent_node_t)
60
61#endif /* JEMALLOC_H_EXTERNS */
62/******************************************************************************/
63#ifdef JEMALLOC_H_INLINES
64
Jason Evansee41ad42015-02-15 18:04:46 -080065#ifndef JEMALLOC_ENABLE_INLINE
66arena_t *extent_node_arena_get(const extent_node_t *node);
67void *extent_node_addr_get(const extent_node_t *node);
68size_t extent_node_size_get(const extent_node_t *node);
69bool extent_node_zeroed_get(const extent_node_t *node);
70bool extent_node_achunk_get(const extent_node_t *node);
71prof_tctx_t *extent_node_prof_tctx_get(const extent_node_t *node);
72void extent_node_arena_set(extent_node_t *node, arena_t *arena);
73void extent_node_addr_set(extent_node_t *node, void *addr);
74void extent_node_size_set(extent_node_t *node, size_t size);
75void extent_node_zeroed_set(extent_node_t *node, bool zeroed);
76void extent_node_achunk_set(extent_node_t *node, bool achunk);
77void extent_node_prof_tctx_set(extent_node_t *node, prof_tctx_t *tctx);
Jason Evansa4e18882015-02-17 15:13:52 -080078void extent_node_init(extent_node_t *node, arena_t *arena, void *addr,
79 size_t size, bool zeroed);
Jason Evans47701b22015-02-17 22:23:10 -080080void extent_node_dirty_linkage_init(extent_node_t *node);
Jason Evansee41ad42015-02-15 18:04:46 -080081#endif
82
83#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_EXTENT_C_))
84JEMALLOC_INLINE arena_t *
85extent_node_arena_get(const extent_node_t *node)
86{
87
88 return (node->en_arena);
89}
90
91JEMALLOC_INLINE void *
92extent_node_addr_get(const extent_node_t *node)
93{
94
95 return (node->en_addr);
96}
97
98JEMALLOC_INLINE size_t
99extent_node_size_get(const extent_node_t *node)
100{
101
102 return (node->en_size);
103}
104
105JEMALLOC_INLINE bool
106extent_node_zeroed_get(const extent_node_t *node)
107{
108
109 return (node->en_zeroed);
110}
111
112JEMALLOC_INLINE bool
113extent_node_achunk_get(const extent_node_t *node)
114{
115
116 return (node->en_achunk);
117}
118
119JEMALLOC_INLINE prof_tctx_t *
120extent_node_prof_tctx_get(const extent_node_t *node)
121{
122
123 return (node->en_prof_tctx);
124}
125
126JEMALLOC_INLINE void
127extent_node_arena_set(extent_node_t *node, arena_t *arena)
128{
129
130 node->en_arena = arena;
131}
132
133JEMALLOC_INLINE void
134extent_node_addr_set(extent_node_t *node, void *addr)
135{
136
137 node->en_addr = addr;
138}
139
140JEMALLOC_INLINE void
141extent_node_size_set(extent_node_t *node, size_t size)
142{
143
144 node->en_size = size;
145}
146
147JEMALLOC_INLINE void
148extent_node_zeroed_set(extent_node_t *node, bool zeroed)
149{
150
151 node->en_zeroed = zeroed;
152}
153
154JEMALLOC_INLINE void
155extent_node_achunk_set(extent_node_t *node, bool achunk)
156{
157
158 node->en_achunk = achunk;
159}
160
161JEMALLOC_INLINE void
162extent_node_prof_tctx_set(extent_node_t *node, prof_tctx_t *tctx)
163{
164
165 node->en_prof_tctx = tctx;
166}
Jason Evansa4e18882015-02-17 15:13:52 -0800167
168JEMALLOC_INLINE void
169extent_node_init(extent_node_t *node, arena_t *arena, void *addr, size_t size,
170 bool zeroed)
171{
172
173 extent_node_arena_set(node, arena);
174 extent_node_addr_set(node, addr);
175 extent_node_size_set(node, size);
176 extent_node_zeroed_set(node, zeroed);
177 extent_node_achunk_set(node, false);
178 if (config_prof)
179 extent_node_prof_tctx_set(node, NULL);
180}
Jason Evans47701b22015-02-17 22:23:10 -0800181
182JEMALLOC_INLINE void
183extent_node_dirty_linkage_init(extent_node_t *node)
184{
185
186 qr_new(node, cd_link);
187 qr_new(&node->runs_dirty, rd_link);
188}
Jason Evansee41ad42015-02-15 18:04:46 -0800189#endif
190
Jason Evanse476f8a2010-01-16 09:53:50 -0800191#endif /* JEMALLOC_H_INLINES */
192/******************************************************************************/
193