summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/pmalloc.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/vppinfra/pmalloc.c b/src/vppinfra/pmalloc.c
index 9c5f475e8dd..365ee044392 100644
--- a/src/vppinfra/pmalloc.c
+++ b/src/vppinfra/pmalloc.c
@@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include <linux/mempolicy.h>
#include <linux/memfd.h>
@@ -260,6 +261,7 @@ pmalloc_map_pages (clib_pmalloc_main_t * pm, clib_pmalloc_arena_t * a,
int old_mpol = -1;
long unsigned int mask[16] = { 0 };
long unsigned int old_mask[16] = { 0 };
+ uword page_size = 1 << a->log2_subpage_sz;
uword size = (uword) n_pages << pm->def_log2_page_sz;
clib_error_free (pm->error);
@@ -332,6 +334,25 @@ 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)
+ {
+ 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;
+ }
+ }
+ }
+
clib_memset (va, 0, size);
rv = set_mempolicy (old_mpol, old_mask, sizeof (old_mask) * 8 + 1);