public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED)
@ 2022-10-13 13:47 Zhao Gongyi via ltp
  2022-10-13 13:47 ` [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE) Zhao Gongyi via ltp
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-13 13:47 UTC (permalink / raw)
  To: ltp

Test cases for madvise(2) system call, verify that MADV_DONTNEED
can be applied to Huge TLB pages after kernel version 5.18.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/madvise/.gitignore  |  1 +
 testcases/kernel/syscalls/madvise/madvise04.c | 49 +++++++++++++++++++
 3 files changed, 51 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..ba15de092
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise04.c
@@ -0,0 +1,49 @@
+// 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 can be applied to Huge TLB pages after kernel version 5.18.
+ */
+
+#include "tst_test.h"
+
+#define MAP_SIZE (8 * 1024)
+
+static char *addr;
+static int mapsz;
+
+static void run(void)
+{
+	TST_EXP_PASS(madvise(addr, mapsz, MADV_DONTNEED));
+}
+
+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,
+	.min_kver = "5.18",
+	.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] 11+ messages in thread

* [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE)
  2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
@ 2022-10-13 13:47 ` Zhao Gongyi via ltp
  2022-10-13 13:47 ` [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-13 13:47 UTC (permalink / raw)
  To: ltp

1. Check that madvise(2) MADV_DONTNEED operation applied to Huge TLB
   pages successfully after kernel version 5.18, and will result in
   zero-fill-on-demand pages for anonymous private mappings
2. Check that madvise(2) MADV_DONTNEED applied to shared mappings will
   lead to the resident set size(RSS) of the calling process reduced
   immediately
3. Check that after a successful madvise(2) MADV_REMOVE operation,
   subsequent accesses in the specified address range will see bytes
   containing zero
4. Check that in madvise(2) MADV_REMOVE operation, the specified address
   range must be mapped shared and writable and this flag cannot be
   applied to locked pages

Changes in v4:
  - Modify madvise04.c and madvise11.c according to suggestions
  - Add madvise12.c and madvise13.c for madvise(MADV_REMOVE) to this
    patch set since the dependencies of the patches

Changes in v3:
  - Modify madvise04.c according to suggestions

Changes in v2:
  - Modify the test adn split the test into two as suggestion
  - Add a new test for madvise

Zhao Gongyi (4):
  syscalls/madvise04: new test for madvise(MADV_DONTNEED)
  syscalls/madvise11: new test for madvise(MADV_DONTNEED)
  syscalls/madvise12: new test for madvise(MADV_REMOVE)
  syscalls/madvise13: new test for madvise(MADV_REMOVE)

 runtest/syscalls                              |  4 +
 testcases/kernel/syscalls/madvise/.gitignore  |  4 +
 testcases/kernel/syscalls/madvise/madvise04.c | 62 ++++++++++++++
 testcases/kernel/syscalls/madvise/madvise11.c | 82 ++++++++++++++++++
 testcases/kernel/syscalls/madvise/madvise12.c | 85 +++++++++++++++++++
 testcases/kernel/syscalls/madvise/madvise13.c | 80 +++++++++++++++++
 6 files changed, 317 insertions(+)
 create mode 100644 testcases/kernel/syscalls/madvise/madvise04.c
 create mode 100644 testcases/kernel/syscalls/madvise/madvise11.c
 create mode 100644 testcases/kernel/syscalls/madvise/madvise12.c
 create mode 100644 testcases/kernel/syscalls/madvise/madvise13.c

--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED)
  2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
  2022-10-13 13:47 ` [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE) Zhao Gongyi via ltp
