# Refresh/release swap space



## hurricane_sh (May 11, 2011)

My server had a DOS attack which almost used up the swap space, it decreased to 10% after the attack stopped and have been the same for several hours. It should be 0% with the current server load (always 0% when no attack), is it possible to update it somehow?


```
# swapinfo
Device          1K-blocks     Used    Avail Capacity
/dev/ad8s1b       2097152   203992  1893160    10%
```


----------



## teckk (May 11, 2011)

```
#swapoff -a
```


```
#swapon -a
```

Will remove the swap, then restore it.

You'll loose anything that was in the swap though.

swapctl(8)


----------



## hurricane_sh (May 12, 2011)

Thanks, that did the trick.


----------



## fwaggle (May 12, 2011)

That last 10% is probably rarely used stuff that got swapped out and will never be touched again. I brought up on IRC a while back - when I was asking about how on my Apache servers, performance always goes to hell if it gets into swap, so since I try keep it out of swap is there any need to have swap at all - about how things like getty and so on, if they're never used, will get swapped out and that frees up real RAM for other things that could use it.

So my guess is you're equating 0% swap with "healthy", and 10% swap with "unhealthy", and that's possibly incorrect.

But yes, swapoff/swapon will do the trick - just make sure that used RAM + used swap does not exceed the real ram of your server, as I think you'd cause a panic (correct me if I'm wrong on that).


----------



## SirDice (May 12, 2011)

fwaggle said:
			
		

> So my guess is you're equating 0% swap with "healthy", and 10% swap with "unhealthy", and that's possibly incorrect.


Exactly. Swap usage in and of itself isn't a problem. It's excessive paging that will cause problems and slow things down. 

So instead of looking at your swap usage you should look at your paging. If swap is being used but there's hardly any paging in/out of swap then it's not a problem.


----------



## z662 (May 13, 2011)

SirDice said:
			
		

> So instead of looking at your swap usage you should look at your paging.



With what?


----------



## SirDice (May 13, 2011)

z662 said:
			
		

> With what?



vmstat(8) for instance. Look at pi (Pages In) and po (Pages Out).


----------



## DutchDaemon (May 13, 2011)

[cmd=]systat -vmstat 1[/cmd]

Look at information at the top-right:


```
SWAP PAGER
in   out
```


----------

