aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vlib/threads.c7
-rw-r--r--src/vppinfra/linux/mem.c157
-rw-r--r--src/vppinfra/mem.h34
-rw-r--r--src/vppinfra/mem_dlmalloc.c25
4 files changed, 5 insertions, 218 deletions
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 0fc306db6f2..270ccc325ba 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -640,8 +640,11 @@ vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned cpu_id)
/* If the user requested a NUMA heap, create it... */
if (tm->numa_heap_size)
{
- numa_heap = clib_mem_init_thread_safe_numa
- (0 /* DIY */ , tm->numa_heap_size, w->numa_id);
+ clib_mem_set_numa_affinity (w->numa_id, 1 /* force */ );
+ numa_heap = clib_mem_create_heap (0 /* DIY */ , tm->numa_heap_size,
+ 1 /* is_locked */ ,
+ "numa %u heap", w->numa_id);
+ clib_mem_set_default_numa_affinity ();
mm->per_numa_mheaps[w->numa_id] = numa_heap;
}
else
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)
{
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index e998eb0f7bc..34283f5aab1 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -345,8 +345,6 @@ void *clib_mem_init (void *heap, uword size);
void *clib_mem_init_with_page_size (uword memory_size,
clib_mem_page_sz_t log2_page_sz);
void *clib_mem_init_thread_safe (void *memory, uword memory_size);
-void *clib_mem_init_thread_safe_numa (void *memory, uword memory_size,
- u8 numa);
void clib_mem_exit (void);
@@ -427,36 +425,6 @@ int clib_mem_vm_unmap (void *base);
clib_mem_vm_map_hdr_t *clib_mem_vm_get_next_map_hdr (clib_mem_vm_map_hdr_t *
hdr);
-typedef struct
-{
-#define CLIB_MEM_VM_F_SHARED (1 << 0)
-#define CLIB_MEM_VM_F_HUGETLB (1 << 1)
-#define CLIB_MEM_VM_F_NUMA_PREFER (1 << 2)
-#define CLIB_MEM_VM_F_NUMA_FORCE (1 << 3)
-#define CLIB_MEM_VM_F_HUGETLB_PREALLOC (1 << 4)
-#define CLIB_MEM_VM_F_LOCKED (1 << 5)
- u32 flags; /**< vm allocation flags:
- <br> CLIB_MEM_VM_F_SHARED: request shared memory, file
- descriptor will be provided on successful allocation.
- <br> CLIB_MEM_VM_F_HUGETLB: request hugepages.
- <br> CLIB_MEM_VM_F_NUMA_PREFER: numa_node field contains valid
- numa node preference.
- <br> CLIB_MEM_VM_F_NUMA_FORCE: fail if setting numa policy fails.
- <br> CLIB_MEM_VM_F_HUGETLB_PREALLOC: pre-allocate hugepages if
- number of available pages is not sufficient.
- <br> CLIB_MEM_VM_F_LOCKED: request locked memory.
- */
- char *name; /**< Name for memory allocation, set by caller. */
- uword size; /**< Allocation size, set by caller. */
- int numa_node; /**< numa node preference. Valid if CLIB_MEM_VM_F_NUMA_PREFER set. */
- void *addr; /**< Pointer to allocated memory, set on successful allocation. */
- int fd; /**< File descriptor, set on successful allocation if CLIB_MEM_VM_F_SHARED is set. */
- int log2_page_size; /* Page size in log2 format, set on successful allocation. */
- int n_pages; /* Number of pages. */
- uword requested_va; /**< Request fixed position mapping */
-} clib_mem_vm_alloc_t;
-
-
static_always_inline clib_mem_page_sz_t
clib_mem_get_log2_page_size (void)
{
@@ -476,8 +444,6 @@ clib_mem_get_log2_default_hugepage_size ()
}
int clib_mem_vm_create_fd (clib_mem_page_sz_t log2_page_size, char *fmt, ...);
-clib_error_t *clib_mem_vm_ext_alloc (clib_mem_vm_alloc_t * a);
-void clib_mem_vm_ext_free (clib_mem_vm_alloc_t * a);
uword clib_mem_get_fd_page_size (int fd);
uword clib_mem_get_default_hugepage_size (void);
clib_mem_page_sz_t clib_mem_get_fd_log2_page_size (int fd);
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 069a0add24b..1c57373e650 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -278,31 +278,6 @@ clib_mem_destroy (void)
clib_mem_vm_unmap (base);
}
-void *
-clib_mem_init_thread_safe_numa (void *memory, uword memory_size, u8 numa)
-{
- clib_mem_vm_alloc_t alloc = { 0 };
- clib_error_t *err;
- void *heap;
-
- alloc.size = memory_size;
- alloc.flags = CLIB_MEM_VM_F_NUMA_FORCE;
- alloc.numa_node = numa;
- if ((err = clib_mem_vm_ext_alloc (&alloc)))
- {
- clib_error_report (err);
- return 0;
- }
-
- heap = clib_mem_init_internal (memory, memory_size,
- CLIB_MEM_PAGE_SZ_DEFAULT,
- 0 /* do NOT clib_mem_set_heap */ );
-
- ASSERT (heap);
-
- return heap;
-}
-
u8 *
format_clib_mem_usage (u8 * s, va_list * va)
{