Changing the Swap file(s) ?

Status
Not open for further replies.

Sir.Robin

Guru
Joined
Apr 14, 2012
Messages
554
I found this on a blog:

FreeNAS by default creates a swap partition on each drive, and then stripes the swap across them so that if any one drive fails there’s a chance your system will crash. We don’t want this.

System, Advanced…

Swap size on each drive in GiB, affects new disks only. Setting this to 0 disables swap creation completely (STRONGLY DISCOURAGED). Set this to 0.

Open the shell. This will create a 4GB swap file (based on https://www.freebsd.org/doc/handbook/adding-swap-space.html)

Code:
dd if=/dev/zero of=/usr/swap0 bs=1m count=4096 chmod 0600 /usr/swap0



System, Tunables, Add Tunable.

Variable=swapfile, Value=/usr/swap0, Type=rc.conf


Can someone with the knowledge on this please explain? Is this true and should one do this?
 
Last edited:

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
I found this on a blog:

FreeNAS by default creates a swap partition on each drive, and then stripes the swap across them so that if any one drive fails there’s a chance your system will crash. We don’t want this.

System, Advanced…

Swap size on each drive in GiB, affects new disks only. Setting this to 0 disables swap creation completely (STRONGLY DISCOURAGED). Set this to 0.
[CO
Open the shell. This will create a 4GB swap file (based on https://www.freebsd.org/doc/handbook/adding-swap-space.html)

Code:
dd if=/dev/zero of=/usr/swap0 bs=1m count=4096 chmod 0600 /usr/swap0



System, Tunables, Add Tunable.

Variable=swapfile, Value=/usr/swap0, Type=rc.conf


Can someone with the knowledge on this please explain? Is this true and should one do this?

Yes, if you're an idiot or a moron.

A properly sized FreeNAS system normally shouldn't be pushing anything out to swap. It'll primarily use swap if it is doing a pool import and has to resolve a mess.

The rest of the time, creating a 4GB swap file is a stupid thing to do... add 4GB of RAM instead, it'll increase your virtual memory by the same amount but IT WILL ALSO BE USEFUL.

Code:
last pid: 46942;  load averages:  0.00,  0.00,  0.00   up 15+19:28:57  13:55:10
65 processes:  1 running, 63 sleeping, 1 stopped
CPU:  0.0% user,  0.0% nice,  0.0% system,  0.0% interrupt,  100% idle
Mem: 390M Active, 159M Inact, 24G Wired, 1792K Cache, 6601M Free
ARC: 21G Total, 15G MFU, 6685M MRU, 288K Anon, 98M Header, 70M Other
Swap: 24G Total, 24G Free


Nothing in swap.

Code:
last pid: 66731;  load averages:  1.02,  0.99,  0.92   up 129+05:14:45 13:55:29
42 processes:  2 running, 40 sleeping
CPU:  3.9% user,  0.0% nice, 29.3% system,  0.6% interrupt, 66.2% idle
Mem: 619M Active, 916M Inact, 5985M Wired, 155M Cache, 432M Buf, 231M Free
Swap: 8192M Total, 6096K Used, 8186M Free


6M of stuff in swap, but the poor little devil is heavily beat-upon, only has 8GB RAM, and I occasionally do other nasties. Were some of the underlying swap to fail, then, yes, it is indeed possible that some of the userland daemons would crash. Look at the load and the uptime.

A non-idiot would leave the partitioned swap space alone. It's there for multiple reasons, including to act as slush space in the event a ZFS replacement drive is a tad bit smaller than an old drive. Instead you could set the tunable "vm.swap_enabled=0".
 

Sir.Robin

Guru
Joined
Apr 14, 2012
Messages
554
Sweet... :)

So what he does is just createing a file on the pool for swap then?
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
No, he's creating it on the USB. Which is really duhhhhh-mb. All the average USB device needs is further writes being thrown at it, especially at the rate pagedaemon will do it.
 

Sir.Robin

Guru
Joined
Apr 14, 2012
Messages
554
Can you instead create it on a pool and larger... and if so, would it still be better to leave it alone?

What cli command did you use to display the system info you posted?

:)
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Can you instead create it on a pool and larger... and if so, would it still be better to leave it alone?

The time you're most likely to need swap is during the pool import operation, where by definition you don't have a pool available for such use, because you're trying to clean it up to mount it and make it usable.

It would be theoretically possible to use a ZFS pool for swap after that point, but usually after that point you no longer need swap.

What cli command did you use to display the system info you posted?

:)

top
 

Sir.Robin

Guru
Joined
Apr 14, 2012
Messages
554
Thanx for clearing it up for me. Should have known about top from before thoug... :oops:
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
And just to be extra clear, on re-reading, the point is that adding 4GB of swap to your USB device isn't as useful as just adding another 4GB of RAM. Adding the RAM means the system can be using that for ARC and probably improves overall system performance.