@ 2022-10-13 13:47 ` Zhao Gongyi via ltp
  2022-10-24  7:58   ` Richard Palethorpe
  2022-10-13 13:47 ` [LTP] [PATCH v4 2/4] syscalls/madvise11: " Zhao Gongyi via ltp
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-13 13:47 UTC (permalink / raw)
  To: ltp

Check that madvise(2) MADV_DONTNEED operation applied to Huge
TLB pages successfully after kernel version 5.18, and 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/madvise04.c | 62 +++++++++++++++++++
 3 files changed, 64 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..a970fb33e
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise04.c
@@ -0,0 +1,62 @@
+// 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]
+ *
+ * Check that madvise(2) MADV_DONTNEED operation applied to Huge TLB pages
+ * successfully after kernel version 5.18, and 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 int mapsz;
+
+static void run(void)
+{
+	TST_EXP_PASS(madvise(addr, mapsz, MADV_DONTNEED));
+	for (int i = 0; i < mapsz; i++) {
+		if (addr[i]) {
+			tst_res(TFAIL,
+				"There are no zero-fill-on-demand pages "
+				"for anonymous private mappings");
+			return;
+		}
+	}
+
+	tst_res(TPASS, "There are zero-fill-on-demand pages "
+		       "for anonymous private mappings");
+}
+
+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);
+	memset(addr, 1, mapsz);
+}
+
+static void cleanup(void)
+{
+	if (addr)
+		SAFE_MUNMAP(addr, mapsz);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "5.18",
+	.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] 11+ messages in thread

* [LTP] [PATCH v4 2/4] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
  2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
  2022-10-13 13:47 ` [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE) Zhao Gongyi via ltp
  2022-10-13 13:47 ` [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
@ 2022-10-13 13:47 ` Zhao Gongyi via ltp
  2022-10-24  9:48   ` Richard Palethorpe
  2022-10-13 13:47 ` [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE) Zhao Gongyi via ltp
  2022-10-13 13:47 ` [LTP] [PATCH v4 4/4] syscalls/madvise13: " Zhao Gongyi via ltp
  4 siblings, 1 reply; 11+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-13 13:47 UTC (permalink / raw)
  To: ltp

Check that madvise(2) MADV_DONTNEED applied to shared mappings 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 | 82 +++++++++++++++++++
 3 files changed, 84 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..0132c091c
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise11.c
@@ -0,0 +1,82 @@
+// 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]
+ *
+ * Check that madvise(2) MADV_DONTNEED applied to shared mappings 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) failed",
+			addr, MAP_SIZE, MADV_DONTNEED);
+	}
+
+	sprintf(vm_area_addr, "%p", addr);
+	sprintf(cmd, "cat /proc/%d/smaps", getpid());
+	fp = popen(cmd, "r");
+
+	/* Find the vm area */
+	while (fgets(line, sizeof(line), fp) != NULL) {
+		if (strstr(line, &(vm_area_addr[2])))
+			break;
+	}
+
+	/* Find Rss size of the vm area */
+	while (fgets(line, sizeof(line), fp) != NULL) {
+		if (strstr(line, "Rss:")) {
+			if (strstr(line, " 0 kB"))
+				tst_res(TPASS, "RSS is released");
+			else
+				tst_res(TFAIL, "RSS is not released");
+			return;
+		}
+	}
+
+	tst_brk(TBROK, "There is no 'Rss:' or vm_area %p in smaps?", addr);
+}
+
+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] 11+ messages in thread

* [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE)
  2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
                   ` (2 preceding siblings ...)
  2022-10-13 13:47 ` [LTP] [PATCH v4 2/4] syscalls/madvise11: " Zhao Gongyi via ltp
@ 2022-10-13 13:47 ` Zhao Gongyi via ltp
  2022-10-24 10:47   ` Richard Palethorpe
  2022-10-13 13:47 ` [LTP] [PATCH v4 4/4] syscalls/madvise13: " Zhao Gongyi via ltp
  4 siblings, 1 reply; 11+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-13 13:47 UTC (permalink / raw)
  To: ltp

