1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017-2018 Intel Corporation 3 */ 4 5 #ifndef EAL_MEMALLOC_H 6 #define EAL_MEMALLOC_H 7 8 #include <stdbool.h> 9 10 #include <rte_memory.h> 11 12 /* 13 * Allocate segment of specified page size. 14 */ 15 struct rte_memseg * 16 eal_memalloc_alloc_seg(size_t page_sz, int socket); 17 18 /* 19 * Allocate `n_segs` segments. 20 * 21 * Note: `ms` can be NULL. 22 * 23 * Note: it is possible to request best-effort allocation by setting `exact` to 24 * `false`, in which case allocator will return however many pages it managed to 25 * allocate successfully. 26 */ 27 int 28 eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz, 29 int socket, bool exact); 30 31 /* 32 * Deallocate segment 33 */ 34 int 35 eal_memalloc_free_seg(struct rte_memseg *ms); 36 37 /* 38 * Deallocate `n_segs` segments. Returns 0 on successful deallocation of all 39 * segments, returns -1 on error. Any segments that could have been deallocated, 40 * will be deallocated even in case of error. 41 */ 42 int 43 eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs); 44 45 /* 46 * Check if memory pointed to by `start` and of `length` that resides in 47 * memseg list `msl` is IOVA-contiguous. 48 */ 49 bool 50 eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start, 51 size_t len); 52 53 /* synchronize local memory map to primary process */ 54 int 55 eal_memalloc_sync_with_primary(void); 56 57 int 58 eal_memalloc_mem_event_callback_register(const char *name, 59 rte_mem_event_callback_t clb, void *arg); 60 61 int 62 eal_memalloc_mem_event_callback_unregister(const char *name, void *arg); 63 64 void 65 eal_memalloc_mem_event_notify(enum rte_mem_event event, const void *start, 66 size_t len); 67 68 int 69 eal_memalloc_mem_alloc_validator_register(const char *name, 70 rte_mem_alloc_validator_t clb, int socket_id, size_t limit); 71 72 int 73 eal_memalloc_mem_alloc_validator_unregister(const char *name, int socket_id); 74 75 int 76 eal_memalloc_mem_alloc_validate(int socket_id, size_t new_len); 77 78 /* returns fd or -errno */ 79 int 80 eal_memalloc_get_seg_fd(int list_idx, int seg_idx); 81 82 /* returns 0 or -errno */ 83 int 84 eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd); 85 86 /* returns 0 or -errno */ 87 int 88 eal_memalloc_set_seg_list_fd(int list_idx, int fd); 89 90 int 91 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset); 92 93 int 94 eal_memalloc_init(void) 95 __rte_shared_locks_required(rte_mcfg_mem_get_lock()); 96 97 int 98 eal_memalloc_cleanup(void); 99 100 #endif /* EAL_MEMALLOC_H */ 101