LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 07-14-2014, 07:36 AM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Lightbulb RAM is 30 % Free and SWAP is 100% Used


Why Swap is 100% used while there is almost 30% RAM available / unused on this host?

RAM and Swap Info:

Code:
# free -g
             total       used       free     shared    buffers     cached
Mem:           125         88         37          0          0          0
-/+ buffers/cache:         88         37
Swap:            1          1          0

OS Info:

Code:
# uname -a
Linux example.com 2.6.18-348.el5 #1 SMP Wed Nov 28 21:22:00 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
top and ps commands can tell me how much memory is being used by any process but how do we exactly figure out what process is making use of swap the most?

Here is the output from top command as well:

Code:
Mem:  132061308k total, 93212472k used, 38848836k free,   123292k buffers
Swap:  2031608k total,  2028940k used,     2668k free,   289864k cached
 
Old 07-14-2014, 08:08 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Since you have zero buffers and zero cache, I expect you are not running Linux directly on the hardware nor in a clean VM. You have some kind of quasi-virtual or more likely split OS.

Memory use stats in such systems are not generally accurate and methods of diagnosing memory use must be specific to the type of quasi-virtual system you are running (not the same as methods for diagnosing memory use in ordinary Linux systems). If you know what type of virtual system you have, post that and someone here might know more specific details.

Your 2GB use of swap might still be true and might represent a memory leak in some process that should be diagnosed. Finding actual swap use in processes is a bit tricky. I recall some scripts posted in other threads here at LW, for parsing those details out of /proc/*/smaps but at the moment I'm not sure what keywords would make an effective search to rediscover those threads.

Last edited by johnsfine; 07-14-2014 at 08:10 AM.
 
Old 07-14-2014, 09:25 AM   #3
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by johnsfine View Post
Since you have zero buffers and zero cache, I expect you are not running Linux directly on the hardware nor in a clean VM. You have some kind of quasi-virtual or more likely split OS.
It's an HP Server.


System Information

Code:
# dmidecode | grep -iE 'vendor|product'
        Vendor: HP
        Product Name: ProLiant BL460c Gen8
 
Old 07-14-2014, 09:37 AM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
The one line script in the first post of this thread might answer your question about swap usage:
http://www.linuxquestions.org/questi...3/#post4906470

I misread your initial post and thought the buffers and cache indicated something strange. On a more careful look at your first post I see they are less strange than I thought.

Did you do something to drop caches as an earlier attempt to correct a memory use problem?

There are two very different (probably unrelated) memory use mysteries in the data you provided:
1) What used up all the free memory at some earlier point in time, but was no longer using it when you got the memory use data you posted?
2) What allocated and still holds (but isn't accessing) the 2GB of anonymous data in swap?

The simple explanation for (1) would be file caching, assuming this is a large active server of some kind and you recently made a misguided attempt to correct a memory use problem by dropping caches. If you did not do that, there are many other possibilities for (1) but any of them I can think of are unusual.

The simple explanation for (2) would be a memory leak in some process. That would be important to diagnose. One of many alternate explanations is some service mis-configured to pre allocate far more resources than it is actually using.

Last edited by johnsfine; 07-14-2014 at 09:48 AM.
 
Old 07-14-2014, 09:54 AM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by johnsfine View Post
The one line script in the first post of this thread might answer your question about swap usage:
http://www.linuxquestions.org/questi...3/#post4906470

I misread your initial post and thought the buffers and cache indicated something strange. On a more careful look at your first post I see they are less strange than I thought.

The script is very helpful indeed:

Code:
for i in /proc/*/smaps ; do awk '/Swap/ {sum += $2}; END{ print FILENAME " Total: " sum}' $i; done | sort -nr -k 3
I have tweaked it to be more helpful (to me, at least):

