All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 17/17] ndctl, test: hugetlb fault
Date: Fri, 01 Dec 2017 15:25:59 -0800	[thread overview]
Message-ID: <151217075965.28402.12790882591361777536.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <151217066885.28402.7962437173336388439.stgit@dwillia2-desk3.amr.corp.intel.com>

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

diff --git a/test/Makefile.am b/test/Makefile.am
index d4c2bd6b2640..a8e047bfd36c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -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 \
diff --git a/test/dax-pmd.c b/test/dax-pmd.c
index 1a296aff32ea..06fe52200e4f 100644
--- a/test/dax-pmd.c
+++ b/test/dax-pmd.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;
 		}
diff --git a/test/hugetlb.c b/test/hugetlb.c
new file mode 100644
index 000000000000..a08a93ad40f3
--- /dev/null
+++ b/test/hugetlb.c
@@ -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();
+}

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

  parent reply	other threads:[~2017-12-01 23:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-01 23:24 [ndctl PATCH 00/16] ndctl: update SMART support for NVDIMM_FAMILY_INTEL Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 01/17] libndctl: rename dimm dsm_mask to cmd_mask Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 02/17] libndctl: add nfit_dsm_mask as a private dimm property Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 03/17] ndctl, smart: rename 'temperature' helpers to 'media_temperature' Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 04/17] ndctl, intel: switch to ND_CMD_CALL passthrough for SMART commands Dan Williams
2017-12-01 23:24 ` [ndctl PATCH 05/17] ndctl: remove support for compiling against the kernel ndctl.h header Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 06/17] ndctl, test: emit smart field names Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 07/17] ndctl, smart: cleanup smart_cmd_op() macro Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 08/17] ndctl, test: reset all nfit_test data for each test/libndctl run Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 09/17] ndctl, region: cleanup error message Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 10/17] ndctl: support set smart alarm/threshold Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 11/17] ndctl: refactor 'smart_ops' into generic 'dimm_ops' Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 12/17] ndctl, debug: improve do_cmd output for ND_CMD_CALL Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 13/17] ndctl, list: teach the list command about the 'fsdax' and 'devdax' modes Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 14/17] ndctl, smart: move smart temperature parsing to a library routine Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 15/17] ndctl, test: trigger notifications Dan Williams
2017-12-01 23:25 ` [ndctl PATCH 16/17] ndctl, test: listen for smart notifications Dan Williams
2017-12-01 23:25 ` Dan Williams [this message]
2017-12-01 23:36 ` [ndctl PATCH 00/16] ndctl: update SMART support for NVDIMM_FAMILY_INTEL Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=151217075965.28402.12790882591361777536.stgit@dwillia2-desk3.amr.corp.intel.com \
    --to=dan.j.williams@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.