If you see the system doing swapping, this is a clue that you should contemplate adding RAM. Especially with something like jails, you can find yourself unexpectedly undersizing a FreeNAS system...
 

reqlez

Explorer
Joined
Mar 15, 2014
Messages
84
He's not creating it on USB... Usually ( I do ) is to create an SSD mirror boot for freenas. But ... I can tell you this: I have had like 3 cases already where a mirror ZFS drive in freenas failed and the freenas system crashes due to errors reading from swap ... i'm not cool with that. Somebody said that in freenas 10 the swap will be mirrored by default, but until then ... I have no choice but to use that procedure of setting the number to "0" in advanced settings and creating a swap file and placing it on the ZFS boot volume. Yes, creating the swap file on USB would be very stupid because I don't even use USB devices anymore to boot freenas because since 9.3 using USB drives for boot it asking for weekly "rebuilds" and other stuff happening to your boot volume.

And just so you know, the systems that crashed from swap errors were given 8GB RAM and they only were storing 2TB of data, so i know freenas wants to use swap anyway ... why ? beats me.
 

rogerh

Guru
Joined
Apr 18, 2014
Messages
1,111
I've never seen my FreeNAS system (16GB RAM) using swap, but non-redundant swap seems unfortunate. Could the ZFS filesystem be corrupted by a single swap bit error, or would it take more than one coincident error - which could of course occur if a drive failed?
 

reqlez

Explorer
Joined
Mar 15, 2014
Messages
84
I've never seen my FreeNAS system (16GB RAM) using swap, but non-redundant swap seems unfortunate. Could the ZFS filesystem be corrupted by a single swap bit error, or would it take more than one coincident error - which could of course occur if a drive failed?
I don't really want to find out, so until Freenas 10 or unless somebody has a good explanation as to why me using swap on ZFS is a worse idea than my system crashing because I "don't " do it ... I'll just keep doing it ;-)
 

reqlez

Explorer
Joined
Mar 15, 2014
Messages
84
Okay I should probably expand on this:

I have heard from people saying that when you use swap on a ZFS volume, you can potentially starve the system and crash it when there are those "low resources" situations because now swap is being used due to low memory and ZFS has no memory to work so in turn it can't use swap... Great. But... I rather take my chances on a "potential" issue by using swap on my ZFS SSD mirror than a "confirmed" system crash by NOT using swap on ZFS mirror. You see my logic here ? Potential ? Versus confirmed ?

And I never see those systems use swap either, I've monitored them and they never seem to use swap, but of course during that hard drive crash it still complains about read error page in and crashes. Maybe FreeBSD is like Microsoft ? Uses a small amount of swap anyway for some stuff even tho it has resources not to ?
 

reqlez

Explorer
Joined
Mar 15, 2014
Messages
84
I've never seen a system do what you describe.
Look at the logs this guy posted: https://forums.freenas.org/index.ph...ch-one-error-messages-need-more-detail.36975/

Clearly you can see swap errors afters drive fell out of the array.

"
  1. Sep 2 02:06:34 freenas swap_pager: I/O error - pagein failed; blkno 2621777,size 4096, error 6
  2. Sep 2 02:06:34 freenas vm_fault: pager read error, pid 1374 (devd)
  3. Sep 2 02:06:34 freenas (ada5:ahcich5:0:0:0): Periph destroyed
  4. Sep 2 02:06:34 freenas swap_pager: I/O error - pagein failed; blkno 2621777,size 4096, error 6
  5. Sep 2 02:06:34 freenas vm_fault: pager read error, pid 1374 (devd)
  6. Sep 2 02:06:34 freenas kernel: Failed to write core file for process devd (error 14)
  7. Sep 2 02:06:34 freenas kernel: Failed to write core file for process devd (error 14)
  8. Sep 2 02:06:34 freenas kernel: pid 1374 (devd), uid 0: exited on signal 11"

    so it's not just me !
 

Scharbag

Guru
Joined
Feb 1, 2012
Messages
620
I believe that the reference post assumes that you are booting FreeNAS from at least 1, if not 2, SSDs that are used as datastores in ESXi.

I hot-swap drives all the time and I really never want to get bitten by having swap files on the drive that I removed. There is also a groovy script to page-in swap periodically (I really should have given props to Stux at this point, but he came through!!).

Now, what I need to find out, is how do I remove swap from drives in a pool.

Cheers,
 
Last edited:

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
I believe that the reference post assumes that you are booting FreeNAS from at least 1, if not 2, SSDs that are used as datastores in ESXi.

I hot-swap drives all the time and I really never want to get bitten by having swap files on the drive that I removed. There is also a groovy script to page-in swap periodically.

Now, what I need to find out, is how do I remove swap from drives in a pool.

Cheers,

Groovy swap script:
https://forums.freenas.org/index.ph...ny-used-swap-to-prevent-kernel-crashes.46206/
 
Status
Not open for further replies.
Top