Continuous growth of swap usage but RAM not fully used

I seem to be having problems with my computer using swap space even when there is plenty of RAM left. Currently I am using about 51% of my RAM and the swap usage is at 28%. It seems as though once it is using the swap space it never stops. Occasionally I am using a lot of ram and it will almost get maxed out, shouldn’t it stop using the swap space and use just the RAM once it becomes free? This seems to be slowing my computer down greatly. I am using 12.1, and currently using kernel 3.1.10-1.16-default. Here is a copy of the current usage:

        total       used       free     shared    buffers     cached

Mem: 4053076 2844884 1208192 0 22400 1060352
-/+ buffers/cache: 1762132 2290944
Swap: 6289404 1730324 4559080

If you need any more hardware info or any other info let me know.

Can you print the output of these commands:

cat /proc/sys/vm/swappiness
cat /proc/sys/vm/dirty_ratio
cat /proc/sys/vm/dirty_background_ratio
cat /proc/sys/vm/overcommit_ratio

You might try setting swappiness to 1, dirty_ratio to 10, and dirty_background_ratio to 5. You can do so temporarily (until reboot) by running (for example, and as root):

echo 1 > /proc/sys/vm/swappiness

Permanently by editing the file /etc/sysctl.conf and adding the following at the bottom (as an example):

vm.swappiness = 1
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5

Then on every reboot those values will be used. An explanation is the swappiness is a tunable from 0-100 of if the system prefers to swap cache out. Generally for non-interactive machines a value of 50+ is suitable for performance reasons, though for a desktop you might use 1 through 10. The values dirty_ratio and dirty_background_ratio are for how much percentage of memory is used before the write cache is written out. If the value is large it might mean a very long period of i/o as the disk is written.

I have a blog on the subject of SWAP you can read here: https://forums.opensuse.org/blogs/jdmcdaniel3/setting-up-proper-size-swap-file-opensuse-114/

For digging up even more info on your PC, have a look here: https://forums.opensuse.org/blogs/jdmcdaniel3/h-i-hardware-information-bash-script-install-run-inxi-default-options-79/

Thank You,

On 2012-12-14 02:06, hito kiri wrote:
>
> I seem to be having problems with my computer using swap space even when
> there is plenty of RAM left.

As it should be. There is no problem.

> Currently I am using about 51% of my RAM
> and the swap usage is at 28%. It seems as though once it is using the
> swap space it never stops. Occasionally I am using a lot of ram and it
> will almost get maxed out, shouldn’t it stop using the swap space and
> use just the RAM once it becomes free?

No.
Swapped memory will go into memory when it is needed, not before.

> This seems to be slowing my
> computer down greatly.

No, that is not true.

That “free” memory is used for more interesting things, like caching
disk reads. Trust the kernel to do the right thing. Somethings stay in
swap simply because they are not needed. If they go into memory they
will use memory, and that WILL slow down the computer, because it is
idle memory, used for nothing.

It is best to have those things in swap where they don’t interfere.

> I am using 12.1, and currently using kernel
> 3.1.10-1.16-default. Here is a copy of the current usage:

Please use code tags, so that computer generated text does not wrap.

Posting in
Code Tags - A Guide


>              total       used       free     shared    buffers     cached
> Mem:       4053076    2844884    1208192          0      22400    1060352
> -/+ buffers/cache:    1762132    2290944
> Swap:      6289404    1730324    4559080

If you want more speed, your problem is getting more RAM chips into your
machine, no less swap. That’s a common misconception.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

To the OP:

Just for comparison, on my machine running oS 11.4 64bit KDE 4.8.5


Mem:   4055668k total,  4026072k used,    29596k free,    37924k buffers
Swap:  4192252k total,      132k used,  4192120k free,  2675148k cached


:~> cat /proc/sys/vm/swappiness
60
:~> cat /proc/sys/vm/dirty_ratio
10
:~> cat /proc/sys/vm/dirty_background_ratio
5
:~> cat /proc/sys/vm/overcommit_ratio
50

It’s very rare that swap is used. Only if I load one or two VMs concurrently I see some swap activity. If you’re using KDE there’s a nice taskbar widget called “system Monitor” you can install that shows a small bar graph for CPU/RAM/SWAP usage. Te swap bar in mine is typically at the minimum (a few Kb only).

