2 #ifdef JEMALLOC_H_TYPES
23 #define RUN_MAX_OVRHD 0x0000003dU
24 #define RUN_MAX_OVRHD_RELAX 0x00001800U
27 #define LG_RUN_MAXREGS 11
28 #define RUN_MAXREGS (1U << LG_RUN_MAXREGS)
34 #define REDZONE_MINSIZE 16
44 #define LG_DIRTY_MULT_DEFAULT 3
46 typedef struct arena_chunk_map_s arena_chunk_map_t;
47 typedef struct arena_chunk_s arena_chunk_t;
48 typedef struct arena_run_s arena_run_t;
49 typedef struct arena_bin_info_s arena_bin_info_t;
50 typedef struct arena_bin_s arena_bin_t;
51 typedef struct arena_s arena_t;
55 #ifdef JEMALLOC_H_STRUCTS
58 struct arena_chunk_map_s {
76 rb_node(arena_chunk_map_t) rb_link;
83 ql_elm(arena_chunk_map_t) ql_link;
147 #define CHUNK_MAP_BININD_SHIFT 4
148 #define BININD_INVALID ((size_t)0xffU)
150 #define CHUNK_MAP_BININD_MASK ((size_t)0xff0U)
151 #define CHUNK_MAP_BININD_INVALID CHUNK_MAP_BININD_MASK
152 #define CHUNK_MAP_FLAGS_MASK ((size_t)0xcU)
153 #define CHUNK_MAP_DIRTY ((size_t)0x8U)
154 #define CHUNK_MAP_UNZEROED ((size_t)0x4U)
155 #define CHUNK_MAP_LARGE ((size_t)0x2U)
156 #define CHUNK_MAP_ALLOCATED ((size_t)0x1U)
157 #define CHUNK_MAP_KEY CHUNK_MAP_ALLOCATED
159 typedef rb_tree(arena_chunk_map_t) arena_avail_tree_t;
160 typedef
rb_tree(arena_chunk_map_t) arena_run_tree_t;
161 typedef
ql_head(arena_chunk_map_t) arena_chunk_mapelms_t;
164 struct arena_chunk_s {
169 rb_node(arena_chunk_t) dirty_link;
192 arena_chunk_map_t map[1];
194 typedef
rb_tree(arena_chunk_t) arena_chunk_tree_t;
245 struct arena_bin_info_s {
271 bitmap_info_t bitmap_info;
305 arena_run_tree_t runs;
308 malloc_bin_stats_t stats;
343 arena_chunk_tree_t chunks_dirty;
355 arena_chunk_t *spare;
380 arena_avail_tree_t runs_avail;
383 arena_bin_t bins[NBINS];
388 #ifdef JEMALLOC_H_EXTERNS
397 #define SMALL_SIZE2BIN(s) (small_size2bin[(s-1) >> LG_TINY_MIN])
402 #define nlclasses (chunk_npages - map_bias)
406 size_t binind,
uint64_t prof_accumbytes);
410 typedef void (arena_redzone_corruption_t)(
void *, size_t,
bool, size_t,
413 typedef void (arena_dalloc_junk_small_t)(
void *, arena_bin_info_t *);
421 void *
arena_palloc(arena_t *arena,
size_t size,
size_t alignment,
bool zero);
424 arena_chunk_map_t *mapelm);
426 size_t pageind, arena_chunk_map_t *mapelm);
430 typedef void (arena_dalloc_junk_large_t)(
void *, size_t);
437 typedef void (arena_ralloc_junk_large_t)(
void *, size_t, size_t);
441 size_t extra,
bool zero);
442 void *
arena_ralloc(arena_t *arena,
void *ptr,
size_t oldsize,
size_t size,
443 size_t extra,
size_t alignment,
bool zero,
bool try_tcache_alloc,
444 bool try_tcache_dalloc);
448 size_t *ndirty, arena_stats_t *astats, malloc_bin_stats_t *bstats,
449 malloc_large_stats_t *lstats);
450 bool arena_new(arena_t *arena,
unsigned ind);
458 #ifdef JEMALLOC_H_INLINES
460 #ifndef JEMALLOC_ENABLE_INLINE
476 size_t size,
size_t flags);
480 size_t size,
size_t flags);
484 size_t runind,
size_t binind,
size_t flags);
496 void *
arena_malloc(arena_t *arena,
size_t size,
bool zero,
bool try_tcache);
502 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_ARENA_C_))
503 # ifdef JEMALLOC_ARENA_INLINE_A
511 return (&chunk->map[pageind-
map_bias]);
541 assert((mapbits & (CHUNK_MAP_LARGE|CHUNK_MAP_ALLOCATED)) == 0);
551 assert((mapbits & (CHUNK_MAP_LARGE|CHUNK_MAP_ALLOCATED)) ==
552 (CHUNK_MAP_LARGE|CHUNK_MAP_ALLOCATED));
562 assert((mapbits & (CHUNK_MAP_LARGE|CHUNK_MAP_ALLOCATED)) ==
563 CHUNK_MAP_ALLOCATED);
574 binind = (mapbits & CHUNK_MAP_BININD_MASK) >> CHUNK_MAP_BININD_SHIFT;
575 assert(binind < NBINS || binind == BININD_INVALID);
585 return (mapbits & CHUNK_MAP_DIRTY);
594 return (mapbits & CHUNK_MAP_UNZEROED);
603 return (mapbits & CHUNK_MAP_LARGE);
612 return (mapbits & CHUNK_MAP_ALLOCATED);
629 assert((flags & ~CHUNK_MAP_FLAGS_MASK) == 0);
630 assert((flags & (CHUNK_MAP_DIRTY|CHUNK_MAP_UNZEROED)) == flags);
642 assert((mapbits & (CHUNK_MAP_LARGE|CHUNK_MAP_ALLOCATED)) == 0);
655 assert((flags & CHUNK_MAP_DIRTY) == flags);
656 unzeroed = mapbits & CHUNK_MAP_UNZEROED;
658 | unzeroed | CHUNK_MAP_LARGE | CHUNK_MAP_ALLOCATED);
668 assert(binind <= BININD_INVALID);
671 (binind << CHUNK_MAP_BININD_SHIFT));
676 size_t binind,
size_t flags)
682 assert(binind < BININD_INVALID);
683 assert(pageind - runind >=
map_bias);
684 assert((flags & CHUNK_MAP_DIRTY) == flags);
685 unzeroed = mapbits & CHUNK_MAP_UNZEROED;
687 CHUNK_MAP_BININD_SHIFT) | flags | unzeroed | CHUNK_MAP_ALLOCATED);
708 arena->prof_accumbytes += accumbytes;
751 binind = (mapbits & CHUNK_MAP_BININD_MASK) >> CHUNK_MAP_BININD_SHIFT;
754 arena_chunk_t *chunk;
757 size_t actual_mapbits;
760 size_t actual_binind;
761 arena_bin_info_t *bin_info;
763 assert(binind != BININD_INVALID);
764 assert(binind < NBINS);
765 chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
766 arena = chunk->arena;
769 assert(mapbits == actual_mapbits);
775 actual_binind = bin - arena->bins;
776 assert(binind == actual_binind);
777 bin_info = &arena_bin_info[actual_binind];
779 (
uintptr_t)bin_info->reg0_offset)) % bin_info->reg_interval
787 # ifdef JEMALLOC_ARENA_INLINE_B
791 size_t binind = bin - arena->bins;
792 assert(binind < NBINS);
797 arena_run_regind(arena_run_t *run, arena_bin_info_t *bin_info,
const void *ptr)
799 unsigned shift, diff, regind;
814 bin_info->reg0_offset);
817 interval = bin_info->reg_interval;
818 shift =
ffs(interval) - 1;
840 #define SIZE_INV_SHIFT ((sizeof(unsigned) << 3) - LG_RUN_MAXREGS)
841 #define SIZE_INV(s) (((1U << SIZE_INV_SHIFT) / (s)) + 1)
842 static const unsigned interval_invs[] = {
844 SIZE_INV(4), SIZE_INV(5), SIZE_INV(6), SIZE_INV(7),
845 SIZE_INV(8), SIZE_INV(9), SIZE_INV(10), SIZE_INV(11),
846 SIZE_INV(12), SIZE_INV(13), SIZE_INV(14), SIZE_INV(15),
847 SIZE_INV(16), SIZE_INV(17), SIZE_INV(18), SIZE_INV(19),
848 SIZE_INV(20), SIZE_INV(21), SIZE_INV(22), SIZE_INV(23),
849 SIZE_INV(24), SIZE_INV(25), SIZE_INV(26), SIZE_INV(27),
850 SIZE_INV(28), SIZE_INV(29), SIZE_INV(30), SIZE_INV(31)
853 if (interval <= ((
sizeof(interval_invs) /
sizeof(
unsigned)) +
855 regind = (diff * interval_invs[interval - 3]) >>
858 regind = diff / interval;
860 #undef SIZE_INV_SHIFT
862 assert(diff == regind * interval);
863 assert(regind < bin_info->nregs);
872 arena_chunk_t *chunk;
873 size_t pageind, mapbits;
877 assert(CHUNK_ADDR2BASE(ptr) != ptr);
879 chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
882 assert((mapbits & CHUNK_MAP_ALLOCATED) != 0);
883 if ((mapbits & CHUNK_MAP_LARGE) == 0) {
887 arena_run_t *run = (arena_run_t *)((
uintptr_t)chunk +
892 arena_bin_info_t *bin_info = &arena_bin_info[binind];
897 bin_info->ctx0_offset + (regind *
898 sizeof(prof_ctx_t *)));
909 arena_chunk_t *chunk;
914 assert(CHUNK_ADDR2BASE(ptr) != ptr);
916 chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
929 arena_run_t *run = (arena_run_t *)((
uintptr_t)chunk +
933 arena_bin_info_t *bin_info;
937 bin_info = &arena_bin_info[binind];
941 bin_info->ctx0_offset + (regind *
sizeof(prof_ctx_t
955 if (size <= SMALL_MAXCLASS) {
982 arena_chunk_t *chunk;
983 size_t pageind, binind;
986 assert(CHUNK_ADDR2BASE(ptr) != ptr);
988 chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
992 if (binind == BININD_INVALID || (
config_prof && demote ==
false &&
1005 pageind+(ret>>
LG_PAGE)-1) == 0);
1017 pageind)) == binind);
1018 ret = arena_bin_info[binind].reg_size;
1025 arena_dalloc(arena_t *arena, arena_chunk_t *chunk,
void *ptr,
bool try_tcache)
1027 size_t pageind, mapbits;
1030 assert(arena !=
NULL);
1031 assert(chunk->arena == arena);
1032 assert(ptr !=
NULL);
1033 assert(CHUNK_ADDR2BASE(ptr) != ptr);
1038 if ((mapbits & CHUNK_MAP_LARGE) == 0) {
#define malloc_mutex_lock
Definition: private_namespace.h:237
#define arena_mapbits_unzeroed_get
Definition: private_namespace.h:34
#define arena_malloc_small
Definition: private_namespace.h:20
#define arena_mapbits_small_runind_get
Definition: private_namespace.h:29
#define JEMALLOC_INLINE
Definition: jemalloc_internal.h:259
static __forceinline int ffs(int x)
Definition: strings.h:17
#define arena_dss_prec_set
Definition: private_namespace.h:17
#define arena_ralloc_no_move
Definition: private_namespace.h:57
#define arena_dalloc_large_locked
Definition: private_namespace.h:14
#define arena_dalloc
Definition: private_namespace.h:8
#define ql_head(a_type)
Definition: ql.h:4
#define arena_dalloc_large
Definition: private_namespace.h:13
#define arena_mapbits_allocated_get
Definition: private_namespace.h:21
arena_t NULL
Definition: jemalloc_internal.h:624
#define arena_postfork_parent
Definition: private_namespace.h:44
#define arena_maxclass
Definition: private_namespace.h:40
#define arena_mapbits_large_set
Definition: private_namespace.h:27
#define arena_purge_all
Definition: private_namespace.h:53
JEMALLOC_INLINE arena_t * choose_arena(arena_t *arena)
Definition: jemalloc_internal.h:734
#define arena_stats_merge
Definition: private_namespace.h:61
#define arena_bin_info
Definition: private_namespace.h:6
#define ql_elm(a_type)
Definition: ql.h:11
#define arena_prof_accum_locked
Definition: private_namespace.h:48
#define arena_dalloc_junk_large
Definition: private_namespace.h:11
#define tcache_get
Definition: private_namespace.h:387
#define bool
Definition: CascPort.h:16
#define arena_mapbitsp_write
Definition: private_namespace.h:38
#define arena_mapbits_binind_get
Definition: private_namespace.h:22
#define arena_prof_ctx_get
Definition: private_namespace.h:49
unsigned int uint32_t
Definition: stdint.h:80
#define arena_malloc
Definition: private_namespace.h:18
#define arena_dalloc_bin
Definition: private_namespace.h:9
#define tcache_dalloc_large
Definition: private_namespace.h:369
_W64 unsigned int uintptr_t
Definition: stdint.h:119
#define arena_mapbits_unallocated_size_get
Definition: private_namespace.h:32
#define arena_ptr_small_binind_get
Definition: private_namespace.h:52
#define arena_mapp_get
Definition: private_namespace.h:39
#define tcache_maxclass
Definition: private_namespace.h:389
#define opt_lg_dirty_mult
Definition: private_namespace.h:265
#define arena_mapbits_large_size_get
Definition: private_namespace.h:28
#define map_bias
Definition: private_namespace.h:253
unsigned __int64 uint64_t
Definition: stdint.h:90
#define arena_prefork
Definition: private_namespace.h:45
#define small_size2bin
Definition: private_namespace.h:349
#define prof_promote
Definition: private_namespace.h:306
#define arena_postfork_child
Definition: private_namespace.h:43
#define LG_PAGE
Definition: jemalloc_internal.h:359
#define arena_tcache_fill_small
Definition: private_namespace.h:62
#define arena_prof_accum
Definition: private_namespace.h:46
static const bool config_debug
Definition: jemalloc_internal.h:78
#define arena_mapbitsp_read
Definition: private_namespace.h:37
uint16 bits() const
Returns the underlying bits in this representation. Equivalent to:
Definition: unorm16.h:89
#define tcache_alloc_large
Definition: private_namespace.h:357
#define arena_mapbits_get
Definition: private_namespace.h:24
#define arena_new
Definition: private_namespace.h:41
#define arena_mapbits_small_set
Definition: private_namespace.h:30
#define arena_prof_ctx_set
Definition: private_namespace.h:50
#define PAGE_MASK
Definition: jemalloc_internal.h:361
#define malloc_mutex_unlock
Definition: private_namespace.h:241
#define arena_palloc
Definition: private_namespace.h:42
#define JEMALLOC_ALWAYS_INLINE
Definition: jemalloc_internal.h:256
#define arena_salloc
Definition: private_namespace.h:60
#define arena_ralloc_junk_large
Definition: private_namespace.h:56
#define arena_ralloc
Definition: private_namespace.h:55
unsigned char uint8_t
Definition: stdint.h:78
#define arena_prof_accum_impl
Definition: private_namespace.h:47
static const bool config_prof
Definition: jemalloc_internal.h:106
#define arena_mapbits_large_get
Definition: private_namespace.h:26
#define arena_mapbits_unallocated_size_set
Definition: private_namespace.h:33
#define arena_dalloc_junk_small
Definition: private_namespace.h:12
static unorm16 zero()
Definition: unorm16.h:82
#define tcache_alloc_small
Definition: private_namespace.h:358
#define arena_dss_prec_get
Definition: private_namespace.h:16
#define arena_redzone_corruption
Definition: private_namespace.h:58
#define arena_dalloc_small
Definition: private_namespace.h:15
IntFormatSpec< int, TypeSpec<'b'> > bin(int value)
#define arena_boot
Definition: private_namespace.h:7
#define arena_mapbits_dirty_get
Definition: private_namespace.h:23
#define arena_bin_index
Definition: private_namespace.h:5
#define arena_mapbits_large_binind_set
Definition: private_namespace.h:25
uint8 flags
Definition: DisableMgr.cpp:44
#define arena_prof_promoted
Definition: private_namespace.h:51
#define tcache_dalloc_small
Definition: private_namespace.h:370
#define arena_dalloc_bin_locked
Definition: private_namespace.h:10
#define arena_alloc_junk_small
Definition: private_namespace.h:4
#define prof_interval
Definition: private_namespace.h:299
#define rb_tree(a_type)
Definition: rb.h:42
#define arena_malloc_large
Definition: private_namespace.h:19
#define PAGE
Definition: jemalloc_internal.h:360
#define arena_mapbits_unzeroed_set
Definition: private_namespace.h:35
#define arena_run_regind
Definition: private_namespace.h:59
#define arena_mapbitsp_get
Definition: private_namespace.h:36
#define arena_quarantine_junk_small
Definition: private_namespace.h:54
#define chunk_npages
Definition: private_namespace.h:119
#define arena_mapbits_unallocated_set
Definition: private_namespace.h:31
#define rb_node(a_type)
Definition: rb.h:33