33 u8 junk = 0, *ssvm_filename;
35 uword page_size, requested_va = 0;
39 return SSVM_API_ERROR_NO_SIZE;
45 ssvm_filename =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
46 unlink ((
char *) ssvm_filename);
49 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR | O_CREAT | O_EXCL, 0777);
53 return SSVM_API_ERROR_CREATE_FAILURE;
56 if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
62 if (fchown (ssvm_fd, smr->
uid, smr->
gid) < 0)
66 if (lseek (ssvm_fd, ssvm->
ssvm_size, SEEK_SET) < 0)
70 return SSVM_API_ERROR_SET_SIZE;
73 if (write (ssvm_fd, &junk, 1) != 1)
77 return SSVM_API_ERROR_SET_SIZE;
95 return SSVM_API_ERROR_MMAP;
135 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR, 0777);
141 if (fstat (ssvm_fd, &stat) < 0)
147 if (stat.st_size > 0)
151 return SSVM_API_ERROR_SLAVE_TIMEOUT;
154 sh = (
void *) mmap (0,
MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
156 if (sh == MAP_FAILED)
160 return SSVM_API_ERROR_MMAP;
171 return SSVM_API_ERROR_SLAVE_TIMEOUT;
179 PROT_READ | PROT_WRITE,
180 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
182 if (sh == MAP_FAILED)
186 return SSVM_API_ERROR_MMAP;
197 fn =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
200 clib_warning (
"[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
204 if (unlink ((
char *) fn) < 0)
226 return SSVM_API_ERROR_NO_SIZE;
242 return SSVM_API_ERROR_CREATE_FAILURE;
245 memfd->
fd = alloc.
fd;
247 memfd->
my_pid = getpid ();
289 return SSVM_API_ERROR_MMAP;
296 mapa.
size = page_size;
302 return SSVM_API_ERROR_MMAP;
319 return SSVM_API_ERROR_MMAP;
350 rnd_size &= ~(pagesize - 1);
353 alloc.
size = rnd_size + pagesize;
363 return SSVM_API_ERROR_CREATE_FAILURE;
391 sh->ssvm_size = rnd_size;
394 sh->name = ssvm->
name;
#define CLIB_MEM_UNPOISON(a, s)
svm_region_t * svm_get_root_rp(void)
static init_fn slave_init_fns[SSVM_N_SEGMENT_TYPES]
static init_fn master_init_fns[SSVM_N_SEGMENT_TYPES]
#define vec_c_string_is_terminated(V)
Test whether a vector is a NULL terminated c-string.
#define CLIB_MEM_VM_F_NUMA_PREFER
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
void * addr
Pointer to allocated memory, set on successful allocation.
uword requested_va
Request fixed position mapping.
void(* delete_fn)(ssvm_private_t *)
int numa_node
numa node preference.
int ssvm_slave_init_shm(ssvm_private_t *ssvm)
ssvm_shared_header_t * sh
DLMALLOC_EXPORT struct dlmallinfo mspace_mallinfo(mspace msp)
int ssvm_master_init_shm(ssvm_private_t *ssvm)
static uword min_log2(uword x)
void ssvm_delete(ssvm_private_t *ssvm)
int ssvm_slave_init_private(ssvm_private_t *ssvm)
DLMALLOC_EXPORT mspace create_mspace_with_base(void *base, size_t capacity, int locked)
u8 * ssvm_name(const ssvm_private_t *ssvm)
enum ssvm_segment_type_ ssvm_segment_type_t
clib_error_t * clib_mem_vm_ext_map(clib_mem_vm_map_t *a)
clib_error_t * clib_mem_vm_ext_alloc(clib_mem_vm_alloc_t *a)
uword requested_va
Request fixed position mapping.
int(* init_fn)(ssvm_private_t *)
int ssvm_master_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment master.
char * name
Name for memory allocation, set by caller.
static void * ssvm_push_heap(ssvm_shared_header_t *sh)
uword size
Allocation size, set by caller.
int attach_timeout
shm segments attach timeout (sec)
int ssvm_master_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
static void ssvm_pop_heap(void *oldheap)
vl_api_fib_path_type_t type
#define CLIB_MEM_VM_F_SHARED
int fd
File descriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set.
DLMALLOC_EXPORT void mspace_disable_expand(mspace msp)
uword clib_mem_get_page_size(void)
u8 numa
Numa requested at alloc time.
u64 clib_mem_get_fd_page_size(int fd)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
int ssvm_slave_init(ssvm_private_t *ssvm, ssvm_segment_type_t type)
u32 flags
vm allocation flags: CLIB_MEM_VM_F_SHARED: request shared memory, file descriptor will be provided ...
#define clib_error_report(e)
static uword pointer_to_uword(const void *p)
static void clib_mem_vm_free(void *addr, uword size)
static delete_fn delete_fns[SSVM_N_SEGMENT_TYPES]
#define clib_unix_warning(format, args...)
void ssvm_delete_memfd(ssvm_private_t *memfd)
void clib_mem_vm_randomize_va(uword *requested_va, u32 log2_page_size)
int ssvm_master_init_private(ssvm_private_t *ssvm)
Initialize segment in a private heap.
DLMALLOC_EXPORT size_t destroy_mspace(mspace msp)
int fd
File descriptor to be mapped.
void ssvm_delete_private(ssvm_private_t *ssvm)
void ssvm_delete_shm(ssvm_private_t *ssvm)
MALLINFO_FIELD_TYPE fordblks
int ssvm_slave_init_memfd(ssvm_private_t *memfd)
Initialize memfd segment slave.
void * addr
Pointer to mapped memory, if successful.
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)