From 567e61d09cd00174203eff85f63a598420476951 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Wed, 24 Oct 2018 17:08:26 +0200 Subject: pmalloc: support for 4K pages Change-Id: Iecceffe06a92660976ebb58cd3cbec4be8931db0 Signed-off-by: Damjan Marion --- src/vlib/buffer.c | 28 ++++++++++++++++++++++++---- src/vlib/linux/vfio.c | 2 +- src/vlib/physmem.c | 13 ++++++++----- src/vlib/physmem_funcs.h | 4 ++-- 4 files changed, 35 insertions(+), 12 deletions(-) (limited to 'src/vlib') diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index 22cf7999be7..ff91d3b920c 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -55,6 +55,9 @@ static u32 vlib_buffer_physmem_sz = 14 << 20; vlib_buffer_main_t buffer_main; +/* logging */ +static vlib_log_class_t buffer_log_default; + uword vlib_buffer_length_in_chain_slow_path (vlib_main_t * vm, vlib_buffer_t * b_first) @@ -963,6 +966,9 @@ vlib_buffer_main_init (struct vlib_main_t * vm) clib_error_t *error; u32 physmem_map_index; u8 pool_index; + int log2_page_size = 0; + + buffer_log_default = vlib_log_register_class ("buffer", 0); if (vlib_buffer_callbacks) { @@ -981,10 +987,24 @@ vlib_buffer_main_init (struct vlib_main_t * vm) &vlib_buffer_delete_free_list_internal; clib_spinlock_init (&bm->buffer_known_hash_lockp); - if ((error = vlib_physmem_shared_map_create (vm, "buffers", - vlib_buffer_physmem_sz, - CLIB_PMALLOC_NUMA_LOCAL, - &physmem_map_index))) +retry: + error = vlib_physmem_shared_map_create (vm, "buffers", + vlib_buffer_physmem_sz, + log2_page_size, + CLIB_PMALLOC_NUMA_LOCAL, + &physmem_map_index); + + if (error && log2_page_size == 0) + { + vlib_log_warn (buffer_log_default, "%U", format_clib_error, error); + clib_error_free (error); + vlib_log_warn (buffer_log_default, "falling back to non-hugepage " + "backed buffer pool"); + log2_page_size = min_log2 (clib_mem_get_page_size ()); + goto retry; + } + + if (error) return error; pool_index = vlib_buffer_register_physmem_map (vm, physmem_map_index); diff --git a/src/vlib/linux/vfio.c b/src/vlib/linux/vfio.c index d300a683dd7..1ed99ceee55 100644 --- a/src/vlib/linux/vfio.c +++ b/src/vlib/linux/vfio.c @@ -40,7 +40,7 @@ vfio_map_physmem_page (vlib_main_t * vm, void *addr) vlib_physmem_main_t *vpm = &vm->physmem_main; linux_vfio_main_t *lvm = &vfio_main; struct vfio_iommu_type1_dma_map dm = { 0 }; - uword log2_page_size = vpm->pmalloc_main->log2_page_sz; + uword log2_page_size = vpm->pmalloc_main->def_log2_page_sz; uword physmem_start = pointer_to_uword (vpm->pmalloc_main->base); if (lvm->container_fd == -1) diff --git a/src/vlib/physmem.c b/src/vlib/physmem.c index 2599bce944d..f881e0a8e71 100755 --- a/src/vlib/physmem.c +++ b/src/vlib/physmem.c @@ -31,7 +31,8 @@ clib_error_t * vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, uword size, - u32 numa_node, u32 * map_index) + u32 log2_page_sz, u32 numa_node, + u32 * map_index) { clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main; vlib_physmem_main_t *vpm = &vm->physmem_main; @@ -41,7 +42,8 @@ vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, uword size, void *va; uword i; - va = clib_pmalloc_create_shared_arena (pm, name, size, numa_node); + va = clib_pmalloc_create_shared_arena (pm, name, size, log2_page_sz, + numa_node); if (va == 0) return clib_error_return (0, "%U", format_clib_error, @@ -53,12 +55,13 @@ vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, uword size, *map_index = map->index = map - vpm->maps; map->base = va; map->fd = a->fd; - map->n_pages = a->n_pages; - map->log2_page_size = a->log2_page_sz; + map->n_pages = a->n_pages * a->subpages_per_page; + map->log2_page_size = a->log2_subpage_sz; for (i = 0; i < a->n_pages; i++) { - uword pa = clib_pmalloc_get_pa (pm, (u8 *) va + (i << a->log2_page_sz)); + uword pa = + clib_pmalloc_get_pa (pm, (u8 *) va + (i << a->log2_subpage_sz)); /* maybe iova */ if (pa == 0) diff --git a/src/vlib/physmem_funcs.h b/src/vlib/physmem_funcs.h index 0082f85c70d..70fb8e74fc7 100644 --- a/src/vlib/physmem_funcs.h +++ b/src/vlib/physmem_funcs.h @@ -42,8 +42,8 @@ clib_error_t *vlib_physmem_init (vlib_main_t * vm); clib_error_t *vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, - uword size, u32 numa_node, - u32 * map_index); + uword size, u32 log2_page_sz, + u32 numa_node, u32 * map_index); vlib_physmem_map_t *vlib_physmem_get_map (vlib_main_t * vm, u32 index); -- cgit 1.2.3-korg