LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Calculate Swap Usage (https://www.linuxquestions.org/questions/linux-server-73/calculate-swap-usage-776727/)

Dig 12-18-2009 12:23 PM

Calculate Swap Usage
 
hello all,

my monitor tools indicate that the percentage of swap used is more than the ideal , so i want to calculate which process is consuming from the swap

- I tried the following but it didn't help be 100%

#ps -eo vsz,rss,pid,args | sort -n

- any suggestion to accurately calculate which process consuming from swap , just the swap no ram + swap !

- Thanks

raju.mopidevi 12-18-2009 12:58 PM

Code:

ps -eo vsz,rss,pid,args | sort -n
this command displays all the processes which are using swap memory.

if you want to know how much they are using....then
use
Code:

pmap pid
to see how much it is using.

see my example
Code:

$ pmap 3476
3476: amarokapp
START      SIZE    RSS    PSS  DIRTY PERM MAPPING
08048000    144K    20K    20K      0K r-xp /opt/kde3/bin/amarokapp
0806c000      4K      4K      4K      4K r--p /opt/kde3/bin/amarokapp
0806d000      4K      4K      4K      4K rw-p /opt/kde3/bin/amarokapp
0806e000  4252K  3412K  3412K  3404K rw-p [heap]
b15b9000    216K    200K      8K      0K r-xp /lib/libdbus-1.so.3.4.0
...............
...............
.........


johnsfine 12-18-2009 03:37 PM

Quote:

Originally Posted by Dig (Post 3797004)
my monitor tools indicate that the percentage of swap used is more than the ideal

The monitor tool itself decides what percentage is "more than ideal"? Or it just reports the percentage and you have some idea what "more than ideal" is? Or what?

Either way, I think you might be underestimating legitimate use of swap that does not represent any performance problem.

johnsfine 12-18-2009 03:43 PM

Quote:

Originally Posted by raju.mopidevi (Post 3797043)
Code:

ps -eo vsz,rss,pid,args | sort -n
this command displays all the processes which are using swap memory.

I don't think it distinguishes at all whether processes are using swap memory. The VSZ value reported by swap is not a measure of swap+ram or of any other particularly meaningful kind of "memory use".

The use of swap by individual mappings of individual pids is available in /proc/pid/smaps but I don't know if there is any decent place to get totals. Also I think there are strange interactions with the page cache that make even the detailed info less meaningful.

syg00 12-18-2009 04:21 PM

Something as simple as this should work
Code:

for i in /proc/*/smaps ; do echo $i ; awk '/Swap/ {sum += $2}; END{print "Total: " sum}' $i; done
You need to correlate pid to process name - left as an exercise for the OP.

johnsfine 12-18-2009 05:09 PM

Quote:

Originally Posted by syg00 (Post 3797231)
Something as simple as this should work
Code:

for i in /proc/*/smaps ; do echo $i ; awk '/Swap/ {sum += $2}; END{print "Total: " sum}' $i; done
You need to correlate pid to process name - left as an exercise for the OP.

I think reducing the excess output is more important than mapping pids to names for this problem.

I have never used awk. But since you did almost all the work, a quick look at the man page for awk told me how to improve it to
Code:

for i in /proc/*/smaps ; do awk '/Swap/ {sum += $2}; END{if (sum>0) print FILENAME " Total: " sum}' $i; done
That avoids one line for each pid that uses swap and avoids both lines for each pid that doesn't, which gets you down to manageable output.

Sorting on the last field of that output is left as another exercise for the OP.

Also note, it only works as root.

Dig 12-20-2009 05:48 PM

Really thanks , all of the replies really will help me


All times are GMT -5. The time now is 02:37 AM.