From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb
Date: Wed, 9 Feb 2022 16:52:13 +0800 [thread overview]
Message-ID: <20220209085213.2882229-1-liwang@redhat.com> (raw)
In-Reply-To: <20220208132414.2852202-1-liwang@redhat.com>
It is trying to test without swap happen to guarantee less disturbing
for the ’->ru_maxrss‘ counting.
Therefore add mlockall() to prevent that memory address space
of the calling process from being paged to the swap area.
Due to that lock needs CAP_IPC_LOCK capability and child can not
inherit memory locks from parent, here add the definition and put
the mlockall() in consume_mb.
Signed-off-by: Li Wang <liwang@redhat.com>
---
include/lapi/capability.h | 4 ++++
testcases/kernel/syscalls/getrusage/getrusage03.c | 4 ++++
testcases/kernel/syscalls/getrusage/getrusage03.h | 2 ++
3 files changed, 10 insertions(+)
diff --git a/include/lapi/capability.h b/include/lapi/capability.h
index 8cabd0f28..17ec107b1 100644
--- a/include/lapi/capability.h
+++ b/include/lapi/capability.h
@@ -24,6 +24,10 @@
# define CAP_NET_RAW 13
#endif
+#ifndef CAP_IPC_LOCK
+# define CAP_IPC_LOCK 14
+#endif
+
#ifndef CAP_SYS_CHROOT
# define CAP_SYS_CHROOT 18
#endif
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index 201d258fa..43fab0605 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -193,4 +193,8 @@ static struct tst_test test = {
.setup = setup,
.test = run,
.tcnt = ARRAY_SIZE(testfunc_list),
+ .caps = (struct tst_cap []) {
+ TST_CAP(TST_CAP_REQ, CAP_IPC_LOCK),
+ {}
+ },
};
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h b/testcases/kernel/syscalls/getrusage/getrusage03.h
index f1bbe9be5..b28b9d4c3 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.h
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
@@ -16,6 +16,8 @@ static void consume_mb(int consume_nr)
size_t size;
unsigned long vmswap_size;
+ mlockall(MCL_CURRENT|MCL_FUTURE);
+
size = consume_nr * 1024 * 1024;
ptr = SAFE_MALLOC(size);
memset(ptr, 0, size);
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-02-09 8:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 13:24 [LTP] [PATCH] getrusage03: mlock the memory area in consume_mb Li Wang
2022-02-08 13:36 ` Li Wang
2022-02-09 8:52 ` Li Wang [this message]
2022-02-16 9:54 ` [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb Cyril Hrubis
2022-02-17 6:59 ` Li Wang
2022-02-17 15:19 ` Cyril Hrubis
2022-02-21 1:57 ` Li Wang
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=20220209085213.2882229-1-liwang@redhat.com \
--to=liwang@redhat.com \
--cc=ltp@lists.linux.it \
/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