From a119a9a333fdd3b86260137306a28017e9f78525 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Fri, 6 Oct 2023 22:59:11 -0300 Subject: [PATCH 1/3] x/sys/unix: add cachestat system call The cachestat system call is an alternative to mincore that offers more extensive page cache statistics, aiming to enhance scalability. It was added on Linux 6.5. Fixes golang/go#61917 --- unix/linux/types.go | 17 +++++++++++++++++ unix/syscall_linux.go | 2 ++ unix/zsyscall_linux.go | 10 ++++++++++ unix/ztypes_linux.go | 12 ++++++++++++ 4 files changed, 41 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index 389eed4bd..a0b4a9fb1 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -461,6 +461,20 @@ struct my_can_bittiming_const { struct riscv_hwprobe {}; #endif + +// copied from /usr/include/uapi/linux/mman.h +struct cachestat_range { + __u64 off; + __u64 len; +}; + +struct cachestat { + __u64 nr_cache; + __u64 nr_dirty; + __u64 nr_writeback; + __u64 nr_evicted; + __u64 nr_recently_evicted; +}; */ import "C" @@ -5813,3 +5827,6 @@ const ( type SchedAttr C.struct_sched_attr const SizeofSchedAttr = C.sizeof_struct_sched_attr + +type Cachestat C.struct_cachestat +type CachestatRange C.struct_cachestat_range diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index fb4e50224..f86a5b85d 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2482,3 +2482,5 @@ func SchedGetAttr(pid int, flags uint) (*SchedAttr, error) { } return attr, nil } + +//sys Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat, flags uint) (err error) diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 1ff3aec74..0c4466aa7 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -2195,3 +2195,13 @@ func schedGetattr(pid int, attr *SchedAttr, size uint, flags uint) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat, flags uint) (err error) { + _, _, e1 := Syscall6(SYS_CACHESTAT, uintptr(fd), uintptr(unsafe.Pointer(crange)), uintptr(unsafe.Pointer(cstat)), uintptr(flags), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 18aa70b42..332699547 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -5883,3 +5883,15 @@ type SchedAttr struct { } const SizeofSchedAttr = 0x38 + +type Cachestat struct { + Cache uint64 + Dirty uint64 + Writeback uint64 + Evicted uint64 + Recently_evicted uint64 +} +type CachestatRange struct { + Off uint64 + Len uint64 +} From 909e5b98eb3c9f5c7a532c007f27fba5bc24ca6c Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Fri, 6 Oct 2023 23:48:53 -0300 Subject: [PATCH 2/3] types s/Cachestat/CachestatArgpack/g --- unix/linux/types.go | 2 +- unix/syscall_linux.go | 2 +- unix/zsyscall_linux.go | 2 +- unix/ztypes_linux.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index a0b4a9fb1..401fc949c 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -5828,5 +5828,5 @@ type SchedAttr C.struct_sched_attr const SizeofSchedAttr = C.sizeof_struct_sched_attr -type Cachestat C.struct_cachestat +type CachestatArgpack C.struct_cachestat type CachestatRange C.struct_cachestat_range diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index f86a5b85d..d7918f475 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2483,4 +2483,4 @@ func SchedGetAttr(pid int, flags uint) (*SchedAttr, error) { return attr, nil } -//sys Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat, flags uint) (err error) +//sys Cachestat(fd uint, crange *CachestatRange, cstat *CachestatArgpack, flags uint) (err error) diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 0c4466aa7..61dacfc01 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -2198,7 +2198,7 @@ func schedGetattr(pid int, attr *SchedAttr, size uint, flags uint) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat, flags uint) (err error) { +func Cachestat(fd uint, crange *CachestatRange, cstat *CachestatArgpack, flags uint) (err error) { _, _, e1 := Syscall6(SYS_CACHESTAT, uintptr(fd), uintptr(unsafe.Pointer(crange)), uintptr(unsafe.Pointer(cstat)), uintptr(flags), 0, 0) if e1 != 0 { err = errnoErr(e1) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 332699547..5734a2501 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -5884,7 +5884,7 @@ type SchedAttr struct { const SizeofSchedAttr = 0x38 -type Cachestat struct { +type CachestatArgpack struct { Cache uint64 Dirty uint64 Writeback uint64 From d18fbb9c48348e5f1f663395647a9ca89a578f60 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Sun, 8 Oct 2023 16:28:14 -0300 Subject: [PATCH 3/3] s/CachestatArgpack/Cachestat_t/g --- unix/linux/types.go | 2 +- unix/syscall_linux.go | 2 +- unix/zsyscall_linux.go | 2 +- unix/ztypes_linux.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index 401fc949c..f5a6ae9e7 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -5828,5 +5828,5 @@ type SchedAttr C.struct_sched_attr const SizeofSchedAttr = C.sizeof_struct_sched_attr -type CachestatArgpack C.struct_cachestat +type Cachestat_t C.struct_cachestat type CachestatRange C.struct_cachestat_range diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index d7918f475..6b8a4ad69 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2483,4 +2483,4 @@ func SchedGetAttr(pid int, flags uint) (*SchedAttr, error) { return attr, nil } -//sys Cachestat(fd uint, crange *CachestatRange, cstat *CachestatArgpack, flags uint) (err error) +//sys Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat_t, flags uint) (err error) diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 61dacfc01..863d7dde2 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -2198,7 +2198,7 @@ func schedGetattr(pid int, attr *SchedAttr, size uint, flags uint) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Cachestat(fd uint, crange *CachestatRange, cstat *CachestatArgpack, flags uint) (err error) { +func Cachestat(fd uint, crange *CachestatRange, cstat *Cachestat_t, flags uint) (err error) { _, _, e1 := Syscall6(SYS_CACHESTAT, uintptr(fd), uintptr(unsafe.Pointer(crange)), uintptr(unsafe.Pointer(cstat)), uintptr(flags), 0, 0) if e1 != 0 { err = errnoErr(e1) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 5734a2501..cdba4c77d 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -5884,7 +5884,7 @@ type SchedAttr struct { const SizeofSchedAttr = 0x38 -type CachestatArgpack struct { +type Cachestat_t struct { Cache uint64 Dirty uint64 Writeback uint64