arena.h revision b172610317babc7f365584ddd7fdaf4eb8d9d04c
1/******************************************************************************/
2#ifdef JEMALLOC_H_TYPES
3
4/*
5 * RUN_MAX_OVRHD indicates maximum desired run header overhead.  Runs are sized
6 * as small as possible such that this setting is still honored, without
7 * violating other constraints.  The goal is to make runs as small as possible
8 * without exceeding a per run external fragmentation threshold.
9 *
10 * We use binary fixed point math for overhead computations, where the binary
11 * point is implicitly RUN_BFP bits to the left.
12 *
13 * Note that it is possible to set RUN_MAX_OVRHD low enough that it cannot be
14 * honored for some/all object sizes, since when heap profiling is enabled
15 * there is one pointer of header overhead per object (plus a constant).  This
16 * constraint is relaxed (ignored) for runs that are so small that the
17 * per-region overhead is greater than:
18 *
19 *   (RUN_MAX_OVRHD / (reg_size << (3+RUN_BFP))
20 */
21#define	RUN_BFP			12
22/*                                    \/   Implicit binary fixed point. */
23#define	RUN_MAX_OVRHD		0x0000003dU
24#define	RUN_MAX_OVRHD_RELAX	0x00001800U
25
26/* Maximum number of regions in one run. */
27#define	LG_RUN_MAXREGS		11
28#define	RUN_MAXREGS		(1U << LG_RUN_MAXREGS)
29
30/*
31 * The minimum ratio of active:dirty pages per arena is computed as:
32 *
33 *   (nactive >> opt_lg_dirty_mult) >= ndirty
34 *
35 * So, supposing that opt_lg_dirty_mult is 5, there can be no less than 32
36 * times as many active pages as dirty pages.
37 */
38#define	LG_DIRTY_MULT_DEFAULT	5
39
40typedef struct arena_chunk_map_s arena_chunk_map_t;
41typedef struct arena_chunk_s arena_chunk_t;
42typedef struct arena_run_s arena_run_t;
43typedef struct arena_bin_info_s arena_bin_info_t;
44typedef struct arena_bin_s arena_bin_t;
45typedef struct arena_s arena_t;
46
47#endif /* JEMALLOC_H_TYPES */
48/******************************************************************************/
49#ifdef JEMALLOC_H_STRUCTS
50
51/* Each element of the chunk map corresponds to one page within the chunk. */
52struct arena_chunk_map_s {
53#ifndef JEMALLOC_PROF
54	/*
55	 * Overlay prof_ctx in order to allow it to be referenced by dead code.
56	 * Such antics aren't warranted for per arena data structures, but
57	 * chunk map overhead accounts for a percentage of memory, rather than
58	 * being just a fixed cost.
59	 */
60	union {
61#endif
62	union {
63		/*
64		 * Linkage for run trees.  There are two disjoint uses:
65		 *
66		 * 1) arena_t's runs_avail_{clean,dirty} trees.
67		 * 2) arena_run_t conceptually uses this linkage for in-use
68		 *    non-full runs, rather than directly embedding linkage.
69		 */
70		rb_node(arena_chunk_map_t)	rb_link;
71		/*
72		 * List of runs currently in purgatory.  arena_chunk_purge()
73		 * temporarily allocates runs that contain dirty pages while
74		 * purging, so that other threads cannot use the runs while the
75		 * purging thread is operating without the arena lock held.
76		 */
77		ql_elm(arena_chunk_map_t)	ql_link;
78	}				u;
79
80	/* Profile counters, used for large object runs. */
81	prof_ctx_t			*prof_ctx;
82#ifndef JEMALLOC_PROF
83	}; /* union { ... }; */
84#endif
85
86	/*
87	 * Run address (or size) and various flags are stored together.  The bit
88	 * layout looks like (assuming 32-bit system):
89	 *
90	 *   ???????? ???????? ????---- ----dula
91	 *
92	 * ? : Unallocated: Run address for first/last pages, unset for internal
93	 *                  pages.
94	 *     Small: Run page offset.
95	 *     Large: Run size for first page, unset for trailing pages.
96	 * - : Unused.
97	 * d : dirty?
98	 * u : unzeroed?
99	 * l : large?
100	 * a : allocated?
101	 *
102	 * Following are example bit patterns for the three types of runs.
103	 *
104	 * p : run page offset
105	 * s : run size
106	 * c : (binind+1) for size class (used only if prof_promote is true)
107	 * x : don't care
108	 * - : 0
109	 * + : 1
110	 * [DULA] : bit set
111	 * [dula] : bit unset
112	 *
113	 *   Unallocated (clean):
114	 *     ssssssss ssssssss ssss---- ----du-a
115	 *     xxxxxxxx xxxxxxxx xxxx---- -----Uxx
116	 *     ssssssss ssssssss ssss---- ----dU-a
117	 *
118	 *   Unallocated (dirty):
119	 *     ssssssss ssssssss ssss---- ----D--a
120	 *     xxxxxxxx xxxxxxxx xxxx---- ----xxxx
121	 *     ssssssss ssssssss ssss---- ----D--a
122	 *
123	 *   Small:
124	 *     pppppppp pppppppp pppp---- ----d--A
125	 *     pppppppp pppppppp pppp---- -------A
126	 *     pppppppp pppppppp pppp---- ----d--A
127	 *
128	 *   Large:
129	 *     ssssssss ssssssss ssss---- ----D-LA
130	 *     xxxxxxxx xxxxxxxx xxxx---- ----xxxx
131	 *     -------- -------- -------- ----D-LA
132	 *
133	 *   Large (sampled, size <= PAGE_SIZE):
134	 *     ssssssss ssssssss sssscccc ccccD-LA
135	 *
136	 *   Large (not sampled, size == PAGE_SIZE):
137	 *     ssssssss ssssssss ssss---- ----D-LA
138	 */
139	size_t				bits;
140#define	CHUNK_MAP_CLASS_SHIFT	4
141#define	CHUNK_MAP_CLASS_MASK	((size_t)0xff0U)
142#define	CHUNK_MAP_FLAGS_MASK	((size_t)0xfU)
143#define	CHUNK_MAP_DIRTY		((size_t)0x8U)
144#define	CHUNK_MAP_UNZEROED	((size_t)0x4U)
145#define	CHUNK_MAP_LARGE		((size_t)0x2U)
146#define	CHUNK_MAP_ALLOCATED	((size_t)0x1U)
147#define	CHUNK_MAP_KEY		CHUNK_MAP_ALLOCATED
148};
149typedef rb_tree(arena_chunk_map_t) arena_avail_tree_t;
150typedef rb_tree(arena_chunk_map_t) arena_run_tree_t;
151
152/* Arena chunk header. */
153struct arena_chunk_s {
154	/* Arena that owns the chunk. */
155	arena_t		*arena;
156
157	/* Linkage for the arena's chunks_dirty list. */
158	ql_elm(arena_chunk_t) link_dirty;
159
160	/*
161	 * True if the chunk is currently in the chunks_dirty list, due to
162	 * having at some point contained one or more dirty pages.  Removal
163	 * from chunks_dirty is lazy, so (dirtied && ndirty == 0) is possible.
164	 */
165	bool		dirtied;
166
167	/* Number of dirty pages. */
168	size_t		ndirty;
169
170	/*
171	 * Map of pages within chunk that keeps track of free/large/small.  The
172	 * first map_bias entries are omitted, since the chunk header does not
173	 * need to be tracked in the map.  This omission saves a header page
174	 * for common chunk sizes (e.g. 4 MiB).
175	 */
176	arena_chunk_map_t map[1]; /* Dynamically sized. */
177};
178typedef rb_tree(arena_chunk_t) arena_chunk_tree_t;
179
180struct arena_run_s {
181	/* Bin this run is associated with. */
182	arena_bin_t	*bin;
183
184	/* Index of next region that has never been allocated, or nregs. */
185	uint32_t	nextind;
186
187	/* Number of free regions in run. */
188	unsigned	nfree;
189};
190
191/*
192 * Read-only information associated with each element of arena_t's bins array
193 * is stored separately, partly to reduce memory usage (only one copy, rather
194 * than one per arena), but mainly to avoid false cacheline sharing.
195 */
196struct arena_bin_info_s {
197	/* Size of regions in a run for this bin's size class. */
198	size_t		reg_size;
199
200	/* Total size of a run for this bin's size class. */
201	size_t		run_size;
202
203	/* Total number of regions in a run for this bin's size class. */
204	uint32_t	nregs;
205
206	/*
207	 * Offset of first bitmap_t element in a run header for this bin's size
208	 * class.
209	 */
210	uint32_t	bitmap_offset;
211
212	/*
213	 * Metadata used to manipulate bitmaps for runs associated with this
214	 * bin.
215	 */
216	bitmap_info_t	bitmap_info;
217
218	/*
219	 * Offset of first (prof_ctx_t *) in a run header for this bin's size
220	 * class, or 0 if (config_prof == false || opt_prof == false).
221	 */
222	uint32_t	ctx0_offset;
223
224	/* Offset of first region in a run for this bin's size class. */
225	uint32_t	reg0_offset;
226};
227
228struct arena_bin_s {
229	/*
230	 * All operations on runcur, runs, and stats require that lock be
231	 * locked.  Run allocation/deallocation are protected by the arena lock,
232	 * which may be acquired while holding one or more bin locks, but not
233	 * vise versa.
234	 */
235	malloc_mutex_t	lock;
236
237	/*
238	 * Current run being used to service allocations of this bin's size
239	 * class.
240	 */
241	arena_run_t	*runcur;
242
243	/*
244	 * Tree of non-full runs.  This tree is used when looking for an
245	 * existing run when runcur is no longer usable.  We choose the
246	 * non-full run that is lowest in memory; this policy tends to keep
247	 * objects packed well, and it can also help reduce the number of
248	 * almost-empty chunks.
249	 */
250	arena_run_tree_t runs;
251
252	/* Bin statistics. */
253	malloc_bin_stats_t stats;
254};
255
256struct arena_s {
257	/* This arena's index within the arenas array. */
258	unsigned		ind;
259
260	/*
261	 * Number of threads currently assigned to this arena.  This field is
262	 * protected by arenas_lock.
263	 */
264	unsigned		nthreads;
265
266	/*
267	 * There are three classes of arena operations from a locking
268	 * perspective:
269	 * 1) Thread asssignment (modifies nthreads) is protected by
270	 *    arenas_lock.
271	 * 2) Bin-related operations are protected by bin locks.
272	 * 3) Chunk- and run-related operations are protected by this mutex.
273	 */
274	malloc_mutex_t		lock;
275
276	arena_stats_t		stats;
277	/*
278	 * List of tcaches for extant threads associated with this arena.
279	 * Stats from these are merged incrementally, and at exit.
280	 */
281	ql_head(tcache_t)	tcache_ql;
282
283	uint64_t		prof_accumbytes;
284
285	/* List of dirty-page-containing chunks this arena manages. */
286	ql_head(arena_chunk_t)	chunks_dirty;
287
288	/*
289	 * In order to avoid rapid chunk allocation/deallocation when an arena
290	 * oscillates right on the cusp of needing a new chunk, cache the most
291	 * recently freed chunk.  The spare is left in the arena's chunk trees
292	 * until it is deleted.
293	 *
294	 * There is one spare chunk per arena, rather than one spare total, in
295	 * order to avoid interactions between multiple threads that could make
296	 * a single spare inadequate.
297	 */
298	arena_chunk_t		*spare;
299
300	/* Number of pages in active runs. */
301	size_t			nactive;
302
303	/*
304	 * Current count of pages within unused runs that are potentially
305	 * dirty, and for which madvise(... MADV_DONTNEED) has not been called.
306	 * By tracking this, we can institute a limit on how much dirty unused
307	 * memory is mapped for each arena.
308	 */
309	size_t			ndirty;
310
311	/*
312	 * Approximate number of pages being purged.  It is possible for
313	 * multiple threads to purge dirty pages concurrently, and they use
314	 * npurgatory to indicate the total number of pages all threads are
315	 * attempting to purge.
316	 */
317	size_t			npurgatory;
318
319	/*
320	 * Size/address-ordered trees of this arena's available runs.  The trees
321	 * are used for first-best-fit run allocation.  The dirty tree contains
322	 * runs with dirty pages (i.e. very likely to have been touched and
323	 * therefore have associated physical pages), whereas the clean tree
324	 * contains runs with pages that either have no associated physical
325	 * pages, or have pages that the kernel may recycle at any time due to
326	 * previous madvise(2) calls.  The dirty tree is used in preference to
327	 * the clean tree for allocations, because using dirty pages reduces
328	 * the amount of dirty purging necessary to keep the active:dirty page
329	 * ratio below the purge threshold.
330	 */
331	arena_avail_tree_t	runs_avail_clean;
332	arena_avail_tree_t	runs_avail_dirty;
333
334	/* bins is used to store trees of free regions. */
335	arena_bin_t		bins[NBINS];
336};
337
338#endif /* JEMALLOC_H_STRUCTS */
339/******************************************************************************/
340#ifdef JEMALLOC_H_EXTERNS
341
342extern ssize_t	opt_lg_dirty_mult;
343/*
344 * small_size2bin is a compact lookup table that rounds request sizes up to
345 * size classes.  In order to reduce cache footprint, the table is compressed,
346 * and all accesses are via the SMALL_SIZE2BIN macro.
347 */
348extern uint8_t const	small_size2bin[];
349#define	SMALL_SIZE2BIN(s)	(small_size2bin[(s-1) >> LG_TINY_MIN])
350
351extern arena_bin_info_t	arena_bin_info[NBINS];
352
353/* Number of large size classes. */
354#define			nlclasses (chunk_npages - map_bias)
355
356void	arena_purge_all(arena_t *arena);
357void	arena_prof_accum(arena_t *arena, uint64_t accumbytes);
358void	arena_tcache_fill_small(arena_t *arena, tcache_bin_t *tbin,
359    size_t binind, uint64_t prof_accumbytes);
360void	*arena_malloc_small(arena_t *arena, size_t size, bool zero);
361void	*arena_malloc_large(arena_t *arena, size_t size, bool zero);
362void	*arena_palloc(arena_t *arena, size_t size, size_t alloc_size,
363    size_t alignment, bool zero);
364size_t	arena_salloc(const void *ptr);
365void	arena_prof_promoted(const void *ptr, size_t size);
366size_t	arena_salloc_demote(const void *ptr);
367void	arena_dalloc_bin(arena_t *arena, arena_chunk_t *chunk, void *ptr,
368    arena_chunk_map_t *mapelm);
369void	arena_dalloc_large(arena_t *arena, arena_chunk_t *chunk, void *ptr);
370void	arena_stats_merge(arena_t *arena, size_t *nactive, size_t *ndirty,
371    arena_stats_t *astats, malloc_bin_stats_t *bstats,
372    malloc_large_stats_t *lstats);
373void	*arena_ralloc_no_move(void *ptr, size_t oldsize, size_t size,
374    size_t extra, bool zero);
375void	*arena_ralloc(void *ptr, size_t oldsize, size_t size, size_t extra,
376    size_t alignment, bool zero);
377bool	arena_new(arena_t *arena, unsigned ind);
378void	arena_boot(void);
379
380#endif /* JEMALLOC_H_EXTERNS */
381/******************************************************************************/
382#ifdef JEMALLOC_H_INLINES
383
384#ifndef JEMALLOC_ENABLE_INLINE
385size_t	arena_bin_index(arena_t *arena, arena_bin_t *bin);
386unsigned	arena_run_regind(arena_run_t *run, arena_bin_info_t *bin_info,
387    const void *ptr);
388prof_ctx_t	*arena_prof_ctx_get(const void *ptr);
389void	arena_prof_ctx_set(const void *ptr, prof_ctx_t *ctx);
390void	*arena_malloc(size_t size, bool zero);
391void	arena_dalloc(arena_t *arena, arena_chunk_t *chunk, void *ptr);
392#endif
393
394#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_ARENA_C_))
395JEMALLOC_INLINE size_t
396arena_bin_index(arena_t *arena, arena_bin_t *bin)
397{
398	size_t binind = bin - arena->bins;
399	assert(binind < NBINS);
400	return (binind);
401}
402
403JEMALLOC_INLINE unsigned
404arena_run_regind(arena_run_t *run, arena_bin_info_t *bin_info, const void *ptr)
405{
406	unsigned shift, diff, regind;
407	size_t size;
408
409	/*
410	 * Freeing a pointer lower than region zero can cause assertion
411	 * failure.
412	 */
413	assert((uintptr_t)ptr >= (uintptr_t)run +
414	    (uintptr_t)bin_info->reg0_offset);
415
416	/*
417	 * Avoid doing division with a variable divisor if possible.  Using
418	 * actual division here can reduce allocator throughput by over 20%!
419	 */
420	diff = (unsigned)((uintptr_t)ptr - (uintptr_t)run -
421	    bin_info->reg0_offset);
422
423	/* Rescale (factor powers of 2 out of the numerator and denominator). */
424	size = bin_info->reg_size;
425	shift = ffs(size) - 1;
426	diff >>= shift;
427	size >>= shift;
428
429	if (size == 1) {
430		/* The divisor was a power of 2. */
431		regind = diff;
432	} else {
433		/*
434		 * To divide by a number D that is not a power of two we
435		 * multiply by (2^21 / D) and then right shift by 21 positions.
436		 *
437		 *   X / D
438		 *
439		 * becomes
440		 *
441		 *   (X * size_invs[D - 3]) >> SIZE_INV_SHIFT
442		 *
443		 * We can omit the first three elements, because we never
444		 * divide by 0, and 1 and 2 are both powers of two, which are
445		 * handled above.
446		 */
447#define	SIZE_INV_SHIFT	((sizeof(unsigned) << 3) - LG_RUN_MAXREGS)
448#define	SIZE_INV(s)	(((1U << SIZE_INV_SHIFT) / (s)) + 1)
449		static const unsigned size_invs[] = {
450		    SIZE_INV(3),
451		    SIZE_INV(4), SIZE_INV(5), SIZE_INV(6), SIZE_INV(7),
452		    SIZE_INV(8), SIZE_INV(9), SIZE_INV(10), SIZE_INV(11),
453		    SIZE_INV(12), SIZE_INV(13), SIZE_INV(14), SIZE_INV(15),
454		    SIZE_INV(16), SIZE_INV(17), SIZE_INV(18), SIZE_INV(19),
455		    SIZE_INV(20), SIZE_INV(21), SIZE_INV(22), SIZE_INV(23),
456		    SIZE_INV(24), SIZE_INV(25), SIZE_INV(26), SIZE_INV(27),
457		    SIZE_INV(28), SIZE_INV(29), SIZE_INV(30), SIZE_INV(31)
458		};
459
460		if (size <= ((sizeof(size_invs) / sizeof(unsigned)) + 2))
461			regind = (diff * size_invs[size - 3]) >> SIZE_INV_SHIFT;
462		else
463			regind = diff / size;
464#undef SIZE_INV
465#undef SIZE_INV_SHIFT
466	}
467	assert(diff == regind * size);
468	assert(regind < bin_info->nregs);
469
470	return (regind);
471}
472
473JEMALLOC_INLINE prof_ctx_t *
474arena_prof_ctx_get(const void *ptr)
475{
476	prof_ctx_t *ret;
477	arena_chunk_t *chunk;
478	size_t pageind, mapbits;
479
480	cassert(config_prof);
481	assert(ptr != NULL);
482	assert(CHUNK_ADDR2BASE(ptr) != ptr);
483
484	chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
485	pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> PAGE_SHIFT;
486	mapbits = chunk->map[pageind-map_bias].bits;
487	assert((mapbits & CHUNK_MAP_ALLOCATED) != 0);
488	if ((mapbits & CHUNK_MAP_LARGE) == 0) {
489		if (prof_promote)
490			ret = (prof_ctx_t *)(uintptr_t)1U;
491		else {
492			arena_run_t *run = (arena_run_t *)((uintptr_t)chunk +
493			    (uintptr_t)((pageind - (mapbits >> PAGE_SHIFT)) <<
494			    PAGE_SHIFT));
495			size_t binind = arena_bin_index(chunk->arena, run->bin);
496			arena_bin_info_t *bin_info = &arena_bin_info[binind];
497			unsigned regind;
498
499			regind = arena_run_regind(run, bin_info, ptr);
500			ret = *(prof_ctx_t **)((uintptr_t)run +
501			    bin_info->ctx0_offset + (regind *
502			    sizeof(prof_ctx_t *)));
503		}
504	} else
505		ret = chunk->map[pageind-map_bias].prof_ctx;
506
507	return (ret);
508}
509
510JEMALLOC_INLINE void
511arena_prof_ctx_set(const void *ptr, prof_ctx_t *ctx)
512{
513	arena_chunk_t *chunk;
514	size_t pageind, mapbits;
515
516	cassert(config_prof);
517	assert(ptr != NULL);
518	assert(CHUNK_ADDR2BASE(ptr) != ptr);
519
520	chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
521	pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> PAGE_SHIFT;
522	mapbits = chunk->map[pageind-map_bias].bits;
523	assert((mapbits & CHUNK_MAP_ALLOCATED) != 0);
524	if ((mapbits & CHUNK_MAP_LARGE) == 0) {
525		if (prof_promote == false) {
526			arena_run_t *run = (arena_run_t *)((uintptr_t)chunk +
527			    (uintptr_t)((pageind - (mapbits >> PAGE_SHIFT)) <<
528			    PAGE_SHIFT));
529			arena_bin_t *bin = run->bin;
530			size_t binind;
531			arena_bin_info_t *bin_info;
532			unsigned regind;
533
534			binind = arena_bin_index(chunk->arena, bin);
535			bin_info = &arena_bin_info[binind];
536			regind = arena_run_regind(run, bin_info, ptr);
537
538			*((prof_ctx_t **)((uintptr_t)run + bin_info->ctx0_offset
539			    + (regind * sizeof(prof_ctx_t *)))) = ctx;
540		} else
541			assert((uintptr_t)ctx == (uintptr_t)1U);
542	} else
543		chunk->map[pageind-map_bias].prof_ctx = ctx;
544}
545
546JEMALLOC_INLINE void *
547arena_malloc(size_t size, bool zero)
548{
549	tcache_t *tcache;
550
551	assert(size != 0);
552	assert(QUANTUM_CEILING(size) <= arena_maxclass);
553
554	if (size <= SMALL_MAXCLASS) {
555		if ((tcache = tcache_get()) != NULL)
556			return (tcache_alloc_small(tcache, size, zero));
557		else
558			return (arena_malloc_small(choose_arena(), size, zero));
559	} else {
560		/*
561		 * Initialize tcache after checking size in order to avoid
562		 * infinite recursion during tcache initialization.
563		 */
564		if (size <= tcache_maxclass && (tcache = tcache_get()) != NULL)
565			return (tcache_alloc_large(tcache, size, zero));
566		else
567			return (arena_malloc_large(choose_arena(), size, zero));
568	}
569}
570
571JEMALLOC_INLINE void
572arena_dalloc(arena_t *arena, arena_chunk_t *chunk, void *ptr)
573{
574	size_t pageind;
575	arena_chunk_map_t *mapelm;
576	tcache_t *tcache = tcache_get();
577
578	assert(arena != NULL);
579	assert(chunk->arena == arena);
580	assert(ptr != NULL);
581	assert(CHUNK_ADDR2BASE(ptr) != ptr);
582
583	pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> PAGE_SHIFT;
584	mapelm = &chunk->map[pageind-map_bias];
585	assert((mapelm->bits & CHUNK_MAP_ALLOCATED) != 0);
586	if ((mapelm->bits & CHUNK_MAP_LARGE) == 0) {
587		/* Small allocation. */
588		if (tcache != NULL)
589			tcache_dalloc_small(tcache, ptr);
590		else {
591			arena_run_t *run;
592			arena_bin_t *bin;
593
594			run = (arena_run_t *)((uintptr_t)chunk +
595			    (uintptr_t)((pageind - (mapelm->bits >>
596			    PAGE_SHIFT)) << PAGE_SHIFT));
597			bin = run->bin;
598			if (config_debug) {
599				size_t binind = arena_bin_index(arena, bin);
600				UNUSED arena_bin_info_t *bin_info =
601				    &arena_bin_info[binind];
602				assert(((uintptr_t)ptr - ((uintptr_t)run +
603				    (uintptr_t)bin_info->reg0_offset)) %
604				    bin_info->reg_size == 0);
605			}
606			malloc_mutex_lock(&bin->lock);
607			arena_dalloc_bin(arena, chunk, ptr, mapelm);
608			malloc_mutex_unlock(&bin->lock);
609		}
610	} else {
611		size_t size = mapelm->bits & ~PAGE_MASK;
612
613		assert(((uintptr_t)ptr & PAGE_MASK) == 0);
614
615		if (size <= tcache_maxclass && tcache != NULL) {
616			tcache_dalloc_large(tcache, ptr, size);
617		} else {
618			malloc_mutex_lock(&arena->lock);
619			arena_dalloc_large(arena, chunk, ptr);
620			malloc_mutex_unlock(&arena->lock);
621		}
622	}
623}
624#endif
625
626#endif /* JEMALLOC_H_INLINES */
627/******************************************************************************/
628