LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   swap used up , even though RAM free (https://www.linuxquestions.org/questions/linux-newbie-8/swap-used-up-even-though-ram-free-4175421143/)

vicky007aggrwal 08-09-2012 12:26 AM

swap used up , even though RAM free
 
Hello Everyone.

can somebody will help me in understanding the swap memory concept.
As in my application i have seen that swap memory is getting used fully even when the Free space is available in RAM.
My understanding was swap wil be used only when there is RAM crunch issue..

Kindly suggest why space is used fully , any article,link will be of great help

My application setting
RAM- 10 G
SWAP 3 G

kedarp 08-09-2012 12:56 AM

First of all, how do yo know that your Swap space is being used?
Also mention your Distribution.

vicky007aggrwal 08-09-2012 01:08 AM

I checked the swap usage using free -g command



uname -a
Linux localhost.com 2.6.18-128.1.6 Mar 24 12:05 2009 x86_64 x86_64 x86_64 GNU/Linux


cat /etc/issue

linux64-5.3.2

kedarp 08-09-2012 01:35 AM

Use "free" with -m parameter and list the output here.
You should try the command "swapon -s", and also list the output.
For details, refer "man swapon".
As I studied, Swap is outside the control of the user and is managed by the kernel.
So you actually cannot find the solution. Your swap may be used only because your
system cannot use more RAM.

TobiSGD 08-09-2012 03:35 AM

The Linux kernel usually swaps out some not RAM that is occupied by applications that are not used for a long time to use that RAM as cache to speed up the system. So even on systems with high amount of RAM you can sometimes see a few MB of used swap although there is plenty of RAM.
This is normal behavior, I wouldn't bother about that.

syg00 08-09-2012 03:47 AM

The OP did say (my emphasis)...
Quote:

Originally Posted by vicky007aggrwal (Post 4749576)
As in my application i have seen that swap memory is getting used fully even when the Free space is available in RAM.

Post the contents of /proc/meminfo.

TobiSGD 08-09-2012 04:01 AM

Sorry, seems that I have overlooked the "fully" part.

jefro 08-09-2012 05:27 PM

"My understanding was swap wil be used only when there is RAM crunch issue"

I would have thought that too but seems there are some other factors going on. I researched this a bit a while ago. Seems that what you say can happen under some issues and to make things worse the swap doesn't flush parts.

The cure is not an exact cure. One part is to see if the app is locking up swap bit by bit or is it a one time shot that goes to swap.

I'd maybe start by changing the swappiness of your swap.

If this application just can't be fixed or figured out you might end up using a combined swap of multiple to act like a swap raid.

Might end up having to force swap to clear based on time or metric.

johnsfine 08-09-2012 05:57 PM

Quote:

Originally Posted by vicky007aggrwal (Post 4749576)
swap memory is getting used fully even when the Free space is available in RAM
...
My application setting
RAM- 10 G
SWAP 3 G

Use of some swap despite free ram is common. Use of 3GB of swap despite free ram is unusual, but still might be normal behavior. You haven't provided enough info.

Linux does not pull pages back from swap until they are accessed again. So if memory was used and then freed, you might leave a lot of swap space in use.

If you do have a problem, it is likely a memory leak in some process. To further investigate that, you would need to look into those processes with high virtual memory use and then look into whether that use is "anonymous" (possible memory leak) vs. file mappings (which don't contribute to swap usage).

Quote:

Originally Posted by jefro (Post 4750316)
I'd maybe start by changing the swappiness of your swap.
...
Might end up having to force swap to clear based on time or metric.

Both very bad ideas. You are attacking the symptom rather than the problem and doing it in a way that does more harm than just ignoring the problem would do.

If there is a memory leak or other problem, you need to start by identifying the problem processes, then deal with it or ignore it based on understanding what those processes are doing. But "deal with it" will not involve either of those methods of attacking the symptom.


All times are GMT -5. The time now is 12:48 AM.