@@ -16,6 +16,7 @@ TESTS =\
blk-exhaust.sh \
sector-mode.sh \
inject-error.sh \
+ hugetlb \
btt-errors.sh
check_PROGRAMS =\
@@ -27,6 +28,7 @@ check_PROGRAMS =\
dax-errors \
smart-notify \
smart-listen \
+ hugetlb \
daxdev-errors
if ENABLE_DESTRUCTIVE
@@ -82,6 +84,8 @@ dax_dev_SOURCES = dax-dev.c $(testcore)
dax_dev_LDADD = $(LIBNDCTL_LIB) $(KMOD_LIBS)
dax_pmd_SOURCES = dax-pmd.c
+hugetlb_SOURCES = hugetlb.c \
+ dax-pmd.c
mmap_SOURCES = mmap.c
dax_errors_SOURCES = dax-errors.c
daxdev_errors_SOURCES = daxdev-errors.c \
@@ -13,6 +13,7 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <linux/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -42,12 +43,50 @@ int test_dax_directio(int dax_fd, unsigned long align, void *dax_addr, off_t off
return -ENOMEM;
for (i = 0; i < 5; i++) {
- void *addr = mmap(dax_addr, 2*align,
- PROT_READ|PROT_WRITE, MAP_SHARED, dax_fd,
- offset);
+ unsigned long flags;
+ void *addr;
int fd2;
+ if (dax_fd >= 0)
+ flags = MAP_SHARED;
+ else {
+ /* hugetlbfs instead of device-dax */
+ const char *base = "/sys/kernel/mm/hugepages";
+ FILE *f_nrhuge;
+ char path[256];
+
+ flags = MAP_SHARED | MAP_ANONYMOUS;
+ if (align >= SZ_2M) {
+ char setting[] = { "2\n" };
+
+ sprintf(path, "%s/hugepages-%ldkB/nr_hugepages",
+ base, align / 1024);
+ f_nrhuge = fopen(path, "r+");
+ if (!f_nrhuge) {
+ rc = -errno;
+ faili(i);
+ return rc;
+ }
+ if (fwrite(setting, sizeof(setting), 1, f_nrhuge) != 1) {
+ rc = -errno;
+ faili(i);
+ fclose(f_nrhuge);
+ return rc;
+ }
+ fclose(f_nrhuge);
+
+ /* FIXME: support non-x86 page sizes */
+ if (align > SZ_2M)
+ flags |= MAP_HUGETLB | MAP_HUGE_1GB;
+ else
+ flags |= MAP_HUGETLB | MAP_HUGE_2MB;
+ }
+ }
+ addr = mmap(dax_addr, 2*align,
+ PROT_READ|PROT_WRITE, flags, dax_fd, offset);
+
if (addr == MAP_FAILED) {
+ rc = -errno;
faili(i);
break;
}
new file mode 100644
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <errno.h>
+
+#include <ccan/array_size/array_size.h>
+#include <util/size.h>
+#include <test.h>
+
+static int test_hugetlb(void)
+{
+ int rc, i;
+ unsigned long aligns[] = { SZ_4K, SZ_2M, SZ_1G };
+
+ for (i = 0; i < (int) ARRAY_SIZE(aligns); i++) {
+ fprintf(stderr, "%s: page_size: %#lx\n", __func__, aligns[i]);
+ rc = test_dax_directio(-1, aligns[i], NULL, 0);
+ if (rc == -ENOMEM || rc == -EACCES)
+ return 77;
+ else if (rc == -ENOENT && aligns[i] == SZ_1G)
+ continue; /* system not configured for 1G pages */
+ else if (rc)
+ return rc;
+ }
+ return 0;
+}
+
+int __attribute__((weak)) main(int argc, char *argv[])
+{
+ return test_hugetlb();
+}
Compliment the fsdax and devdax huge page tests with hugetlbfs tests since they share some of the same code paths. Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- test/Makefile.am | 4 ++++ test/dax-pmd.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- test/hugetlb.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 test/hugetlb.c