Check that after a successful madvise(2) MADV_REMOVE operation, subsequent
accesses in the specified address range will see bytes containing zero.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/madvise/.gitignore  |  1 +
 testcases/kernel/syscalls/madvise/madvise12.c | 85 +++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 testcases/kernel/syscalls/madvise/madvise12.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 296af9f9d..0697b31ab 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -949,6 +949,7 @@ madvise08 madvise08
 madvise09 madvise09
 madvise10 madvise10
 madvise11 madvise11
+madvise12 madvise12

 newuname01 newuname01

diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
index ffd8823d1..dc82c82bd 100644
--- a/testcases/kernel/syscalls/madvise/.gitignore
+++ b/testcases/kernel/syscalls/madvise/.gitignore
@@ -9,3 +9,4 @@
 /madvise09
 /madvise10
 /madvise11
+/madvise12
diff --git a/testcases/kernel/syscalls/madvise/madvise12.c b/testcases/kernel/syscalls/madvise/madvise12.c
new file mode 100644
index 000000000..7c22e464d
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise12.c
@@ -0,0 +1,85 @@
+// 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]
+ *
+ * Check that after a successful madvise(2) MADV_REMOVE operation, subsequent
+ * accesses in the specified address range will see bytes containing zero.
+ */
+
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include "tst_test.h"
+
+#define MAP_SIZE (8 * 1024)
+#define FNAME "madvise_remove"
+#define MOUNT_POINT "mntpoint"
+
+static char *addr;
+static int fd;
+
+static void run(void)
+{
+	TEST(madvise(addr, MAP_SIZE, MADV_REMOVE));
+	if (TST_RET == -1) {
+		if (TST_ERR == EOPNOTSUPP)
+			tst_brk(TCONF, "'MADV_REMOVE' not supported?");
+		else {
+			tst_res(TFAIL | TTERRNO, "madvise(%p, %d, 0x%x) failed",
+				addr, MAP_SIZE, MADV_REMOVE);
+			return;
+		}
+	}
+
+	for (int i = 0; i < MAP_SIZE; i++) {
+		if (addr[0]) {
+			tst_res(TFAIL,
+				"The content of mapping memory is not removed");
+			return;
+		}
+	}
+
+	tst_res(TPASS, "The content of mapping memory is removed");
+}
+
+static void setup(void)
+{
+	fd = SAFE_OPEN(FNAME, O_CREAT | O_RDWR, 0777);
+	TEST(fallocate(fd, 0, 0, MAP_SIZE));
+	if (TST_RET) {
+		if (TST_ERR == ENOSYS || TST_ERR == EOPNOTSUPP)
+			tst_brk(TCONF, "fallocate not support");
+		else
+			tst_brk(TBROK | TERRNO, "fallocate failed");
+	}
+
+	addr = SAFE_MMAP(NULL, MAP_SIZE,
+			PROT_READ | PROT_WRITE,
+			MAP_SHARED,
+			fd, 0);
+	memset(addr, 1, MAP_SIZE);
+}
+
+static void cleanup(void)
+{
+	SAFE_CLOSE(fd);
+	SAFE_UNLINK(FNAME);
+	if (addr)
+		SAFE_MUNMAP(addr, MAP_SIZE);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+	.min_kver = "2.6.16",
+	.setup = setup,
+	.cleanup = cleanup,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MOUNT_POINT,
+};
+
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [LTP] [PATCH v4 4/4] syscalls/madvise13: new test for madvise(MADV_REMOVE)
  2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
                   ` (3 preceding siblings ...)
  2022-10-13 13:47 ` [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE) Zhao Gongyi via ltp
@ 2022-10-13 13:47 ` Zhao Gongyi via ltp
  2022-10-24 11:01   ` Richard Palethorpe
  4 siblings, 1 reply; 11+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-13 13:47 UTC (permalink / raw)
  To: ltp

Check that the specified address range must be mapped shared and writable
and this flag cannot be applied to locked pages.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/madvise/.gitignore  |  1 +
 testcases/kernel/syscalls/madvise/madvise13.c | 80 +++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 testcases/kernel/syscalls/madvise/madvise13.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 0697b31ab..bd74373a4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -950,6 +950,7 @@ madvise09 madvise09
 madvise10 madvise10
 madvise11 madvise11
 madvise12 madvise12
