xref: /aosp_15_r20/external/jemalloc_new/include/jemalloc/internal/arena_inlines_a.h (revision 1208bc7e437ced7eb82efac44ba17e3beba411da)
1 #ifndef JEMALLOC_INTERNAL_ARENA_INLINES_A_H
2 #define JEMALLOC_INTERNAL_ARENA_INLINES_A_H
3 
4 static inline unsigned
arena_ind_get(const arena_t * arena)5 arena_ind_get(const arena_t *arena) {
6 	return base_ind_get(arena->base);
7 }
8 
9 static inline void
arena_internal_add(arena_t * arena,size_t size)10 arena_internal_add(arena_t *arena, size_t size) {
11 #if !defined(ANDROID_MINIMIZE_STRUCTS)
12 	atomic_fetch_add_zu(&arena->stats.internal, size, ATOMIC_RELAXED);
13 #endif
14 }
15 
16 static inline void
arena_internal_sub(arena_t * arena,size_t size)17 arena_internal_sub(arena_t *arena, size_t size) {
18 #if !defined(ANDROID_MINIMIZE_STRUCTS)
19 	atomic_fetch_sub_zu(&arena->stats.internal, size, ATOMIC_RELAXED);
20 #endif
21 }
22 
23 static inline size_t
arena_internal_get(arena_t * arena)24 arena_internal_get(arena_t *arena) {
25 #if !defined(ANDROID_MINIMIZE_STRUCTS)
26 	return atomic_load_zu(&arena->stats.internal, ATOMIC_RELAXED);
27 #else
28 	return 0;
29 #endif
30 }
31 
32 static inline bool
arena_prof_accum(tsdn_t * tsdn,arena_t * arena,uint64_t accumbytes)33 arena_prof_accum(tsdn_t *tsdn, arena_t *arena, uint64_t accumbytes) {
34 #if !defined(ANDROID_MINIMIZE_STRUCTS)
35 	cassert(config_prof);
36 
37 	if (likely(prof_interval == 0 || !prof_active_get_unlocked())) {
38 		return false;
39 	}
40 
41 	return prof_accum_add(tsdn, &arena->prof_accum, accumbytes);
42 #else
43   return false;
44 #endif
45 }
46 
47 static inline void
percpu_arena_update(tsd_t * tsd,unsigned cpu)48 percpu_arena_update(tsd_t *tsd, unsigned cpu) {
49 	assert(have_percpu_arena);
50 	arena_t *oldarena = tsd_arena_get(tsd);
51 	assert(oldarena != NULL);
52 	unsigned oldind = arena_ind_get(oldarena);
53 
54 	if (oldind != cpu) {
55 		unsigned newind = cpu;
56 		arena_t *newarena = arena_get(tsd_tsdn(tsd), newind, true);
57 		assert(newarena != NULL);
58 
59 		/* Set new arena/tcache associations. */
60 		arena_migrate(tsd, oldind, newind);
61 		tcache_t *tcache = tcache_get(tsd);
62 		if (tcache != NULL) {
63 			tcache_arena_reassociate(tsd_tsdn(tsd), tcache,
64 			    newarena);
65 		}
66 	}
67 }
68 
69 #endif /* JEMALLOC_INTERNAL_ARENA_INLINES_A_H */
70