I have the same amount of RAM you do - 4 GB, and a 4GB SWAP (yours is 6GB).

Perhaps you’re using a non-desktop kernel build?

I’d also check for an application that leaks into memory, eating it up.

Good luck.

What you describe (the full description, not just the part that I quoted), sounds normal to me.

Most of the time, I see 0 swap used. However, if I do something that requires a lot of memory, swap usage goes up and never returns to 0 until the next boot.

This does not slow things down. What stays in swap is data that is not being actively used. It costs nothing to leave it there in swap.

And the next one being sure something else is going on. Try running

top

to see what’s slowing down your machine.

BTW: Could you also provide some extra info, like videocard + driver used?

My system is set up just like yours, so it is odd that mine is using so much more swap. I already have that widget installed which is how I started noticing this. The kernel I have should be the same build that comes with 12.1, other than any updates I have gotten.

I figured that the swap usage was a problem because even while my computer is idle I can hear the hard drive working, which it never seemed to do until the swap usage grew. I had thought that swap was used when the machine was maxing out it’s memory usage, but I guess that’s not the case. I have looked at top quite a bit trying to figure out if an application was leaking memory, but I don’t see anything strange or anything that would lead to the sluggishness I am experiencing. I guess I just need more RAM lol.

There is an algorithm that decides what should go into swap. So it is not quite so linear as when you run out of ram. Though generally if you are excessively swapping it does mean to sustain this workload you need more ram. I have 3gb and even with many applications running I never touch swap often. I have heard this reported as a problem before where the allocation of ram compared to swap/cache seems sub optimal causing slowdowns due to swapping. I could never reproduce them on my machine. Some say it is due to overcommit ratio, or swappiness setting. For me I just reduce all of them, even if it does cost me some performance.

On 12/15/2012 11:16 PM, hito kiri wrote:
> I figured that the swap usage was a problem because even while my
> computer is idle I can hear the hard drive working, which it never
> seemed to do until the swap usage grew.

you may have a problem, but i do not think the problem is “continuous
growth of swap usage” because (as others have said) your memory/swap
usage looks normal for Linux…by that i mean that Windows and Linux
use memory/swap in totally different ways, and if you watch Linux and
measure it using Windows standards it will scare you, have a read here
http://www.linuxatemyram.com/

but, you may have a problem! it would be good to learn what is hitting
your hard drive while the system is ‘idle’?

first: it is nearly impossible to hear any activity going on in hard
drives made in the last few years…some are absolutely silent, other
almost so…so, are you sure it is a hard drive sound you are
hearing? do you have an LED which lights to show disk activity? watch it
and if you see it blink without that sound, or you hear that sound
without the light blinking then you are not hearing the hard drive…

could you be hearing a CPU/GPU/case or power supply cooling fan?? or
maybe a chicken bone rattling around?? :slight_smile:

if it for sure is the disk being hit it would be good to learn by what!

but what is idle? i’d say start by turning off browser, email client,
IRC client, music application, torrent…every application you have
started…

then watch the LED and listen for the sound…how often is the drive
being hit? how many times per minute? and/or how many seconds between
each sound?

then, open one terminal and start top…wait a minute for all activity
to smooth out and then watch the drive LED while listening for the
sound: each time you see the LED blink AS you hear the sound then look
to Top to tell what is happening…

Top lags a little bit because it show you a “snap shot” of what is
happening each few seconds…so when you see the LED blink AND hear the
sound look immediately look at top and see what is on top…but, THEN
the important thing is what does it change to immediately after the sound.

for several minutes watch the LED, listen and note what jumps to the top
of top immediately after each sound…

if i do that here i will see a series of different processes jump to the
top of top, like: Xorg, konsole, top, Xorg, plasma-desktop, Xorg, kde4,
and those just kinda bounce in and out of being somewhere in the top
five…each using zero or 1 percent of CPU and everything else using
zero CPU…

all the while (here) about 880 MB of 1 GB of RAM and about 260 MB of 2
GB of swap is used…those figures bounce around a little, but not much
and if i watch for hours (without moving the mouse or touching the
keyboard) the used swap will not climb enough to mention…

what do you see and hear during an experiment like that?


dd http://tinyurl.com/DD-Caveat