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.