1MEMKIND_ARENA(3) MEMKIND_ARENA MEMKIND_ARENA(3)
2
3
4
6 memkind_arena - jemalloc arena allocation memkind operations.
7 Note: This is EXPERIMENTAL API. The functionality and the header file
8 itself can be changed (including non-backward compatible changes) or
9 removed.
10
12 #include <memkind/internal/memkind_arena.h>
13
14 Link with -lmemkind
15
16 int memkind_arena_create(struct memkind *kind, struct memkind_ops *ops, const char *name);
17 int memkind_arena_create_map(struct memkind *kind, extent_hooks_t *hooks);
18 int memkind_arena_destroy(struct memkind *kind);
19 void *memkind_arena_malloc(struct memkind *kind, size_t size);
20 void *memkind_arena_calloc(struct memkind *kind, size_t num, size_t size);
21 void *memkind_arena_pmem_calloc(struct memkind *kind, size_t num, size_t size);
22 int memkind_arena_posix_memalign(struct memkind *kind, void **memptr, size_t alignment, size_t size);
23 void *memkind_arena_realloc(struct memkind *kind, void *ptr, size_t size);
24 void *memkind_arena_realloc_with_kind_detect(void *ptr, size_t size);
25 int memkind_thread_get_arena(struct memkind *kind, unsigned int *arena, size_t size);
26 int memkind_bijective_get_arena(struct memkind *kind, unsigned int *arena, size_t size);
27 struct memkind *get_kind_by_arena(unsigned arena_ind);
28 struct memkind *memkind_arena_detect_kind(void *ptr);
29 int memkind_arena_finalize(struct memkind *kind);
30 void memkind_arena_init(struct memkind *kind);
31 void memkind_arena_free(struct memkind *kind, void *ptr);
32 void memkind_arena_free_with_kind_detect(void *ptr);
33 size_t memkind_arena_malloc_usable_size(void *ptr);
34 int memkind_arena_update_memory_usage_policy(struct memkind *kind, memkind_mem_usage_policy policy);
35
37 This header file is a collection of functions can be used to populate
38 the memkind operations structure for memory kinds that use jemalloc.
39
40 memkind_arena_create() is an implementation of the memkind "create"
41 operation for memory kinds that use jemalloc. This calls
42 memkind_default_create() (see memkind_default(3)) followed by
43 memkind_arena_create_map() described below.
44
45 memkind_arena_create_map() creates the arena_map array for the memkind
46 structure pointed to by kind which can be indexed by the
47 ops.get_arena() function from the kind's operations. If get_arena
48 points memkind_thread_get_arena() then there will be four arenas cre‐
49 ated for each processor, and if get_arena points to memkind_bijec‐
50 tive_get_arena() then just one arena is created.
51
52 memkind_arena_destroy() is an implementation of the memkind "destroy"
53 operation for memory kinds that use jemalloc. This releases all of the
54 resources allocated by memkind_arena_create().
55
56 memkind_arena_malloc() is an implementation of the memkind "malloc"
57 operation for memory kinds that use jemalloc. This allocates memory
58 using the arenas created by memkind_arena_create() through the jemal‐
59 loc's mallocx() interface. It uses the memkind "get_arena" operation
60 to select the arena.
61
62 memkind_arena_calloc() is an implementation of the memkind "calloc"
63 operation for memory kinds that use jemalloc. This allocates memory
64 using the arenas created by memkind_arena_create() through the jemal‐
65 loc's mallocx() interface. It uses the memkind "get_arena" operation
66 to select the arena.
67
68 memkind_arena_pmem_calloc() is an implementation of the memkind "cal‐
69 loc" operation for file-backed memory kinds that use jemalloc. This
70 allocates memory using the arenas created by memkind_arena_create()
71 through the jemalloc's mallocx() interface. It uses the memkind
72 "get_arena" operation to select the arena.
73
74 memkind_arena_posix_memalign() is an implementation of the memkind
75 "posix_memalign" operation for memory kinds that use jemalloc. This
76 allocates memory using the arenas created by memkind_arena_create()
77 through the jemalloc's mallocx() interface. It uses the memkind
78 "get_arena" operation to select the arena. The POSIX standard requires
79 that posix_memalign(3) may not set errno however the jemalloc's mal‐
80 locx() routine may. In an attempt to abide by the standard errno is
81 recorded before calling jemalloc's mallocx() and then reset after the
82 call.
83
84 memkind_arena_realloc() is an implementation of the memkind "realloc"
85 operation for memory kinds that use jemalloc. This allocates memory
86 using the arenas created by memkind_arena_create() through the jemal‐
87 loc's mallocx() interface. It uses the memkind "get_arena" operation
88 to select the arena.
89
90 memkind_arena_realloc_with_kind_detect() function will look up for kind
91 associated to the allocated memory referenced by ptr and call (depend‐
92 ing on kind value) memkind_arena_realloc() or memkind_default_real‐
93 loc().
94
95 memkind_thread_get_arena() retrieves the arena index that is bound to
96 to the calling thread based on a hash of its thread ID. The arena
97 index can be used with the MALLOCX_ARENA macro to set flags for jemal‐
98 loc's mallocx().
99
100 memkind_bijective_arena_get_arena() retrieves the arena index to be
101 used with the MALLOCX_ARENA macro to set flags for jemalloc's mal‐
102 locx(). Use of this operation implies that only one arena is used for
103 the kind.
104
105 memkind_arena_free() is an implementation of the memkind "free" opera‐
106 tion for memory kinds that use jemalloc. It causes the allocated mem‐
107 ory referenced by ptr, which must have been returned by a previous call
108 to memkind_arena_malloc(), memkind_arena_calloc() or
109 memkind_arena_realloc() to be made available for future allocations.
110 It uses the memkind "get_arena" operation to select the arena.
111
112 memkind_arena_free_with_kind_detect() function will look up for kind
113 associated to the allocated memory referenced by ptr and call
114 memkind_arena_free().
115
116 memkind_arena_detect_kind() returns pointer to memory kind structure
117 associated with given allocated memory referenced by ptr.
118
119 get_kind_by_arena() returns pointer to memory kind structure associated
120 with given arena.
121
122 memkind_arena_malloc_usable_size() is an implementation of the memkind
123 "usable_size" operation for memory kinds that use jemalloc.
124
125 memkind_arena_finalize() is an implementation of the memkind "finalize"
126 operation for memory kinds that use jemalloc. This function releases
127 all resources allocated by memkind_arena_create() and it's called when
128 main() finishes or after calling exit() function.
129
130 memkind_arena_init() creates arena map with proper hooks per specified
131 kind.
132
133 memkind_arena_update_memory_usage_policy() function changes time, which
134 determine how fast jemalloc returns unused pages back to the operating
135 system, in other words how fast it deallocates file space.
136
138 Copyright (C) 2014 - 2019 Intel Corporation. All rights reserved.
139
141 memkind(3), memkind_default(3), memkind_hbw(3), memkind_hugetlb(3),
142 memkind_pmem(3), jemalloc(3), mbind(2), mmap(2)
143
144
145
146Intel Corporation 2015-04-21 MEMKIND_ARENA(3)