* [LTP] [PATCH] getrusage03: mlock the memory area in consume_mb
@ 2022-02-08 13:24 Li Wang
2022-02-08 13:36 ` Li Wang
2022-02-09 8:52 ` [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb Li Wang
0 siblings, 2 replies; 7+ messages in thread
From: Li Wang @ 2022-02-08 13:24 UTC (permalink / raw)
To: ltp
Seems it trying to test without swap happen to guarantee less
disturbing for the ’->ru_maxrss‘ counting.
Therefore add mlock() to prevent that memory allocated by consume_mb
from being paged to the swap area.
Signed-off-by: Li Wang <liwang@redhat.com>
---
testcases/kernel/syscalls/getrusage/getrusage03.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h b/testcases/kernel/syscalls/getrusage/getrusage03.h
index f1bbe9be5..d46fdff85 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.h
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
@@ -18,6 +18,7 @@ static void consume_mb(int consume_nr)
size = consume_nr * 1024 * 1024;
ptr = SAFE_MALLOC(size);
+ mlock(ptr, size);
memset(ptr, 0, size);
SAFE_FILE_LINES_SCANF("/proc/self/status", "VmSwap: %lu", &vmswap_size);
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH] getrusage03: mlock the memory area in consume_mb
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 ` [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb Li Wang
1 sibling, 0 replies; 7+ messages in thread
From: Li Wang @ 2022-02-08 13:36 UTC (permalink / raw)
To: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 1357 bytes --]
On Tue, Feb 8, 2022 at 9:24 PM Li Wang <liwang@redhat.com> wrote:
> Seems it trying to test without swap happen to guarantee less
> disturbing for the ’->ru_maxrss‘ counting.
>
> Therefore add mlock() to prevent that memory allocated by consume_mb
> from being paged to the swap area.
>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> testcases/kernel/syscalls/getrusage/getrusage03.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h
> b/testcases/kernel/syscalls/getrusage/getrusage03.h
> index f1bbe9be5..d46fdff85 100644
> --- a/testcases/kernel/syscalls/getrusage/getrusage03.h
> +++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
> @@ -18,6 +18,7 @@ static void consume_mb(int consume_nr)
>
> size = consume_nr * 1024 * 1024;
> ptr = SAFE_MALLOC(size);
> + mlock(ptr, size);
>
Hmm, seems using mlockall() will be better than mlock().
Because that locks all pages mapped into the address space of the calling
process.
(includes code, data, stack segment, shared libraries, etc).
> memset(ptr, 0, size);
>
> SAFE_FILE_LINES_SCANF("/proc/self/status", "VmSwap: %lu",
> &vmswap_size);
> --
> 2.31.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 2480 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb
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
2022-02-16 9:54 ` Cyril Hrubis
1 sibling, 1 reply; 7+ messages in thread
From: Li Wang @ 2022-02-09 8:52 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb
2022-02-09 8:52 ` [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb Li Wang
@ 2022-02-16 9:54 ` Cyril Hrubis
2022-02-17 6:59 ` Li Wang
0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2022-02-16 9:54 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi!
> --- 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),
> + {}
> + },
> };
I wonder if we should start to track the capabilities like this instead
of the .needs_root approach. I guess that it may be useful to keep
things granular in the future.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb
2022-02-16 9:54 ` Cyril Hrubis
@ 2022-02-17 6:59 ` Li Wang
2022-02-17 15:19 ` Cyril Hrubis
0 siblings, 1 reply; 7+ messages in thread
From: Li Wang @ 2022-02-17 6:59 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 1007 bytes --]
On Wed, Feb 16, 2022 at 5:54 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> > --- 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),
> > + {}
> > + },
> > };
>
> I wonder if we should start to track the capabilities like this instead
> of the .needs_root approach. I guess that it may be useful to keep
> things granular in the future.
>
I think yes, Linux Capabilities makes it possible for specific privileges to
the test process, and avoid that .needs_root limited many tests scenario
to skip directly with non-root users. Especially beneficial for running LTP
in the docker with only part of root privileges for reasons like strict
security
verification.
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 1948 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb
2022-02-17 6:59 ` Li Wang
@ 2022-02-17 15:19 ` Cyril Hrubis
2022-02-21 1:57 ` Li Wang
0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2022-02-17 15:19 UTC (permalink / raw)
To: Li Wang; +Cc: LTP List
Hi!
> I think yes, Linux Capabilities makes it possible for specific privileges to
> the test process, and avoid that .needs_root limited many tests scenario
> to skip directly with non-root users. Especially beneficial for running LTP
> in the docker with only part of root privileges for reasons like strict
> security
> verification.
Looks good then:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb
2022-02-17 15:19 ` Cyril Hrubis
@ 2022-02-21 1:57 ` Li Wang
0 siblings, 0 replies; 7+ messages in thread
From: Li Wang @ 2022-02-21 1:57 UTC (permalink / raw)
To: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 38 bytes --]
Pushed, thanks.
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 309 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-02-21 1:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [LTP] [PATCH v2] getrusage03: mlock all address space for process calling consume_mb Li Wang
2022-02-16 9:54 ` Cyril Hrubis
2022-02-17 6:59 ` Li Wang
2022-02-17 15:19 ` Cyril Hrubis
2022-02-21 1:57 ` Li Wang
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.