KMountPoint: cache mount lookups by unique mount id

Looking up a mount with currentMountPoints().findByMountId() or findByPath() re-parses /proc/self/mountinfo and stats every mount on each call. When many files on the same mount are looked up one after another this repeated parsing dominates.

Store only the unique mount id (STATX_MNT_ID_UNIQUE) in m_mountId, so a non-zero value always identifies the same mount for the life of the system. Add currentMountPointForUniqueId() backed by a small QCache keyed on that id: a hit avoids the parse and a miss re-reads the table once. A libmount monitor watches the kernel mount table and refreshes the cached entries when something changes, so "mount --move" or "mount -o remount" cannot leave a stale mountPoint() or mountOptions() behind. currentMountPointForPath() resolves a path to its unique id with a single statx and reuses the same cache.

The unique mount id needs Linux 6.8, and the lookups fall back to reading the whole table on an older kernel. The monitor needs the libmount 2.26 so set a minimum required version.

The preview job and the file worker go through the cached accessors now. A microbenchmark of repeated lookups on one mount shows about 700x for the by-id lookup and 170x for the by-path lookup.


This does not saves time, but reduce compute on the main thread, and it scales with mount point, reducing slight CPU usage. About ~100us of CPU time per file being previewed.

Here we could have used Solid but not in !2329 (merged) which uses currentMountPointForUniqueId from a separate thread.

Used in !2329 (merged) and can then be reused in KFileItem::isSlow to reduce syscalls further.

Edited by Méven Car

Merge request reports

Loading
Loading