Skip to contentSkip to conversation

cachestat testing suite

PATCH Superseded Andrea Cervesato 1 participant 5 messages Jul 15, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 v2:
- cachestat01: run test on multiple test pages
- remove cachestat01A
- cachestat02: run test on multiple test pages
- add new cachestat03 test

---
Andrea Cervesato (4):
Add cachestat fallback definitions
Add cachestat01 test
Add cachestat02 test
Add cachestat03 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                                  |   4 +
 testcases/kernel/syscalls/cachestat/.gitignore    |   3 +
 testcases/kernel/syscalls/cachestat/Makefile      |  10 +++
 testcases/kernel/syscalls/cachestat/cachestat.h   |  27 ++++++
 testcases/kernel/syscalls/cachestat/cachestat01.c | 105 ++++++++++++++++++++++
 testcases/kernel/syscalls/cachestat/cachestat02.c |  89 ++++++++++++++++++
 testcases/kernel/syscalls/cachestat/cachestat03.c |  80 +++++++++++++++++
 27 files changed, 384 insertions(+)

---
base-commit: 87c632c8bfbb772efde047e83e72c215bfeb1aba
change-id: 20240515-cachestat-11fc82af07ec

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/4 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
index 1f8796c87..cbcf308e5 100644
@@ -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
index 3e7797718..ef0aa04a3 100644
@@ -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
index 7fde1d263..3eaa6a8f1 100644
@@ -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
index 8e76ad164..b52a32b6b 100644
@@ -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
index 60c02aff2..4919ee65d 100644
@@ -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
index 31ec1ecb2..cff40957a 100644
@@ -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
index 2e56da7f9..11d4b46f4 100644
@@ -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
index 301f611f6..9bf6a7deb 100644
@@ -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
index 5f0fe65eb..a76c82593 100644
@@ -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
index f81c60e66..df991efd5 100644
@@ -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
index c2beffb75..826b7d66e 100644
@@ -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
index 5460e4197..798ed9050 100644
@@ -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
index 5460e4197..798ed9050 100644
@@ -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
index 275b27f47..126938095 100644
@@ -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
index c200d02b2..18f2496a0 100644
@@ -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
index 6f482a77b..ae6f26050 100644
@@ -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
index 7181e80a0..409fa2729 100644
@@ -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
index c96ab2021..e13cf163e 100644
@@ -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
index 3082ca110..05b1bee55 100644
@@ -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
#2 lore raw

PATCH v2 2/4 Add cachestat01 test

In reply to Andrea Cervesato

From: 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 | 105 ++++++++++++++++++++++
 5 files changed, 145 insertions(+)
runtest/syscalls +2 -0
index 136fd03fa..9a1827e88 100644
@@ -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
new file mode 100644
index 000000000..daea1f4be
@@ -0,0 +1 @@
+cachestat01
testcases/kernel/syscalls/cachestat/Makefile new file +10 -0
new file mode 100644
index 000000000..62b00d2f4
@@ -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
new file mode 100644
index 000000000..efce6dc7f
@@ -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 +105 -0

105 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v2 3/4 Add cachestat02 test

In reply to Andrea Cervesato

From: 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 | 89 +++++++++++++++++++++++
 3 files changed, 91 insertions(+)
runtest/syscalls +1 -0
index 9a1827e88..887ac217b 100644
@@ -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
index daea1f4be..0f70fb801 100644
@@ -1 +1,2 @@
 cachestat01
+cachestat02
testcases/kernel/syscalls/cachestat/cachestat02.c new file +89 -0

89 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH v2 4/4 Add cachestat03 test

In reply to Andrea Cervesato

From: 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
index 887ac217b..de5a21749 100644
@@ -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
index 0f70fb801..6cfa3fa10 100644
@@ -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