# 16g ram and I assigned 64g swap,  mistake?



## azathoth (Jan 13, 2018)

I wonder if so much swap disturbs freebsd auto tuning?

zfs on root
2x500g sas drives in zfs root


----------



## scottro (Jan 13, 2018)

Sounds like too much swap.  If you're running ZFS sometimes it's useful to have a (usually inactive) swap partition if using synth, which takes a lot of swap, but even in that case 64GB seems excessive.


----------



## azathoth (Jan 13, 2018)

What would I tune to mitigate the error? if anything?


----------



## Beastie (Jan 13, 2018)

It's a complete waste of disk space. Most probably you won't be using 1/4 of it. Just repartition if it's not too much of a hassle.


----------



## SirDice (Jan 13, 2018)

Yeah, it's too much. I generally don't assign more than 4-8GB of swap. On low RAM systems (less than 4GB) it's good to keep a ratio of 1,5-2.0 times the amount of RAM. Above 4GB RAM and 8GB of swap that ratio doesn't make sense anymore and it'll just be wasted.

Ideally swap won't get used much any way. Modern operating systems will always use a little bit of swap but this is usually just a tiny amount. If applications start using swap it's typically an indication there's not enough memory in the machine. Some swap usage is acceptable, it's excessive swapping that's problematic.


----------



## Snurg (Jan 13, 2018)

scottro said:


> ...if using synth, which takes a lot of swap, but even in that case 64GB seems excessive.


Will synth use swap if there is sufficient memory? Or, asked the other way, how much RAM should be present to use synth without swapping?


Beastie said:


> Most probably you won't be using 1/4 of it.


Considering the transfer rate of around 100MB/sec for modern disks, filling 16GB sequentially (ideal case) would take about three minutes. 
The reality is not the ideal case. It would slow down the computer that much that one probably will just prefer buying a few more memory modules.
Considering the current street price of around $2 per GB ECC DDR3, I think it makes no real sense to use much swap.


----------



## scottro (Jan 13, 2018)

I've had synth start 6 parallel builds (heh, took 3 tries to spell parallel right, shame on me), and wind up using a lot. marino has suggested a large amount--I'd have to give it 4x RAM at times.

https://forums.freebsd.org/threads/59107/page-2#post-342058

but mostly for really large ports like chromium and friends.


----------



## Snurg (Jan 13, 2018)

aww... would that mean to have 256gb swap when using 64gb of ram?


----------



## scottro (Jan 13, 2018)

Those were marino's loose recommendations. You can also limit parallel builds to lessen the requirements.


----------



## ralphbsz (Jan 13, 2018)

No.  It depends on the workload, or more accurately, on the balance between workload and memory.  Example: On your current machine, you have 16G of RAM.  Imagine that your workload (I don't care what the workload is, synth is fundamentally no different from others) needs 27G, plus the operating system wants to use some RAM for file system cache.  In that case, you will use a little bit over 11G of your swap.  Now upgrade your machine to 64G of RAM, and it will need no swap at all (and use a little bit, because the OS will move rarely used stuff into swap and use RAM for file system buffer cache instead).

You need to figure out the balance of swap and RAM for your workload.  Parallel compiles are difficult workloads to measure and characterize, because their resource usage fluctuates so much between different phases.  They also tend to stress everything (CPU, file IO, memory footprint, memory bandwidth) at different times, and balancing that is hard.  For a hobbyist user, the easiest answer is probably to reduce the degree of parallelism: it only makes the compiles slightly slower, and hopefully moves the resource usage out of the problem zone.  Everything else will require pain-staking measurements and optimization.


----------



## Snurg (Jan 13, 2018)

(sorry for OT)
Good to know! I now read the full thread scottro linked above. marino mentioned that with sufficient ram one needs practically no swap.
I really must try out Synth soon for that parallel build thing. I guess with 4 builders and 48GB, like marino mentioned, it could reduce the wait time for building very substantially, compared to the normal make.
Does there exist some kind of "Synth guide for dummies" to get an idea how to use it?


----------



## chrbr (Jan 13, 2018)

With too much swap one should get a warning as

```
kern.maxswzone exceeded
```
in /var/log/messages. This happened to my system with 2G RAM and 2x4G swap. I have simple reduced the swap partitions to 3G each because the machine has never run out of swap.


----------



## azathoth (Jan 14, 2018)

hmm if I have zfs on root, how do I shrink swap?


----------



## Sensucht94 (Jan 14, 2018)

azathoth said:


> hmm if I have zfs on root, how do I shrink swap?



`gpart resize [B][I]-i[/I][/B] index [[B][I]-a[/I][/B] alignment] [[B][I]-s[/I][/B] size] [[B][I]-f[/I][/B] flags] geom`, see gpart(8)

So, in your case, if you want a 16Gb swap:

```
doas swapoff /dev/ada0p*
doas gpart resize -i * -a 4K -s 16G -f C ada0
```

Where `*` is the partition number, as shown in `gpart show ada0`, or given from the output of something like:
`swapinfo | grep ada0 | cut -b 11` (if you're on GPT and swap is not a partition of a BSD slice)


----------



## poorandunlucky (Jan 19, 2018)

I have 16 GB of RAM and I think the only time swap was ever used was that time something was configured to use all of it for itself and the OS had no choice...

It's rarely ever used...  You might want to keep 2-4, maybe 5 GB of swap, depending what you're doing, for safety, but 


```
last pid: 11415;  load averages:  1.99,  2.84,  2.54                                                up 21+00:54:34  18:14:15
134 processes: 1 running, 130 sleeping, 3 zombie
CPU:  1.8% user,  0.0% nice, 11.0% system,  0.1% interrupt, 87.0% idle
Mem: 1210M Active, 4600M Inact, 330M Laundry, 9440M Wired, 271M Free
ARC: 7044M Total, 4735M MFU, 1011M MRU, 6980K Anon, 384M Header, 907M Other
     5300M Compressed, 5941M Uncompressed, 1.12:1 Ratio
Swap: 5120M Total, 275M Used, 4845M Free, 5% Inuse
```

.

That's even with kern.vm.swap_idle_enabled="1".

FreeBSD just doesn't swap stuff...


----------



## azathoth (Jan 20, 2018)

im afraid to jack my disk by reducing the swap so just guna leave it...


----------

