[opensuse] What is using swap?
The 'swapon' command will tell me how much swap is being used. Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is? -- "Be brave enough to live creatively. The creative is the place where no one else has ever been. You have to leave the city of your comfort and go into the wilderness of your intuition. You can't get there by bus, only by hard work, risking, and by not quite knowing what you"re doing. What you"ll discover will be wonderful: yourself." -- Alan Alda. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
You can tell how much is being used, but getting a breakdown of what is using swap is sort of an oxymoron. Swap is used to warehouse things that are not being uses, memory for programs that are not being run. If they were being run, they wouldn't be in swap. If a burst of high memory usage pushes inactive programs and work space to swap it will get paged back into main memory when it needs to run again. If it doesn't need to run, it might live out there on swap for a long time. More to the point, there is no need to worry about swap, or memory management in general on Linux. Its not windows, and it will use memory and swap to the best advantage. These days, if you see any significant swap usage you probably need more memory. Until you see massive io and sustained disk activity and top shows your swap space being gobbled up, and your machine gets slow, just don't worry about swap. -- Explain again the part about rm -rf / -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
jsa said the following on 06/13/2011 12:14 AM:
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
You can tell how much is being used, but getting a breakdown of what is using swap is sort of an oxymoron.
Dirk said I was asking the wrong question: well almost; I was asking the question backwards. You are right: 'top' can tell me what I need to know.
Swap is used to warehouse things that are not being uses, memory for programs that are not being run. If they were being run, they wouldn't be in swap.
That statement was literally correct with the old PDP-11 which ran in roll-in/roll-out mode. But with paged virtual memory a process can be running even if a lot, perhaps most of its memory is not 'in core'. Only its working set needs to be in core. And the way memory is mapped, the executable parts never need to be swapped out; when they fall of the end of the page LRU they are discarded because they can be retrieved from the binary image in /lib:/usr/lib:/bin:/usr/bin or wherever.
If a burst of high memory usage pushes inactive programs and work space to swap it will get paged back into main memory when it needs to run again. If it doesn't need to run, it might live out there on swap for a long time.
And that's where it has become odd. I have a little widget telling me cpu, memory and swap use. (Mathew Dawson's "System Load Viewer") For a long time I though that the 30% use of swap was because of all the web pages I had under tabs in Firefox. Some days that would reach 60% or 70%. But suddenly that's not happening any more. I still have the same 30-40 tabs, but now swap use in single digits. Even with day long sessions during which I view many more pages, look at spreadsheets and graphics-heavy presentation with LO, download and read PDFs ..
More to the point, there is no need to worry about swap, or memory management in general on Linux. Its not windows, and it will use memory and swap to the best advantage. These days, if you see any significant swap usage you probably need more memory.
All this I know; as I said, I've been doing this since PDP-11 days :-) I know full well that Linux - and even old UNIX - could make use memory if you threw more at it, something that Windows never really mastered (after all, why would any want more than 640k?) What I'm concerned about is the SUDDEN CHANGE IN BEHAVIOUR.
Until you see massive io and sustained disk activity and top shows your swap space being gobbled up, and your machine gets slow, just don't worry about swap.
That's exactly what I mean. That _was_ happening, now its not. I've not updated the kernel. I'm sure some apps have been updated in the normal course of events, but this seems a dramatic change. Its as if some major .memory leak has been fixed. -- The spirit of resistance to government is so valuable on certain occasions that I wish it to be always kept alive. It will often be exercised when wrong, but better so than not to be exercised at all. --Thomas Jefferson -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage. Just don't get too carried away trying to micro-manage it. -- Explain again the part about rm -rf / -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
jsa wrote:
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
Or just swap = virtual - resident. -- Per Jessen, Zürich (16.1°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hello, On Mon, 13 Jun 2011, Per Jessen wrote:
jsa wrote:
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
Or just swap = virtual - resident.
So: ps -eo vsz,rss,cmd | awk '{ printf("%10s %s\n", $1 - $2, $3); }' (add a '| sort -n' if you like). You can add the pid too, and add a header for "SWAP" Column, e.g.: ps -eo vsz,rss,pid,cmd | awk ' NR==1{ printf("%10s %10s %s\n", "SWAP", $3, $4); } NR>1{ printf("%10s %10s %s\n", $1-$2, $3, $4); }' HTH, -dnh -- "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners." -- Ernst Jan Plugge -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 13 June 2011 14:43:08 David Haller wrote:
Hello,
On Mon, 13 Jun 2011, Per Jessen wrote:
jsa wrote:
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
Or just swap = virtual - resident.
So:
ps -eo vsz,rss,cmd | awk '{ printf("%10s %s\n", $1 - $2, $3); }'
Nah, that won't work. The virtual size of a process includes everything, even things that haven't been loaded yet, parts of mmap:ed files that have never touched memory, allocated memory that hasn't been used, shared memory that has been mapped into the process address space, shared libraries etc. That calculation will very likely tell you that you are using a million times more swap than you actually have Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Anders Johansson wrote:
On Monday 13 June 2011 14:43:08 David Haller wrote:
Hello,
On Mon, 13 Jun 2011, Per Jessen wrote:
jsa wrote:
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
Or just swap = virtual - resident.
So:
ps -eo vsz,rss,cmd | awk '{ printf("%10s %s\n", $1 - $2, $3); }'
Nah, that won't work. The virtual size of a process includes everything, even things that haven't been loaded yet, parts of mmap:ed files that have never touched memory, allocated memory that hasn't been used, shared memory that has been mapped into the process address space, shared libraries etc. That calculation will very likely tell you that you are using a million times more swap than you actually have
If you take a quick(!) look at top with the swap column added, my calculation of swap = virtual - resident is pretty close on a regular system. I'm sure there are plenty of exceptions, but if one is concerned about memory usage and swap usage, top does provide a good starting point. -- Per Jessen, Zürich (20.6°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 13 June 2011 19:08:09 Per Jessen wrote:
If you take a quick(!) look at top with the swap column added
Trust me, I have, on several occasions, and I have no idea what that thing measures. It is nothing with any relation to reality On my system it is telling me right now that kontact is consuming 629 megabytes of swap - the truth is that the entire system is only consuming 25 megabytes. In total if I sum up the swap column I'm looking at multiple gigabytes, possibly a terabyte (I'm too lazy to do the math but I see large numbers) It is just a useless value In my experience, the only value that comes close to the truth is the one in smaps, and then you have to do a lot of manual adding up. It is a very neglected part of the system and has been for years The virtual memory size is as I described, absolutely anything that a process has even thought about putting into its address space. It is not a value you can use to base any calculations on Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Anders Johansson wrote:
On Monday 13 June 2011 19:08:09 Per Jessen wrote:
If you take a quick(!) look at top with the swap column added
Trust me, I have, on several occasions, and I have no idea what that thing measures. It is nothing with any relation to reality
Yeah, something's not quite right, I agree - my virt-res calculation certainly does not bear any relation to amount of swap-space in use.
On my system it is telling me right now that kontact is consuming 629 megabytes of swap - the truth is that the entire system is only consuming 25 megabytes. In total if I sum up the swap column I'm looking at multiple gigabytes, possibly a terabyte (I'm too lazy to do the math but I see large numbers)
I totalled up the swap column on a small box - it came out as 666Mb, but in fact of 2051648k total memory, 1892464k was used of which 1403000k as filesystem cache. -- Per Jessen, Zürich (18.8°C) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Jun 13, 2011, at 19:15 , Anders Johansson wrote:
If you take a quick(!) look at top with the swap column added
Trust me, I have, on several occasions, and I have no idea what that thing measures. It is nothing with any relation to reality
It's been a while since I've looked at the sources, but if I remember correctly, top will just use swap=virt-rss. That does not work for all the same reasons doing the subtraction by hand does not. A. -- Ansgar Esztermann DV-Systemadministration Max-Planck-Institut für biophysikalische Chemie, Abteilung 105 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On 13/06/11 18:56, Anders Johansson wrote:
On Monday 13 June 2011 14:43:08 David Haller wrote:
Hello,
On Mon, 13 Jun 2011, Per Jessen wrote:
jsa wrote:
On 06/12/2011 07:46 AM, Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
Or just swap = virtual - resident.
So:
ps -eo vsz,rss,cmd | awk '{ printf("%10s %s\n", $1 - $2, $3); }'
Nah, that won't work. The virtual size of a process includes everything, even things that haven't been loaded yet, parts of mmap:ed files that have never touched memory, allocated memory that hasn't been used, shared memory that has been mapped into the process address space, shared libraries etc. That calculation will very likely tell you that you are using a million times more swap than you actually have
I'd be interested to know your opinion of the accuracy of ksysguard's memory stats (alt-f2, "System Monitor" under KDE). It seems to be going out of its way to deter people from drawing any conclusions from the classic top metrics (see the What's This help on the column headers: from Virtual Size: "This value in practice means next to nothing"), but I'd like to know if the alternative calculations it provides based on statm (Memory column) and smaps (Detailed Memory Information dialog for a given process are realistic. Due to their high degree of integration and shared components, and top, KDE apps routinely get clobbered by the uninformed for being "bloated", so the ksysguard author has tried to produce a tool that provides accurate stats. Will -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday 14 June 2011 15:04:01 Will Stephenson wrote:
I'd be interested to know your opinion of the accuracy of ksysguard's memory stats (alt-f2, "System Monitor" under KDE). It seems to be going out of its way to deter people from drawing any conclusions from the classic top metrics (see the What's This help on the column headers: from Virtual Size: "This value in practice means next to nothing"), but I'd like to know if the alternative calculations it provides based on statm (Memory column) and smaps (Detailed Memory Information dialog for a given process are realistic.
Ooh, that is indeed nice. I hadn't looked at ksysguard in ages. Last I looked at it, it was more or less just a graphical replacement for top, but now it looks much better. The values there look correct, and if they get them from smaps that would explain it, because smaps should be the real truth about usage. I hope they will add a "swap" column too.
Due to their high degree of integration and shared components, and top, KDE apps routinely get clobbered by the uninformed for being "bloated", so the ksysguard author has tried to produce a tool that provides accurate stats.
That indeed looks very useful. Thanks for pointing it out. As I said, I hadn't looked at ksysguard in years, I didn't know how much they had improved it Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Will Stephenson said the following on 06/14/2011 09:04 AM:
I'd be interested to know your opinion of the accuracy of ksysguard's memory stats (alt-f2, "System Monitor" under KDE).
I'd seen and used it as a version of 'top' that better illustrated threads, but after this posting, Will, I drilled down and ... WOW!
[snip
Due to their high degree of integration and shared components, and top, KDE apps routinely get clobbered by the uninformed for being "bloated", so the ksysguard author has tried to produce a tool that provides accurate stats.
WOW! I see what is pasted below, and when I expand on the "Show Full Details" of memory usage, all my questions about what is where are answered. It also answers the questions about what libraries and binaries should be on fast store/SSD for the programs you use. Its a shame there is no way to 'dump' the output to a file. The only shortcoming is that I have to proceed forward. Clearly FF isn't the one contributing to the use of swap, despite what I had though. Its memory use is prodigious, but the way Linux maps and shares libraries wins out in the end, and the way it handles threads and shares memory between threads is another example of conservatism. Here we go: Process 4059 - firefox Summary The process firefox (with pid 4059) is using approximately 430.9 MB of memory. It is using 412.2 MB privately, 15.8 MB for pixmaps, and a further 12.0 MB that is, or could be, shared with other programs. Dividing up the shared memory between all the processes sharing that memory we get a reduced shared memory usage of 2.9 MB. Adding that to the private and pixmap usage, we get the above mentioned total memory footprint of 430.9 MB. Library Usage The memory usage of a process is found by adding up the memory usage of each of its libraries, plus the process's own heap, stack and any other mappings, plus the stack of its 24 threads. Private more 402716 KB [heap] 12468 KB /usr/lib/xulrunner-2.0.1/libxul.so 2756 KB /usr/lib/xulrunner-2.0.1/libmozjs.so 540 KB /home/anton/.mozilla/firefox/tav9xtnm.2006-07-07/extensions/{DDC359D1-844A-42a7-9AA1-88A850A938A8}.xpi 488 KB /usr/lib/xulrunner-2.0.1/libmozsqlite3.so Shared more 972 KB /usr/lib/libgtk-x11-2.0.so.0.2200.1 832 KB /usr/lib/libnss3.so 712 KB /lib/libc-2.11.3.so 584 KB /var/cache/fontconfig/7ef2298fde41cc6eeb7af42e48b7d293-le32d4.cache-3 484 KB /lib/libglib-2.0.so.0.2800.0 Totals Pixmap 16177 KB (Might be stored in the graphics card's memory) Private 422128 KB (= 16660 KB clean + 405468 KB dirty) Shared 12252 KB (= 12188 KB clean + 64 KB dirty) Rss 434380 KB (= Private + Shared) Pss 425098 KB (= Private + Shared/Number of Processes) Swap 0 KB Full Details Information about the complete virtual space for the process is available, with sortable columns. An empty filename means that it is an anonymous mapping. Both the MMU page size and the kernel page size are 4 KB. Show Full Details ------------------- END ----------------- -- There is only one quality worse than hardness of heart and that is softness of head. --Theodore Roosevelt -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday 14 June 2011 16:46:22 Anton Aylward wrote:
The only shortcoming is that I have to proceed forward. Clearly FF isn't the one contributing to the use of swap, despite what I had though.
One additional point: what is seen as swap usage isn't always swap usage, so to speak. For example IPC shared memory (shm) is sometimes shown as swap usage (it's seen as either that or cache) so just because your system says it's using a lot of swap, it doesn't necessarily have to mean there is an application that's using a lot of swap, it could also be an application that is using shm and it's just displayed as swap even when it's not Just an additional data point for your investigation :) Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Anders Johansson said the following on 06/14/2011 11:08 AM:
On Tuesday 14 June 2011 16:46:22 Anton Aylward wrote:
The only shortcoming is that I have to proceed forward. Clearly FF isn't the one contributing to the use of swap, despite what I had though.
One additional point: what is seen as swap usage isn't always swap usage, so to speak. For example IPC shared memory (shm) is sometimes shown as swap usage (it's seen as either that or cache) so just because your system says it's using a lot of swap, it doesn't necessarily have to mean there is an application that's using a lot of swap, it could also be an application that is using shm and it's just displayed as swap even when it's not
Just an additional data point for your investigation :)
Yes, I'm very aware of this as I have # grep tmp /etc/fstab .... varrun /var/run tmpfs rw,nosuid,mode=0755,size=150K 0 0 varlock /var/lock tmpfs rw,noexec,nosuid,nodev,mode=1777,size=20K 0 0 vartmp /var/tmp tmpfs rw,noexec,nosuid,nodev,mode=1777,size=1G 0 0 and wonder if those allocations are enough/too-much and under what load they actually get pushed out of memory onto swap. After all, varrun and varlock are not the busiest of file systems :-) -- Don't let anyone rob you of your imagination, your creativity, or your curiosity. It's your place in the world; it's your life. Go on and do all you can with it, and make it the life you want to live. -- Mae Jemison -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 13 of June 2011 07:22:18 jsa wrote:
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
This is misleading, since on my system swap is barely used, and swap values in top reach gigabyte levels. From a quick check I made, the swap column is VIRT-RES, which includes mmaped files. Regards, Peter -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2011-06-13 06:22, jsa wrote:
Forgot to add, you can run top in a terminal and then press f followed by p to add a column for swap usage.
Mmm... ]> PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ SWAP COMMAND ]> 21893 cer 20 0 2401m 1.3g 57m S 2 16.6 4:13.39 1.0g firefox So, firefox has 1 Gigabit in swap. But total swap is 420644k... where is that 1 G stored? It can not be true. Unless is reserved but not used memory, holes.
Just don't get too carried away trying to micro-manage it.
Half a gig lost... not "micro" really. - -- Cheers / Saludos, Carlos E. R. (from 11.4 x86_64 "Celadon" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iEYEARECAAYFAk33WrYACgkQtTMYHG2NR9WE9wCfRHJjQNaCejy2tpzSvBV4JWec NLgAnRNsVnYL4E9igec7qTMxnW/pOsG9 =VzlO -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday 12 June 2011 10:46:07 Anton Aylward wrote:
The 'swapon' command will tell me how much swap is being used.
Is there anything that will tell me what is using swap, what programs, processes etc are using it or what the contents of swap is?
If you look in the /proc directory for a process, you will find a virtual file called smaps. This tells you exactly how much a particular process is using in the swap partition. If you only look at the private segments (the ones with a p in the "permissions") then you can exclude shared data I am not aware of a good tool that sums up the values and separates private from non-private though. It doesn't look as though it would be too hard to write, but maybe I'm overlooking something. You're right that ps and top take a too simplistic approach to it Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (10)
-
Anders Johansson
-
Anders Johansson
-
Anton Aylward
-
auxsvr@gmail.com
-
Carlos E. R.
-
David Haller
-
Esztermann, Ansgar
-
jsa
-
Per Jessen
-
Will Stephenson