Commit bc0bf4e97a

Stephen Gregoratto <dev@sgregoratto.me>
2023-09-28 10:27:37
Linux: Add cachestat wrapper.
Can be tested using this program I whipped up: https://gist.github.com/The-King-of-Toasters/aee448f5975c50f735fd1946794574f7
1 parent 5f456b2
Changed files (1)
lib
std
lib/std/os/linux.zig
@@ -1876,6 +1876,21 @@ pub fn ptrace(
     );
 }
 
+pub fn cachestat(
+    fd: fd_t,
+    cstat_range: *const cache_stat_range,
+    cstat: *cache_stat,
+    flags: u32,
+) usize {
+    return syscall4(
+        .cachestat,
+        @as(usize, @bitCast(@as(isize, fd))),
+        @intFromPtr(cstat_range),
+        @intFromPtr(cstat),
+        flags,
+    );
+}
+
 pub const E = switch (native_arch) {
     .mips, .mipsel => @import("linux/errno/mips.zig").E,
     .sparc, .sparcel, .sparc64 => @import("linux/errno/sparc.zig").E,
@@ -5829,3 +5844,16 @@ pub const PTRACE = struct {
     pub const SECCOMP_GET_METADATA = 0x420d;
     pub const GET_SYSCALL_INFO = 0x420e;
 };
+
+pub const cache_stat_range = extern struct {
+    off: u64,
+    len: u64,
+};
+
+pub const cache_stat = extern struct {
+    cache: u64,
+    dirty: u64,
+    writeback: u64,
+    evicted: u64,
+    recently_evicted: u64,
+};