+madvise13 madvise13

 newuname01 newuname01

diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
index dc82c82bd..fcf04c749 100644
--- a/testcases/kernel/syscalls/madvise/.gitignore
+++ b/testcases/kernel/syscalls/madvise/.gitignore
@@ -10,3 +10,4 @@
 /madvise10
 /madvise11
 /madvise12
+/madvise13
diff --git a/testcases/kernel/syscalls/madvise/madvise13.c b/testcases/kernel/syscalls/madvise/madvise13.c
new file mode 100644
index 000000000..15b17a6a8
--- /dev/null
+++ b/testcases/kernel/syscalls/madvise/madvise13.c
@@ -0,0 +1,80 @@
+// 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]
+ *
+ * Check that in madvise(2) MADV_REMOVE operation, the specified address
+ * range must be mapped shared and writable and this flag cannot be applied
+ * to locked pages.
+ */
+
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include "tst_test.h"
+
+#define MAP_SIZE (8 * 1024)
+#define FNAME "madvise_remove"
+#define MOUNT_POINT "mntpoint"
+
+static int fd;
+static struct tcase {
+	int prot;
+	int flags;
+	int exp;
+	int err;
+} tcases[] = {
+	{PROT_READ, MAP_PRIVATE, -1, EACCES},
+	{PROT_READ, MAP_PRIVATE | MAP_LOCKED, -1, EINVAL},
+	{PROT_READ, MAP_SHARED, -1, EACCES},
+	{PROT_READ, MAP_SHARED | MAP_LOCKED, -1, EINVAL},
+	{PROT_WRITE, MAP_PRIVATE, -1, EACCES},
+	{PROT_WRITE, MAP_PRIVATE | MAP_LOCKED, -1, EINVAL},
+	{PROT_WRITE, MAP_SHARED | MAP_LOCKED, -1, EINVAL},
+	{PROT_WRITE, MAP_SHARED, 0, 0},
+	{PROT_WRITE | PROT_READ, MAP_SHARED, 0, 0},
+};
+
+
+static void run(unsigned int i)
+{
+	char *addr = SAFE_MMAP(NULL, MAP_SIZE,
+			tcases[i].prot,
+			tcases[i].flags,
+			fd, 0);
+
+	if (tcases[i].exp)
+		TST_EXP_FAIL(madvise(addr, MAP_SIZE, MADV_REMOVE),
+			     tcases[i].err);
+	else
+		TST_EXP_PASS(madvise(addr, MAP_SIZE, MADV_REMOVE));
+
+	SAFE_MUNMAP(addr, MAP_SIZE);
+}
+
+static void setup(void)
+{
+	fd = SAFE_OPEN(FNAME, O_CREAT | O_RDWR, 0777);
+}
+
+static void cleanup(void)
+{
+	SAFE_CLOSE(fd);
+	SAFE_UNLINK(FNAME);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.min_kver = "2.6.16",
+	.setup = setup,
+	.cleanup = cleanup,
+	.all_filesystems = 1,
+	.mntpoint = MOUNT_POINT,
+	.mount_device = 1,
+};
+
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED)
  2022-10-13 13:47 ` [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
@ 2022-10-24  7:58   ` Richard Palethorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Palethorpe @ 2022-10-24  7:58 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> Check that madvise(2) MADV_DONTNEED operation applied to Huge
> TLB pages successfully after kernel version 5.18, and 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/madvise04.c | 62 +++++++++++++++++++
>  3 files changed, 64 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..a970fb33e
> --- /dev/null
> +++ b/testcases/kernel/syscalls/madvise/madvise04.c
> @@ -0,0 +1,62 @@
> +// 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]
> + *
> + * Check that madvise(2) MADV_DONTNEED operation applied to Huge TLB pages
> + * successfully after kernel version 5.18, and 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 int mapsz;
> +
> +static void run(void)
> +{
> +	TST_EXP_PASS(madvise(addr, mapsz, MADV_DONTNEED));
> +	for (int i = 0; i < mapsz; i++) {
> +		if (addr[i]) {
> +			tst_res(TFAIL,
> +				"There are no zero-fill-on-demand pages "
> +				"for anonymous private mappings");
> +			return;
> +		}
> +	}
> +
> +	tst_res(TPASS, "There are zero-fill-on-demand pages "
> +		       "for anonymous private mappings");
> +}
> +
> +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);
> +	memset(addr, 1, mapsz);

