1*1208bc7eSAndroid Build Coastguard Worker #ifndef JEMALLOC_INTERNAL_PAGES_EXTERNS_H 2*1208bc7eSAndroid Build Coastguard Worker #define JEMALLOC_INTERNAL_PAGES_EXTERNS_H 3*1208bc7eSAndroid Build Coastguard Worker 4*1208bc7eSAndroid Build Coastguard Worker /* Page size. LG_PAGE is determined by the configure script. */ 5*1208bc7eSAndroid Build Coastguard Worker #ifdef PAGE_MASK 6*1208bc7eSAndroid Build Coastguard Worker # undef PAGE_MASK 7*1208bc7eSAndroid Build Coastguard Worker #endif 8*1208bc7eSAndroid Build Coastguard Worker #define PAGE ((size_t)(1U << LG_PAGE)) 9*1208bc7eSAndroid Build Coastguard Worker #define PAGE_MASK ((size_t)(PAGE - 1)) 10*1208bc7eSAndroid Build Coastguard Worker /* Return the page base address for the page containing address a. */ 11*1208bc7eSAndroid Build Coastguard Worker #define PAGE_ADDR2BASE(a) \ 12*1208bc7eSAndroid Build Coastguard Worker ((void *)((uintptr_t)(a) & ~PAGE_MASK)) 13*1208bc7eSAndroid Build Coastguard Worker /* Return the smallest pagesize multiple that is >= s. */ 14*1208bc7eSAndroid Build Coastguard Worker #define PAGE_CEILING(s) \ 15*1208bc7eSAndroid Build Coastguard Worker (((s) + PAGE_MASK) & ~PAGE_MASK) 16*1208bc7eSAndroid Build Coastguard Worker 17*1208bc7eSAndroid Build Coastguard Worker /* Huge page size. LG_HUGEPAGE is determined by the configure script. */ 18*1208bc7eSAndroid Build Coastguard Worker #define HUGEPAGE ((size_t)(1U << LG_HUGEPAGE)) 19*1208bc7eSAndroid Build Coastguard Worker #define HUGEPAGE_MASK ((size_t)(HUGEPAGE - 1)) 20*1208bc7eSAndroid Build Coastguard Worker /* Return the huge page base address for the huge page containing address a. */ 21*1208bc7eSAndroid Build Coastguard Worker #define HUGEPAGE_ADDR2BASE(a) \ 22*1208bc7eSAndroid Build Coastguard Worker ((void *)((uintptr_t)(a) & ~HUGEPAGE_MASK)) 23*1208bc7eSAndroid Build Coastguard Worker /* Return the smallest pagesize multiple that is >= s. */ 24*1208bc7eSAndroid Build Coastguard Worker #define HUGEPAGE_CEILING(s) \ 25*1208bc7eSAndroid Build Coastguard Worker (((s) + HUGEPAGE_MASK) & ~HUGEPAGE_MASK) 26*1208bc7eSAndroid Build Coastguard Worker 27*1208bc7eSAndroid Build Coastguard Worker /* PAGES_CAN_PURGE_LAZY is defined if lazy purging is supported. */ 28*1208bc7eSAndroid Build Coastguard Worker #if defined(_WIN32) || defined(JEMALLOC_PURGE_MADVISE_FREE) 29*1208bc7eSAndroid Build Coastguard Worker # define PAGES_CAN_PURGE_LAZY 30*1208bc7eSAndroid Build Coastguard Worker #endif 31*1208bc7eSAndroid Build Coastguard Worker /* 32*1208bc7eSAndroid Build Coastguard Worker * PAGES_CAN_PURGE_FORCED is defined if forced purging is supported. 33*1208bc7eSAndroid Build Coastguard Worker * 34*1208bc7eSAndroid Build Coastguard Worker * The only supported way to hard-purge on Windows is to decommit and then 35*1208bc7eSAndroid Build Coastguard Worker * re-commit, but doing so is racy, and if re-commit fails it's a pain to 36*1208bc7eSAndroid Build Coastguard Worker * propagate the "poisoned" memory state. Since we typically decommit as the 37*1208bc7eSAndroid Build Coastguard Worker * next step after purging on Windows anyway, there's no point in adding such 38*1208bc7eSAndroid Build Coastguard Worker * complexity. 39*1208bc7eSAndroid Build Coastguard Worker */ 40*1208bc7eSAndroid Build Coastguard Worker #if !defined(_WIN32) && ((defined(JEMALLOC_PURGE_MADVISE_DONTNEED) && \ 41*1208bc7eSAndroid Build Coastguard Worker defined(JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS)) || \ 42*1208bc7eSAndroid Build Coastguard Worker defined(JEMALLOC_MAPS_COALESCE)) 43*1208bc7eSAndroid Build Coastguard Worker # define PAGES_CAN_PURGE_FORCED 44*1208bc7eSAndroid Build Coastguard Worker #endif 45*1208bc7eSAndroid Build Coastguard Worker 46*1208bc7eSAndroid Build Coastguard Worker static const bool pages_can_purge_lazy = 47*1208bc7eSAndroid Build Coastguard Worker #ifdef PAGES_CAN_PURGE_LAZY 48*1208bc7eSAndroid Build Coastguard Worker true 49*1208bc7eSAndroid Build Coastguard Worker #else 50*1208bc7eSAndroid Build Coastguard Worker false 51*1208bc7eSAndroid Build Coastguard Worker #endif 52*1208bc7eSAndroid Build Coastguard Worker ; 53*1208bc7eSAndroid Build Coastguard Worker static const bool pages_can_purge_forced = 54*1208bc7eSAndroid Build Coastguard Worker #ifdef PAGES_CAN_PURGE_FORCED 55*1208bc7eSAndroid Build Coastguard Worker true 56*1208bc7eSAndroid Build Coastguard Worker #else 57*1208bc7eSAndroid Build Coastguard Worker false 58*1208bc7eSAndroid Build Coastguard Worker #endif 59*1208bc7eSAndroid Build Coastguard Worker ; 60*1208bc7eSAndroid Build Coastguard Worker 61*1208bc7eSAndroid Build Coastguard Worker typedef enum { 62*1208bc7eSAndroid Build Coastguard Worker thp_mode_default = 0, /* Do not change hugepage settings. */ 63*1208bc7eSAndroid Build Coastguard Worker thp_mode_always = 1, /* Always set MADV_HUGEPAGE. */ 64*1208bc7eSAndroid Build Coastguard Worker thp_mode_never = 2, /* Always set MADV_NOHUGEPAGE. */ 65*1208bc7eSAndroid Build Coastguard Worker 66*1208bc7eSAndroid Build Coastguard Worker thp_mode_names_limit = 3, /* Used for option processing. */ 67*1208bc7eSAndroid Build Coastguard Worker thp_mode_not_supported = 3 /* No THP support detected. */ 68*1208bc7eSAndroid Build Coastguard Worker } thp_mode_t; 69*1208bc7eSAndroid Build Coastguard Worker 70*1208bc7eSAndroid Build Coastguard Worker #define THP_MODE_DEFAULT thp_mode_default 71*1208bc7eSAndroid Build Coastguard Worker extern thp_mode_t opt_thp; 72*1208bc7eSAndroid Build Coastguard Worker extern thp_mode_t init_system_thp_mode; /* Initial system wide state. */ 73*1208bc7eSAndroid Build Coastguard Worker extern const char *thp_mode_names[]; 74*1208bc7eSAndroid Build Coastguard Worker 75*1208bc7eSAndroid Build Coastguard Worker void *pages_map(void *addr, size_t size, size_t alignment, bool *commit); 76*1208bc7eSAndroid Build Coastguard Worker void pages_unmap(void *addr, size_t size); 77*1208bc7eSAndroid Build Coastguard Worker bool pages_commit(void *addr, size_t size); 78*1208bc7eSAndroid Build Coastguard Worker bool pages_decommit(void *addr, size_t size); 79*1208bc7eSAndroid Build Coastguard Worker bool pages_purge_lazy(void *addr, size_t size); 80*1208bc7eSAndroid Build Coastguard Worker bool pages_purge_forced(void *addr, size_t size); 81*1208bc7eSAndroid Build Coastguard Worker bool pages_huge(void *addr, size_t size); 82*1208bc7eSAndroid Build Coastguard Worker bool pages_nohuge(void *addr, size_t size); 83*1208bc7eSAndroid Build Coastguard Worker bool pages_dontdump(void *addr, size_t size); 84*1208bc7eSAndroid Build Coastguard Worker bool pages_dodump(void *addr, size_t size); 85*1208bc7eSAndroid Build Coastguard Worker bool pages_boot(void); 86*1208bc7eSAndroid Build Coastguard Worker void pages_set_thp_state (void *ptr, size_t size); 87*1208bc7eSAndroid Build Coastguard Worker 88*1208bc7eSAndroid Build Coastguard Worker #endif /* JEMALLOC_INTERNAL_PAGES_EXTERNS_H */ 89