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