8ca1fac3d08b9ad0fdfb7b0f34329ac9663a551d
[dpdk.git] / lib / librte_eal / common / eal_memalloc.h
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 #include <rte_eal_memconfig.h>
12
13 /*
14  * Allocate segment of specified page size.
15  */
16 struct rte_memseg *
17 eal_memalloc_alloc_seg(size_t page_sz, int socket);
18
19 /*
20  * Allocate `n_segs` segments.
21  *
22  * Note: `ms` can be NULL.
23  *
24  * Note: it is possible to request best-effort allocation by setting `exact` to
25  * `false`, in which case allocator will return however many pages it managed to
26  * allocate successfully.
27  */
28 int
29 eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz,
30                 int socket, bool exact);
31
32 /*
33  * Deallocate segment
34  */
35 int
36 eal_memalloc_free_seg(struct rte_memseg *ms);
37
38 /*
39  * Deallocate `n_segs` segments. Returns 0 on successful deallocation of all
40  * segments, returns -1 on error. Any segments that could have been deallocated,
41  * will be deallocated even in case of error.
42  */
43 int
44 eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs);
45
46 /*
47  * Check if memory pointed to by `start` and of `length` that resides in
48  * memseg list `msl` is IOVA-contiguous.
49  */
50 bool
51 eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
52                 size_t len);
53
54 /* synchronize local memory map to primary process */
55 int
56 eal_memalloc_sync_with_primary(void);
57
58 #endif /* EAL_MEMALLOC_H */