# Swap memory is not getting used, swap broken?

## tommy_fila

I came across a very strange problem today. For a long time I have wondered my Gentoo system never seems to be using the swap memory. I read in several other threads that Gentoo hardly ever uses swap, so I figured that everything was fine and I did not have to worry. Today I rememberd again that I had never seen my swap getting used, so I decided to investigate. After poking around for a while, I finally discovered that my vm.swappiness variable was set to 0

```
# cat /proc/sys/vm/swappiness

0
```

So I wanted to set a new value (60 because it should be the default).

```
# echo 60 > /proc/sys/vm/swappiness

-bash: /proc/sys/vm/swappiness: Operation not permitted
```

I also tried this command:

```
# sysctl -w vm.swappiness=60

error: unknown error 1 setting key 'vm.swappiness'
```

Something is obviously very wrong, but I don't know what. Any help or suggestions would be greatly appreciated.

I tried searching the forums and found surprisingly few topics covering anything about "vm.swappiness" problems. I seem to be the only one with a screwed up swap.  :Confused: 

----------

## Little Nemo

swappiness on my Gentoo box is 29. Where does this setting come from? Is it a Gentoo choice?

Anyway, I had no problem changing this setting through either method.

----------

## avendesora

Not problem changing it here either (was 60). What's your kernel?