Code:
for i in /proc/*/smaps ; do awk '/Swap/ {sum += $2}; END{ print FILENAME " Total: " sum}' $i; done | grep '[0-9]$' | grep -v 'Total: 0'
so that the above script will not show files where Swap is "0" or null.
 
Old 07-14-2014, 10:21 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
It appears that some process needed a lot of memory, forcing swap to be fully used, and then terminated. Pages that were written to swap during a time of heavy memory usage will not be paged back in again until they are needed.

Rounding to the nearest Gigabyte can make it hard to interpret the results. The output from free with "-m", or the default ("-k"), units might be less confusing.
 
Old 07-14-2014, 10:23 AM   #7
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi

The swap and buffer is not empty, just lower than 0.5Gb.

If you find the process in swap, it could be completely innocent. You can get this situation easily if you have one program start, use a lot of RAM and then quit or be killed. The kernel will put all other programs in swap, give the memory to the memory hog, and it will end up free when the program ends.

Edit:
rknichols posted while I wrote, but say the same thing.

Last edited by Guttorm; 07-14-2014 at 10:26 AM.
 
Old 07-14-2014, 10:53 AM   #8
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 rknichols View Post
It appears that some process needed a lot of memory, forcing swap to be fully used, and then terminated.
That is one possibility for the condition of the system as reported. It is not the only possibility and not my first guess.

Quote:
Pages that were written to swap during a time of heavy memory usage will not be paged back in again until they are needed.
That is an important point for the OP to understand (and true regardless of what was previously using a lot of ram and no longer doing so).

Quote:
Originally Posted by devUnix View Post
I have tweaked it to be more helpful
If I was at all competent in awk, I would have made the same enhancement inside the awk portion. Your approach is less efficient, but it gets the job done and is in the Unix spirit of stacking simpler filters instead of doing a job in one more complicated step.

Quote:
Originally Posted by Guttorm View Post
buffer is not empty, just lower than 0.5Gb.
Yes, I feel stupid for initially misinterpreting that.

Quote:
If you find the process in swap, it could be completely innocent.
It could be completely innocent. In many threads similar to this, I'm the one explaining that some swap use is normal and doesn't indicate anything wrong.

But this time, I think the swap use is more likely to be a symptom of something wrong. 2GB of stale anonymous ram is a lot, even for a big system like that with 88GB ram in use.

Last edited by johnsfine; 07-14-2014 at 11:08 AM.
 
Old 07-14-2014, 11:14 AM   #9
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Well, there was a process "Alert Engine" which was restarted and the RAM looked about 70% free and the SWAP also looked about 81% free.
 
Old 07-15-2014, 01:47 AM   #10
root4sp
LQ Newbie
 
Registered: Jul 2014
Posts: 10

Rep: Reputation: Disabled
Can you paste the output of below command ?

vmstat 1 40
 
Old 07-15-2014, 02:29 AM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by devUnix View Post
Why Swap is 100% used while there is almost 30% RAM available / unused on this host?
Mybe you should scale your numbers properly.
Used swap is around 1.5% of total installed RAM
Used swap is around 2.2% of currently used RAM

Why do you care ?.
 
Old 07-15-2014, 06:07 AM   #12
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by syg00 View Post
Why do you care ?.
With 37GB of RAM unused, 1 GB of Swap being fully used must mean something is wrong. The basics tell me Swap is utilized only when RAM is low.
 
Old 07-15-2014, 06:29 AM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Nope.
Memory management isn't that simplistic. Long term unreferenced pages can be moved to swap anytime.
 
Old 07-15-2014, 07:01 AM   #14
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 devUnix View Post
With 37GB of RAM unused, 1 GB of Swap being fully used must mean something is wrong. The basics tell me Swap is utilized only when RAM is low.
Pages are not moved to Swap when there is a large amount of ram unused. But once moved, pages stay in cache until needed again.

It is normal for very little ram to be unused, even when it would not be meaningful to say "ram is low". You might have had a very large amount of ram used by buffers and cache, causing stale anonymous pages to be moved to swap, even though ram was never "low".

You showed a snapshot of the system with a very small fraction of ram used by buffers and cache. How it got that way is an important question.

Last edited by johnsfine; 07-15-2014 at 07:05 AM.
 
Old 07-17-2014, 10:44 AM   #15
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
I have almost forgotten which server here had the issue. So I cannot recheck it.

Moderators:

If you feel we have come to a conclusion wrt the original question or our discussion on the differences why Swap is largely used when a large amount of RAM is available then please close the topic or I will mark it so.
 
  


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
swap used up , even though RAM free vicky007aggrwal Linux - Newbie 8 08-09-2012 05:57 PM
Why size of swap space is 2x of RAM??? Why not 1.5x of RAM or 2.5x of RAM??? Saurav Ghosh Linux - Newbie 7 11-01-2011 03:49 AM
100% Swap usage with loads of free memory AlienWolf Linux - Server 5 12-14-2010 08:33 PM
[SOLVED] Existeth a way to 'clear out' all the old/cached crap from RAM/SWAP to free up space? GrapefruiTgirl Linux - General 37 07-29-2010 12:46 PM
Odd swap usage even though there is free RAM Artanicus Linux - Hardware 5 09-28-2005 02:25 AM

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

All times are GMT -5. The time now is 04:55 AM.

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