If we only do memset here then we are only testing the zero-fill feature
on the first iteration.

> +}
> +
> +static void cleanup(void)
> +{
> +	if (addr)
> +		SAFE_MUNMAP(addr, mapsz);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.min_kver = "5.18",

What happens before 5.18? Could we try applying MADV_DONTNEED and return
TCONF instead?

> +	.needs_root = 1,

Why does this need root?

> +	.hugepages = {1, TST_NEEDS},
> +};
> +
> --
> 2.17.1


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v4 2/4] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
  2022-10-13 13:47 ` [LTP] [PATCH v4 2/4] syscalls/madvise11: " Zhao Gongyi via ltp
@ 2022-10-24  9:48   ` Richard Palethorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Palethorpe @ 2022-10-24  9:48 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> Check that madvise(2) MADV_DONTNEED applied to shared mappings 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 | 82 +++++++++++++++++++
>  3 files changed, 84 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..0132c091c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/madvise/madvise11.c
> @@ -0,0 +1,82 @@
> +// 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]
> + *
> + * Check that madvise(2) MADV_DONTNEED applied to shared mappings 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) failed",
> +			addr, MAP_SIZE, MADV_DONTNEED);
> +	}

You have a lot of madvise patches, so why not create SAFE_MADVISE?

Or there are the TST_EXP_* macros.

> +
> +	sprintf(vm_area_addr, "%p", addr);
> +	sprintf(cmd, "cat /proc/%d/smaps", getpid());
> +	fp = popen(cmd, "r");
> +
> +	/* Find the vm area */
> +	while (fgets(line, sizeof(line), fp) != NULL) {
> +		if (strstr(line, &(vm_area_addr[2])))

AFAICT this could match more than one line by matching the end of the
preceding range.

I think that in general it's better to avoid strstr if memcmp can be
easily used instead.

> +			break;
> +	}
> +
> +	/* Find Rss size of the vm area */
> +	while (fgets(line, sizeof(line), fp) != NULL) {
> +		if (strstr(line, "Rss:")) {

Same here although Rss: seems to be unique. Then again it could be added
to another field in new kernel.

Perhaps sscanf would be better?

> +			if (strstr(line, " 0 kB"))
> +				tst_res(TPASS, "RSS is released");
> +			else
> +				tst_res(TFAIL, "RSS is not released");
> +			return;
> +		}
> +	}
> +
> +	tst_brk(TBROK, "There is no 'Rss:' or vm_area %p in smaps?", addr);
> +}
> +
> +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

