Bug 254723 - [patch] systat -swap to display per-process swap space usage ordered by highest
Summary: [patch] systat -swap to display per-process swap space usage ordered by highest
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-02 15:57 UTC by ota
Modified: 2021-04-15 00:50 UTC (History)
1 user (show)

See Also:


Attachments
Display per-process swap usage - diff against releng/13.0 and contains extra improvements (18.75 KB, patch)
2021-04-02 15:57 UTC, ota
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description ota 2021-04-02 15:57:59 UTC
Created attachment 223771 [details]
Display per-process swap usage - diff against releng/13.0 and contains extra improvements

This is an improvement to "systat -swap" to display high swap space processes in addition to swap process.

It uses libprocstat to find swap backed vm entries.  It adds each of vm size from the address space minus resident memory to figure out swapped out page size.

Some example outputs are pasted below:

                    /0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10
     Load Average   | 

Device/Path       Size  Used |0%  /10  /20  /30  /40  / 60\  70\  80\  90\ 100|
ada0s1b          2048M 2034M XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
zvol/sys/tempora 1024M 1015M XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
zvol/sys/swap    1024M 1014M XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Total            4096M 4063M XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Pid    Username   Command     Swap/Total Per-Process    Per-System
 24153 hiro       seamonkey   98M /   1G  7%              2%
 23677 hiro       xfce4-pane  28M /  81M 34% XXX          0%
 23629 hiro       xfce4-sess  25M / 118M 21% XX           0%
 23681 hiro       xfdesktop   20M /  58M 34% XXX          0%
 23678 hiro       thunar      15M /  43M 36% XXX          0%
 23658 hiro       at-spi-bus  14M /  23M 63% XXXXXX       0%
 23660 hiro       gvfsd       12M /  21M 56% XXXXX        0%

Disks  ada0  ada1  ada2   cd0 pass0 pass1 pass2 pass3
KB/t   8.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
tps       0     0     0     0     1     0     0     0
MB/s   0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
%busy     0     0     0     0     0     0     0     0


                    /0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10
     Load Average   |

Device/Path       Size  Used |0%  /10  /20  /30  /40  / 60\  70\  80\  90\ 100|
ada0s1b          2048M 1046M XXXXXXXXXXXXXXXXXXXXXXXXX

Pid    Username   Command     Swap/Total Per-Process    Per-System
 12696 hiro       java         2G /   3G 62% XXXXXX      85% XXXXXXXX
  2201 hiro       xfdesktop   21M /  51M 41% XXXX         1%
  2217 hiro       gvfsd-tras  19M /  31M 61% XXXXXX       0%
  2214 hiro       gvfs-gphot  17M /  26M 64% XXXXXX       0%
  2212 hiro       gvfs-hal-v  17M /  25M 64% XXXXXX       0%
  2206 hiro       gvfsd       16M /  27M 59% XXXXX        0%
  2203 hiro       xfsettings  15M /  44M 35% XXX          0%
  2260 hiro       xterm       15M /  24M 64% XXXXXX       0%
  2197 hiro       xfce4-pane  15M /  45M 33% XXX          0%


Disks  ada0   da0   cd0 pass0 pass1 pass2
KB/t  13.87  0.00  0.00  0.00  0.00  0.00
tps      14     0     0     1     0     0
MB/s   0.18  0.00  0.00  0.00  0.00  0.00
%busy     1     0     0     0     0     0
Comment 1 ota 2021-04-10 15:23:16 UTC
Created https://reviews.freebsd.org/D29695.
Comment 2 Andriy Gapon freebsd_committer 2021-04-14 08:47:25 UTC
Just curious, do you consider adding this functionality to top?
Its current implementation of -w option is useless.
Comment 3 ota 2021-04-15 00:37:32 UTC
(In reply to Andriy Gapon from comment #2)

We can consider adding to top as well if such demand is popular

When I'm interested in swap in/out activities, I'd like to see each of swap device usages and also disk I/O activities.  systat -swap shows both and had spaces in the middle.  It was more attractive place to add.  I have been adding extra displays to systat over years and familiar than top.

I had to access all vm page usage via libprocstat to calculate swap usage for each process. Top uses kinfo_proc.  We will need to query libprocstat for every process and I wonder how much it weight it adds to top.  I think we can do that only when -w is passed, though.
Comment 4 ota 2021-04-15 00:41:54 UTC
By the way, https://reviews.freebsd.org/D29337, systat: Handle SIGWINCH to properly window resizing and adjust -swap disk stat based on new size., is a separate review that goes very well with this new feature.

Before I dived into "systat -swap", I wondered if I could add swap usage to "systat -pigs" and created https://reviews.freebsd.org/D29303 to reduce memory re-allocations.
  -pigs also uses kinfo_proc like top and wasn't a good place to add/experiment, though.