* [LTP] [PATCH v1 0/3] cachestat testing suite
@ 2024-05-16 10:42 Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 1/3] Add cachestat fallback definitions Andrea Cervesato
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Andrea Cervesato @ 2024-05-16 10:42 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
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/
Andrea Cervesato (3):
Add cachestat fallback definitions
Add cachestat01 and cachestat01A tests
Add cachestat02 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 +
.../kernel/syscalls/cachestat/.gitignore | 2 +
testcases/kernel/syscalls/cachestat/Makefile | 10 ++
.../kernel/syscalls/cachestat/cachestat.h | 27 +++++
.../kernel/syscalls/cachestat/cachestat01.c | 102 ++++++++++++++++++
.../kernel/syscalls/cachestat/cachestat02.c | 82 ++++++++++++++
26 files changed, 293 insertions(+)
create mode 100644 include/lapi/mman.h
create mode 100644 testcases/kernel/syscalls/cachestat/.gitignore
create mode 100644 testcases/kernel/syscalls/cachestat/Makefile
create mode 100644 testcases/kernel/syscalls/cachestat/cachestat.h
create mode 100644 testcases/kernel/syscalls/cachestat/cachestat01.c
create mode 100644 testcases/kernel/syscalls/cachestat/cachestat02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* [LTP] [PATCH v1 1/3] Add cachestat fallback definitions
2024-05-16 10:42 [LTP] [PATCH v1 0/3] cachestat testing suite Andrea Cervesato
@ 2024-05-16 10:42 ` Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests Andrea Cervesato
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Andrea Cervesato @ 2024-05-16 10:42 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
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(+)
create mode 100644 include/lapi/mman.h
diff --git a/configure.ac b/configure.ac
index 85c5739c4..8d59cb605 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,6 +90,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 \
@@ -233,6 +234,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
diff --git a/include/lapi/mman.h b/include/lapi/mman.h
new file mode 100644
index 000000000..244ad9f31
--- /dev/null
+++ b/include/lapi/mman.h
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef LAPI_MMAN_H__
+#define LAPI_MMAN_H__
+
+#include <stdint.h>
+#include <sys/mman.h>
+#include "config.h"
+#include "syscalls.h"
+
+#ifndef HAVE_STRUCT_CACHESTAT_RANGE
+struct cachestat_range {
+ uint64_t off;
+ uint64_t len;
+};
+#endif
+
+#ifndef HAVE_STRUCT_CACHESTAT
+struct cachestat {
+ uint64_t nr_cache;
+ uint64_t nr_dirty;
+ uint64_t nr_writeback;
+ uint64_t nr_evicted;
+ uint64_t nr_recently_evicted;
+};
+#endif
+
+#ifndef HAVE_CACHESTAT
+/*
+ * cachestat: wrapper function of cachestat
+ *
+ * Returns: It returns status of cachestat syscall
+ */
+static inline int cachestat(int fd, struct cachestat_range *cstat_range,
+ struct cachestat *cstat, unsigned int flags)
+{
+ return tst_syscall(__NR_cachestat, fd, cstat_range, cstat, flags);
+}
+#endif
+
+#endif /* LAPI_MMAN_H__ */
diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 2cb6c2d87..1c0218eae 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -297,4 +297,5 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
_sysctl 1078
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 3e2ee9061..5d7cd6ca4 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -317,3 +317,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 7bdbca533..e41a7e576 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -395,3 +395,4 @@ faccessat2 (__NR_SYSCALL_BASE+439)
epoll_pwait2 (__NR_SYSCALL_BASE+441)
quotactl_fd (__NR_SYSCALL_BASE+443)
futex_waitv (__NR_SYSCALL_BASE+449)
+cachestat (__NR_SYSCALL_BASE+451)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index 8ebdafafb..2772e7334 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -44,3 +44,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index 1472631c4..2d341182e 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -431,3 +431,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 0ea6e9722..141c6be51 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -344,3 +344,4 @@ faccessat2 1463
epoll_pwait2 1465
quotactl_fd 1467
futex_waitv 1473
+cachestat 1475
diff --git a/include/lapi/syscalls/loongarch.in b/include/lapi/syscalls/loongarch.in
index 301f611f6..9bf6a7deb 100644
--- a/include/lapi/syscalls/loongarch.in
+++ b/include/lapi/syscalls/loongarch.in
@@ -305,3 +305,4 @@ memfd_secret 447
process_mrelease 448
futex_waitv 449
set_mempolicy_home_node 450
+cachestat 451
diff --git a/include/lapi/syscalls/mips_n32.in b/include/lapi/syscalls/mips_n32.in
index e818c9d92..3b08add08 100644
--- a/include/lapi/syscalls/mips_n32.in
+++ b/include/lapi/syscalls/mips_n32.in
@@ -371,3 +371,4 @@ epoll_pwait2 6441
mount_setattr 6442
quotactl_fd 6443
futex_waitv 6449
+cachestat 6451
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips_n64.in
index 6e15f43b3..bfc65cd2b 100644
--- a/include/lapi/syscalls/mips_n64.in
+++ b/include/lapi/syscalls/mips_n64.in
@@ -347,3 +347,4 @@ epoll_pwait2 5441
mount_setattr 5442
quotactl_fd 5443
futex_waitv 5449
+cachestat 5451
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mips_o32.in
index 921d5d331..8dc542b48 100644
--- a/include/lapi/syscalls/mips_o32.in
+++ b/include/lapi/syscalls/mips_o32.in
@@ -417,3 +417,4 @@ epoll_pwait2 4441
mount_setattr 4442
quotactl_fd 4443
futex_waitv 4449
+cachestat 4451
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index 545d9d3d6..67e928951 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -424,3 +424,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index 545d9d3d6..67e928951 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -424,3 +424,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 7213ac5f8..b456ea408 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -411,3 +411,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index 879012e2b..2c57eacdf 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -359,3 +359,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 7d5192a27..25eb9bb26 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -405,3 +405,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 91d2fb1c2..e934591dd 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -410,3 +410,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 1f2fc59b7..4c489e38d 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -375,3 +375,4 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index dc61aa56e..4afea6019 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -352,6 +352,7 @@ faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
+cachestat 451
rt_sigaction 512
rt_sigreturn 513
ioctl 514
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests
2024-05-16 10:42 [LTP] [PATCH v1 0/3] cachestat testing suite Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 1/3] Add cachestat fallback definitions Andrea Cervesato
@ 2024-05-16 10:42 ` Andrea Cervesato
2024-07-08 14:29 ` Cyril Hrubis
2024-05-16 10:42 ` [LTP] [PATCH v1 3/3] Add cachestat02 test Andrea Cervesato
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
3 siblings, 1 reply; 14+ messages in thread
From: Andrea Cervesato @ 2024-05-16 10:42 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
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.
The cachestat01 covers the first scenario and cachestat01A covers the
second one.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 3 +
.../kernel/syscalls/cachestat/.gitignore | 1 +
testcases/kernel/syscalls/cachestat/Makefile | 10 ++
.../kernel/syscalls/cachestat/cachestat.h | 27 +++++
.../kernel/syscalls/cachestat/cachestat01.c | 102 ++++++++++++++++++
5 files changed, 143 insertions(+)
create mode 100644 testcases/kernel/syscalls/cachestat/.gitignore
create mode 100644 testcases/kernel/syscalls/cachestat/Makefile
create mode 100644 testcases/kernel/syscalls/cachestat/cachestat.h
create mode 100644 testcases/kernel/syscalls/cachestat/cachestat01.c
diff --git a/runtest/syscalls b/runtest/syscalls
index cf06ee563..961775cf7 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -62,6 +62,9 @@ capset04 capset04
cacheflush01 cacheflush01
+cachestat01 cachestat01
+cachestat01A cachestat01 -s
+
chdir01 chdir01
chdir01A symlink01 -T chdir01
chdir04 chdir04
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
new file mode 100644
index 000000000..daea1f4be
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -0,0 +1 @@
+cachestat01
diff --git a/testcases/kernel/syscalls/cachestat/Makefile b/testcases/kernel/syscalls/cachestat/Makefile
new file mode 100644
index 000000000..62b00d2f4
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+LDLIBS += -lrt
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/cachestat/cachestat.h b/testcases/kernel/syscalls/cachestat/cachestat.h
new file mode 100644
index 000000000..efce6dc7f
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#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
diff --git a/testcases/kernel/syscalls/cachestat/cachestat01.c b/testcases/kernel/syscalls/cachestat/cachestat01.c
new file mode 100644
index 000000000..7362a9dcf
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat01.c
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * 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.
+ *
+ * [Algorithm]
+ *
+ * * create a file with specific amount of pages
+ * ** synchronize storage device, if needed
+ * * monitor file with cachestat()
+ * * check if the right amount of pages have been moved into cache
+ * ** if storage device synchronization is requested, check that dirty pages is
+ * zero
+ */
+
+#include "cachestat.h"
+
+#define MNTPOINT "mntpoint"
+#define FILENAME MNTPOINT "/myfile.bin"
+#define NUMPAGES 32
+
+static char *data;
+static int file_size;
+static struct cachestat *cs;
+static struct cachestat_range *cs_range;
+static char *run_fsync;
+
+static void run(void)
+{
+ int fd;
+
+ memset(cs, 0, sizeof(struct cachestat));
+
+ fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, 0600);
+ SAFE_WRITE(0, fd, data, file_size);
+
+ if (run_fsync)
+ fsync(fd);
+
+ TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
+ print_cachestat(cs);
+
+ TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, NUMPAGES);
+
+ if (run_fsync)
+ TST_EXP_EQ_LI(cs->nr_dirty, 0);
+
+ SAFE_CLOSE(fd);
+ SAFE_UNLINK(FILENAME);
+}
+
+static void setup(void)
+{
+ int page_size;
+
+ page_size = (int)sysconf(_SC_PAGESIZE);
+ file_size = page_size * NUMPAGES;
+
+ data = SAFE_MALLOC(file_size);
+ memset(data, 'a', file_size);
+
+ cs_range->off = 0;
+ cs_range->len = file_size;
+}
+
+static void cleanup(void)
+{
+ if (data)
+ free(data);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .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)},
+ {}
+ },
+ .options = (struct tst_option[]) {
+ {"s", &run_fsync, "Synchronize file with storage device"},
+ {},
+ },
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [LTP] [PATCH v1 3/3] Add cachestat02 test
2024-05-16 10:42 [LTP] [PATCH v1 0/3] cachestat testing suite Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 1/3] Add cachestat fallback definitions Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests Andrea Cervesato
@ 2024-05-16 10:42 ` Andrea Cervesato
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
3 siblings, 0 replies; 14+ messages in thread
From: Andrea Cervesato @ 2024-05-16 10:42 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that cachestat() syscall is properly counting cached
pages written inside a shared memory.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/cachestat/.gitignore | 1 +
.../kernel/syscalls/cachestat/cachestat02.c | 82 +++++++++++++++++++
3 files changed, 84 insertions(+)
create mode 100644 testcases/kernel/syscalls/cachestat/cachestat02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 961775cf7..1b0a3bb23 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -64,6 +64,7 @@ cacheflush01 cacheflush01
cachestat01 cachestat01
cachestat01A cachestat01 -s
+cachestat02 cachestat02
chdir01 chdir01
chdir01A symlink01 -T chdir01
diff --git a/testcases/kernel/syscalls/cachestat/.gitignore b/testcases/kernel/syscalls/cachestat/.gitignore
index daea1f4be..0f70fb801 100644
--- a/testcases/kernel/syscalls/cachestat/.gitignore
+++ b/testcases/kernel/syscalls/cachestat/.gitignore
@@ -1 +1,2 @@
cachestat01
+cachestat02
diff --git a/testcases/kernel/syscalls/cachestat/cachestat02.c b/testcases/kernel/syscalls/cachestat/cachestat02.c
new file mode 100644
index 000000000..0221cead4
--- /dev/null
+++ b/testcases/kernel/syscalls/cachestat/cachestat02.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that cachestat() syscall is properly counting cached pages
+ * written inside a shared memory.
+ *
+ * [Algorithm]
+ *
+ * * create a shared memory with a specific amount of pages
+ * * monitor file with cachestat()
+ * * check if the right amount of pages have been moved into cache
+ */
+
+#include "cachestat.h"
+
+#define FILENAME "myfile.bin"
+#define NUMPAGES 32
+
+static char *data;
+static int file_size;
+static struct cachestat *cs;
+static struct cachestat_range *cs_range;
+
+static void run(void)
+{
+ int fd;
+
+ memset(cs, 0, sizeof(struct cachestat));
+
+ fd = shm_open(FILENAME, O_RDWR | O_CREAT, 0600);
+ if (fd < 0)
+ tst_brk(TBROK | TERRNO, "shm_open error");
+
+ SAFE_FTRUNCATE(fd, file_size);
+ SAFE_WRITE(0, fd, data, file_size);
+
+ TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
+ print_cachestat(cs);
+
+ TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, NUMPAGES);
+
+ SAFE_CLOSE(fd);
+ shm_unlink(FILENAME);
+}
+
+static void setup(void)
+{
+ int page_size;
+
+ page_size = (int)sysconf(_SC_PAGESIZE);
+ file_size = page_size * NUMPAGES;
+
+ data = SAFE_MALLOC(file_size);
+ memset(data, 'a', file_size);
+
+ cs_range->off = 0;
+ cs_range->len = file_size;
+}
+
+static void cleanup(void)
+{
+ if (data)
+ free(data);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+ .min_kver = "6.5",
+ .bufs = (struct tst_buffers []) {
+ {&cs, .size = sizeof(struct cachestat)},
+ {&cs_range, .size = sizeof(struct cachestat_range)},
+ {}
+ },
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests
2024-05-16 10:42 ` [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests Andrea Cervesato
@ 2024-07-08 14:29 ` Cyril Hrubis
0 siblings, 0 replies; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-08 14:29 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> diff --git a/testcases/kernel/syscalls/cachestat/cachestat01.c b/testcases/kernel/syscalls/cachestat/cachestat01.c
> new file mode 100644
> index 000000000..7362a9dcf
> --- /dev/null
> +++ b/testcases/kernel/syscalls/cachestat/cachestat01.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * 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.
> + *
> + * [Algorithm]
> + *
> + * * create a file with specific amount of pages
> + * ** synchronize storage device, if needed
> + * * monitor file with cachestat()
> + * * check if the right amount of pages have been moved into cache
> + * ** if storage device synchronization is requested, check that dirty pages is
> + * zero
> + */
> +
> +#include "cachestat.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define FILENAME MNTPOINT "/myfile.bin"
> +#define NUMPAGES 32
> +
> +static char *data;
> +static int file_size;
> +static struct cachestat *cs;
> +static struct cachestat_range *cs_range;
> +static char *run_fsync;
> +
> +static void run(void)
> +{
> + int fd;
> +
> + memset(cs, 0, sizeof(struct cachestat));
> +
> + fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, 0600);
> + SAFE_WRITE(0, fd, data, file_size);
> +
> + if (run_fsync)
> + fsync(fd);
> +
> + TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
> + print_cachestat(cs);
> +
> + TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, NUMPAGES);
> +
> + if (run_fsync)
> + TST_EXP_EQ_LI(cs->nr_dirty, 0);
> +
> + SAFE_CLOSE(fd);
> + SAFE_UNLINK(FILENAME);
> +}
> +
> +static void setup(void)
> +{
> + int page_size;
> +
> + page_size = (int)sysconf(_SC_PAGESIZE);
> + file_size = page_size * NUMPAGES;
> +
> + data = SAFE_MALLOC(file_size);
> + memset(data, 'a', file_size);
I would just allocate a single page and run the write in a loop in the
test. That way we can make the number of pages command line parameter
and try with a bigger mapping as well.
> + cs_range->off = 0;
> + cs_range->len = file_size;
> +}
> +
> +static void cleanup(void)
> +{
> + if (data)
> + free(data);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .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)},
> + {}
> + },
> + .options = (struct tst_option[]) {
> + {"s", &run_fsync, "Synchronize file with storage device"},
> + {},
> + },
Can we, rather than adding a command line option, change the test so
that it has two subtests with .tcnt = 2?
I think that it's better that the test runs all testcases by default and
the command like parameters should be used to change parameters of the
test (such as number of pages) rather than to enable/disable tests.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-05-16 10:42 [LTP] [PATCH v1 0/3] cachestat testing suite Andrea Cervesato
` (2 preceding siblings ...)
2024-05-16 10:42 ` [LTP] [PATCH v1 3/3] Add cachestat02 test Andrea Cervesato
@ 2024-07-08 14:38 ` Cyril Hrubis
2024-07-08 14:41 ` Cyril Hrubis
` (2 more replies)
3 siblings, 3 replies; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-08 14:38 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
This series is missing all kind of "interesting" tests namely:
- tst_fd iterator test that passes all kinds of unexpected fds to the
cachestat syscall
- invalid parameters tests, invalid fd, invalid pointers
- what does happen if we supply len = 0
- what does happen if we pass off or len out of the file?
All these corner cases are probably more interesting that the basic
functional test.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
@ 2024-07-08 14:41 ` Cyril Hrubis
2024-07-15 10:58 ` Andrea Cervesato via ltp
2024-07-15 11:03 ` Andrea Cervesato via ltp
2 siblings, 0 replies; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-08 14:41 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> This series is missing all kind of "interesting" tests namely:
>
> - tst_fd iterator test that passes all kinds of unexpected fds to the
> cachestat syscall
>
> - invalid parameters tests, invalid fd, invalid pointers
> - what does happen if we supply len = 0
> - what does happen if we pass off or len out of the file?
+ non-zero flags, I suppose that at this point non-zero flags should
yield EINVAL
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
2024-07-08 14:41 ` Cyril Hrubis
@ 2024-07-15 10:58 ` Andrea Cervesato via ltp
2024-07-15 11:03 ` Andrea Cervesato via ltp
2 siblings, 0 replies; 14+ messages in thread
From: Andrea Cervesato via ltp @ 2024-07-15 10:58 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
Hi!
On 7/8/24 16:38, Cyril Hrubis wrote:
> Hi!
> This series is missing all kind of "interesting" tests namely:
>
> - tst_fd iterator test that passes all kinds of unexpected fds to the
> cachestat syscall
I had a try, but it seems like the only 2 unsupported file types are
TST_FD_OPEN_TREE and TST_FD_PATH.
I don't know if it makes much sense to add this test.
> - invalid parameters tests, invalid fd, invalid pointers
> - what does happen if we supply len = 0
> - what does happen if we pass off or len out of the file?
>
> All these corner cases are probably more interesting that the basic
> functional test.
>
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
2024-07-08 14:41 ` Cyril Hrubis
2024-07-15 10:58 ` Andrea Cervesato via ltp
@ 2024-07-15 11:03 ` Andrea Cervesato via ltp
2024-07-15 12:08 ` Cyril Hrubis
2 siblings, 1 reply; 14+ messages in thread
From: Andrea Cervesato via ltp @ 2024-07-15 11:03 UTC (permalink / raw)
To: Cyril Hrubis, Andrea Cervesato; +Cc: ltp
On 7/8/24 16:38, Cyril Hrubis wrote:
> Hi!
> This series is missing all kind of "interesting" tests namely:
>
> - tst_fd iterator test that passes all kinds of unexpected fds to the
> cachestat syscall
>
> - invalid parameters tests, invalid fd, invalid pointers
> - what does happen if we supply len = 0
> - what does happen if we pass off or len out of the file?
And another thing....the kselftests only check for EBADF and now I
understand why: basically cachestat() seems to always pass but when file
descriptor is invalid....
>
> All these corner cases are probably more interesting that the basic
> functional test.
>
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-15 11:03 ` Andrea Cervesato via ltp
@ 2024-07-15 12:08 ` Cyril Hrubis
2024-07-15 12:14 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-15 12:08 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> And another thing....the kselftests only check for EBADF and now I
> understand why: basically cachestat() seems to always pass but when file
> descriptor is invalid....
That smells like a kernel bug.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-15 12:08 ` Cyril Hrubis
@ 2024-07-15 12:14 ` Andrea Cervesato via ltp
2024-07-15 12:30 ` Cyril Hrubis
0 siblings, 1 reply; 14+ messages in thread
From: Andrea Cervesato via ltp @ 2024-07-15 12:14 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On 7/15/24 14:08, Cyril Hrubis wrote:
> Hi!
>> And another thing....the kselftests only check for EBADF and now I
>> understand why: basically cachestat() seems to always pass but when file
>> descriptor is invalid....
> That smells like a kernel bug.
>
I had to go through the cachestat code and maybe i found the solution. I
will send the tests soon.
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-15 12:14 ` Andrea Cervesato via ltp
@ 2024-07-15 12:30 ` Cyril Hrubis
2024-07-15 16:00 ` Cyril Hrubis
0 siblings, 1 reply; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-15 12:30 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> I had to go through the cachestat code and maybe i found the solution. I
> will send the tests soon.
I had a look as well and it looks that cachestat should work fine for
all file descriptors that can be mmaped(). So as long as you get success
for a file descriptor that returns EBADF for mmap() it shouldn't
probably work with cachestat() either.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-15 12:30 ` Cyril Hrubis
@ 2024-07-15 16:00 ` Cyril Hrubis
2024-07-16 8:16 ` Cyril Hrubis
0 siblings, 1 reply; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-15 16:00 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> > I had to go through the cachestat code and maybe i found the solution. I
> > will send the tests soon.
>
> I had a look as well and it looks that cachestat should work fine for
> all file descriptors that can be mmaped(). So as long as you get success
> for a file descriptor that returns EBADF for mmap() it shouldn't
> probably work with cachestat() either.
And after more staring at the kernel sources I've found that:
- anonymous inodes have the page cache mappings initialized to zeros and
empty list
- this is not used for anything for most types of file descriptors (e.g.
sockets)
So if you call cacestat() on a socket fd it will try to loop over empty
list of vmas and the end result would be statistics that are full of
zeroes. Maybe that is worth of a special test just for this case.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [LTP] [PATCH v1 0/3] cachestat testing suite
2024-07-15 16:00 ` Cyril Hrubis
@ 2024-07-16 8:16 ` Cyril Hrubis
0 siblings, 0 replies; 14+ messages in thread
From: Cyril Hrubis @ 2024-07-16 8:16 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> So if you call cacestat() on a socket fd it will try to loop over empty
> list of vmas and the end result would be statistics that are full of
> zeroes. Maybe that is worth of a special test just for this case.
Thinking of it over night it may make sense to write the tst_fd test and
either expect EBADF or the statistics to be zeroed for file descriptors
that do not use page cache (i.e. are not file based).
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-07-16 8:14 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 10:42 [LTP] [PATCH v1 0/3] cachestat testing suite Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 1/3] Add cachestat fallback definitions Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests Andrea Cervesato
2024-07-08 14:29 ` Cyril Hrubis
2024-05-16 10:42 ` [LTP] [PATCH v1 3/3] Add cachestat02 test Andrea Cervesato
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
2024-07-08 14:41 ` Cyril Hrubis
2024-07-15 10:58 ` Andrea Cervesato via ltp
2024-07-15 11:03 ` Andrea Cervesato via ltp
2024-07-15 12:08 ` Cyril Hrubis
2024-07-15 12:14 ` Andrea Cervesato via ltp
2024-07-15 12:30 ` Cyril Hrubis
2024-07-15 16:00 ` Cyril Hrubis
2024-07-16 8:16 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox