diff options
author | Damjan Marion <damarion@cisco.com> | 2020-10-02 15:01:12 +0200 |
---|---|---|
committer | Damjan Marion <damarion@cisco.com> | 2020-10-02 15:04:17 +0200 |
commit | 2bc1af5578a9c669c16839656bb661ce950c2246 (patch) | |
tree | 7390e803f9d5fb0d698976a5c5ac682d7d59de52 /src/vppinfra/linux | |
parent | eb530a24b4ec2b055f5ef40f4b01ca4579dd87b0 (diff) |
vppinfra: use clib_mem_create_heap() to create numa heap(s)
Type: improvement
Change-Id: Ie04302c576869bc7bfaa9f13ed2ea8a403a393d4
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/linux')
-rw-r--r-- | src/vppinfra/linux/mem.c | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c index 8b2fd14d210..06e18cd400d 100644 --- a/src/vppinfra/linux/mem.c +++ b/src/vppinfra/linux/mem.c @@ -196,163 +196,6 @@ clib_mem_vm_randomize_va (uword * requested_va, (clib_cpu_time_now () & bit_mask) * (1ull << log2_page_size); } -clib_error_t * -clib_mem_vm_ext_alloc (clib_mem_vm_alloc_t * a) -{ - clib_mem_main_t *mm = &clib_mem_main; - int fd = -1; - clib_error_t *err = 0; - void *addr = 0; - u8 *filename = 0; - int mmap_flags = 0; - int log2_page_size; - int n_pages; - int old_mpol = -1; - long unsigned int old_mask[16] = { 0 }; - - /* save old numa mem policy if needed */ - if (a->flags & (CLIB_MEM_VM_F_NUMA_PREFER | CLIB_MEM_VM_F_NUMA_FORCE)) - { - int rv; - rv = get_mempolicy (&old_mpol, old_mask, sizeof (old_mask) * 8 + 1, - 0, 0); - - if (rv == -1) - { - if (a->numa_node != 0 && (a->flags & CLIB_MEM_VM_F_NUMA_FORCE) != 0) - { - err = clib_error_return_unix (0, "get_mempolicy"); - goto error; - } - else - old_mpol = -1; - } - } - - if (a->flags & CLIB_MEM_VM_F_LOCKED) - mmap_flags |= MAP_LOCKED; - - /* if we are creating shared segment, we need file descriptor */ - if (a->flags & CLIB_MEM_VM_F_SHARED) - { - mmap_flags |= MAP_SHARED; - /* if hugepages are needed we need to create mount point */ - if (a->flags & CLIB_MEM_VM_F_HUGETLB) - { - log2_page_size = CLIB_MEM_PAGE_SZ_DEFAULT_HUGE; - mmap_flags |= MAP_LOCKED; - } - else - log2_page_size = CLIB_MEM_PAGE_SZ_DEFAULT; - - if ((fd = clib_mem_vm_create_fd (log2_page_size, "%s", a->name)) == -1) - { - err = clib_error_return (0, "%U", format_clib_error, mm->error); - goto error; - } - - log2_page_size = clib_mem_get_fd_log2_page_size (fd); - if (log2_page_size == 0) - { - err = clib_error_return_unix (0, "cannot determine page size"); - goto error; - } - - if (a->requested_va) - { - clib_mem_vm_randomize_va (&a->requested_va, log2_page_size); - mmap_flags |= MAP_FIXED; - } - } - else /* not CLIB_MEM_VM_F_SHARED */ - { - mmap_flags |= MAP_PRIVATE | MAP_ANONYMOUS; - if (a->flags & CLIB_MEM_VM_F_HUGETLB) - { - mmap_flags |= MAP_HUGETLB; - log2_page_size = 21; - } - else - { - log2_page_size = min_log2 (sysconf (_SC_PAGESIZE)); - } - } - - n_pages = ((a->size - 1) >> log2_page_size) + 1; - - if (a->flags & CLIB_MEM_VM_F_HUGETLB_PREALLOC) - { - err = clib_sysfs_prealloc_hugepages (a->numa_node, log2_page_size, - n_pages); - if (err) - goto error; - - } - - if (fd != -1) - if ((ftruncate (fd, (u64) n_pages * (1 << log2_page_size))) == -1) - { - err = clib_error_return_unix (0, "ftruncate"); - goto error; - } - - if (old_mpol != -1) - { - int rv; - long unsigned int mask[16] = { 0 }; - mask[0] = 1 << a->numa_node; - rv = set_mempolicy (MPOL_BIND, mask, sizeof (mask) * 8 + 1); - if (rv == -1 && a->numa_node != 0 && - (a->flags & CLIB_MEM_VM_F_NUMA_FORCE) != 0) - { - err = clib_error_return_unix (0, "set_mempolicy"); - goto error; - } - } - - addr = mmap (uword_to_pointer (a->requested_va, void *), a->size, - (PROT_READ | PROT_WRITE), mmap_flags, fd, 0); - if (addr == MAP_FAILED) - { - err = clib_error_return_unix (0, "mmap"); - goto error; - } - - /* re-apply old numa memory policy */ - if (old_mpol != -1 && - set_mempolicy (old_mpol, old_mask, sizeof (old_mask) * 8 + 1) == -1) - { - err = clib_error_return_unix (0, "set_mempolicy"); - goto error; - } - - a->log2_page_size = log2_page_size; - a->n_pages = n_pages; - a->addr = addr; - a->fd = fd; - CLIB_MEM_UNPOISON (addr, a->size); - goto done; - -error: - if (fd != -1) - close (fd); - -done: - vec_free (filename); - return err; -} - -void -clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a) -{ - if (a != 0) - { - clib_mem_vm_free (a->addr, 1ull << a->log2_page_size); - if (a->fd != -1) - close (a->fd); - } -} - static int legacy_memfd_create (u8 * name) { |