Otherwise looks good.

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE)
  2022-10-13 13:47 ` [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE) Zhao Gongyi via ltp
@ 2022-10-24 10:47   ` Richard Palethorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Palethorpe @ 2022-10-24 10:47 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> Check that after a successful madvise(2) MADV_REMOVE operation, subsequent
> accesses in the specified address range will see bytes containing zero.
>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  runtest/syscalls                              |  1 +
>  testcases/kernel/syscalls/madvise/.gitignore  |  1 +
>  testcases/kernel/syscalls/madvise/madvise12.c | 85 +++++++++++++++++++
>  3 files changed, 87 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/madvise/madvise12.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 296af9f9d..0697b31ab 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -949,6 +949,7 @@ madvise08 madvise08
>  madvise09 madvise09
>  madvise10 madvise10
>  madvise11 madvise11
> +madvise12 madvise12
>
>  newuname01 newuname01
>
> diff --git a/testcases/kernel/syscalls/madvise/.gitignore b/testcases/kernel/syscalls/madvise/.gitignore
> index ffd8823d1..dc82c82bd 100644
> --- a/testcases/kernel/syscalls/madvise/.gitignore
> +++ b/testcases/kernel/syscalls/madvise/.gitignore
> @@ -9,3 +9,4 @@
>  /madvise09
>  /madvise10
>  /madvise11
> +/madvise12
> diff --git a/testcases/kernel/syscalls/madvise/madvise12.c b/testcases/kernel/syscalls/madvise/madvise12.c
> new file mode 100644
> index 000000000..7c22e464d
> --- /dev/null
> +++ b/testcases/kernel/syscalls/madvise/madvise12.c
> @@ -0,0 +1,85 @@
> +// 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]
> + *
> + * Check that after a successful madvise(2) MADV_REMOVE operation, subsequent
> + * accesses in the specified address range will see bytes containing zero.
> + */
> +
> +#define _GNU_SOURCE
> +#include <fcntl.h>
> +#include "tst_test.h"
> +
> +#define MAP_SIZE (8 * 1024)
> +#define FNAME "madvise_remove"
> +#define MOUNT_POINT "mntpoint"
> +
> +static char *addr;
> +static int fd;
> +
> +static void run(void)
> +{

Same as the other test, memset is required here

> +	TEST(madvise(addr, MAP_SIZE, MADV_REMOVE));
> +	if (TST_RET == -1) {
> +		if (TST_ERR == EOPNOTSUPP)
> +			tst_brk(TCONF, "'MADV_REMOVE' not supported?");
> +		else {
> +			tst_res(TFAIL | TTERRNO, "madvise(%p, %d, 0x%x) failed",
> +				addr, MAP_SIZE, MADV_REMOVE);
> +			return;
> +		}
> +	}

Also same as other test, this could be put in SAFE_MADVISE.

> +
> +	for (int i = 0; i < MAP_SIZE; i++) {
> +		if (addr[0]) {
> +			tst_res(TFAIL,
> +				"The content of mapping memory is not
> removed");

This could be replaced with memcmp. Unless you print the location of
where the bytes are non-zero.

> +			return;
> +		}
> +	}
> +
> +	tst_res(TPASS, "The content of mapping memory is removed");
> +}
> +
> +static void setup(void)
> +{
> +	fd = SAFE_OPEN(FNAME, O_CREAT | O_RDWR, 0777);
> +	TEST(fallocate(fd, 0, 0, MAP_SIZE));
> +	if (TST_RET) {
> +		if (TST_ERR == ENOSYS || TST_ERR == EOPNOTSUPP)
> +			tst_brk(TCONF, "fallocate not support");
> +		else
> +			tst_brk(TBROK | TERRNO, "fallocate failed");
> +	}
> +
> +	addr = SAFE_MMAP(NULL, MAP_SIZE,
> +			PROT_READ | PROT_WRITE,
> +			MAP_SHARED,
> +			fd, 0);
> +	memset(addr, 1, MAP_SIZE);
> +}
> +
> +static void cleanup(void)
> +{
> +	SAFE_CLOSE(fd);
> +	SAFE_UNLINK(FNAME);
> +	if (addr)
> +		SAFE_MUNMAP(addr, MAP_SIZE);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.needs_root = 1,
> +	.min_kver = "2.6.16",
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.all_filesystems = 1,
> +	.mount_device = 1,
> +	.mntpoint = MOUNT_POINT,
> +};
> +
> --
> 2.17.1


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v4 4/4] syscalls/madvise13: new test for madvise(MADV_REMOVE)
  2022-10-13 13:47 ` [LTP] [PATCH v4 4/4] syscalls/madvise13: " Zhao Gongyi via ltp
@ 2022-10-24 11:01   ` Richard Palethorpe
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Palethorpe @ 2022-10-24 11:01 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hello,

