# Swap not being used?

## Budoka

I have been checking randomly using htop and as best I can tell my swap partition isn't being utilized at all. It is always zero. Does this mean I have something misconfigured and if so how do I diagnose it? Is it necessarily a bad thing to have no swap? I only noticed it was being used by chance and haven't seen any unusual behavior with my laptop to date. I am able to "sleep" and "hibernate" without any problem so I assume swap is being used then but if I want to forego that functionality can I get rid of it since my system isn't using it anyway?

 *Quote:*   

> # fdisk -l
> 
> Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
> 
> Units: sectors of 1 * 512 = 512 bytes
> ...

 

----------

## krinn

Just remove it from your fstab entry or use swapoff to stop using it.

Now you can test really without one and stop guessing if you need one or not. Better than removing that partition just to discover you were in need of it.

----------

## NeddySeagoon

Budoka,

Your swap can only be used for dynamically allocated memory.

Because of the way Linux works, any data or code that has a permanent location on disk can be 'swapped' just by flushing the RAM.  It will be reloaded when its needed again.

If you don't have any swap, the kernel is forced to keep dynamically allocated memory in RAM. This cam be a bad thing, an the kernel will flush data/code to free up RAM.

Swap not being used is not wrong, its just that the kernel has net decided to use it yet.  Thats not the same as saying you don't need swap.

----------

## Budoka

 *NeddySeagoon wrote:*   

> Budoka,
> 
> Your swap can only be used for dynamically allocated memory.
> 
> Because of the way Linux works, any data or code that has a permanent location on disk can be 'swapped' just by flushing the RAM.  It will be reloaded when its needed again.
> ...

 

Thanks Neddy. I kind of understand what you are saying but how can I tell that the kernel actually has access to the swap partition if it isn't being used as far as I can tell. I guess I am concerned that I may have incorrectly configured my install somehow.

Also do you think I may have over or under allocated memory to swap and that might be part of what is going on?

 *Quote:*   

> # cat /proc/meminfo
> 
> MemTotal:        8092340 kB
> 
> MemFree:         3981820 kB
> ...

 

----------

## NeddySeagoon

Budoka,

```
# cat /proc/meminfo

MemTotal: 8092340 kB

MemFree: 3981820 kB 
```

You have 8G RAM and have used less than half of it.  You will need to make your system work hard to push it into swapping.

Run top in a terminal window.  In another terminal window - keep top visible, do

```
cd /usr/src/linux

make -j 40
```

This will compile the kernel, allowing 40 parallel makes which will put the pressure on a bit.

It may even lock op your box, so you might want to start with smaller numbers.

Running gcc 40 times might well push you into swapping.

----------

## cwr

You'll know when the system starts swapping - you'll be running in molasses.

I have 2G of RAM on a 32 bit system and generally zero swap, though sometimes it will

use one or two MB.  I run Conky on my desktop, so I can keep an eye on swap and

other stuff, and really, it's never touched.  I just keep it for use by hibernation.

Will

----------

## szatox

Use 'free' to check your memory usage.

```
free -h

             total       used       free     shared    buffers     cached

Mem:          7.3G       6.4G       965M       6.0M        74M       4.2G

-/+ buffers/cache:       2.1G       5.2G

Swap:           0B         0B         0B

```

Here you have an example with no swap at all.

I just though I won't run out of RAM anyway, even while compiling OOo in memory  :Smile: 

If you want to see your system using swap, you can use sysctl to change swappiness to 100. On the other hand, setting swappiness to 0 makes system avoid swapping stuff from RAM unless it's really nessecery.

----------

## NeddySeagoon

szatox,

Now build libreoffice and firefox at the same time  :)

----------

