mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-13 01:08:41 -09:00
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:
parent
cc26ead5f8
commit
39517c01a8
1 changed files with 2 additions and 10 deletions
12
src/scan.zig
12
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue