dpdk/lib/librte_eal/common/eal_memalloc.h
<<
>>
Prefs
   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 */
  15struct rte_memseg *
  16eal_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 */
  27int
  28eal_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 */
  34int
  35eal_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 */
  42int
  43eal_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 */
  49bool
  50eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
  51                size_t len);
  52
  53/* synchronize local memory map to primary process */
  54int
  55eal_memalloc_sync_with_primary(void);
  56
  57int
  58eal_memalloc_mem_event_callback_register(const char *name,
  59                rte_mem_event_callback_t clb, void *arg);
  60
  61int
  62eal_memalloc_mem_event_callback_unregister(const char *name, void *arg);
  63
  64void
  65eal_memalloc_mem_event_notify(enum rte_mem_event event, const void *start,
  66                size_t len);
  67
  68int
  69eal_memalloc_mem_alloc_validator_register(const char *name,
  70                rte_mem_alloc_validator_t clb, int socket_id, size_t limit);
  71
  72int
  73eal_memalloc_mem_alloc_validator_unregister(const char *name, int socket_id);
  74
  75int
  76eal_memalloc_mem_alloc_validate(int socket_id, size_t new_len);
  77
  78/* returns fd or -errno */
  79int
  80eal_memalloc_get_seg_fd(int list_idx, int seg_idx);
  81
  82/* returns 0 or -errno */
  83int
  84eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd);
  85
  86/* returns 0 or -errno */
  87int
  88eal_memalloc_set_seg_list_fd(int list_idx, int fd);
  89
  90int
  91eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
  92
  93int
  94eal_memalloc_init(void);
  95
  96#endif /* EAL_MEMALLOC_H */
  97