fincore command
cover fincore command
This patch set proposes adding fincore command to util-linux distribution. The command counts pages of file contents being resident in memory(in core), and reports the numbers.
It helps system administrators understand how their systems use physical memory, especially about page caches when they have to do trouble shooting and/or performance tuning.
This is just my case. A person in other role may also get benefits from this command.
Masatake YAMATO (4):
fincore: new command for counting pages of file contents in core
man: add a page for fincore command
tests: add cases for testing fincore command
bash-completion: add a function for fincore command
bash-completion/Makemodule.am | 3 + bash-completion/fincore | 25 +++++ configure.ac | 4 + misc-utils/Makemodule.am | 6 ++ misc-utils/fincore.1 | 76 ++++++++++++++ misc-utils/fincore.c | 209 +++++++++++++++++++++++++++++++++++++ misc-utils/fincore_orig.c | 235 ++++++++++++++++++++++++++++++++++++++++++ tests/commands.sh | 1 + tests/expected/fincore/count | 62 +++++++++++ tests/ts/fincore/count | 194 ++++++++++++++++++++++++++++++++++ 10 files changed, 815 insertions(+) create mode 100644 bash-completion/fincore create mode 100644 misc-utils/fincore.1 create mode 100644 misc-utils/fincore.c create mode 100644 misc-utils/fincore_orig.c create mode 100644 tests/expected/fincore/count create mode 100755 tests/ts/fincore/count
Signature · 1 line
2.9.3
PATCH 1/4 fincore: new command for counting pages of file contents in core
--- configure.ac | 4 + misc-utils/Makemodule.am | 5 + misc-utils/fincore.c | 209 +++++++++++++++++++++++++++++++++++++++++ misc-utils/fincore_orig.c | 235 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 453 insertions(+) create mode 100644 misc-utils/fincore.c create mode 100644 misc-utils/fincore_orig.c
configure.ac +4 -0
@@ -1589,6 +1589,10 @@ dnl earlier than 2.x. UL_REQUIRES_HAVE([ctrlaltdel], [reboot], [reboot function]) AM_CONDITIONAL([BUILD_CTRLALTDEL], [test "x$build_ctrlaltdel" = xyes]) +UL_BUILD_INIT([fincore], [check]) +UL_REQUIRES_LINUX([fincore]) +AM_CONDITIONAL([BUILD_FINCORE], [test "x$build_fincore" = xyes]) + UL_BUILD_INIT([fsfreeze], [check]) UL_REQUIRES_LINUX([fsfreeze]) AM_CONDITIONAL([BUILD_FSFREEZE], [test "x$build_fsfreeze" = xyes])
misc-utils/Makemodule.am +5 -0
@@ -180,3 +180,8 @@ dist_getoptexample_SCRIPTS = \ misc-utils/getopt-parse.bash \ misc-utils/getopt-parse.tcsh endif + +if BUILD_FINCORE +usrbin_exec_PROGRAMS += fincore +fincore_SOURCES = misc-utils/fincore.c +endif
misc-utils/fincore.c new file +209 -0
209 lines not on this page · raw message
misc-utils/fincore_orig.c new file +235 -0
235 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 2/4 man: add a page for fincore command
In reply to Masatake YAMATO--- misc-utils/Makemodule.am | 1 + misc-utils/fincore.1 | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 misc-utils/fincore.1
misc-utils/Makemodule.am +1 -0
@@ -183,5 +183,6 @@ endif if BUILD_FINCORE usrbin_exec_PROGRAMS += fincore +dist_man_MANS += misc-utils/fincore.1 fincore_SOURCES = misc-utils/fincore.c endif
misc-utils/fincore.1 new file +76 -0
76 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 3/4 tests: add cases for testing fincore command
In reply to Masatake YAMATO--- tests/commands.sh | 1 + tests/expected/fincore/count | 62 ++++++++++++++ tests/ts/fincore/count | 194 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 tests/expected/fincore/count create mode 100755 tests/ts/fincore/count
tests/commands.sh +1 -0
@@ -50,6 +50,7 @@ TS_CMD_FALLOCATE=${TS_CMD_FALLOCATE-"$top_builddir/fallocate"} TS_CMD_FDISK=${TS_CMD_FDISK-"$top_builddir/fdisk"} TS_CMD_FLOCK=${TS_CMD_FLOCK-"$top_builddir/flock"} TS_CMD_SFDISK=${TS_CMD_SFDISK-"$top_builddir/sfdisk"} +TS_CMD_FINCORE=${TS_CMD_FINCORE-"$top_builddir/fincore"} TS_CMD_FINDMNT=${TS_CMD_FINDMNT-"$top_builddir/findmnt"} TS_CMD_FSCKCRAMFS=${TS_CMD_FSCKCRAMFS:-"$top_builddir/fsck.cramfs"} TS_CMD_FSCKMINIX=${TS_CMD_FSCKMINIX:-"$top_builddir/fsck.minix"}
tests/expected/fincore/count new file +62 -0
62 lines not on this page · raw message
tests/ts/fincore/count new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 4/4 bash-completion: add a function for fincore command
In reply to Masatake YAMATO--- bash-completion/Makemodule.am | 3 +++ bash-completion/fincore | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 bash-completion/fincore
bash-completion/Makemodule.am +3 -0
@@ -18,6 +18,9 @@ endif if BUILD_COLUMN dist_bashcompletion_DATA += bash-completion/column endif +if BUILD_FINCORE +dist_bashcompletion_DATA += bash-completion/fincore +endif if BUILD_FINDMNT dist_bashcompletion_DATA += bash-completion/findmnt endif
bash-completion/fincore new file +25 -0
@@ -0,0 +1,25 @@ +_fincore_module() +{ + local cur prev OPTS + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + case $prev in + '-h'|'--help'|'-V'|'--version') + return 0 + ;; + esac + case $cur in + -*) + OPTS="--help + --version" + COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) + return 0 + ;; + esac + local IFS=$'\n' + compopt -o filenames + COMPREPLY=( $(compgen -f -- ${cur:-"/"}) ) + return 0 +} +complete -F _fincore_module fincore
Signature · 1 line
2.9.3
Karel Zak
maintainerQuoted 10 lines · Masatake YAMATO
This patch set proposes adding fincore command to util-linux distribution. The command counts pages of file contents being resident in memory(in core), and reports the numbers.
It helps system administrators understand how their systems use physical memory, especially about page caches when they have to do trouble shooting and/or performance tuning.
This is just my case. A person in other role may also get benefits from this command.
Not sure if I like the format ;-)
$ fincore /etc/fstab /bin/emacs 1 1544 /etc/fstab 4156 17163144 /bin/emacs
Why we need file size there? Would be better to use filename as the first column?
$ fincore /etc/fstab /bin/emacs /etc/fstab 1 /bin/emacs 4156
it would be also nice have a way how to print only the number if only one file specified. Then you can use it in scripts without awk (or so), just:
FILEPAGES=$(fincore /bin/emacs)
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Hi, thank you for comments.
Quoted 8 lines · Karel Zak
Not sure if I like the format ;-)
$ fincore /etc/fstab /bin/emacs 1 1544 /etc/fstab 4156 17163144 /bin/emacsWhy we need file size there? Would be better to use filename as the first column?
* Why we need file size there?
I don't insist including the file size column.
The original reason was that I assumed that a user may want to know how much part of the file printed by fincore is in core. The file-size column is for the hint.
How about adding an option to control show the column (--file-size|-s)? Or should I delete the column fron the output completely?
* Would be better to use filename as the first column?
I follow the format that du and ls commands use:
$ du /etc/passwd
4 /etc/passwd $ ls -i /tmp | head
67003 emacs1000
47611 systemd-private-dd34e7d700c6441db79e4caa7b3c3205-colord.service-N7dhub
24891 systemd-private-dd34e7d700c6441db79e4caa7b3c3205-rtkit-daemon.service-WbOmt1du and ls are popular enough. So potential users of fincore command may be familiar with the formats.
There are two benefits this(du style) format.
+ awk/read/cut commands friendly
White spaces can be included in a file name.
As the result, a user cannot assume the column
for the page counts easily if filename is at the
first column.
e.g.
(the format in my patch)
$ touch 'a b'
$ ./util-linux/fincore 'a b'
0 0 a b
$ ./util-linux/fincore 'a b' | awk '{print $1}'
0
$ ./util-linux/fincore 'a b' | { read A REST; echo $A; }
0
$ ./util-linux/fincore 'a b' | cut -d ' ' -f1
0+ beauty of output
If filename is at the first column, I wonder
how can I print lines in column aligned way:
0 -1 /foo/bar/baz/very---long---file---name
0 0 shortname
By finding the longest file name from arguments passed to fincore command, the column length can be calumniated, and fincore may be able to print following lines:
/foo/bar/baz/very---long---file---name 0 -1
shortname 0 0However, I wonder what I should do if multibyte characters are used in the file name.
Of course, the column alignment is less important than providing the way to know much file contents are incore to users.
Quoted 6 lines
it would be also nice have a way how to print only the number if only one file specified. Then you can use it in scripts without awk (or so), just:
FILEPAGES=$(fincore /bin/emacs)
In the station(interactive use) that a user of fincore knows the number of file names passed to the command, printing only the number is bettern. However, there can be a situation(scripting) that a user cannot know the number of file names.
{
FILES=...
FILES="$FILES $tmp"
...
fincore $FILES
} | do_something
In such case the columns are fixed(the page numbers and file name) will be better for people writing `do_something'. For the such use case, I would like to add an option --print-filename-always. The default behavior (behavior without the option) should be implemented as what you wrote (just printing the number). Is it o.k.?
After getting feedback from you, I will submit v2 patches.
Masatake YAMATO
Karel Zak
maintainerQuoted 1 line · Masatake YAMATO
After getting feedback from you, I will submit v2 patches.
That's fine, the current version is good enough. Thanks.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerQuoted 9 lines · Masatake YAMATO
bash-completion/Makemodule.am | 3 + bash-completion/fincore | 25 +++++ configure.ac | 4 + misc-utils/Makemodule.am | 6 ++ misc-utils/fincore.1 | 76 ++++++++++++++ misc-utils/fincore.c | 209 +++++++++++++++++++++++++++++++++++++ misc-utils/fincore_orig.c | 235 ++++++++++++++++++++++++++++++++++++++++++ tests/commands.sh | 1 + tests/expected/fincore/count | 62 +++++++++++
Quoted 8 lines
tests/ts/fincore/count | 194 ++++++++++++++++++++++++++++++++++ 10 files changed, 815 insertions(+) create mode 100644 bash-completion/fincore create mode 100644 misc-utils/fincore.1 create mode 100644 misc-utils/fincore.c create mode 100644 misc-utils/fincore_orig.c create mode 100644 tests/expected/fincore/count create mode 100755 tests/ts/fincore/count
Merged (except fincore_orig.c).
I'll very probably a little bit play with the output :-) It's like to have human readable sizes (10M) by default, align the numbers to the right (maybe use libsmartcols if more files specified).
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerQuoted 19 lines · Karel Zak
Quoted 9 lines · Masatake YAMATO
bash-completion/Makemodule.am | 3 + bash-completion/fincore | 25 +++++ configure.ac | 4 + misc-utils/Makemodule.am | 6 ++ misc-utils/fincore.1 | 76 ++++++++++++++ misc-utils/fincore.c | 209 +++++++++++++++++++++++++++++++++++++ misc-utils/fincore_orig.c | 235 ++++++++++++++++++++++++++++++++++++++++++ tests/commands.sh | 1 + tests/expected/fincore/count | 62 +++++++++++Quoted 8 lines
tests/ts/fincore/count | 194 ++++++++++++++++++++++++++++++++++ 10 files changed, 815 insertions(+) create mode 100644 bash-completion/fincore create mode 100644 misc-utils/fincore.1 create mode 100644 misc-utils/fincore.c create mode 100644 misc-utils/fincore_orig.c create mode 100644 tests/expected/fincore/count create mode 100755 tests/ts/fincore/count
Quoted 5 lines
Merged (except
fincore_orig.c).I'll very probably a little bit play with the output :-) It's like to have human readable sizes (10M) by default, align the numbers to the right (maybe use libsmartcols if more files specified).
Implemented, changes:
* errors are printed to stderr only, the output is not affected by errors
* use libsmartcols
* numbers aligned to the right
* add --bytes --raw --noheadings --json and --output <list>
* you can use $(fincore -o PAGES -nr /etc/passwd) to get only the number
The default output is:
$ fincore ~/Mail/Maildir/.notmuch/xapian/*
PAGES SIZE FILE
0 0B /home/kzak/Mail/Maildir/.notmuch/xapian/flintlock
1 28B /home/kzak/Mail/Maildir/.notmuch/xapian/iamchert
17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseA
17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseB
1185 4.2G /home/kzak/Mail/Maildir/.notmuch/xapian/position.DB
9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseA
9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseB
87831 2.2G /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.DB
1 208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseA
1 208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseB
66 11.5M /home/kzak/Mail/Maildir/.notmuch/xapian/record.DB
7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseA
7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseB
1941 1.7G /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.DBI'd like to have also PAGES-IN-BYTES column to make it easy for humans, but not sure how to call the column... "RES" or "RSS"?
For example "343M" rather than "87831" (see above).
Nice util, thanks!
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Thank you for merging.
The output looks sophisticated.
About RES and RSS, I don't know which is better. As you know top command users RES and ps command uses RSS...
Masatake YAMATO
Quoted 66 lines · Karel Zak
Quoted 19 lines · Masatake YAMATO
Quoted 9 lines
bash-completion/Makemodule.am | 3 + bash-completion/fincore | 25 +++++ configure.ac | 4 + misc-utils/Makemodule.am | 6 ++ misc-utils/fincore.1 | 76 ++++++++++++++ misc-utils/fincore.c | 209 +++++++++++++++++++++++++++++++++++++ misc-utils/fincore_orig.c | 235 ++++++++++++++++++++++++++++++++++++++++++ tests/commands.sh | 1 + tests/expected/fincore/count | 62 +++++++++++Quoted 8 lines
tests/ts/fincore/count | 194 ++++++++++++++++++++++++++++++++++ 10 files changed, 815 insertions(+) create mode 100644 bash-completion/fincore create mode 100644 misc-utils/fincore.1 create mode 100644 misc-utils/fincore.c create mode 100644 misc-utils/fincore_orig.c create mode 100644 tests/expected/fincore/count create mode 100755 tests/ts/fincore/countQuoted 5 lines
Merged (except
fincore_orig.c).I'll very probably a little bit play with the output :-) It's like to have human readable sizes (10M) by default, align the numbers to the right (maybe use libsmartcols if more files specified).
Implemented, changes:
* errors are printed to stderr only, the output is not affected by errors
* use libsmartcols
* numbers aligned to the right
* add --bytes --raw --noheadings --json and --output <list>
* you can use $(fincore -o PAGES -nr/etc/passwd) to get only the numberThe default output is:
$ fincore ~/Mail/Maildir/.notmuch/xapian/* PAGES SIZE FILE 0 0B /home/kzak/Mail/Maildir/.notmuch/xapian/flintlock 1 28B /home/kzak/Mail/Maildir/.notmuch/xapian/iamchert 17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseA 17 67.4K /home/kzak/Mail/Maildir/.notmuch/xapian/position.baseB 1185 4.2G /home/kzak/Mail/Maildir/.notmuch/xapian/position.DB 9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseA 9 35.7K /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.baseB 87831 2.2G /home/kzak/Mail/Maildir/.notmuch/xapian/postlist.DB 1 208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseA 1 208B /home/kzak/Mail/Maildir/.notmuch/xapian/record.baseB 66 11.5M /home/kzak/Mail/Maildir/.notmuch/xapian/record.DB 7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseA 7 27.6K /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.baseB 1941 1.7G /home/kzak/Mail/Maildir/.notmuch/xapian/termlist.DBI'd like to have also PAGES-IN-BYTES column to make it easy for humans, but not sure how to call the column... "RES" or "RSS"?
For example "343M" rather than "87831" (see above).
Nice util, thanks!
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Karel Zak
maintainerQuoted 2 lines · Masatake YAMATO
About RES and RSS, I don't know which is better. As you know top command users RES and ps command uses RSS...
Added column RES.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com