== DESCRIPTION
*fincore* counts pages of file contents being resident in memory (in core), and reports the numbers. If an error occurs during counting, then an error message is printed to the stderr and *fincore* continues processing the rest of files listed in a command line.
+*fincore* uses the *cachestat*(2) syscall to count resident pages. If the *cachestat* syscall is not available and *cachestat* usage is not forced with the *--cachestat* option, then *fincore* uses the *mincore*(2) syscall as a fallback.
+The *cachestat* syscall is more efficient than *mincore* because it does not require a page table lock to walks page tables, and also reports more information than *mincore*, like the number of cached pages, dirty pages, pages marked for writeback, evicted pages, and recently evicted pages.
+Another difference between the two syscalls is that if write permissions are not granted to the file, then *cachestat* returns an error, while *mincore* for security reasons, returns fake data as if all pages were resident in memory (c.f.r. link:https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=134fca9063ad4851de767d1768180e5dede9a881[kernel commit "make mincore() more conservative"]).
The default output is subject to change. So whenever possible, you should avoid using default outputs in your scripts. Always explicitly define expected columns by using *--output* _columns-list_ in environments where a stable output is required.
*-c*, *--total*::
produce a grand total.
+*-C*, *--cachestat*::
+force usage of the cachestat() syscall instead of mincore(), and fail if it's not available.
+
*-o*, *--output* _list_::
Define output columns. See the *--help* output to get a list of the currently supported columns. The default list of columns may be extended if _list_ is specified in the format _{plus}list_.
//TRANSLATORS: Keep {plus} untranslated.
raw : 1,
json : 1,
recursive : 1,
- total : 1;
+ total : 1,
+ cachestat : 1;
};
return 0;
}
- if (errno != ENOSYS)
+ if (errno != ENOSYS || ctl->cachestat)
warn(_("failed to do cachestat: %s"), st->name);
+ if (ctl->cachestat)
+ return -errno;
+
return mincore_fd(ctl, fd, st);
}
fputs(_(" --output-all output all columns\n"), out);
fputs(_(" -r, --raw use raw output format\n"), out);
fputs(_(" -R, --recursive recursively check all files in directories\n"), out);
+ fputs(_(" -C, --cachestat force useage of cachestat syscall\n"), out);
fputs(USAGE_SEPARATOR, out);
fprintf(out, USAGE_HELP_OPTIONS(23));
{ "json", no_argument, NULL, 'J' },
{ "raw", no_argument, NULL, 'r' },
{ "recursive", no_argument, NULL, 'R' },
+ { "cachestat", no_argument, NULL, 'C' },
{ NULL, 0, NULL, 0 },
};
textdomain(PACKAGE);
close_stdout_atexit();
- while ((c = getopt_long (argc, argv, "bcno:JrRVh", longopts, NULL)) != -1) {
+ while ((c = getopt_long (argc, argv, "bcCno:JrRVh", longopts, NULL)) != -1) {
switch (c) {
case 'b':
ctl.bytes = 1;
case 'c':
ctl.total = 1;
break;
+ case 'C':
+#ifndef HAVE_CACHESTAT
+ errx(EXIT_FAILURE, _("cachestat option is not supported"));
+#endif
+ ctl.cachestat = 1;
+ break;
case 'n':
ctl.noheadings = 1;
break;