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)
This commit is contained in:
Yorhel 2024-08-25 09:29:39 +02:00
parent cc26ead5f8
commit 39517c01a8

View file

@ -12,14 +12,7 @@ const c_statfs = @cImport(@cInclude("sys/vfs.h"));
// This function only works on Linux // This function only works on Linux
fn isKernfs(dir: std.fs.Dir, dev: u64) bool { fn isKernfs(dir: std.fs.Dir) 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;
var buf: c_statfs.struct_statfs = undefined; var buf: c_statfs.struct_statfs = undefined;
if (c_statfs.fstatfs(dir.fd, &buf) != 0) return false; // silently ignoring errors isn't too nice. 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)) { const iskern = switch (util.castTruncate(u32, buf.f_type)) {
@ -39,7 +32,6 @@ fn isKernfs(dir: std.fs.Dir, dev: u64) bool {
=> true, => true,
else => false, else => false,
}; };
state.cache.put(dev, iskern) catch {};
return iskern; return iskern;
} }
@ -247,7 +239,7 @@ const Thread = struct {
if (@import("builtin").os.tag == .linux if (@import("builtin").os.tag == .linux
and main.config.exclude_kernfs and main.config.exclude_kernfs
and stat.dev != dir.dev and stat.dev != dir.dev
and isKernfs(edir, stat.dev) and isKernfs(edir)
) { ) {
edir.close(); edir.close();
dir.sink.addSpecial(t.sink, name, .kernfs); dir.sink.addSpecial(t.sink, name, .kernfs);