]> git.ipfire.org Git - thirdparty/util-linux.git/commit
add option to force cachestat() usage
authorMatteo Croce <teknoraver@meta.com>
Fri, 23 May 2025 01:59:36 +0000 (03:59 +0200)
committerMatteo Croce <teknoraver@meta.com>
Thu, 29 May 2025 14:15:01 +0000 (16:15 +0200)
commit36965bbfb36328e80e3511a11b85b63e8a41d998
tree4b61a752ec0d6b9da305091b5b426142c6710ffa
parente4071d496fdbd8b2f1ae8d44a19888f8bbd60f5e
add option to force cachestat() usage

When cachestat() is not available, mmap() and fincore() are used to get
cache statistics.
This fallback returns less data than cachestat, and potentially hides
read errors by reporting that the file is all mapped in memory:

$ fincore /usr/bin/java
fincore: failed to do cachestat: /usr/bin/java: Operation not permitted
  RES PAGES   SIZE FILE
 208K    13 198,1K /usr/bin/java
$ echo $?
0
$ sudo fincore /usr/bin/java
RES PAGES   SIZE FILE
 0B     0 198,1K /usr/bin/java

Add a --cachestat argument which forces cachestat usage and fails if
it's not available:

$ fincore -C /usr/bin/java
fincore: failed to do cachestat: /usr/bin/java: Operation not permitted
$ echo $?
1

Also, on huge files the fallback is very slow and memory consuming,
so this flag can be user to avoid doing it by mistake.
bash-completion/fincore
misc-utils/fincore.1.adoc
misc-utils/fincore.c