summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/pmalloc.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2019-10-30 18:07:35 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-02-06 12:29:37 +0000
commit5b2eea6e0705b7e8f8b77f0efe6535885717cbee (patch)
treedb6808b6af10431099ccbf1191da174014eec8cc /src/vppinfra/pmalloc.c
parent5ec78926b6ba97e3808abe54b2aef981ab26d038 (diff)
pmalloc: always lock pages
Type: feature Change-Id: I5bbf37969c9c51e40a013d1fc3ab966838eeb80d Signed-off-by: Damjan Marion <damarion@cisco.com> (cherry picked from commit 801c7016ad90e5f5618f523b3f9284daee0b696c)
Diffstat (limited to 'src/vppinfra/pmalloc.c')
-rw-r--r--src/vppinfra/pmalloc.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c
index d9e50d15733..ce78ca00334 100644
--- a/src/vppinfra/pmalloc.c
+++ b/src/vppinfra/pmalloc.c
@@ -261,11 +261,10 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a,
{
clib_pmalloc_page_t *pp = 0;
int status, rv, i, mmap_flags;
- void *va;
+ void *va = MAP_FAILED;
int old_mpol = -1;
long unsigned int mask[16] = { 0 };
long unsigned int old_mask[16] = { 0 };
- uword page_size = 1ULL << a->log2_subpage_sz;
uword size = (uword) n_pages << pm->def_log2_page_sz;
clib_error_free (pm->error);
@@ -304,9 +303,6 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a,
mmap_flags = MAP_FIXED;
- if ((pm->flags & CLIB_PMALLOC_F_NO_PAGEMAP) == 0)
- mmap_flags |= MAP_LOCKED;
-
if (a->flags & CLIB_PMALLOC_ARENA_F_SHARED_MEM)
{
mmap_flags |= MAP_SHARED;
@@ -338,23 +334,10 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a,
goto error;
}
- /* Check if huge page is not allocated,
- wrong allocation will generate the SIGBUS */
- if (a->log2_subpage_sz != pm->sys_log2_page_sz)
+ if (a->log2_subpage_sz != pm->sys_log2_page_sz && mlock (va, size) != 0)
{
- for (int i = 0; i < n_pages; i++)
- {
- unsigned char flag;
- mincore (va + i * page_size, 1, &flag);
- // flag is 1 if the page was successfully allocated and in memory
- if (!flag)
- {
- pm->error =
- clib_error_return_unix (0,
- "Unable to fulfill huge page allocation request");
- goto error;
- }
- }
+ pm->error = clib_error_return_unix (0, "Unable to lock pages");
+ goto error;
}
clib_memset (va, 0, size);
@@ -377,10 +360,6 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a,
clib_error_return (0, "page allocated on wrong node, numa node "
"%u status %d", numa_node, status);
- /* unmap & reesrve */
- munmap (va, size);
- mmap (va, size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
- -1, 0);
goto error;
}
@@ -410,6 +389,13 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a,
return pp - (n_pages - 1);
error:
+ if (va != MAP_FAILED)
+ {
+ /* unmap & reserve */
+ munmap (va, size);
+ mmap (va, size, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
+ -1, 0);
+ }
if (a->fd != -1)
close (a->fd);
return 0;