@@ -78,6 +78,8 @@ struct vm_mem_backing_src_alias {
enum vm_mem_backing_src_type type;
};
+bool thp_configured(void);
+size_t get_trans_hugepagesz(void);
void backing_src_help(void);
enum vm_mem_backing_src_type parse_backing_src_type(const char *type_name);
@@ -10,6 +10,7 @@
#include <limits.h>
#include <stdlib.h>
#include <time.h>
+#include <sys/stat.h>
#include "linux/kernel.h"
#include "test_util.h"
@@ -117,6 +118,41 @@ const struct vm_mem_backing_src_alias backing_src_aliases[] = {
{"anonymous_hugetlb", VM_MEM_SRC_ANONYMOUS_HUGETLB,},
};
+bool thp_configured(void)
+{
+ int ret;
+ struct stat statbuf;
+
+ ret = stat("/sys/kernel/mm/transparent_hugepage", &statbuf);
+ TEST_ASSERT(ret == 0 || (ret == -1 && errno == ENOENT),
+ "Error in stating /sys/kernel/mm/transparent_hugepage: %d",
+ errno);
+
+ return ret == 0;
+}
+
+size_t get_trans_hugepagesz(void)
+{
+ size_t size;
+ char buf[16];
+ FILE *f;
+
+ TEST_ASSERT(thp_configured(), "THP is not configured in host kernel");
+
+ f = fopen("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", "r");
+ TEST_ASSERT(f != NULL,
+ "Error in opening transparent_hugepage/hpage_pmd_size: %d",
+ errno);
+
+ if (fread(buf, sizeof(char), sizeof(buf), f) == 0) {
+ fclose(f);
+ TEST_FAIL("Unable to read transparent_hugepage/hpage_pmd_size");
+ }
+
+ size = strtoull(buf, NULL, 10);
+ return size;
+}
+
void backing_src_help(void)
{
int i;