(I'm running mm-sources 2.6.6-mm1)

----------

## tommy_fila

Currently I am running the 2.6.3-gentoo-r1 kernel. This problem is really frustrating. No one else has it!  :Confused:   :Crying or Very sad: 

----------

## avendesora

Well, the thing is, I don't really see why you would want to use your swap in the first place.

If you really want to change the swappiness, try a -mm kernel maybe, or maybe a -aa kernel (he's the one who did the most work on the VM area, AFAIK, so it might be a good idea to give it a try).

----------

## darksbane

 *tommy_fila wrote:*   

> 
> 
> ```
> # echo 60 > /proc/sys/vm/swappiness
> 
> ...

 

This may be a silly question, but you're root when you try this right?

Also as someone said in an earlier post, not using swap is a good thing in most cases. If you can keep everything in memory then your computer will be a happy camper. 

What kernel are you using?

----------

## avendesora

BTW, if you want to check that you _can_ swap, try something stupid like starting a couple vi's on absurdly large files (gentoo iso images for instance...) and watch your mem go down, swap kicking in at some point, then god knows what once you've maxed everything out  :Twisted Evil: 

----------

## tommy_fila

I don't think any of you are quite understanding the problem. It's not a matter of whether I want to use swap or not, it's a matter of swap simply not working. A swappiness setting of 0 means that swap is not getting used at all. No matter what application I run, swap is not getting used. I tried changing this value, but it doesn't work. The problem is I don't understand why it will not let me change the swappiness value.

@darksbane

Yes I am using root. Check above for the kernel I'm using.

Thank you all for your help! Some input is better than none at all!

I was thinking perhaps it could be that I have the wrong permissions set on /proc or something along those lines. Anyone?

----------

## avendesora

swappiness == 0 does not mean no swap. It just means the kernel will very reluctantly use swap.

```
saidin root # cat /proc/sys/vm/swappiness

0

saidin root # free

             total       used       free     shared    buffers     cached

Mem:       1028696    1023344       5352          0        168      49532

-/+ buffers/cache:     973644      55052

Swap:      1999832     136324    1863508

```

EDIT: There's a good article about swappiness over at kerneltrap.org (last week I think).

(EDIT #2: Running 2.6.5-aa5 right now)

----------

## tommy_fila

 *mseigneurin wrote:*   

> swappiness == 0 does not mean no swap. It just means the kernel will very reluctantly use swap.

 

I didn't know that. Anyways, my swap doesn't work at all. I can't change the swappiness settings or ever actually use the swap. How did you get your system to use swap even when your swappiness was at 0?

----------

## avendesora

Simple: in KDE right now, three konsoles:

- one running top to see what's going on

- one doing vi KNOPPIX-something.iso (700M RAM eaten up right there)

- one doing vi on another large .iso so that total RAM need > physical RAM

(and < total RAM+swap)

System does slow down a bit for a while when the two vi's are running, but settle down after that.

----------

## tommy_fila

Success! Opening the stage3 tarball did the job and got my kernel to use some swap memory! Thank you very much for that tip!

What I still don't understand, and it still bothers me is why I can't change the swappinss variable. I would like to be able to experiment around with my swap and see what works best for my system. Any idea what could be causing that. My swap does indeed work, but I can't fiddle around with it.  :Sad: 

Thanks for hanging in there with me!  :Wink: 

----------

## avendesora

I really don't know why you can't change your swappiness.

I'd suggest trying out other kernel varieties if you're interested in VM tuning.

(Or maybe try a fresh compile of your kernel - maybe something wasn't exactly

right when you built yours? - not very likely)

You wouldn't have errors in dmesg when you cat to swappiness, would you?

Have you tried changing other sysctl settings (like kernel/shmmax for instance) ?

----------

## avendesora

BTW, the kerneltrap article is here: http://kerneltrap.org/node/view/3000

There's also a real good interview with Andrea Arcangeli on the front page right now.

----------

## tommy_fila

I solved the problem by switching kernels. It must have been the kernel that was either configured imporperly or the kernel itself that did not support changing the swappiness variable. Thank you all for your help!  :Very Happy: 

----------

## tommy_fila

Now I have a new problem with my swap. Whenever I change the /proc/sys/vm/swappiness variable it doesn't save the changes. After a reboot, it always resets back to 60 and not to what I had it set at. Is this intentional or am I making a mistake setting the swappiness?

----------

## infirit

Put the line in localstart!

```
echo "command" >> /etc/conf.d/localstart
```

do not forget the doubble quotes

----------

## tommy_fila

I guess I could do that, but I'm more interested in what's causing the problem than a solution. There are many ways to fix the problem. I'm just wondering if this is supposed to happen. It would seem more logic for the kernel to save your changes.

----------

## infirit

Dont know if you can use sysctl for this (im at work now and connot test it) but you can try.

```
sys.vm.swappiness=60
```

in /etc/sysctl

EDIT: Unless there is a kernel option when you compile the kernel to set swappiness i think the kernel will forget the setting on every shutdown. Please someone correct me if im wrong.

----------

## Little Nemo

 *infirit wrote:*   

> Unless there is a kernel option when you compile the kernel to set swappiness i think the kernel will forget the setting on every shutdown.

 

If that's correct, where does the "Gentoo default" of 60 come from? And why is my swappiness always 29? I haven't found anything in the Gentoo scripts that would set this.

----------

## tommy_fila

 *Little Nemo wrote:*   

> If that's correct, where does the "Gentoo default" of 60 come from? And why is my swappiness always 29? I haven't found anything in the Gentoo scripts that would set this.

 

I think the values are determined by the kernel developers. They decide what level of swappiness they want. My kernel puts it at 60, your kernel might put it at 29. This is just my theory. I have a bad feeling it might be wrong because it seems kind of strange that kernel developers would set the swappiness at 29 - why not make it 30. 

It would be nice if we could get a kernel developer in here to clear up the issue.

----------

## tommy_fila

For anyone who is interested, the answers to all the above questions can be found here:

https://forums.gentoo.org/viewtopic.php?t=175419

----------

## bk0

 *tommy_fila wrote:*   

> Now I have a new problem with my swap. Whenever I change the /proc/sys/vm/swappiness variable it doesn't save the changes. After a reboot, it always resets back to 60 and not to what I had it set at. Is this intentional or am I making a mistake setting the swappiness?

 

gentoo-dev-sources (and probably other gentoo 2.6 kernels) contains the Con Kolivas autoregulated swappiness patch. This means that the kernel automatically adjusts the /proc/sys/vm/swappiness value as needed during runtime, so any changes you make will be clobbered next time it updates. A good explanation of this patch and how it works is here on KernelTrap.

I repeat: With gentoo-dev-sources it is neither necessary nor possible to permanently adjust the swappiness value. It's taken care of automatically, no need to worry.  :Smile: 

----------

## tommy_fila

Great! Finally the one and only correct answer!  :Very Happy:  Thanks

----------

