* [LTP] [PATCH v2 0/3] new test for madvise(MADV_DONTNEED)
@ 2022-10-11 12:16 Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 1/3] syscalls/madvise03: " Zhao Gongyi via ltp
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-11 12:16 UTC (permalink / raw)
To: ltp
1. verify that after a successful MADV_DONTNEED operation, it will
result in zero-fill-on-demand pages for anonymous private mappings.
2. Test cases for madvise(2) system call, verify that MADV_DONTNEED
cannot be applied to Huge TLB pages.
3. Verify that when MADV_DONTNEED applied to shared mappings, it will
lead to the resident set size(RSS) of the calling process reduced
immediately.
Changes in v2:
- Modify the test adn split the test into two as suggestion
- Add a new test for madvise
Zhao Gongyi (3):
syscalls/madvise03: new test for madvise(MADV_DONTNEED)
syscalls/madvise04: new test for madvise(MADV_DONTNEED)
syscalls/madvise11: new test for madvise(MADV_DONTNEED)
runtest/syscalls | 3 +
testcases/kernel/syscalls/madvise/.gitignore | 3 +
testcases/kernel/syscalls/madvise/madvise03.c | 69 ++++++++++++++++
testcases/kernel/syscalls/madvise/madvise04.c | 48 ++++++++++++
testcases/kernel/syscalls/madvise/madvise11.c | 78 +++++++++++++++++++
5 files changed, 201 insertions(+)
create mode 100644 testcases/kernel/syscalls/madvise/madvise03.c
create mode 100644 testcases/kernel/syscalls/madvise/madvise04.c
create mode 100644 testcases/kernel/syscalls/madvise/madvise11.c
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2 1/3] syscalls/madvise03: new test for madvise(MADV_DONTNEED)
2022-10-11 12:16 [LTP] [PATCH v2 0/3] new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
@ 2022-10-11 12:16 ` Zhao Gongyi via ltp
2022-10-11 14:25 ` Cyril Hrubis
2022-10-11 12:16 ` [LTP] [PATCH v2 2/3] syscalls/madvise04: " Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 3/3] syscalls/madvise11: " Zhao Gongyi via ltp
2 siblings, 1 reply; 8+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-11 12:16 UTC (permalink / raw)
To: ltp
Test cases for madvise(2) system call, verify that after a successful
MADV_DONTNEED operation, it will result in zero-fill-on-demand pages
for anonymous private mappings.
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/madvise/.gitignore | 1 +
testcases/kernel/syscalls/madvise/madvise03.c | 69 +++++++++++++++++++
3 files changed, 71 insertions(+)
create mode 100644 testcases/kernel/syscalls/madvise/madvise03.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 51de0a614..c81764df4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -940,6 +940,7 @@ mincore04 mincore04
madvise01 madvise01
madvise02 madvise02
+madvise03 madvise03
madvise05 madvise05
madvise06 madvise06
madvise07 madvise07
diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
index 002d8e5d9..f4bfdfefe 100644
--- a/testcases/kernel/syscalls/madvise/.gitignore
+++ b/testcases/kernel/syscalls/madvise/.gitignore
@@ -1,5 +1,6 @@
/madvise01
/madvise02
+/madvise03
/madvise05
/madvise06
/madvise07
diff --git a/testcases/kernel/syscalls/madvise/madvise03.c b/testcases/kernel/syscalls/madvise/madvise03.c
new file mode 100644
index 000000000..70330060e
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise03.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
+ * Author: Zhao Gongyi <zhaogongyi@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test cases for madvise(2) system call, advise value as "MADV_MADV_DONTNEED":
+ * After a successful MADV_DONTNEED operation, it will result in
+ * zero-fill-on-demand pages for anonymous private mappings.
+ */
+
+#include "tst_test.h"
+
+#define MAP_SIZE (8 * 1024)
+
+static char *addr;
+
+static void run(void)
+{
+ int i;
+
+ TEST(madvise(addr, MAP_SIZE, MADV_DONTNEED));
+ if (TST_RET == -1) {
+ tst_brk(TBROK | TTERRNO, "madvise(%p, %d, 0x%x) failed",
+ addr, MAP_SIZE, MADV_DONTNEED);
+ }
+
+ for (i = 0; i < MAP_SIZE; i++) {
+ if (addr[i]) {
+ tst_res(TFAIL,
+ "There are no zero-fill-on-demand pages "
+ "for anonymous private mappings");
+ return;
+ }
+ }
+
+ if (i == MAP_SIZE) {
+ tst_res(TPASS,
+ "There are zero-fill-on-demand pages "
+ "for anonymous private mappings");
+ }
+}
+
+static void setup(void)
+{
+ addr = SAFE_MMAP(NULL, MAP_SIZE,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS,
+ -1, 0);
+ memset(addr, 1, MAP_SIZE);
+}
+
+static void cleanup(void)
+{
+ if (addr)
+ SAFE_MUNMAP(addr, MAP_SIZE);
+}
+
+
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+};
+
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2 2/3] syscalls/madvise04: new test for madvise(MADV_DONTNEED)
2022-10-11 12:16 [LTP] [PATCH v2 0/3] new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 1/3] syscalls/madvise03: " Zhao Gongyi via ltp
@ 2022-10-11 12:16 ` Zhao Gongyi via ltp
2022-10-11 14:29 ` Cyril Hrubis
2022-10-11 12:16 ` [LTP] [PATCH v2 3/3] syscalls/madvise11: " Zhao Gongyi via ltp
2 siblings, 1 reply; 8+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-11 12:16 UTC (permalink / raw)
To: ltp
Test cases for madvise(2) system call, verify that MADV_DONTNEED
cannot be applied to Huge TLB pages.
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/madvise/.gitignore | 1 +
testcases/kernel/syscalls/madvise/madvise04.c | 48 +++++++++++++++++++
3 files changed, 50 insertions(+)
create mode 100644 testcases/kernel/syscalls/madvise/madvise04.c
diff --git a/runtest/syscalls b/runtest/syscalls
index c81764df4..eb1910cec 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -941,6 +941,7 @@ mincore04 mincore04
madvise01 madvise01
madvise02 madvise02
madvise03 madvise03
+madvise04 madvise04
madvise05 madvise05
madvise06 madvise06
madvise07 madvise07
diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
index f4bfdfefe..db8ce47c1 100644
--- a/testcases/kernel/syscalls/madvise/.gitignore
+++ b/testcases/kernel/syscalls/madvise/.gitignore
@@ -1,6 +1,7 @@
/madvise01
/madvise02
/madvise03
+/madvise04
/madvise05
/madvise06
/madvise07
diff --git a/testcases/kernel/syscalls/madvise/madvise04.c b/testcases/kernel/syscalls/madvise/madvise04.c
new file mode 100644
index 000000000..d7ccaf97e
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise04.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
+ * Author: Zhao Gongyi <zhaogongyi@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test cases for madvise(2) system call, advise value as "MADV_MADV_DONTNEED":
+ * MADV_DONTNEED cannot be applied to Huge TLB pages.
+ */
+
+#include "tst_test.h"
+
+#define MAP_SIZE (8 * 1024)
+
+static char *addr;
+static int mapsz;
+
+static void run(void)
+{
+ TST_EXP_FAIL(madvise(addr, mapsz, MADV_DONTNEED), EINVAL);
+}
+
+static void setup(void)
+{
+ mapsz = tst_get_hugepage_size();
+ addr = SAFE_MMAP(NULL, mapsz,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
+ -1, 0);
+}
+
+static void cleanup(void)
+{
+ if (addr)
+ SAFE_MUNMAP(addr, mapsz);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+ .hugepages = {1, TST_NEEDS},
+};
+
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2 3/3] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
2022-10-11 12:16 [LTP] [PATCH v2 0/3] new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 1/3] syscalls/madvise03: " Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 2/3] syscalls/madvise04: " Zhao Gongyi via ltp
@ 2022-10-11 12:16 ` Zhao Gongyi via ltp
2022-10-12 8:52 ` Cyril Hrubis
2 siblings, 1 reply; 8+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-11 12:16 UTC (permalink / raw)
To: ltp
Test cases for madvise(2) system call, verify that when MADV_DONTNEED
applied to shared mappings, it will lead to the resident set size(RSS)
of the calling process reduced immediately.
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/madvise/.gitignore | 1 +
testcases/kernel/syscalls/madvise/madvise11.c | 78 +++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100644 testcases/kernel/syscalls/madvise/madvise11.c
diff --git a/runtest/syscalls b/runtest/syscalls
index eb1910cec..296af9f9d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -948,6 +948,7 @@ madvise07 madvise07
madvise08 madvise08
madvise09 madvise09
madvise10 madvise10
+madvise11 madvise11
newuname01 newuname01
diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
index db8ce47c1..ffd8823d1 100644
--- a/testcases/kernel/syscalls/madvise/.gitignore
+++ b/testcases/kernel/syscalls/madvise/.gitignore
@@ -8,3 +8,4 @@
/madvise08
/madvise09
/madvise10
+/madvise11
diff --git a/testcases/kernel/syscalls/madvise/madvise11.c b/testcases/kernel/syscalls/madvise/madvise11.c
new file mode 100644
index 000000000..77f0b91ac
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise11.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
+ * Author: Zhao Gongyi <zhaogongyi@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test cases for madvise(2) system call, advise value as "MADV_MADV_DONTNEED":
+ * When MADV_DONTNEED applied to shared mappings, it will lead to the
+ * resident set size(RSS) of the calling process reduced immediately.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "tst_test.h"
+
+#define MAP_SIZE (8 * 1024)
+#define BUF_SIZE 1024
+
+static FILE *fp;
+static char *addr;
+
+static void run(void)
+{
+ char cmd[BUF_SIZE];
+ char line[BUF_SIZE];
+ char vm_area_addr[128];
+
+ TEST(madvise(addr, MAP_SIZE, MADV_DONTNEED));
+ if (TST_RET == -1) {
+ tst_brk(TBROK | TTERRNO, "madvise(%p, %d, 0x%x)",
+ addr, MAP_SIZE, MADV_DONTNEED);
+ }
+
+ sprintf(vm_area_addr, "%p", addr);
+ sprintf(cmd,
+ "cat /proc/%d/smaps | grep %s -A 4 | grep Rss: | grep '0 kB'",
+ getpid(), &(vm_area_addr[2]));
+
+ fp = popen(cmd, "r");
+ if (!fp)
+ tst_brk(TBROK, "popen failed");
+
+ if (fgets(line, sizeof(line), fp) != NULL) {
+ if (strstr(line, " 0 kB"))
+ tst_res(TPASS, "RSS is released");
+ else
+ tst_res(TFAIL, "RSS is not released");
+
+ } else
+ tst_brk(TBROK, "There is no 'Rss:' in smaps?");
+}
+
+static void setup(void)
+{
+ addr = SAFE_MMAP(NULL, MAP_SIZE,
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS,
+ -1, 0);
+ memset(addr, 1, MAP_SIZE);
+}
+
+static void cleanup(void)
+{
+ if (addr)
+ SAFE_MUNMAP(addr, MAP_SIZE);
+ if (fp)
+ pclose(fp);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+};
+
--
2.17.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 1/3] syscalls/madvise03: new test for madvise(MADV_DONTNEED)
2022-10-11 12:16 ` [LTP] [PATCH v2 1/3] syscalls/madvise03: " Zhao Gongyi via ltp
@ 2022-10-11 14:25 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2022-10-11 14:25 UTC (permalink / raw)
To: Zhao Gongyi; +Cc: ltp
Hi!
Pushed with two minor changes, thanks.
* Moved the memset() to the start of the run() function, so that the
pages are populated again in case that we run with the -i 10 option
* Rewrote the documentation comment so that it renders nicely in the
exported documentation
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 2/3] syscalls/madvise04: new test for madvise(MADV_DONTNEED)
2022-10-11 12:16 ` [LTP] [PATCH v2 2/3] syscalls/madvise04: " Zhao Gongyi via ltp
@ 2022-10-11 14:29 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2022-10-11 14:29 UTC (permalink / raw)
To: Zhao Gongyi; +Cc: ltp
Hi!
The MADV_DONTNEED has been implemented for hugepages since:
commit 90e7e7f5ef3f712da992d505aee2d921797c3f96
Author: Mike Kravetz <mike.kravetz@oracle.com>
Date: Thu Mar 24 18:13:18 2022 -0700
mm: enable MADV_DONTNEED for hugetlb mappings
So for newer kernels this actually works fine. I guess that we should
change the test to expect the call to pass for v5.18 and newer.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 3/3] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
2022-10-11 12:16 ` [LTP] [PATCH v2 3/3] syscalls/madvise11: " Zhao Gongyi via ltp
@ 2022-10-12 8:52 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2022-10-12 8:52 UTC (permalink / raw)
To: Zhao Gongyi; +Cc: ltp
Hi!
> +static void run(void)
> +{
> + char cmd[BUF_SIZE];
> + char line[BUF_SIZE];
> + char vm_area_addr[128];
> +
> + TEST(madvise(addr, MAP_SIZE, MADV_DONTNEED));
> + if (TST_RET == -1) {
> + tst_brk(TBROK | TTERRNO, "madvise(%p, %d, 0x%x)",
> + addr, MAP_SIZE, MADV_DONTNEED);
> + }
> +
> + sprintf(vm_area_addr, "%p", addr);
> + sprintf(cmd,
> + "cat /proc/%d/smaps | grep %s -A 4 | grep Rss: | grep '0 kB'",
> + getpid(), &(vm_area_addr[2]));
This is way too ugly and may break easily too.
If we are going to parse the file we should do it properly in C instead.
Why can't we just read the file line by line until we find the right
address at the start of the line and once we do look for the Rss?
> + fp = popen(cmd, "r");
> + if (!fp)
> + tst_brk(TBROK, "popen failed");
> +
> + if (fgets(line, sizeof(line), fp) != NULL) {
> + if (strstr(line, " 0 kB"))
> + tst_res(TPASS, "RSS is released");
> + else
> + tst_res(TFAIL, "RSS is not released");
> +
> + } else
> + tst_brk(TBROK, "There is no 'Rss:' in smaps?");
> +}
> +
> +static void setup(void)
> +{
> + addr = SAFE_MMAP(NULL, MAP_SIZE,
> + PROT_READ | PROT_WRITE,
> + MAP_PRIVATE | MAP_ANONYMOUS,
> + -1, 0);
> + memset(addr, 1, MAP_SIZE);
> +}
> +
> +static void cleanup(void)
> +{
> + if (addr)
> + SAFE_MUNMAP(addr, MAP_SIZE);
> + if (fp)
> + pclose(fp);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .setup = setup,
> + .cleanup = cleanup,
> +};
> +
> --
> 2.17.1
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 3/3] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
@ 2022-10-12 8:56 zhaogongyi via ltp
0 siblings, 0 replies; 8+ messages in thread
From: zhaogongyi via ltp @ 2022-10-12 8:56 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi,
>
> Hi!
> > +static void run(void)
> > +{
> > + char cmd[BUF_SIZE];
> > + char line[BUF_SIZE];
> > + char vm_area_addr[128];
> > +
> > + TEST(madvise(addr, MAP_SIZE, MADV_DONTNEED));
> > + if (TST_RET == -1) {
> > + tst_brk(TBROK | TTERRNO, "madvise(%p, %d, 0x%x)",
> > + addr, MAP_SIZE, MADV_DONTNEED);
> > + }
> > +
> > + sprintf(vm_area_addr, "%p", addr);
> > + sprintf(cmd,
> > + "cat /proc/%d/smaps | grep %s -A 4 | grep Rss: | grep '0 kB'",
> > + getpid(), &(vm_area_addr[2]));
>
> This is way too ugly and may break easily too.
>
> If we are going to parse the file we should do it properly in C instead.
> Why can't we just read the file line by line until we find the right address
> at the start of the line and once we do look for the Rss?
I have do it with C at first, but it seems not intuitive. I will change back on next version of the patch.
Regards,
Gongyi
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-10-12 8:57 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-11 12:16 [LTP] [PATCH v2 0/3] new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-11 12:16 ` [LTP] [PATCH v2 1/3] syscalls/madvise03: " Zhao Gongyi via ltp
2022-10-11 14:25 ` Cyril Hrubis
2022-10-11 12:16 ` [LTP] [PATCH v2 2/3] syscalls/madvise04: " Zhao Gongyi via ltp
2022-10-11 14:29 ` Cyril Hrubis
2022-10-11 12:16 ` [LTP] [PATCH v2 3/3] syscalls/madvise11: " Zhao Gongyi via ltp
2022-10-12 8:52 ` Cyril Hrubis
-- strict thread matches above, loose matches on Subject: below --
2022-10-12 8:56 zhaogongyi via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox