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,
rpalethorpe@suse.com
Subject: [LTP] [PATCH v7 1/4] Hugetlb: Add new tst_test options for hugeltb test support
Date: Fri, 4 Nov 2022 11:57:13 +0530 [thread overview]
Message-ID: <20221104062716.615021-2-tsahu@linux.ibm.com> (raw)
In-Reply-To: <20221104062716.615021-1-tsahu@linux.ibm.com>
Most of libhugetlbfs test require mounted hugetlbfs.
Here, this patch adds a new field in tst_test struct(include/tst_test.h)
which user can set if the test requires mounted hugetlbfs. Also, this
patch added support to create the unlinked file in the provided dirpath.
Signed-off-by: Tarun Sahu <tsahu@linux.ibm.com>
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
---
include/tst_hugepage.h | 7 +++++++
include/tst_test.h | 10 ++++++++++
lib/tst_test.c | 32 +++++++++++++++++++++++++++++---
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/include/tst_hugepage.h b/include/tst_hugepage.h
index 7fba02c40..46327c79a 100644
--- a/include/tst_hugepage.h
+++ b/include/tst_hugepage.h
@@ -8,6 +8,13 @@
#define PATH_HUGEPAGES "/sys/kernel/mm/hugepages/"
#define PATH_NR_HPAGES "/proc/sys/vm/nr_hugepages"
+#define PATH_OC_HPAGES "/proc/sys/vm/nr_overcommit_hugepages"
+
+#define MEMINFO_HPAGE_TOTAL "HugePages_Total:"
+#define MEMINFO_HPAGE_FREE "HugePages_Free:"
+#define MEMINFO_HPAGE_RSVD "HugePages_Rsvd:"
+#define MEMINFO_HPAGE_SURP "HugePages_Surp:"
+#define MEMINFO_HPAGE_SIZE "Hugepagesize:"
extern char *nr_opt; /* -s num Set the number of the been allocated hugepages */
extern char *Hopt; /* -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs */
diff --git a/include/tst_test.h b/include/tst_test.h
index a69965b95..acf2421de 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -176,6 +176,10 @@ struct tst_test {
int all_filesystems:1;
int skip_in_lockdown:1;
int skip_in_compat:1;
+ /*
+ * If set, the hugetlbfs will be mounted at .mntpoint.
+ */
+ int needs_hugetlbfs:1;
/*
* The skip_filesystems is a NULL terminated list of filesystems the
@@ -357,6 +361,12 @@ unsigned int tst_remaining_runtime(void);
*/
void tst_set_max_runtime(int max_runtime);
+/*
+ * Create and open a random file inside the given dir path.
+ * It unlinks the file after opening and return file descriptor.
+ */
+int tst_creat_unlinked(const char *path);
+
/*
* Returns path to the test temporary directory in a newly allocated buffer.
*/
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 8ccde1629..b225ba082 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -1021,6 +1021,28 @@ static void prepare_and_mount_dev_fs(const char *mntpoint)
}
}
+static void prepare_and_mount_hugetlb_fs(void)
+{
+ SAFE_MOUNT("none", tst_test->mntpoint, "hugetlbfs", 0, NULL);
+ mntpoint_mounted = 1;
+}
+
+int tst_creat_unlinked(const char *path)
+{
+ char template[PATH_MAX];
+ int fd;
+
+ snprintf(template, PATH_MAX, "%s/ltp_%.3sXXXXXX",
+ path, tid);
+
+ fd = mkstemp(template);
+ if (fd < 0)
+ tst_brk(TBROK | TERRNO, "mkstemp(%s) failed", template);
+
+ SAFE_UNLINK(template);
+ return fd;
+}
+
static const char *limit_tmpfs_mount_size(const char *mnt_data,
char *buf, size_t buf_size, const char *fs_type)
{
@@ -1191,15 +1213,16 @@ static void do_setup(int argc, char *argv[])
SAFE_MKDIR(tst_test->mntpoint, 0777);
if ((tst_test->needs_devfs || tst_test->needs_rofs ||
- tst_test->mount_device || tst_test->all_filesystems) &&
+ tst_test->mount_device || tst_test->all_filesystems ||
+ tst_test->needs_hugetlbfs) &&
!tst_test->mntpoint) {
tst_brk(TBROK, "tst_test->mntpoint must be set!");
}
if (!!tst_test->needs_rofs + !!tst_test->needs_devfs +
- !!tst_test->needs_device > 1) {
+ !!tst_test->needs_device + !!tst_test->needs_hugetlbfs > 1) {
tst_brk(TBROK,
- "Two or more of needs_{rofs, devfs, device} are set");
+ "Two or more of needs_{rofs, devfs, device, hugetlbfs} are set");
}
if (tst_test->needs_devfs)
@@ -1217,6 +1240,9 @@ static void do_setup(int argc, char *argv[])
}
}
+ if (tst_test->needs_hugetlbfs)
+ prepare_and_mount_hugetlb_fs();
+
if (tst_test->needs_device && !mntpoint_mounted) {
tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-11-04 12:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 6:27 [LTP] [PATCH v7 0/4] Hugetlb:Migrating the libhugetlbfs tests Tarun Sahu
2022-11-04 6:27 ` Tarun Sahu [this message]
2022-11-04 6:27 ` [LTP] [PATCH v7 2/4] Hugetlb: Migrating libhugetlbfs brk_near_huge Tarun Sahu
2022-11-04 9:21 ` Cyril Hrubis
2022-11-04 6:27 ` [LTP] [PATCH v7 3/4] Hugetlb: Migrating libhugetlbfs chunk-overcommit Tarun Sahu
2022-11-04 9:36 ` Cyril Hrubis
2022-11-04 13:16 ` Tarun Sahu
2022-11-04 13:19 ` Cyril Hrubis
2022-11-04 6:27 ` [LTP] [PATCH v7 4/4] Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt Tarun Sahu
2022-11-04 9:51 ` Cyril Hrubis
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=20221104062716.615021-2-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=rpalethorpe@suse.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 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.