LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-18-2009, 12:23 PM   #1
Dig
Member
 
Registered: Nov 2009
Posts: 50

Rep: Reputation: 1
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
 
Old 12-18-2009, 12:58 PM   #2
raju.mopidevi
Senior Member
 
Registered: Jan 2009
Location: vijayawada, India
Distribution: openSUSE 11.2, Ubuntu 9.0.4
Posts: 1,155
Blog Entries: 12

Rep: Reputation: 92
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
...............
...............
.........
 
Old 12-18-2009, 03:37 PM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Dig View Post
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.
 
Old 12-18-2009, 03:43 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by raju.mopidevi View Post
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.
 
Old 12-18-2009, 04:21 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,141

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
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.
 
Old 12-18-2009, 05:09 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by syg00 View Post
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.
 
1 members found this post helpful.
Old 12-20-2009, 05:48 PM   #7
Dig
Member
 
Registered: Nov 2009
Posts: 50

Original Poster
Rep: Reputation: 1
Really thanks , all of the replies really will help me
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SLES9 snmp calculate CPU usage peter72 Linux - Software 0 11-04-2009 08:57 PM
[SOLVED] how to calculate the file space usage of every account? uunuu Linux - Software 4 09-19-2009 12:51 AM
How to calculate cpu and memory usage of a process narendra1310 Ubuntu 1 08-30-2008 02:39 AM
calculate /var/tmp usage for different machines on network sun_sun Linux - Networking 3 02-09-2008 06:37 AM
How much swap usage is too much? sneakyimp Linux - Hardware 3 11-30-2006 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration