Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get information on linux whether my program is swapping or not?

Tags:

linux

posix

bsd

More specifically: I want to find this information from inside the program, preferably just before it starts swapping so I can react. So far I found:

  • Information inside /proc, which is not very useful

  • mincore syscall which seems to be available on linux and bsd, but requires me to pass in all the pages I'm interested in (might be enough, but it's a bit tedious)

Any more ideas?

like image 578
fijal Avatar asked Nov 06 '22 06:11

fijal


1 Answers

vmstat

To run every 2 seconds, you say "vmstat 2". It gives you output like:

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0  16124 431352 439000    0    0     4     2   37   18  0  0 100  0  0

The "si" and "so" columns are "swap-in" and "swap-out". Swapd is how much memory is in the swap device. Swapd should be stable, and si and so zero.

Remember:

You shouldn't really ask "is my program swapping" - as opposed to "is the system swapping". You program can cause others to swap - others can cause yours to swap, etc. Either way, when that happens - performance d...i..e...s....

like image 199
Brad Avatar answered Nov 11 '22 05:11

Brad