36 u8 junk = 0, *ssvm_filename;
38 uword page_size, requested_va = 0;
42 return SSVM_API_ERROR_NO_SIZE;
48 ssvm_filename =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
49 unlink ((
char *) ssvm_filename);
52 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR | O_CREAT | O_EXCL, 0777);
56 return SSVM_API_ERROR_CREATE_FAILURE;
59 if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
65 if (fchown (ssvm_fd, smr->
uid, smr->
gid) < 0)
69 if (lseek (ssvm_fd, ssvm->
ssvm_size, SEEK_SET) < 0)
73 return SSVM_API_ERROR_SET_SIZE;
76 if (write (ssvm_fd, &junk, 1) != 1)
80 return SSVM_API_ERROR_SET_SIZE;
97 return SSVM_API_ERROR_MMAP;
106 #if USE_DLMALLOC == 0 141 ssvm_fd = shm_open ((
char *) ssvm->
name, O_RDWR, 0777);
147 if (fstat (ssvm_fd, &stat) < 0)
153 if (stat.st_size > 0)
157 return SSVM_API_ERROR_SLAVE_TIMEOUT;
160 sh = (
void *) mmap (0,
MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
162 if (sh == MAP_FAILED)
166 return SSVM_API_ERROR_MMAP;
177 return SSVM_API_ERROR_SLAVE_TIMEOUT;
185 PROT_READ | PROT_WRITE,
186 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
188 if (sh == MAP_FAILED)
192 return SSVM_API_ERROR_MMAP;
203 fn =
format (0,
"/dev/shm/%s%c", ssvm->
name, 0);
206 clib_warning (
"[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
210 if (unlink ((
char *) fn) < 0)
232 return SSVM_API_ERROR_NO_SIZE;
243 return SSVM_API_ERROR_CREATE_FAILURE;
246 memfd->
fd = alloc.
fd;
248 memfd->
my_pid = getpid ();
258 #if USE_DLMALLOC == 0 297 return SSVM_API_ERROR_MMAP;
304 mapa.
size = page_size;
310 return SSVM_API_ERROR_MMAP;
327 return SSVM_API_ERROR_MMAP;
356 rnd_size &= ~(pagesize - 1);
358 #if USE_DLMALLOC == 0 384 rnd_size = dlminfo.fordblks;
416 #if USE_DLMALLOC == 0
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.
void * mheap_alloc(void *memory, uword size)
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 *)
static mheap_t * mheap_header(u8 *v)
int ssvm_slave_init_shm(ssvm_private_t *ssvm)
ssvm_shared_header_t * sh
DLMALLOC_EXPORT struct dlmallinfo mspace_mallinfo(mspace msp)
#define MHEAP_FLAG_THREAD_SAFE
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 *)
#define MHEAP_FLAG_DISABLE_VM
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)
u64 clib_mem_get_fd_page_size(int fd)
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked)
#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 ...
void * mheap_alloc_with_flags(void *memory, uword memory_size, uword flags)
static void clib_mem_free(void *p)
#define clib_error_report(e)
static heap_header_t * heap_header(void *v)
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)
static void * clib_mem_alloc_aligned(uword size, uword align)
int fd
File descriptor to be mapped.
void ssvm_delete_private(ssvm_private_t *ssvm)
void ssvm_delete_shm(ssvm_private_t *ssvm)
#define CLIB_CACHE_LINE_BYTES
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)