blob: b2ac2b6e77cadefe3c3c892ab396c97ce1298d88 [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 Evansb49a3342015-07-28 11:28:19 -040022 * True if physical memory is committed to the extent, whether
23 * explicitly or implicitly as on a system that overcommits and
24 * satisfies physical mamory needs on demand via soft page faults.
25 */
26 bool en_committed;
27
28 /*
Jason Evansee41ad42015-02-15 18:04:46 -080029 * The zeroed flag is used by chunk recycling code to track whether
30 * memory is zero-filled.
Jason Evanscbf3a6d2015-02-11 12:24:27 -080031 */
Jason Evansee41ad42015-02-15 18:04:46 -080032 bool en_zeroed;
Jason Evans7de92762012-10-08 17:56:11 -070033
Jason Evans918a1a52015-01-30 21:21:16 -080034 /*
Jason Evansee41ad42015-02-15 18:04:46 -080035 * The achunk flag is used to validate that huge allocation lookups
36 * don't return arena chunks.
Jason Evans918a1a52015-01-30 21:21:16 -080037 */
Jason Evansee41ad42015-02-15 18:04:46 -080038 bool en_achunk;
39
Jason Evansa4e18882015-02-17 15:13:52 -080040 /* Profile counters, used for huge objects. */
41 prof_tctx_t *en_prof_tctx;
Jason Evans918a1a52015-01-30 21:21:16 -080042
Jason Evans738e0892015-02-18 01:15:50 -080043 /* Linkage for arena's runs_dirty and chunks_cache rings. */
Jason Evansf5c8f372015-03-10 18:29:49 -070044 arena_runs_dirty_link_t rd;
Jason Evans738e0892015-02-18 01:15:50 -080045 qr(extent_node_t) cc_link;
Jason Evanscbf3a6d2015-02-11 12:24:27 -080046
47 union {
48 /* Linkage for the size/address-ordered tree. */
Jason Evans2195ba42015-02-15 16:43:52 -080049 rb_node(extent_node_t) szad_link;
Jason Evanscbf3a6d2015-02-11 12:24:27 -080050
Jason Evansee41ad42015-02-15 18:04:46 -080051 /* Linkage for arena's huge and node_cache lists. */
Jason Evans2195ba42015-02-15 16:43:52 -080052 ql_elm(extent_node_t) ql_link;
Jason Evanscbf3a6d2015-02-11 12:24:27 -080053 };
54
55 /* Linkage for the address-ordered tree. */
Jason Evans2195ba42015-02-15 16:43:52 -080056 rb_node(extent_node_t) ad_link;
Jason Evanse476f8a2010-01-16 09:53:50 -080057};
58typedef rb_tree(extent_node_t) extent_tree_t;
59
60#endif /* JEMALLOC_H_STRUCTS */
61/******************************************************************************/
62#ifdef JEMALLOC_H_EXTERNS
63
Jason Evanse476f8a2010-01-16 09:53:50 -080064rb_proto(, extent_tree_szad_, extent_tree_t, extent_node_t)
Jason Evanse476f8a2010-01-16 09:53:50 -080065
66rb_proto(, extent_tree_ad_, extent_tree_t, extent_node_t)
67
68#endif /* JEMALLOC_H_EXTERNS */
69/******************************************************************************/
70#ifdef JEMALLOC_H_INLINES
71
Jason Evansee41ad42015-02-15 18:04:46 -080072#ifndef JEMALLOC_ENABLE_INLINE
73arena_t *extent_node_arena_get(const extent_node_t *node);
74void *extent_node_addr_get(const extent_node_t *node);
75size_t extent_node_size_get(const extent_node_t *node);
Jason Evansb49a3342015-07-28 11:28:19 -040076bool extent_node_committed_get(const extent_node_t *node);
Jason Evansee41ad42015-02-15 18:04:46 -080077bool extent_node_zeroed_get(const extent_node_t *node);
78bool extent_node_achunk_get(const extent_node_t *node);
79prof_tctx_t *extent_node_prof_tctx_get(const extent_node_t *node);
80void extent_node_arena_set(extent_node_t *node, arena_t *arena);
81void extent_node_addr_set(extent_node_t *node, void *addr);
82void extent_node_size_set(extent_node_t *node, size_t size);
Jason Evansb49a3342015-07-28 11:28:19 -040083void extent_node_committed_set(extent_node_t *node, bool committed);
Jason Evansee41ad42015-02-15 18:04:46 -080084void extent_node_zeroed_set(extent_node_t *node, bool zeroed);
85void extent_node_achunk_set(extent_node_t *node, bool achunk);
86void extent_node_prof_tctx_set(extent_node_t *node, prof_tctx_t *tctx);
Jason Evansa4e18882015-02-17 15:13:52 -080087void extent_node_init(extent_node_t *node, arena_t *arena, void *addr,
Jason Evansb49a3342015-07-28 11:28:19 -040088 size_t size, bool committed, bool zeroed);
Jason Evans47701b22015-02-17 22:23:10 -080089void extent_node_dirty_linkage_init(extent_node_t *node);
Jason Evans738e0892015-02-18 01:15:50 -080090void extent_node_dirty_insert(extent_node_t *node,
Jason Evans38e42d32015-03-10 18:15:40 -070091 arena_runs_dirty_link_t *runs_dirty, extent_node_t *chunks_dirty);
Jason Evans738e0892015-02-18 01:15:50 -080092void extent_node_dirty_remove(extent_node_t *node);
Jason Evansee41ad42015-02-15 18:04:46 -080093#endif
94
95#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_EXTENT_C_))
96JEMALLOC_INLINE arena_t *
97extent_node_arena_get(const extent_node_t *node)
98{
99
100 return (node->en_arena);
101}
102
103JEMALLOC_INLINE void *
104extent_node_addr_get(const extent_node_t *node)
105{
106
107 return (node->en_addr);
108}
109
110JEMALLOC_INLINE size_t
111extent_node_size_get(const extent_node_t *node)
112{
113
114 return (node->en_size);
115}
116
117JEMALLOC_INLINE bool
Jason Evansb49a3342015-07-28 11:28:19 -0400118extent_node_committed_get(const extent_node_t *node)
119{
120
121 return (node->en_committed);
122}
123
124JEMALLOC_INLINE bool
Jason Evansee41ad42015-02-15 18:04:46 -0800125extent_node_zeroed_get(const extent_node_t *node)
126{
127
128 return (node->en_zeroed);
129}
130
131JEMALLOC_INLINE bool
132extent_node_achunk_get(const extent_node_t *node)
133{
134
135 return (node->en_achunk);
136}
137
138JEMALLOC_INLINE prof_tctx_t *
139extent_node_prof_tctx_get(const extent_node_t *node)
140{
141
142 return (node->en_prof_tctx);
143}
144
145JEMALLOC_INLINE void
146extent_node_arena_set(extent_node_t *node, arena_t *arena)
147{
148
149 node->en_arena = arena;
150}
151
152JEMALLOC_INLINE void
153extent_node_addr_set(extent_node_t *node, void *addr)
154{
155
156 node->en_addr = addr;
157}
158
159JEMALLOC_INLINE void
160extent_node_size_set(extent_node_t *node, size_t size)
161{
162
163 node->en_size = size;
164}
165
166JEMALLOC_INLINE void
Jason Evansb49a3342015-07-28 11:28:19 -0400167extent_node_committed_set(extent_node_t *node, bool committed)
168{
169
170 node->en_committed = committed;
171}
172
173JEMALLOC_INLINE void
Jason Evansee41ad42015-02-15 18:04:46 -0800174extent_node_zeroed_set(extent_node_t *node, bool zeroed)
175{
176
177 node->en_zeroed = zeroed;
178}
179
180JEMALLOC_INLINE void
181extent_node_achunk_set(extent_node_t *node, bool achunk)
182{
183
184 node->en_achunk = achunk;
185}
186
187JEMALLOC_INLINE void
188extent_node_prof_tctx_set(extent_node_t *node, prof_tctx_t *tctx)
189{
190
191 node->en_prof_tctx = tctx;
192}
Jason Evansa4e18882015-02-17 15:13:52 -0800193
194JEMALLOC_INLINE void
195extent_node_init(extent_node_t *node, arena_t *arena, void *addr, size_t size,
Jason Evansb49a3342015-07-28 11:28:19 -0400196 bool committed, bool zeroed)
Jason Evansa4e18882015-02-17 15:13:52 -0800197{
198
199 extent_node_arena_set(node, arena);
200 extent_node_addr_set(node, addr);
201 extent_node_size_set(node, size);
Jason Evansb49a3342015-07-28 11:28:19 -0400202 extent_node_committed_set(node, committed);
Jason Evansa4e18882015-02-17 15:13:52 -0800203 extent_node_zeroed_set(node, zeroed);
204 extent_node_achunk_set(node, false);
205 if (config_prof)
206 extent_node_prof_tctx_set(node, NULL);
207}
Jason Evans47701b22015-02-17 22:23:10 -0800208
209JEMALLOC_INLINE void
210extent_node_dirty_linkage_init(extent_node_t *node)
211{
212
Jason Evansf5c8f372015-03-10 18:29:49 -0700213 qr_new(&node->rd, rd_link);
Jason Evans738e0892015-02-18 01:15:50 -0800214 qr_new(node, cc_link);
Jason Evans47701b22015-02-17 22:23:10 -0800215}
Jason Evans738e0892015-02-18 01:15:50 -0800216
217JEMALLOC_INLINE void
218extent_node_dirty_insert(extent_node_t *node,
Jason Evans38e42d32015-03-10 18:15:40 -0700219 arena_runs_dirty_link_t *runs_dirty, extent_node_t *chunks_dirty)
Jason Evans738e0892015-02-18 01:15:50 -0800220{
221
Jason Evansf5c8f372015-03-10 18:29:49 -0700222 qr_meld(runs_dirty, &node->rd, rd_link);
Jason Evans738e0892015-02-18 01:15:50 -0800223 qr_meld(chunks_dirty, node, cc_link);
224}
225
226JEMALLOC_INLINE void
227extent_node_dirty_remove(extent_node_t *node)
228{
229
Jason Evansf5c8f372015-03-10 18:29:49 -0700230 qr_remove(&node->rd, rd_link);
Jason Evans738e0892015-02-18 01:15:50 -0800231 qr_remove(node, cc_link);
232}
233
Jason Evansee41ad42015-02-15 18:04:46 -0800234#endif
235
Jason Evanse476f8a2010-01-16 09:53:50 -0800236#endif /* JEMALLOC_H_INLINES */
237/******************************************************************************/
238