# Enable SWAP



## alie (Mar 23, 2010)

Hi,

Sorry i have silly question 

Really i didnt know how to enable SWAP on my FreeBSD box... Is there any tutorial to enable SWAP. NOTE: i just checked my SWAP with htop and it always showing 0B

Thanks


----------



## graudeejs (Mar 23, 2010)

in /etc/fstab add somthing like this

```
/dev/[red]ad0s2b[/red] none swap sw 0 0
```
change text in red to fit your setup


now either reboot or simply run `# swapon /dev/ad0s2b`


----------



## SirDice (Mar 23, 2010)

If you have enough internal memory your swap will hardly get touched. This is good because using swap will slow things down. If you have a lot of paging in/out of your swap you need to consider adding more memory to the machine.

swapinfo(8)


----------



## gcooper@ (Mar 23, 2010)

SirDice said:
			
		

> If you have enough internal memory your swap will hardly get touched. This is good because using swap will slow things down. If you have a lot of paging in/out of your swap you need to consider adding more memory to the machine.
> 
> swapinfo(8)



Indeed. Thrashing your cache so that things swap will reduce your performance on your system a _lot_. Also, you can use any combination of swapctl(8), swapoff(8), and swapon(8) to manage swap files / partitions.

Have fun ...


----------



## alie (Mar 27, 2010)

Great, thanks for ur helps guys


----------



## proton1234 (Nov 28, 2019)

freebsd 11.3 current top output:
Mem: 509M Active, 202M Inact, 16K Laundry, 230M Wired, 70M Buf, 23M Free
Swap: 1024M Total, 1024M Free

I don't understand why system aren't using swap partition although it's enabled and in use?


----------



## rufwoof (Nov 29, 2019)

You may want to consider using encrypted swap. I run my laptop entirely in ram, 4GB system with typical 1.5GB used during general use, swap infrequently gets used, but sometimes is. I allocate a 26GB swap file, so when I do the likes of video editing it has enough 'ram' (otherwise would tend to just lock up/grind to a halt). In cases where swap is used typically the system initially slows right down for a few minutes as things are swapped - but then resumes working pretty much a usual. Shutdowns can also be slow, as the system swap off's (flushes). You just have to be patient.


----------



## ShelLuser (Nov 29, 2019)

proton1234 said:


> I don't understand why system aren't using swap partition although it's enabled and in use?


Without giving us any info on the load of that setup (for example: what do you got running in there?) it's impossible to tell. If you only have one service running I wouldn't be surprised here.



rufwoof said:


> You may want to consider using encrypted swap.


Within context of what's being asked that's a pretty dumb suggestion because it doesn't add any improvements nor does it answer proton's question. I suppose it could add up to the total load which makes their system use swap but I don't think that was the goal of all this.

And for the record: I'm not saying there's no merit within encrypted swap, there can be, but not within the context of the question. It adds plain out 0 advantages which leads me to my previous comment. Not to mention that you failed to explain how to set this up. Making your comment plain out useless, once again within context of course.

(edit): and why are we reviving a 9 year old thread?


----------



## proton1234 (Nov 29, 2019)

ShelLuser said:


> Without giving us any info on the load of that setup (for example: what do you got running in there?) it's impossible to tell. If you only have one service running I wouldn't be surprised here.


Pretty standard stuff like apache + mariadb + php but as far as I can see from TOP output only 23 mbytes left of 1024 mbytes of physical ram so usually in such cases swap is used. In my case swap is on dedicated partition, contents of /etc/fstab are:  /dev/vtbd0p3    none            swap    sw                      0       0


ShelLuser said:


> (edit): and why are we reviving a 9 year old thread?


Do you prefer to create a new thread with a similar name?


----------



## SirDice (Nov 29, 2019)

proton1234 said:


> Pretty standard stuff like apache + mariadb + php but as far as I can see from TOP output only 23 mbytes left of 1024 mbytes of physical ram so usually in such cases swap is used.


No, not necessarily. Your internal memory will always be used as much as possible and most of the time it's filled up with all sorts of caches. These cashes are the first to be released when a process requires a bunch of memory. When you start to hit some limits then first a bunch of inactive process will get swapped out, it's going to depend on what you have running how much swap this will use. 

In your case I'm almost certain there's actually some swap in use but the numbers are so low that rounding errors are making it seem like there's nothing used. 



proton1234 said:


> In my case swap is on dedicated partition


Where and how your swap is stored is mostly irrelevant.


----------



## rufwoof (Dec 5, 2019)

ShelLuser said:


> Without giving us any info on the load of that setup (for example: what do you got running in there?) it's impossible to tell. If you only have one service running I wouldn't be surprised here.
> 
> 
> Within context of what's being asked that's a pretty dumb suggestion because it doesn't add any improvements nor does it answer proton's question. I suppose it could add up to the total load which makes their system use swap but I don't think that was the goal of all this.
> ...


And your value add ... negative


----------

