diff options
Diffstat (limited to 'src/vpp/stats/stat_segment.c')
-rw-r--r-- | src/vpp/stats/stat_segment.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c index 8255b16c010..968c0566b3f 100644 --- a/src/vpp/stats/stat_segment.c +++ b/src/vpp/stats/stat_segment.c @@ -316,32 +316,37 @@ vlib_map_stat_segment_init (void) stat_segment_main_t *sm = &stat_segment_main; stat_segment_shared_header_t *shared_header; void *oldheap; - ssize_t memory_size; + uword memory_size, sys_page_sz; int mfd; - char *mem_name = "stat_segment_test"; - void *memaddr; + char *mem_name = "stat segment"; + void *heap, *memaddr; memory_size = sm->memory_size; if (memory_size == 0) memory_size = STAT_SEGMENT_DEFAULT_SIZE; - /* Create shared memory segment */ - if ((mfd = memfd_create (mem_name, 0)) < 0) - return clib_error_return (0, "stat segment memfd_create failure"); + if (sm->log2_page_sz == CLIB_MEM_PAGE_SZ_UNKNOWN) + sm->log2_page_sz = CLIB_MEM_PAGE_SZ_DEFAULT; + + mfd = clib_mem_vm_create_fd (sm->log2_page_sz, mem_name); /* Set size */ if ((ftruncate (mfd, memory_size)) == -1) return clib_error_return (0, "stat segment ftruncate failure"); - if ((memaddr = - mmap (NULL, memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, - 0)) == MAP_FAILED) + if (mfd == -1) + return clib_error_return (0, "stat segment memory fd failure: %U", + format_clib_error, clib_mem_get_last_error ()); + + memaddr = clib_mem_vm_map_shared (0, memory_size, mfd, 0, mem_name); + + if (memaddr == CLIB_MEM_VM_MAP_FAILED) return clib_error_return (0, "stat segment mmap failure"); - void *heap; - heap = - create_mspace_with_base (((u8 *) memaddr) + getpagesize (), - memory_size - getpagesize (), 1 /* locked */ ); + sys_page_sz = clib_mem_get_page_size (); + + heap = create_mspace_with_base (((u8 *) memaddr) + sys_page_sz, memory_size + - sys_page_sz, 1 /* locked */ ); mspace_disable_expand (heap); sm->heap = heap; sm->memfd = mfd; @@ -904,6 +909,9 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input) else if (unformat (input, "size %U", unformat_memory_size, &sm->memory_size)) ; + else if (unformat (input, "page-size %U", + unformat_log2_page_size, &sm->log2_page_sz)) + ; else if (unformat (input, "per-node-counters on")) sm->node_counters_enabled = 1; else if (unformat (input, "per-node-counters off")) |