summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/linux/mem.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2018-10-24 17:08:26 +0200
committerMarco Varlese <marco.varlese@suse.de>2018-10-25 10:52:42 +0000
commit567e61d09cd00174203eff85f63a598420476951 (patch)
tree528e0fb979a25f990a552cbb3c4b14d491cff678 /src/vppinfra/linux/mem.c
parent3935fc8527c340535a00108b78f3de064df50a7f (diff)
pmalloc: support for 4K pages
Change-Id: Iecceffe06a92660976ebb58cd3cbec4be8931db0 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/linux/mem.c')
-rw-r--r--src/vppinfra/linux/mem.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 6a551ec0554..8edae74f9cd 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -82,7 +82,7 @@ done:
}
u64
-clib_mem_vm_get_page_size (int fd)
+clib_mem_get_fd_page_size (int fd)
{
struct stat st = { 0 };
if (fstat (fd, &st) == -1)
@@ -91,9 +91,9 @@ clib_mem_vm_get_page_size (int fd)
}
int
-clib_mem_vm_get_log2_page_size (int fd)
+clib_mem_get_fd_log2_page_size (int fd)
{
- return min_log2 (clib_mem_vm_get_page_size (fd));
+ return min_log2 (clib_mem_get_fd_page_size (fd));
}
void
@@ -117,6 +117,26 @@ clib_mem_vm_randomize_va (uword * requested_va, u32 log2_page_size)
#endif
clib_error_t *
+clib_mem_create_fd (char *name, int *fdp)
+{
+ int fd;
+
+ ASSERT (name);
+
+ if ((fd = memfd_create (name, MFD_ALLOW_SEALING)) == -1)
+ return clib_error_return_unix (0, "memfd_create");
+
+ if ((fcntl (fd, F_ADD_SEALS, F_SEAL_SHRINK)) == -1)
+ {
+ close (fd);
+ return clib_error_return_unix (0, "fcntl (F_ADD_SEALS)");
+ }
+
+ *fdp = fd;
+ return 0;
+}
+
+clib_error_t *
clib_mem_create_hugetlb_fd (char *name, int *fdp)
{
clib_error_t *err = 0;
@@ -212,20 +232,11 @@ clib_mem_vm_ext_alloc (clib_mem_vm_alloc_t * a)
}
else
{
- if ((fd = memfd_create (a->name, MFD_ALLOW_SEALING)) == -1)
- {
- err = clib_error_return_unix (0, "memfd_create");
- goto error;
- }
-
- if ((fcntl (fd, F_ADD_SEALS, F_SEAL_SHRINK)) == -1)
- {
- err = clib_error_return_unix (0, "fcntl (F_ADD_SEALS)");
- goto error;
- }
+ if ((err = clib_mem_create_fd (a->name, &fd)))
+ goto error;
}
- log2_page_size = clib_mem_vm_get_log2_page_size (fd);
+ 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");