From: Tarun Sahu <tsahu@linux.ibm.com>
To: ltp@lists.linux.it
Cc: geetika@linux.ibm.com, sbhat@linux.ibm.com,
aneesh.kumar@linux.ibm.com, vaibhav@linux.ibm.com,
mike.kravetz@oracle.com
Subject: [LTP] [PATCH v2 5/5] Hugetlb: Migrating libhugetlbfs fallocate_basic
Date: Wed, 9 Nov 2022 01:22:07 +0530 [thread overview]
Message-ID: <20221108195207.232115-6-tsahu@linux.ibm.com> (raw)
In-Reply-To: <20221108195207.232115-1-tsahu@linux.ibm.com>
Migrating the libhugetlbfs/testcases/fallocate_basic.c test
Test Description: It tests basic fallocate functionality in hugetlbfs.
Preallocate huge pages to a file in hugetlbfs, and then remove the pages
via hole punch.
Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../hugetlb/hugefallocate/hugefallocate02.c | 90 +++++++++++++++++++
3 files changed, 92 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index ca92dfcff..ec1fc2515 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -1,4 +1,5 @@
hugefallocate01 hugefallocate01
+hugefallocate02 hugefallocate02
hugemmap01 hugemmap01
hugemmap02 hugemmap02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index cafdb5259..c0906f3d3 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,5 +1,6 @@
/cpuset/cpuset01
/hugetlb/hugefallocate/hugefallocate01
+/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugemmap/hugemmap01
/hugetlb/hugemmap/hugemmap02
/hugetlb/hugemmap/hugemmap04
diff --git a/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
new file mode 100644
index 000000000..c8f8f87c9
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugefallocate/hugefallocate02.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2015 Oracle Corporation
+ * Author: Mike Kravetz
+ */
+
+/*\
+ * [Description]
+ *
+ * It tests basic fallocate functionality in hugetlbfs. Preallocate huge
+ * pages to a file in hugetlbfs, and then remove the pages via hole punch.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "hugetlb.h"
+
+#define MAX_PAGES_TO_USE 5
+#define MNTPOINT "hugetlbfs/"
+
+static int fd = -1;
+static long hpage_size;
+
+static void run_test(void)
+{
+ int err;
+ unsigned long max_iterations;
+ unsigned long free_initial, free_after, free_end;
+
+ free_initial = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
+ max_iterations = MIN(free_initial, MAX_PAGES_TO_USE);
+
+ fd = tst_creat_unlinked(MNTPOINT);
+
+ /* First preallocate file with max_iterations pages */
+ err = fallocate(fd, 0, 0, hpage_size * max_iterations);
+ if (err) {
+ if (errno == EOPNOTSUPP)
+ tst_brk(TCONF, "fallocate() Operation is not supported");
+ tst_res(TFAIL|TERRNO, "fallocate()");
+ goto cleanup;
+ }
+
+ free_after = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
+ if (free_initial - free_after != max_iterations) {
+ tst_res(TFAIL, "fallocate did not preallocate %lu huge pages",
+ max_iterations);
+ goto cleanup;
+ }
+
+ /* Now punch a hole of the same size */
+ err = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+ 0, hpage_size * max_iterations);
+ if (err) {
+ tst_res(TFAIL|TERRNO, "fallocate(FALLOC_FL_PUNCH_HOLE)");
+ goto cleanup;
+ }
+
+ free_end = SAFE_READ_MEMINFO(MEMINFO_HPAGE_FREE);
+ TST_EXP_EQ_LU(free_end, free_initial);
+cleanup:
+ SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+}
+
+static void cleanup(void)
+{
+ if (fd > 0)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+};
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2022-11-08 19:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 19:52 [LTP] [PATCH v2 0/5][PART 2] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-11-08 19:52 ` [LTP] [PATCH v2 1/5] Hugetlb: Migrating libhugetlbfs counters Tarun Sahu
2022-11-09 13:12 ` Cyril Hrubis
2022-11-09 21:26 ` Tarun Sahu
2022-11-10 8:20 ` Cyril Hrubis
2022-11-13 18:44 ` Tarun Sahu
2022-11-13 19:03 ` Tarun Sahu
2022-11-14 9:49 ` Cyril Hrubis
2022-11-14 18:51 ` Tarun Sahu
2022-11-08 19:52 ` [LTP] [PATCH v2 2/5] Hugetlb: Migrating libhugetlbfs directio Tarun Sahu
2022-11-09 13:25 ` Cyril Hrubis
2022-11-09 18:09 ` Tarun Sahu
2022-11-08 19:52 ` [LTP] [PATCH v2 3/5] Hugetlb: Migrating libhugetlbfs fadvise_reserve Tarun Sahu
2022-11-09 16:18 ` Cyril Hrubis
2022-11-09 18:40 ` Tarun Sahu
2022-11-10 7:34 ` Cyril Hrubis
2022-11-08 19:52 ` [LTP] [PATCH v2 4/5] Hugetlb: Migrating libhugetlbfs fallocate_align Tarun Sahu
2022-11-08 19:52 ` Tarun Sahu [this message]
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=20221108195207.232115-6-tsahu@linux.ibm.com \
--to=tsahu@linux.ibm.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=geetika@linux.ibm.com \
--cc=ltp@lists.linux.it \
--cc=mike.kravetz@oracle.com \
--cc=sbhat@linux.ibm.com \
--cc=vaibhav@linux.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox