cachestat testing suite
v3 cover cachestat testing suite
This suite is adding covergae for the cachestat() syscall which is providing support for reading the file cache status and it has been added in the kernel 6.5.
There's not a man page yet, so please consider the following link as documentation:
https://lwn.net/Articles/917059/
---
Changes in v3:
- include stdlib.h when free() is used
- add cachestat04 test looping on all file descriptors
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- cachestat01: run test on multiple test pages
- remove cachestat01A
- cachestat02: run test on multiple test pages
- add new cachestat03 test
---
Andrea Cervesato (5):
Add cachestat fallback definitions
Add cachestat01 test
Add cachestat02 test
Add cachestat03 test
Add cachestat04 test
configure.ac | 4 + include/lapi/mman.h | 44 +++++++++ include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/loongarch.in | 1 + include/lapi/syscalls/mips_n32.in | 1 + include/lapi/syscalls/mips_n64.in | 1 + include/lapi/syscalls/mips_o32.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + runtest/syscalls | 5 + testcases/kernel/syscalls/cachestat/.gitignore | 4 + testcases/kernel/syscalls/cachestat/Makefile | 10 ++ testcases/kernel/syscalls/cachestat/cachestat.h | 27 ++++++ testcases/kernel/syscalls/cachestat/cachestat01.c | 106 ++++++++++++++++++++++ testcases/kernel/syscalls/cachestat/cachestat02.c | 90 ++++++++++++++++++ testcases/kernel/syscalls/cachestat/cachestat03.c | 80 ++++++++++++++++ testcases/kernel/syscalls/cachestat/cachestat04.c | 58 ++++++++++++ 28 files changed, 446 insertions(+)
---
base-commit: 2433c503a6657273da895e36adda73942452c482
change-id: 20240515-cachestat-11fc82af07ec
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/5 Add cachestat fallback definitions
From: Andrea Cervesato <[email protected]>
--- configure.ac | 4 ++++ include/lapi/mman.h | 44 ++++++++++++++++++++++++++++++++++++++ include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/loongarch.in | 1 + include/lapi/syscalls/mips_n32.in | 1 + include/lapi/syscalls/mips_n64.in | 1 + include/lapi/syscalls/mips_o32.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 20 files changed, 66 insertions(+)
configure.ac +4 -0
@@ -91,6 +91,7 @@ AC_SUBST(HAVE_FTS_H, $have_fts) AC_CHECK_HEADERS(linux/vm_sockets.h, [], [], [#include <sys/socket.h>]) AC_CHECK_FUNCS_ONCE([ \ + cachestat \ clone3 \ close_range \ copy_file_range \
@@ -243,6 +244,9 @@ AC_CHECK_TYPES([struct mount_attr],,,[ #endif ]) +AC_CHECK_TYPES([struct cachestat_range],,,[#include <sys/mman.h>]) +AC_CHECK_TYPES([struct cachestat],,,[#include <sys/mman.h>]) + # Tools knobs # Bash
include/lapi/mman.h new file +44 -0
44 lines not on this page · raw message
include/lapi/syscalls/aarch64.in +1 -0
@@ -300,4 +300,5 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451 _sysctl 1078
include/lapi/syscalls/arc.in +1 -0
@@ -320,3 +320,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/arm.in +1 -0
@@ -399,3 +399,4 @@ landlock_add_rule (__NR_SYSCALL_BASE+445) landlock_restrict_self (__NR_SYSCALL_BASE+446) memfd_secret (__NR_SYSCALL_BASE+447) futex_waitv (__NR_SYSCALL_BASE+449) +cachestat (__NR_SYSCALL_BASE+451)
include/lapi/syscalls/hppa.in +1 -0
@@ -47,3 +47,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/i386.in +1 -0
@@ -434,3 +434,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/ia64.in +1 -0
@@ -347,3 +347,4 @@ landlock_create_ruleset 1468 landlock_add_rule 1469 landlock_restrict_self 1470 futex_waitv 1473 +cachestat 1475
include/lapi/syscalls/loongarch.in +1 -0
@@ -305,3 +305,4 @@ memfd_secret 447 process_mrelease 448 futex_waitv 449 set_mempolicy_home_node 450 +cachestat 451
include/lapi/syscalls/mips_n32.in +1 -0
@@ -374,3 +374,4 @@ landlock_create_ruleset 6444 landlock_add_rule 6445 landlock_restrict_self 6446 futex_waitv 6449 +cachestat 6451
include/lapi/syscalls/mips_n64.in +1 -0
@@ -350,3 +350,4 @@ landlock_create_ruleset 5444 landlock_add_rule 5445 landlock_restrict_self 5446 futex_waitv 5449 +cachestat 5451
include/lapi/syscalls/mips_o32.in +1 -0
@@ -420,3 +420,4 @@ landlock_create_ruleset 4444 landlock_add_rule 4445 landlock_restrict_self 4446 futex_waitv 4449 +cachestat 4451
include/lapi/syscalls/powerpc.in +1 -0
@@ -427,3 +427,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/powerpc64.in +1 -0
@@ -427,3 +427,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/s390.in +1 -0
@@ -414,3 +414,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/s390x.in +1 -0
@@ -362,3 +362,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/sh.in +1 -0
@@ -408,3 +408,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/sparc.in +1 -0
@@ -413,3 +413,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/sparc64.in +1 -0
@@ -378,3 +378,4 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451
include/lapi/syscalls/x86_64.in +1 -0
@@ -355,6 +355,7 @@ landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 futex_waitv 449 +cachestat 451 rt_sigaction 512 rt_sigreturn 513 ioctl 514
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/5 Add cachestat01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that cachestat() syscall is properly counting cached pages written inside a file. If storage device synchronization is requested, test will check if the number of dirty pages is zero.
--- runtest/syscalls | 2 + testcases/kernel/syscalls/cachestat/.gitignore | 1 + testcases/kernel/syscalls/cachestat/Makefile | 10 ++ testcases/kernel/syscalls/cachestat/cachestat.h | 27 ++++++ testcases/kernel/syscalls/cachestat/cachestat01.c | 106 ++++++++++++++++++++++ 5 files changed, 146 insertions(+)
runtest/syscalls +2 -0
@@ -62,6 +62,8 @@ capset04 capset04 cacheflush01 cacheflush01 +cachestat01 cachestat01 + chdir01 chdir01 chdir01A symlink01 -T chdir01 chdir04 chdir04
testcases/kernel/syscalls/cachestat/.gitignore new file +1 -0
@@ -0,0 +1 @@ +cachestat01
testcases/kernel/syscalls/cachestat/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +LDLIBS += -lrt + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/cachestat/cachestat.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef CACHESTAT_H__ +#define CACHESTAT_H__ + +#include "tst_test.h" +#include "lapi/mman.h" + +static inline void print_cachestat (struct cachestat *cs) +{ +tst_res (TDEBUG , +"nr_cache=%lu " +"nr_dirty=%lu " +"nr_writeback=%lu " +"nr_evicted=%lu " +"nr_recently_evicted=%lu" , + cs->nr_cache, + cs->nr_dirty, + cs->nr_writeback, + cs->nr_evicted, + cs->nr_recently_evicted); +} + +#endif
testcases/kernel/syscalls/cachestat/cachestat01.c new file +106 -0
106 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 2/5] Add cachestat01 test
Hi!
Pushed with a two minor changes, thanks.
Quoted 10 lines
testcases/kernel/syscalls/cachestat/cachestat01.c new file +10
-0+static void test_cached_pages (const unsigned int use_sync,const int num_pages) +{ +int fd; + +tst_res (TINFO ,"%s file synchronization" , use_sync ?"Enable" :"Disable" ); +tst_res (TINFO ,"Number of pages: %d" , num_pages); + +memset (cs,0 ,sizeof (struct cachestat )); + + fd =SAFE_OPEN (FILENAME ,O_RDWR |O_CREAT ,0600 );
testcases/kernel/syscalls/cachestat/cachestat01.c line 53
Quoted 10 lines
testcases/kernel/syscalls/cachestat/cachestat01.c new file +10
-0+ +for (int i =0 ; i < num_pages; i++) +SAFE_WRITE (0 , fd, page_data, page_size); + +if (use_sync) +fsync (fd); + + cs_range->off =0 ; + cs_range->len = page_size * num_pages; +
I've added memset(cs, 0xff, sizeof(*cs)) here to make sure that the structure is initialized with bogus data before the syscall. With that we will make sure that the nr_dirty have been written to (the tst_bufers are initialized to zero to begin with).
Quoted 20 lines
testcases/kernel/syscalls/cachestat/cachestat01.c new file +20
-0+TST_EXP_PASS (cachestat (fd, cs_range, cs,0 )); +print_cachestat (cs); + +TST_EXP_EQ_LI (cs->nr_cache + cs->nr_evicted, num_pages); + +if (use_sync) +TST_EXP_EQ_LI (cs->nr_dirty,0 ); + +SAFE_CLOSE (fd); +SAFE_UNLINK (FILENAME ); +} + +static void run (unsigned int use_sync) +{ +for (int i =0 ; i <15 ; i++) +test_cached_pages (use_sync,1 << i); +} + +static void setup (void ) +{
testcases/kernel/syscalls/cachestat/cachestat01.c line 83
Quoted 10 lines
testcases/kernel/syscalls/cachestat/cachestat01.c new file +10
-0+ page_size = (int )sysconf (_SC_PAGESIZE); + + page_data =SAFE_MALLOC (page_size); +memset (page_data,'a' , page_size); +} + +static void cleanup (void ) +{ +if (page_data) +free (page_data);
free(NULL) is no-op so I've removed the if ().
Quoted 30 lines
testcases/kernel/syscalls/cachestat/cachestat01.c new file +23
-0+} + +static struct tst_test test = { + .test = run, + .tcnt =2 , + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir =1 , + .min_kver ="6.5" , + .mount_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .skip_filesystems = (const char *const []) { +"fuse" , +"tmpfs" , +NULL + }, + .bufs = (struct tst_buffers []) { + {&cs, .size =sizeof (struct cachestat )}, + {&cs_range, .size =sizeof (struct cachestat_range )}, + {} + }, +};Signature · 6 lines
-- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 3/5 Add cachestat02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that cachestat() syscall is properly counting cached pages written inside a shared memory.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/cachestat/.gitignore | 1 + testcases/kernel/syscalls/cachestat/cachestat02.c | 90 +++++++++++++++++++++++ 3 files changed, 92 insertions(+)
runtest/syscalls +1 -0
@@ -63,6 +63,7 @@ capset04 capset04 cacheflush01 cacheflush01 cachestat01 cachestat01 +cachestat02 cachestat02 chdir01 chdir01 chdir01A symlink01 -T chdir01
testcases/kernel/syscalls/cachestat/.gitignore +1 -0
@@ -1 +1,2 @@ cachestat01 +cachestat02
testcases/kernel/syscalls/cachestat/cachestat02.c new file +90 -0
90 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 3/5] Add cachestat02 test
Hi!
Pushed with the same changes as cachestat01, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 4/5 Add cachestat03 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that cachestat() syscall is properly failing with relative error codes according to input parameters.
- EFAULT: cstat or cstat_range points to an illegal address
- EINVAL: invalid flags
- EBADF: invalid file descriptor
- EOPNOTSUPP: file descriptor is of a hugetlbfs file
--- runtest/syscalls | 1 + testcases/kernel/syscalls/cachestat/.gitignore | 1 + testcases/kernel/syscalls/cachestat/cachestat03.c | 80 +++++++++++++++++++++++ 3 files changed, 82 insertions(+)
runtest/syscalls +1 -0
@@ -64,6 +64,7 @@ cacheflush01 cacheflush01 cachestat01 cachestat01 cachestat02 cachestat02 +cachestat03 cachestat03 chdir01 chdir01 chdir01A symlink01 -T chdir01
testcases/kernel/syscalls/cachestat/.gitignore +1 -0
@@ -1,2 +1,3 @@ cachestat01 cachestat02 +cachestat03
testcases/kernel/syscalls/cachestat/cachestat03.c new file +80 -0
80 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 4/5] Add cachestat03 test
Hi!
Pushed thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 5/5 Add cachestat04 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies cachestat() for all possible file descriptors, checking that returned statistics are always zero, unless file descriptor is unsupported and EBADF is raised.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/cachestat/.gitignore | 1 + testcases/kernel/syscalls/cachestat/cachestat04.c | 58 +++++++++++++++++++++++ 3 files changed, 60 insertions(+)
runtest/syscalls +1 -0
@@ -65,6 +65,7 @@ cacheflush01 cacheflush01 cachestat01 cachestat01 cachestat02 cachestat02 cachestat03 cachestat03 +cachestat04 cachestat04 chdir01 chdir01 chdir01A symlink01 -T chdir01
testcases/kernel/syscalls/cachestat/.gitignore +1 -0
@@ -1,3 +1,4 @@ cachestat01 cachestat02 cachestat03 +cachestat04
testcases/kernel/syscalls/cachestat/cachestat04.c new file +58 -0
58 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 5/5] Add cachestat04 test
Hi!
Again I've added memset() before the cachestat call so that we are sure that the structure is acutally set and pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp