Asked 12 years, 9 months ago. Active 2 months ago. Viewed k times. Under Linux, how do I find out which process is using the swap space more? Shameem Shameem Your accepted answer is wrong. Consider changing it to lolotux's answer, which is actually correct.
Six years later, the rest of us have no idea whether you were referring to David Holm's answer the currently-accepted one as of today or some other answer. Well, I see you also said David Holm's answer is wrong, as a comment on his answer The related answer is currently below the two custom scripts answers.
Add a comment. Active Oldest Votes. Community Bot 1 1 1 silver badge. Here is the copy, in case the link dies: gitorious. Like dgunchev it does gives much less total swap than free. Tensibai does not work on Arch; your awk may lack something. Please have a look on my no fork version of this script! The author has a follow-up post about how to do it using top : northernmost. Show 6 more comments. From the htop FAQ : It is not possible to get the exact size of used swap space of a process.
David Holm David Holm From the docs, the SWAP column in top seems to just show how much swap would be necessary if the entire process was swapped out, rather than how much of the process is actually swapped at present. From what I can tell after a short search, there is no way to determine how much of each process is swapped out at the moment. There is no compensation for e.
Also not all memory might have been referenced by the process yet. In this case it's not necessary for the OS to read the complete binary from disk into memory, and thus the value of RES doesn't include this part of memory.
I would upvote this more if I could. This is saving my bacon! Thankfully that's what the comments are for jterrace : although admittedly you have to read them :S Regarding the comment not working anymore: It seems more recent versions of top no longer have 'O' set as the key for choosing the sort fields.
When using the? Show 4 more comments. Here's another variant of the script, but meant to give more readable output you need to run this as root to get exact results :! Very nice script. It gives the same information as lolotux's one, but in a better readable way.
The only thing I changed was using args instead of comm in the ps command since I have a lot of processes with the same name but different arguments a bunch of python gunicorn processes. Flow Tom Tom 2, 2 2 gold badges 14 14 silver badges 21 21 bronze badges. This one is good. Ronny Vindenes Ronny Vindenes 2, 1 1 gold badge 18 18 silver badges 15 15 bronze badges.
Another script variant avoiding the loop in shell:! I hope I've commented the code enough to tell what it does. Stephane Chazelas 5, 2 2 gold badges 28 28 silver badges 29 29 bronze badges. Tensibai Tensibai Note that bash expands the directories in a sorted way lexical, not numerical. The random order is down to how awk stores its arrays hash table and how for p in pname retrieves them.
I agree with the awk hash table, I took a shortcut here. Is there a way to know how much of this tmpfs storage is currently in the swap space? I don't understand how the output of df -ht tmpfs could help with determining that it uses swap space.
AlexisWilke tmpfs stores its content in virtual memory. Virtual memory is a combination of RAM and disk, more precisely of page cache and swap area. There is no point to waste RAM with unused data. That doesn't answer my question, though. The df command is not going to tell me whether the tmpfs module decided to swap some data to disk.
I would think there isn't really a way to know. AlexisWilke There are definitely cases where you can be sure some of the tmpfs used data is stored on swap area pages.
There is also an indirect method, more or less convenient depending on the machine activity. Just read the files stored in tmpfs. If that triggers disk activity, some or all content was on disk. Of course, this is a "destructive" test because at the end, the data will tend to stay on RAM, at least momentarily. Flow 1 1 gold badge 10 10 silver badges 20 20 bronze badges.
Ezwig Ezwig 1 1 gold badge 4 4 silver badges 14 14 bronze badges. Your command gave exactly the same result as mine using status or smaps didn't show a real difference. Alas, your answer doesn't help me to understand what is using my swap space. I am pretty much sure this answers "How can I know which process is using my swap space on my Linux system? Maybe you should reformulate the question, if you are asking something diffrent? I want to know where those MB are consumed.
I will update my question to be more specific. Meir Drago Meir Drago 1 1 1 bronze badge. TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint!
If you like what you are reading, please consider buying us a coffee or 2 as a token of appreciation. We are thankful for your never ending support.
If you want to top to monitor swap, you should add swap to the menu and sort by it. Nice artical and nicely explained but i have one query that why to use swap space even if we have lot of free memory?
Swap space is used to temporarily hold data moved from the system RAM, which is not actively being used by the system or user especially when RAM is filling up. Even if you have enough RAM, it is still recommended to create a swap space for Linux. Another reason is that it helps during hibernation of a computer, where the an image of the RAM captured and saved in the swap area.
On restarting the computer, that image is reloaded into RAM, thereby enabling you to work from where you had stopped point of hibernation. Tomas, Thanks for updating about smem tool, we will try it out and include the tool with examples to this list. Have a question or suggestion? Please leave a comment to start the discussion.
Please keep in mind that all comments are moderated and your email address will NOT be published. Save my name, email, and website in this browser for the next time I comment. Notify me of followup comments via e-mail. You can also subscribe without commenting.
This site uses Akismet to reduce spam. Learn how your comment data is processed. What is Swap space? How do I check Swap space usage in Linux? We shall look at different commands and tools that can help you to monitor your swap space usage in your Linux systems as follows: 1.
0コメント