1 // SPDX-License-Identifier: MIT
2 // SPDX-FileCopyrightText: 2024 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 #include <rseq/mempool.h>
11 #include <rseq/compiler.h>
22 #include "rseq-utils.h"
23 #include <rseq/rseq.h>
26 * rseq-mempool.c: rseq CPU-Local Storage (CLS) memory allocator.
28 * The rseq per-CPU memory allocator allows the application the request
29 * memory pools of CPU-Local memory each of containing objects of a
30 * given size (rounded to next power of 2), reserving a given virtual
31 * address size per CPU, for a given maximum number of CPUs.
33 * The per-CPU memory allocator is analogous to TLS (Thread-Local
34 * Storage) memory: TLS is Thread-Local Storage, whereas the per-CPU
35 * memory allocator provides CPU-Local Storage.
38 #define POOL_SET_NR_ENTRIES RSEQ_BITS_PER_LONG
41 * Smallest allocation should hold enough space for a free list pointer.
43 #if RSEQ_BITS_PER_LONG == 64
44 # define POOL_SET_MIN_ENTRY 3 /* Smallest item_len=8 */
46 # define POOL_SET_MIN_ENTRY 2 /* Smallest item_len=4 */
49 #define BIT_PER_ULONG (8 * sizeof(unsigned long))
51 #define MOVE_PAGES_BATCH_SIZE 4096
53 #define RANGE_HEADER_OFFSET sizeof(struct rseq_mempool_range)
55 //TODO: make this configurable
56 #define MEMPOOL_MAX_NR_RANGES 1
58 struct free_list_node
;
60 struct free_list_node
{
61 struct free_list_node
*next
;
65 MEMPOOL_TYPE_GLOBAL
= 0, /* Default */
66 MEMPOOL_TYPE_PERCPU
= 1,
69 struct rseq_mempool_attr
{
71 void *(*mmap_func
)(void *priv
, size_t len
);
72 int (*munmap_func
)(void *priv
, void *ptr
, size_t len
);
76 int (*init_func
)(void *priv
, void *addr
, size_t len
, int cpu
);
81 enum mempool_type type
;
86 struct rseq_mempool_range
;
88 struct rseq_mempool_range
{
89 struct rseq_mempool_range
*next
; /* Linked list of ranges. */
90 struct rseq_mempool
*pool
; /* Backward reference to container pool. */
94 /* Track alloc/free. */
95 unsigned long *alloc_bitmap
;
99 /* Head of ranges linked-list. */
100 struct rseq_mempool_range
*range_list
;
101 unsigned long nr_ranges
;
107 * The free list chains freed items on the CPU 0 address range.
108 * We should rethink this decision if false sharing between
109 * malloc/free from other CPUs and data accesses from CPU 0
110 * becomes an issue. This is a NULL-terminated singly-linked
113 struct free_list_node
*free_list_head
;
115 /* This lock protects allocation/free within the pool. */
116 pthread_mutex_t lock
;
118 struct rseq_mempool_attr attr
;
123 * Pool set entries are indexed by item_len rounded to the next power of
124 * 2. A pool set can contain NULL pool entries, in which case the next
125 * large enough entry will be used for allocation.
127 struct rseq_mempool_set
{
128 /* This lock protects add vs malloc/zmalloc within the pool set. */
129 pthread_mutex_t lock
;
130 struct rseq_mempool
*entries
[POOL_SET_NR_ENTRIES
];
134 void *__rseq_pool_range_percpu_ptr(struct rseq_mempool_range
*range
, int cpu
,
135 uintptr_t item_offset
, size_t stride
)
137 return range
->base
+ (stride
* cpu
) + item_offset
;
141 void rseq_percpu_zero_item(struct rseq_mempool
*pool
,
142 struct rseq_mempool_range
*range
, uintptr_t item_offset
)
146 for (i
= 0; i
< pool
->attr
.max_nr_cpus
; i
++) {
147 char *p
= __rseq_pool_range_percpu_ptr(range
, i
,
148 item_offset
, pool
->attr
.stride
);
149 memset(p
, 0, pool
->item_len
);
154 int rseq_mempool_range_init_numa(void *addr
, size_t len
, int cpu
, int numa_flags
)
156 unsigned long nr_pages
, page_len
;
157 int status
[MOVE_PAGES_BATCH_SIZE
];
158 int nodes
[MOVE_PAGES_BATCH_SIZE
];
159 void *pages
[MOVE_PAGES_BATCH_SIZE
];
166 page_len
= rseq_get_page_len();
167 nr_pages
= len
>> rseq_get_count_order_ulong(page_len
);
169 nodes
[0] = numa_node_of_cpu(cpu
);
173 for (size_t k
= 1; k
< RSEQ_ARRAY_SIZE(nodes
); ++k
) {
177 for (unsigned long page
= 0; page
< nr_pages
;) {
179 size_t max_k
= RSEQ_ARRAY_SIZE(pages
);
180 size_t left
= nr_pages
- page
;
186 for (size_t k
= 0; k
< max_k
; ++k
, ++page
) {
187 pages
[k
] = addr
+ (page
* page_len
);
191 ret
= move_pages(0, max_k
, pages
, nodes
, status
, numa_flags
);
197 fprintf(stderr
, "%lu pages were not migrated\n", ret
);
198 for (size_t k
= 0; k
< max_k
; ++k
) {
201 "Error while moving page %p to numa node %d: %u\n",
202 pages
[k
], nodes
[k
], -status
[k
]);
209 int rseq_mempool_range_init_numa(void *addr
__attribute__((unused
)),
210 size_t len
__attribute__((unused
)),
211 int cpu
__attribute__((unused
)),
212 int numa_flags
__attribute__((unused
)))
220 void *default_mmap_func(void *priv
__attribute__((unused
)), size_t len
)
224 base
= mmap(NULL
, len
, PROT_READ
| PROT_WRITE
,
225 MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
226 if (base
== MAP_FAILED
)
232 int default_munmap_func(void *priv
__attribute__((unused
)), void *ptr
, size_t len
)
234 return munmap(ptr
, len
);
238 int create_alloc_bitmap(struct rseq_mempool
*pool
, struct rseq_mempool_range
*range
)
242 count
= ((pool
->attr
.stride
>> pool
->item_order
) + BIT_PER_ULONG
- 1) / BIT_PER_ULONG
;
245 * Not being able to create the validation bitmap is an error
246 * that needs to be reported.
248 range
->alloc_bitmap
= calloc(count
, sizeof(unsigned long));
249 if (!range
->alloc_bitmap
)
255 const char *get_pool_name(const struct rseq_mempool
*pool
)
257 return pool
->name
? : "<anonymous>";
261 bool addr_in_pool(const struct rseq_mempool
*pool
, void *addr
)
263 struct rseq_mempool_range
*range
;
265 for (range
= pool
->range_list
; range
; range
= range
->next
) {
266 if (addr
>= range
->base
&& addr
< range
->base
+ range
->next_unused
)
272 /* Always inline for __builtin_return_address(0). */
273 static inline __attribute__((always_inline
))
274 void check_free_list(const struct rseq_mempool
*pool
)
276 size_t total_item
= 0, total_never_allocated
= 0, total_freed
= 0,
277 max_list_traversal
= 0, traversal_iteration
= 0;
278 struct rseq_mempool_range
*range
;
280 if (!pool
->attr
.robust_set
)
283 for (range
= pool
->range_list
; range
; range
= range
->next
) {
284 total_item
+= pool
->attr
.stride
>> pool
->item_order
;
285 total_never_allocated
+= (pool
->attr
.stride
- range
->next_unused
) >> pool
->item_order
;
287 max_list_traversal
= total_item
- total_never_allocated
;
289 for (struct free_list_node
*node
= pool
->free_list_head
, *prev
= NULL
;
294 void *node_addr
= node
;
296 if (traversal_iteration
>= max_list_traversal
) {
297 fprintf(stderr
, "%s: Corrupted free-list; Possibly infinite loop in pool \"%s\" (%p), caller %p.\n",
298 __func__
, get_pool_name(pool
), pool
, __builtin_return_address(0));
302 /* Node is out of range. */
303 if (!addr_in_pool(pool
, node_addr
)) {
305 fprintf(stderr
, "%s: Corrupted free-list node %p -> [out-of-range %p] in pool \"%s\" (%p), caller %p.\n",
306 __func__
, prev
, node
, get_pool_name(pool
), pool
, __builtin_return_address(0));
308 fprintf(stderr
, "%s: Corrupted free-list node [out-of-range %p] in pool \"%s\" (%p), caller %p.\n",
309 __func__
, node
, get_pool_name(pool
), pool
, __builtin_return_address(0));
313 traversal_iteration
++;
317 if (total_never_allocated
+ total_freed
!= total_item
) {
318 fprintf(stderr
, "%s: Corrupted free-list in pool \"%s\" (%p); total-item: %zu total-never-used: %zu total-freed: %zu, caller %p.\n",
319 __func__
, get_pool_name(pool
), pool
, total_item
, total_never_allocated
, total_freed
, __builtin_return_address(0));
324 /* Always inline for __builtin_return_address(0). */
325 static inline __attribute__((always_inline
))
326 void destroy_alloc_bitmap(struct rseq_mempool
*pool
, struct rseq_mempool_range
*range
)
328 unsigned long *bitmap
= range
->alloc_bitmap
;
329 size_t count
, total_leaks
= 0;
334 count
= ((pool
->attr
.stride
>> pool
->item_order
) + BIT_PER_ULONG
- 1) / BIT_PER_ULONG
;
336 /* Assert that all items in the pool were freed. */
337 for (size_t k
= 0; k
< count
; ++k
)
338 total_leaks
+= rseq_hweight_ulong(bitmap
[k
]);
340 fprintf(stderr
, "%s: Pool \"%s\" (%p) has %zu leaked items on destroy, caller: %p.\n",
341 __func__
, get_pool_name(pool
), pool
, total_leaks
, (void *) __builtin_return_address(0));
348 /* Always inline for __builtin_return_address(0). */
349 static inline __attribute__((always_inline
))
350 int rseq_mempool_range_destroy(struct rseq_mempool
*pool
,
351 struct rseq_mempool_range
*range
)
353 destroy_alloc_bitmap(pool
, range
);
354 /* range is a header located one page before the aligned mapping. */
355 return pool
->attr
.munmap_func(pool
->attr
.mmap_priv
, range
->header
,
356 (pool
->attr
.stride
* pool
->attr
.max_nr_cpus
) + rseq_get_page_len());
360 * Allocate a memory mapping aligned on @alignment, with an optional
361 * @pre_header before the mapping.
364 void *aligned_mmap_anonymous(struct rseq_mempool
*pool
,
365 size_t page_size
, size_t len
, size_t alignment
,
366 void **pre_header
, size_t pre_header_len
)
368 size_t minimum_page_count
, page_count
, extra
, total_allocate
= 0;
372 if (len
< page_size
|| alignment
< page_size
||
373 !is_pow2(alignment
) || (len
& (alignment
- 1))) {
377 page_order
= rseq_get_count_order_ulong(page_size
);
378 if (page_order
< 0) {
382 if (pre_header_len
&& (pre_header_len
& (page_size
- 1))) {
387 minimum_page_count
= (pre_header_len
+ len
) >> page_order
;
388 page_count
= (pre_header_len
+ len
+ alignment
- page_size
) >> page_order
;
390 assert(page_count
>= minimum_page_count
);
392 ptr
= pool
->attr
.mmap_func(pool
->attr
.mmap_priv
, page_count
<< page_order
);
396 total_allocate
= page_count
<< page_order
;
398 if (!(((uintptr_t) ptr
+ pre_header_len
) & (alignment
- 1))) {
399 /* Pointer is already aligned. ptr points to pre_header. */
403 /* Unmap extra before. */
404 extra
= offset_align((uintptr_t) ptr
+ pre_header_len
, alignment
);
405 assert(!(extra
& (page_size
- 1)));
406 if (pool
->attr
.munmap_func(pool
->attr
.mmap_priv
, ptr
, extra
)) {
410 total_allocate
-= extra
;
411 ptr
+= extra
; /* ptr points to pre_header */
412 page_count
-= extra
>> page_order
;
414 assert(page_count
>= minimum_page_count
);
416 if (page_count
> minimum_page_count
) {
419 /* Unmap extra after. */
420 extra_ptr
= ptr
+ (minimum_page_count
<< page_order
);
421 extra
= (page_count
- minimum_page_count
) << page_order
;
422 if (pool
->attr
.munmap_func(pool
->attr
.mmap_priv
, extra_ptr
, extra
)) {
426 total_allocate
-= extra
;
429 assert(!(((uintptr_t)ptr
+ pre_header_len
) & (alignment
- 1)));
430 assert(total_allocate
== len
+ pre_header_len
);
436 ptr
+= pre_header_len
;
442 struct rseq_mempool_range
*rseq_mempool_range_create(struct rseq_mempool
*pool
)
444 struct rseq_mempool_range
*range
;
445 unsigned long page_size
;
449 if (pool
->nr_ranges
>= MEMPOOL_MAX_NR_RANGES
) {
453 page_size
= rseq_get_page_len();
455 base
= aligned_mmap_anonymous(pool
, page_size
,
456 pool
->attr
.stride
* pool
->attr
.max_nr_cpus
,
461 range
= (struct rseq_mempool_range
*) (base
- RANGE_HEADER_OFFSET
);
464 range
->header
= header
;
465 if (pool
->attr
.robust_set
) {
466 if (create_alloc_bitmap(pool
, range
))
469 if (pool
->attr
.init_set
) {
470 switch (pool
->attr
.type
) {
471 case MEMPOOL_TYPE_GLOBAL
:
472 if (pool
->attr
.init_func(pool
->attr
.init_priv
,
473 base
, pool
->attr
.stride
, -1)) {
477 case MEMPOOL_TYPE_PERCPU
:
480 for (cpu
= 0; cpu
< pool
->attr
.max_nr_cpus
; cpu
++) {
481 if (pool
->attr
.init_func(pool
->attr
.init_priv
,
482 base
+ (pool
->attr
.stride
* cpu
),
483 pool
->attr
.stride
, cpu
)) {
497 (void) rseq_mempool_range_destroy(pool
, range
);
501 int rseq_mempool_destroy(struct rseq_mempool
*pool
)
503 struct rseq_mempool_range
*range
, *next_range
;
508 check_free_list(pool
);
509 /* Iteration safe against removal. */
510 for (range
= pool
->range_list
; range
&& (next_range
= range
->next
, 1); range
= next_range
) {
511 if (rseq_mempool_range_destroy(pool
, range
))
513 /* Update list head to keep list coherent in case of partial failure. */
514 pool
->range_list
= next_range
;
516 pthread_mutex_destroy(&pool
->lock
);
518 memset(pool
, 0, sizeof(*pool
));
523 struct rseq_mempool
*rseq_mempool_create(const char *pool_name
,
524 size_t item_len
, const struct rseq_mempool_attr
*_attr
)
526 struct rseq_mempool
*pool
;
527 struct rseq_mempool_attr attr
= {};
530 /* Make sure each item is large enough to contain free list pointers. */
531 if (item_len
< sizeof(void *))
532 item_len
= sizeof(void *);
534 /* Align item_len on next power of two. */
535 order
= rseq_get_count_order_ulong(item_len
);
540 item_len
= 1UL << order
;
543 memcpy(&attr
, _attr
, sizeof(attr
));
544 if (!attr
.mmap_set
) {
545 attr
.mmap_func
= default_mmap_func
;
546 attr
.munmap_func
= default_munmap_func
;
547 attr
.mmap_priv
= NULL
;
551 case MEMPOOL_TYPE_PERCPU
:
552 if (attr
.max_nr_cpus
< 0) {
556 if (attr
.max_nr_cpus
== 0) {
558 attr
.max_nr_cpus
= rseq_get_max_nr_cpus();
559 if (attr
.max_nr_cpus
== 0) {
565 case MEMPOOL_TYPE_GLOBAL
:
566 /* Use a 1-cpu pool for global mempool type. */
567 attr
.max_nr_cpus
= 1;
571 attr
.stride
= RSEQ_MEMPOOL_STRIDE
; /* Use default */
572 if (item_len
> attr
.stride
|| attr
.stride
< (size_t) rseq_get_page_len() ||
573 !is_pow2(attr
.stride
)) {
578 pool
= calloc(1, sizeof(struct rseq_mempool
));
582 memcpy(&pool
->attr
, &attr
, sizeof(attr
));
583 pthread_mutex_init(&pool
->lock
, NULL
);
584 pool
->item_len
= item_len
;
585 pool
->item_order
= order
;
587 pool
->range_list
= rseq_mempool_range_create(pool
);
588 if (!pool
->range_list
)
592 pool
->name
= strdup(pool_name
);
599 rseq_mempool_destroy(pool
);
604 /* Always inline for __builtin_return_address(0). */
605 static inline __attribute__((always_inline
))
606 void set_alloc_slot(struct rseq_mempool
*pool
, struct rseq_mempool_range
*range
, size_t item_offset
)
608 unsigned long *bitmap
= range
->alloc_bitmap
;
609 size_t item_index
= item_offset
>> pool
->item_order
;
616 k
= item_index
/ BIT_PER_ULONG
;
617 mask
= 1ULL << (item_index
% BIT_PER_ULONG
);
619 /* Print error if bit is already set. */
620 if (bitmap
[k
] & mask
) {
621 fprintf(stderr
, "%s: Allocator corruption detected for pool: \"%s\" (%p), item offset: %zu, caller: %p.\n",
622 __func__
, get_pool_name(pool
), pool
, item_offset
, (void *) __builtin_return_address(0));
629 void __rseq_percpu
*__rseq_percpu_malloc(struct rseq_mempool
*pool
, bool zeroed
)
631 struct rseq_mempool_range
*range
;
632 struct free_list_node
*node
;
633 uintptr_t item_offset
;
634 void __rseq_percpu
*addr
;
636 pthread_mutex_lock(&pool
->lock
);
637 /* Get first entry from free list. */
638 node
= pool
->free_list_head
;
640 uintptr_t ptr
= (uintptr_t) node
;
641 void *range_base
= (void *) (ptr
& (~(pool
->attr
.stride
- 1)));
643 range
= (struct rseq_mempool_range
*) (range_base
- RANGE_HEADER_OFFSET
);
644 /* Remove node from free list (update head). */
645 pool
->free_list_head
= node
->next
;
646 item_offset
= (uintptr_t) ((void *) node
- range_base
);
647 addr
= (void __rseq_percpu
*) node
;
651 * If the most recent range (first in list) does not have any
652 * room left, create a new range and prepend it to the list
655 range
= pool
->range_list
;
656 if (range
->next_unused
+ pool
->item_len
> pool
->attr
.stride
) {
657 range
= rseq_mempool_range_create(pool
);
663 /* Add range to head of list. */
664 range
->next
= pool
->range_list
;
665 pool
->range_list
= range
;
667 /* First range in list has room left. */
668 item_offset
= range
->next_unused
;
669 addr
= (void __rseq_percpu
*) (range
->base
+ item_offset
);
670 range
->next_unused
+= pool
->item_len
;
673 set_alloc_slot(pool
, range
, item_offset
);
674 pthread_mutex_unlock(&pool
->lock
);
676 rseq_percpu_zero_item(pool
, range
, item_offset
);
680 void __rseq_percpu
*rseq_mempool_percpu_malloc(struct rseq_mempool
*pool
)
682 return __rseq_percpu_malloc(pool
, false);
685 void __rseq_percpu
*rseq_mempool_percpu_zmalloc(struct rseq_mempool
*pool
)
687 return __rseq_percpu_malloc(pool
, true);
690 /* Always inline for __builtin_return_address(0). */
691 static inline __attribute__((always_inline
))
692 void clear_alloc_slot(struct rseq_mempool
*pool
, struct rseq_mempool_range
*range
, size_t item_offset
)
694 unsigned long *bitmap
= range
->alloc_bitmap
;
695 size_t item_index
= item_offset
>> pool
->item_order
;
702 k
= item_index
/ BIT_PER_ULONG
;
703 mask
= 1ULL << (item_index
% BIT_PER_ULONG
);
705 /* Print error if bit is not set. */
706 if (!(bitmap
[k
] & mask
)) {
707 fprintf(stderr
, "%s: Double-free detected for pool: \"%s\" (%p), item offset: %zu, caller: %p.\n",
708 __func__
, get_pool_name(pool
), pool
, item_offset
,
709 (void *) __builtin_return_address(0));
715 void librseq_mempool_percpu_free(void __rseq_percpu
*_ptr
, size_t stride
)
717 uintptr_t ptr
= (uintptr_t) _ptr
;
718 void *range_base
= (void *) (ptr
& (~(stride
- 1)));
719 struct rseq_mempool_range
*range
= (struct rseq_mempool_range
*) (range_base
- RANGE_HEADER_OFFSET
);
720 struct rseq_mempool
*pool
= range
->pool
;
721 uintptr_t item_offset
= ptr
& (stride
- 1);
722 struct free_list_node
*head
, *item
;
724 pthread_mutex_lock(&pool
->lock
);
725 clear_alloc_slot(pool
, range
, item_offset
);
726 /* Add ptr to head of free list */
727 head
= pool
->free_list_head
;
728 /* Free-list is in CPU 0 range. */
729 item
= (struct free_list_node
*) ptr
;
731 pool
->free_list_head
= item
;
732 pthread_mutex_unlock(&pool
->lock
);
735 struct rseq_mempool_set
*rseq_mempool_set_create(void)
737 struct rseq_mempool_set
*pool_set
;
739 pool_set
= calloc(1, sizeof(struct rseq_mempool_set
));
742 pthread_mutex_init(&pool_set
->lock
, NULL
);
746 int rseq_mempool_set_destroy(struct rseq_mempool_set
*pool_set
)
750 for (order
= POOL_SET_MIN_ENTRY
; order
< POOL_SET_NR_ENTRIES
; order
++) {
751 struct rseq_mempool
*pool
= pool_set
->entries
[order
];
755 ret
= rseq_mempool_destroy(pool
);
758 pool_set
->entries
[order
] = NULL
;
760 pthread_mutex_destroy(&pool_set
->lock
);
765 /* Ownership of pool is handed over to pool set on success. */
766 int rseq_mempool_set_add_pool(struct rseq_mempool_set
*pool_set
, struct rseq_mempool
*pool
)
768 size_t item_order
= pool
->item_order
;
771 pthread_mutex_lock(&pool_set
->lock
);
772 if (pool_set
->entries
[item_order
]) {
777 pool_set
->entries
[pool
->item_order
] = pool
;
779 pthread_mutex_unlock(&pool_set
->lock
);
784 void __rseq_percpu
*__rseq_mempool_set_malloc(struct rseq_mempool_set
*pool_set
, size_t len
, bool zeroed
)
786 int order
, min_order
= POOL_SET_MIN_ENTRY
;
787 struct rseq_mempool
*pool
;
788 void __rseq_percpu
*addr
;
790 order
= rseq_get_count_order_ulong(len
);
791 if (order
> POOL_SET_MIN_ENTRY
)
794 pthread_mutex_lock(&pool_set
->lock
);
795 /* First smallest present pool where @len fits. */
796 for (order
= min_order
; order
< POOL_SET_NR_ENTRIES
; order
++) {
797 pool
= pool_set
->entries
[order
];
801 if (pool
->item_len
>= len
)
806 pthread_mutex_unlock(&pool_set
->lock
);
808 addr
= __rseq_percpu_malloc(pool
, zeroed
);
809 if (addr
== NULL
&& errno
== ENOMEM
) {
811 * If the allocation failed, try again with a
814 min_order
= order
+ 1;
825 void __rseq_percpu
*rseq_mempool_set_percpu_malloc(struct rseq_mempool_set
*pool_set
, size_t len
)
827 return __rseq_mempool_set_malloc(pool_set
, len
, false);
830 void __rseq_percpu
*rseq_mempool_set_percpu_zmalloc(struct rseq_mempool_set
*pool_set
, size_t len
)
832 return __rseq_mempool_set_malloc(pool_set
, len
, true);
835 struct rseq_mempool_attr
*rseq_mempool_attr_create(void)
837 return calloc(1, sizeof(struct rseq_mempool_attr
));
840 void rseq_mempool_attr_destroy(struct rseq_mempool_attr
*attr
)
845 int rseq_mempool_attr_set_mmap(struct rseq_mempool_attr
*attr
,
846 void *(*mmap_func
)(void *priv
, size_t len
),
847 int (*munmap_func
)(void *priv
, void *ptr
, size_t len
),
854 attr
->mmap_set
= true;
855 attr
->mmap_func
= mmap_func
;
856 attr
->munmap_func
= munmap_func
;
857 attr
->mmap_priv
= mmap_priv
;
861 int rseq_mempool_attr_set_init(struct rseq_mempool_attr
*attr
,
862 int (*init_func
)(void *priv
, void *addr
, size_t len
, int cpu
),
869 attr
->init_set
= true;
870 attr
->init_func
= init_func
;
871 attr
->init_priv
= init_priv
;
875 int rseq_mempool_attr_set_robust(struct rseq_mempool_attr
*attr
)
881 attr
->robust_set
= true;
885 int rseq_mempool_attr_set_percpu(struct rseq_mempool_attr
*attr
,
886 size_t stride
, int max_nr_cpus
)
892 attr
->type
= MEMPOOL_TYPE_PERCPU
;
893 attr
->stride
= stride
;
894 attr
->max_nr_cpus
= max_nr_cpus
;
898 int rseq_mempool_attr_set_global(struct rseq_mempool_attr
*attr
,
905 attr
->type
= MEMPOOL_TYPE_GLOBAL
;
906 attr
->stride
= stride
;
907 attr
->max_nr_cpus
= 0;
911 int rseq_mempool_get_max_nr_cpus(struct rseq_mempool
*mempool
)
913 if (!mempool
|| mempool
->attr
.type
!= MEMPOOL_TYPE_PERCPU
) {
917 return mempool
->attr
.max_nr_cpus
;
This page took 0.067686 seconds and 4 git commands to generate.