1#define	JEMALLOC_EXTENT_C_
2#include "jemalloc/internal/jemalloc_internal.h"
3
4/******************************************************************************/
5
6JEMALLOC_INLINE_C size_t
7extent_quantize(size_t size)
8{
9
10	/*
11	 * Round down to the nearest chunk size that can actually be requested
12	 * during normal huge allocation.
13	 */
14	return (index2size(size2index(size + 1) - 1));
15}
16
17JEMALLOC_INLINE_C int
18extent_szad_comp(const extent_node_t *a, const extent_node_t *b)
19{
20	int ret;
21	size_t a_qsize = extent_quantize(extent_node_size_get(a));
22	size_t b_qsize = extent_quantize(extent_node_size_get(b));
23
24	/*
25	 * Compare based on quantized size rather than size, in order to sort
26	 * equally useful extents only by address.
27	 */
28	ret = (a_qsize > b_qsize) - (a_qsize < b_qsize);
29	if (ret == 0) {
30		uintptr_t a_addr = (uintptr_t)extent_node_addr_get(a);
31		uintptr_t b_addr = (uintptr_t)extent_node_addr_get(b);
32
33		ret = (a_addr > b_addr) - (a_addr < b_addr);
34	}
35
36	return (ret);
37}
38
39/* Generate red-black tree functions. */
40rb_gen(, extent_tree_szad_, extent_tree_t, extent_node_t, szad_link,
41    extent_szad_comp)
42
43JEMALLOC_INLINE_C int
44extent_ad_comp(const extent_node_t *a, const extent_node_t *b)
45{
46	uintptr_t a_addr = (uintptr_t)extent_node_addr_get(a);
47	uintptr_t b_addr = (uintptr_t)extent_node_addr_get(b);
48
49	return ((a_addr > b_addr) - (a_addr < b_addr));
50}
51
52/* Generate red-black tree functions. */
53rb_gen(, extent_tree_ad_, extent_tree_t, extent_node_t, ad_link, extent_ad_comp)
54