Zhao Gongyi via ltp <ltp@lists.linux.it> writes:

> Check that the specified address range must be mapped shared and writable
> and this flag cannot be applied to locked pages.
>
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>

Looks good!

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [LTP] [PATCH v4 2/4] syscalls/madvise11: new test for madvise(MADV_DONTNEED)
@ 2022-10-26  9:19 zhaogongyi via ltp
  0 siblings, 0 replies; 11+ messages in thread
From: zhaogongyi via ltp @ 2022-10-26  9:19 UTC (permalink / raw)
  To: rpalethorpe@suse.de; +Cc: ltp@lists.linux.it

Hi,

> 
> Hello,
> 
> Zhao Gongyi via ltp <ltp@lists.linux.it> writes:
> 
> > Check that madvise(2) MADV_DONTNEED applied to shared mappings
> 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 | 82
> +++++++++++++++++++
> >  3 files changed, 84 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..0132c091c
> > --- /dev/null
> > +++ b/testcases/kernel/syscalls/madvise/madvise11.c
> > @@ -0,0 +1,82 @@
> > +// 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]
> > + *
> > + * Check that madvise(2) MADV_DONTNEED applied to shared
> mappings
> > +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) failed",
> > +			addr, MAP_SIZE, MADV_DONTNEED);
> > +	}
> 
> You have a lot of madvise patches, so why not create SAFE_MADVISE?

Yes, it seems more better, thanks!


> 
> Or there are the TST_EXP_* macros.
> 
> > +
> > +	sprintf(vm_area_addr, "%p", addr);
> > +	sprintf(cmd, "cat /proc/%d/smaps", getpid());
> > +	fp = popen(cmd, "r");
> > +
> > +	/* Find the vm area */
> > +	while (fgets(line, sizeof(line), fp) != NULL) {
> > +		if (strstr(line, &(vm_area_addr[2])))
> 
> AFAICT this could match more than one line by matching the end of the
> preceding range.

Is it only one vma that inlucde the address?

> 
> I think that in general it's better to avoid strstr if memcmp can be easily
> used instead.
> 
> > +			break;
> > +	}
> > +
> > +	/* Find Rss size of the vm area */
> > +	while (fgets(line, sizeof(line), fp) != NULL) {
> > +		if (strstr(line, "Rss:")) {
> 
> Same here although Rss: seems to be unique. Then again it could be added
> to another field in new kernel.
> 
> Perhaps sscanf would be better?

Maybe it will encounter the same problem with sscanf when the field changed?

It seems there is only one way to get the RSS.

Regards,
Gongyi

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-10-26  9:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-13 13:47 [LTP] [PATCH v3] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-13 13:47 ` [LTP] [PATCH v4 0/4] new test for madvise(MADV_DONTNEED/MADV_REMOVE) Zhao Gongyi via ltp
2022-10-13 13:47 ` [LTP] [PATCH v4 1/4] syscalls/madvise04: new test for madvise(MADV_DONTNEED) Zhao Gongyi via ltp
2022-10-24  7:58   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 2/4] syscalls/madvise11: " Zhao Gongyi via ltp
2022-10-24  9:48   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 3/4] syscalls/madvise12: new test for madvise(MADV_REMOVE) Zhao Gongyi via ltp
2022-10-24 10:47   ` Richard Palethorpe
2022-10-13 13:47 ` [LTP] [PATCH v4 4/4] syscalls/madvise13: " Zhao Gongyi via ltp
2022-10-24 11:01   ` Richard Palethorpe
  -- strict thread matches above, loose matches on Subject: below --
2022-10-26  9:19 [LTP] [PATCH v4 2/4] syscalls/madvise11: new test for madvise(MADV_DONTNEED) 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