New upstream version 18.11-rc1
[deb_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 int
59 eal_memalloc_mem_event_callback_register(const char *name,
60                 rte_mem_event_callback_t clb, void *arg);
61
62 int
63 eal_memalloc_mem_event_callback_unregister(const char *name, void *arg);
64
65 void
66 eal_memalloc_mem_event_notify(enum rte_mem_event event, const void *start,
67                 size_t len);
68
69 int
70 eal_memalloc_mem_alloc_validator_register(const char *name,
71                 rte_mem_alloc_validator_t clb, int socket_id, size_t limit);
72
73 int
74 eal_memalloc_mem_alloc_validator_unregister(const char *name, int socket_id);
75
76 int
77 eal_memalloc_mem_alloc_validate(int socket_id, size_t new_len);
78
79 /* returns fd or -errno */
80 int
81 eal_memalloc_get_seg_fd(int list_idx, int seg_idx);
82
83 /* returns 0 or -errno */
84 int
85 eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd);
86
87 int
88 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
89
90 int
91 eal_memalloc_init(void);
92
93 #endif /* EAL_MEMALLOC_H */