syscalls/madvise04: new test for madvise(MADV_DONTNEED)
Hi,
Quoted 90 lines
Hello,
Quoted 9 lines · Zhao Gongyi via ltp
Check that madvise(2)
MADV_DONTNEEDoperation 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 <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/madvise/.gitignore | 1 +
testcases/kernel/syscalls/madvise/madvise04.c| 62+++++++++++++++++++
Quoted 35 lines
3 files changed, 64 insertions(+) create mode 100644 testcases/kernel/syscalls/madvise/madvise04.cruntest/syscalls index renamed from runtest/syscalls +0
-0
c81764df4..eb1910cec100644runtest/syscalls +1
-0@@ -941,6 +941,7 @@ mincore04 mincore04 madvise01 madvise01 madvise02 madvise02 madvise03 madvise03 +madvise04 madvise04 madvise05 madvise05 madvise06 madvise06 madvise07 madvise07testcases/kernel/syscalls/madvise/.gitignore +1
-0@@ -1,6 +1,7 @@ /madvise01 /madvise02 /madvise03 +/madvise04 /madvise05 /madvise06 /madvise07testcases/kernel/syscalls/madvise/madvise04.c new file +0
-0testcases/kernel/syscalls/madvise/madvise04.c line 9
Quoted 9 lines
testcases/kernel/syscalls/madvise/madvise04.c new file +9
-0@@ -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 <[email protected]> */ + +/*\ +* [Description] +* +* Check that madvise(2) MADV_DONTNEED operation applied to Huge TLB
Quoted 30 lines
testcases/kernel/syscalls/madvise/madvise04.c new file +30
-0+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 ();
Quoted 8 lines
testcases/kernel/syscalls/madvise/madvise04.c line 44
Quoted 5 lines
testcases/kernel/syscalls/madvise/madvise04.c new file +5
-0+ 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.
Yes, thanks. It need to move to run().
Quoted 17 lines
Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise04.c new file +3
-0+} + +static void cleanup (void )testcases/kernel/syscalls/madvise/madvise04.c line 57
Quoted 10 lines
testcases/kernel/syscalls/madvise/madvise04.c new file +10
-0+{ +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_DONTNEEDand return TCONF instead?
MADV_DONTNEED is not supported before 5.18.
Try applying MADV_DONTNEED and return TCONF seems more better, thanks.
Quoted 4 lines
testcases/kernel/syscalls/madvise/madvise04.c line 58
Quoted 2 lines
testcases/kernel/syscalls/madvise/madvise04.c new file +1
-0+ .needs_root = 1,Why does this need root?
When we get or set hugepages, we need to read or write '/proc/sys/vm/nr_hugepages', so we need to set needs_root here.
Regards,
Gongyi
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp