From 39517c01a86de7ba0f8319c604e091fc524bb57a Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sun, 25 Aug 2024 09:29:39 +0200 Subject: [PATCH] Remove kernfs dev id cache Kernfs checking was previously done for every directory scanned, but the new parallel scanning code only performs the check when the dev id is different from parent, which isn't nearly as common. (In fact, in typical scenarios this only ever happens once per dev id, rendering the cache completely useless. But even people will 10k bind mounts are unlikely to notice a performance impact) --- src/scan.zig | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/scan.zig b/src/scan.zig index a76368f..a62555c 100644 --- a/src/scan.zig +++ b/src/scan.zig @@ -12,14 +12,7 @@ const c_statfs = @cImport(@cInclude("sys/vfs.h")); // This function only works on Linux -fn isKernfs(dir: std.fs.Dir, dev: u64) bool { - const state = struct { - var lock: std.Thread.Mutex = .{}; - var cache: std.AutoHashMap(u64,bool) = std.AutoHashMap(u64,bool).init(main.allocator); - }; - state.lock.lock(); - defer state.lock.unlock(); - if (state.cache.get(dev)) |e| return e; +fn isKernfs(dir: std.fs.Dir) bool { var buf: c_statfs.struct_statfs = undefined; if (c_statfs.fstatfs(dir.fd, &buf) != 0) return false; // silently ignoring errors isn't too nice. const iskern = switch (util.castTruncate(u32, buf.f_type)) { @@ -39,7 +32,6 @@ fn isKernfs(dir: std.fs.Dir, dev: u64) bool { => true, else => false, }; - state.cache.put(dev, iskern) catch {}; return iskern; } @@ -247,7 +239,7 @@ const Thread = struct { if (@import("builtin").os.tag == .linux and main.config.exclude_kernfs and stat.dev != dir.dev - and isKernfs(edir, stat.dev) + and isKernfs(edir) ) { edir.close(); dir.sink.addSpecial(t.sink, name, .kernfs);