Linux Swapping - identifying the process


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Linux Swapping - identifying the process
# 1  
Old 05-06-2014
Linux Swapping - identifying the process

Hi

I ran the command
Code:
vmstat -s

, the output is below

Code:
    2335876  total memory
      2307284  used memory
       902984  active memory
       953180  inactive memory
        28592  free memory
       445848  buffer memory
      1234196  swap cache
       779872  total swap
        57184  used swap
       722688  free swap
      1425586 non-nice user cpu ticks
       137569 nice user cpu ticks
      1253812 system cpu ticks
    136556548 idle cpu ticks
       499759 IO-wait cpu ticks
        80609 IRQ cpu ticks
        47344 softirq cpu ticks
      2631596 stolen cpu ticks
      7401052 pages paged in
     19325628 pages paged out
           24 pages swapped in
        14301 pages swapped out
            0 interrupts
    221749766 CPU context switches
   1398654642 boot time
       251203 forks

I can see some swapping of 57184 Kb like about 58MB approximately.

Is there any way to know which process name and timestamp at which this swapping occurred on machine ?

My aim is to make sure that there is no swapping on my system

Any help is much appreciated - Thanks
# 2  
Old 05-06-2014
In that case, you need to add more memory to your system.
# 3  
Old 05-20-2014
If your still struggling you can get information on processes that are swapping by using: top, the VIRT heading shows how much swapping a process is doing.
Not sure how you would identify time unless you continually monitor the system.
Please note swapping isn't a bad thing if the impact on performance is not apparent to the users.
# 4  
Old 05-20-2014
The file "/proc/###/smaps" has all sorts of useful information about memory usage of individual processes, including swap space. It's way more detail than you're looking for but you can extract what you need and ignore the rest.

The only confusing part is that it breaks down memory usage by address segments so you can't just "grep" for "Swap:", sort the output and find the process with the most swap.

But this line:

grep 'Swap:' /proc/[0-9]*/smaps | gawk '$2 > 0'

will give you a raw dump of process id's with allocated swap space. The filename will identify the process. And if you sum up all the per-segment values for each process you'll have the total swap allocated for that process.

That could generate lots of lines of output though, depending on the number of processes running on the system, how much swap they have allocated and how that swap space is allocated to distinct memory segments within those processes. So some secondary parsing to find the interesting data will probably be necessary.

If you're up for installing some Python code to parse the data in /proc, you can clone the repository I published on Github here. https://github.com/cnamejj/PyProc

It won't help you find the process with the most swap with a single command line, but it will give ways to write scripts to pull data from the "smaps" file easier. There's a script included in the repo called "watch-process-smaps" which you could use to monitoring the memory allocations for one or more processes in near-realtime too. But that script itself will consume CPU and memory, so it's really just for diagnostic use IMO.

Finally, as dluk said there's nothing inherently evil about seeing some swapping. If the system doesn't have enough RAM to handle the workload it gets without slowing down, then that swapping would be a bad thing. Understanding the system in more detail is always a good thing though, since you might find a potential memory related problem before it causes noticeable performance issues.

Also, if your system runs into trouble with the available memory and starts swapping things out, the process with the most swap might not be the real problem in all cases. If you have some well behaved process that uses lots of RAM by design, but isn't CPU bound, then other more CPU-centric processes might wind up pushing the well-behaved processes memory to swap over time. So the process(es) that are out of control might be in memory and the well behaved ones might be swapped out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Identifying a process

morning, i introduce the following sentence: "sudo lsof -i | grep smtp" ang get a list of the processes. two of them i don't know what is the function: 29574 & 29575, with the following indication: "memo" the rest of the processes shown are smtpd. i kill these two processes and they disappear,... (4 Replies)
Discussion started by: brijan007
4 Replies

2. Shell Programming and Scripting

Swapping lines

Hi there, I have a text that I'm trying to format into something more readable. However, I'm stuck in the last step. I've searched and tried things over the internet with no avail. OS: Mac After parsing the original text that I won't put here, I managed to get something like this, but this... (8 Replies)
Discussion started by: Kibou
8 Replies

3. Solaris

Swapping

Hi Guys I am using SPARC-T4 (chipid 0, clock 2998 MHz), SunOS 5.10 Generic_150400-38 sun4v. How do I see if the server was doing some swapping like yesterday? I had a java application error with java.lang.OutOfMemoryError, now I want to check if the server was not doing some swapping at... (4 Replies)
Discussion started by: Phuti
4 Replies

4. Shell Programming and Scripting

Swapping fields

Hallo Team, This is the command that i am running : grep ",Call Forward Not Reachable" *2013* this is the output that i am getting (i did a head -10 but the files can be more than 1000) ... (8 Replies)
Discussion started by: kekanap
8 Replies

5. Shell Programming and Scripting

Swapping three lines

I have some text: <date>some_date</date> <text>some_text</text> <name>some_name<name> and I want to transform it to smthng like that: some_name on some_date: some_text I've tried sed: sed 's/<text>\(.*\)<\/text> <name>\(.*\)<\/name>/\2 - \1/' but it says unterminated... (13 Replies)
Discussion started by: dsjkvf
13 Replies

6. UNIX for Dummies Questions & Answers

Swapping in VI editor

Hi, I am attempting to replace several similar words with another word in vi. Here is what I have written for the script: 3dTcat -prefix SuperBrik_4WAY_HRF ../JULY10_2007A/results2TENT/stats.JULY10_2007A+tlrc ../JULY10_2007G/results2TENT/stats.JULY10_2007G+tlrc... (1 Reply)
Discussion started by: Jahn
1 Replies

7. SuSE

Swapping

Hello! Why does my SuSE GNU/Linux machine swap? I have a Gig of ram, currently 14MBs of free RAM, 724MB - buffers and caches... That is 685MB of cached RAM, then kernel really should'nt have to swap, It should release cached memory in my thinkin... It has only swaped 3MB's but still,... (3 Replies)
Discussion started by: Esaia
3 Replies

8. UNIX for Dummies Questions & Answers

how to get swapping info

Hi How can I determine if swapping is occuring on a server. Thanks, Leo (2 Replies)
Discussion started by: leo
2 Replies

9. Filesystems, Disks and Memory

Paging and Swapping

Hi Guys: Would like to know how to check system swapping and paging and some theory on how they function. I am an oracle dba and my environment is 8171 on AIX 433. We have a 1GB of RAM on the box and I am educating myself to see how much more SGA can be accommodated on the box and what are the... (2 Replies)
Discussion started by: ST2000
2 Replies

10. UNIX for Dummies Questions & Answers

Swapping questions

How can you tell how much a Solaris box is swapping? At what point do page in and page out become a problem? Here is a vmstat output. > vmstat procs memory page disk faults cpu r b w swap free re mf pi po fr de sr m0 m1 m2 m3 in sy cs us sy id... (1 Reply)
Discussion started by: 98_1LE
1 Replies
Login or Register to Ask a Question