summaryrefslogtreecommitdiffstats
path: root/lib/librte_eal/common/eal_memalloc.h
blob: af917c2f9da209a60e88026146f73a1d953abdcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2017-2018 Intel Corporation
 */

#ifndef EAL_MEMALLOC_H
#define EAL_MEMALLOC_H

#include <stdbool.h>

#include <rte_memory.h>
#include <rte_eal_memconfig.h>

/*
 * Allocate segment of specified page size.
 */
struct rte_memseg *
eal_memalloc_alloc_seg(size_t page_sz, int socket);

/*
 * Allocate `n_segs` segments.
 *
 * Note: `ms` can be NULL.
 *
 * Note: it is possible to request best-effort allocation by setting `exact` to
 * `false`, in which case allocator will return however many pages it managed to
 * allocate successfully.
 */
int
eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz,
		int socket, bool exact);

/*
 * Deallocate segment
 */
int
eal_memalloc_free_seg(struct rte_memseg *ms);

/*
 * Deallocate `n_segs` segments. Returns 0 on successful deallocation of all
 * segments, returns -1 on error. Any segments that could have been deallocated,
 * will be deallocated even in case of error.
 */
int
eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs);

/*
 * Check if memory pointed to by `start` and of `length` that resides in
 * memseg list `msl` is IOVA-contiguous.
 */
bool
eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
		size_t len);

/* synchronize local memory map to primary process */
int
eal_memalloc_sync_with_primary(void);

int
eal_memalloc_mem_event_callback_register(const char *name,
		rte_mem_event_callback_t clb, void *arg);

int
eal_memalloc_mem_event_callback_unregister(const char *name, void *arg);

void
eal_memalloc_mem_event_notify(enum rte_mem_event event, const void *start,
		size_t len);

int
eal_memalloc_mem_alloc_validator_register(const char *name,
		rte_mem_alloc_validator_t clb, int socket_id, size_t limit);

int
eal_memalloc_mem_alloc_validator_unregister(const char *name, int socket_id);

int
eal_memalloc_mem_alloc_validate(int socket_id, size_t new_len);

/* returns fd or -errno */
int
eal_memalloc_get_seg_fd(int list_idx, int seg_idx);

/* returns 0 or -errno */
int
eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd);

int
eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);

int
eal_memalloc_init(void);

#endif /* EAL_MEMALLOC_H */