[LTP] [PATCH] getrusage03: mlock the memory area in consume_mb

Li Wang liwang@redhat.com
Tue Feb 8 14:36:33 CET 2022


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220208/81c7ff1f/attachment.htm>


More information about the ltp mailing list