# System refuses to swap (almost)

## cbx550f

I've been struggling with this problem for a while now: The system virtually refuses to swap regardless of memory usage.

Here's an example a few minutes ago: Listening to music and browsing the web, and fired up a flash based game... the memory usage climbed to around 100MB remaining, and the disk starts grinding away. It wasn't too bad this time, and after about 20 seconds, I was able to get the machine to ALT-Tab to an xterm and do the following:

```
free -m

             total       used       free     shared    buffers     cached

Mem:          1941       1922         18          0          0         35

-/+ buffers/cache:       1885         55

Swap:         4095        132       3963
```

It actually swapped more than I've seen in ages. It has become normal routine that I have a 10 or 15 minute wait until I can do ANYTHING, not even move the mouse pointer, until the disk activity slows enough to manage to kill something. It's difficult to determine exactly what's happening at the time due to the system being non-responsive.

I have 2GB of RAM and a 4GB swap partition, and have played around with /proc/sys/vm/swappiness extensively, but nothing seems to change. This has also followed many kernel versions from 2.6.x up to the present 3.2.0.

Thoughts?

----------

## wswartzendruber

Better paste a link to your kernel config.  We need to look at your scheduling.

----------

## cbx550f

http://vint.ca/dumps/dot_config

Thanks

----------

## wswartzendruber

Okay the first thing I'm noticing is that you're using the No-op I/O scheduler, which is for devices that have their own scheduling logic.  If I were you, I'd switch to CFQ and see how swap performance goes then.

Enable the block layer ---> IO Schedulers ---> Default I/O scheduler --> CFQ

----------

## cbx550f

No go - it does behave slightly better when it starts to get bad, but a while ago I gently loaded up the ram, and wound up hitting the reset button after 5 minutes of complete unresponsiveness. As it was starting to get bad, I was able to see it using a bit of swap - but only a tiny bit (something to the effect of 40-50MB).

I suspect I could "fix" this by starting with a clean kernel config and configuring from scratch, but I hate to do that and never understand what went wrong.

Thanks BTW - apparently I forgot to put that back to CFQ after playing around with it!

----------

## wswartzendruber

I would like to first pose a question:  Can a process be split between RAM and swap?

Note that it is normal for RAM to read as nearly full.  This is because of aggressive caching on the part of the kernel.  I propose that you create two separate processes and have them each take an equal amount of memory.  But run one and get it bloated, and then run the other.  Make sure that the first one isn't doing anything before you start on the second one.  The results will give us further insight.

----------

## s_bernstein

 *wswartzendruber wrote:*   

> I would like to first pose a question:  Can a process be split between RAM and swap?

 

Yes, because your memory is organized in pages which can be swap independently.

----------

## cbx550f

Too tired now for much of a reply, but I'll link to some notes I made while testing: http://vint.ca/dumps/memTesting

Need to get off to bed now, but I've been putting up with this for a while, and it's time to put this problem to bed too... back at it tomorrow.

Thanks for the help.

Paul

----------

## Logicien

Did you check the value of

```
sysctl vm.swappiness
```

?

If it is 1, that can explain why your system do not swap.

----------

## cbx550f

 *Logicien wrote:*   

> Did you check the value of
> 
> ```
> sysctl vm.swappiness
> ```
> ...

 

```
nautilus pvint # sysctl vm.swappiness

vm.swappiness = 10
```

I've tried changing that a few times - went up to 100, even tried 0 just for fun, and no obvious difference.

I recall that in the early 2.6 days I found a HUGE difference in changing it from 10 to say 25, so that was my first guess.... no luck.

----------

## NeddySeagoon

cbx550f,

Maybe you don't understand what swap is used for ?

It is only used to hold dynamically allocated RAM.  Thats RAM content that has no permanent home on disk.

This means that buffers waiting to be flushed to disk cannot be swapped. Whats the point in writing them to the wrong place ?

Code is not swapped, its just discarded and reloaded as needed.

There is a bug is some 64 bit kernels for some chipsets that makes some systems have very long IOwaits under some circumstances.

Run top before you trigger the condition and watch at the wa figure.

```
Cpu(s):  1.9%us,  0.5%sy,  0.0%ni, 97.6%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
```

Press the numeral 1 key in top to see per core figures

----------

## cbx550f

I do understand swap... but even if I didn't, the situation is the same: When the system needs to swap it becomes unresponsive, sometimes over a period of 30 minutes I am barely able to switch to an xterm or virtual console and kill something. . Ultimately I do indeed need to get more RAM, but that simply is not in the budget ATM.

I have a nagging feeling that you've hit the nail on the head with the IOWait bit, however. When I first built this system in 2009 I noticed this, and found some workarounds, and dealt with it, but it's seriously hurting my productivity. Simply having Eclipse running along with Firefox often puts me in the situation where it's faster to hit the reset button and restart what I was doing than to wait out the machine.

If this is indeed caused by a kernel bug - it's been going on for years now, and a quick google tells me that I'm not alone; there are complaints all over the place, but no signs of solutions.

Anyway... sorry, I seem to be ranting a bit.....

The "wa" figures  as shown in top get high when the system is slowing down - a while ago I was watching it and typically one processor was in the 90% range, and the other three were showing 10-30% (This was while ld was linking in a compile).

Any help you folks can supply is greatly appreciated - I've been running Linux since 1994, and most of that time it has been my only OS at home, and the thought of "doing something rash" has occurred to me more than once recently... <sigh>

Also, I did try the following this afternoon: Updated portage and did a clean config/compile of the kernel (3.2.1), just to be sure, and the problem persists.

----------

