How to find used swap?

I want to find used space (the value that is reported by top, that is at second position on top Swap line) with sysctl variables.

I need that in a C program, and I want to get it with sysctlbyname() function.

Here are sysctl values for swap:

Code:
vm.swap_enabled: 1
vm.nswapdev: 1
vm.swap_async_max: 4
vm.swap_reserved: 10697715712
vm.swap_total: 8589934592
vm.swap_idle_threshold2: 10
vm.swap_idle_threshold1: 2
vm.stats.vm.v_swappgsout: 167146
vm.stats.vm.v_swappgsin: 53192
vm.stats.vm.v_swapout: 37474
vm.stats.vm.v_swapin: 18443
vm.disable_swapspace_pageouts: 0
vm.defer_swapspace_pageouts: 0
vm.swap_idle_enabled: 0

I've tried different computations adding (swappgsout+swappgsin)*4096 and other things but I cannot obtain the value from top utility which means I am not doing something right.

My question is: how used swap value is calculated?
 
  • Thanks
Reactions: grz
On a related note: how does one find out which process(es) use swap easily?

I've been searching for this for a while too. Apparently you cannot. The closest I've come is the [FONT=Courier New]top -w[/FONT] command, but it is very wrong and almost always just shows 0 for every process even if it is using hundreds of K of swap (confirmed by killing that process). Have you ever found anything accurate?
 
Note that you are responding to a thread that's more than 7 years old. You're probably better off starting a new thread.
 
Back
Top