Resource icon

How to relocate swap to the boot drive

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
Stux submitted a new resource:

How to relocate swap to the boot drive - creating a swap file, and replacing pool swap with a Post-Init command

FreeNAS by default will allocate 2GiB on each pool HD and use this as swap. Unfortunately, if a disk fails, your system may crash.

If your boot devices is more reliable than a USB, and you have the space, it may be beneficial to relocate swap to a swap file on your boot device. An alternative is to use a dedicated swap device, or partition, and that approach is...

Read more about this resource...
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
I'm having a very very easy time envisioning the type of user that this can harm. This is such an extraordinarily bad idea for some users...

I'm having an exceptionally difficult time envisioning the type of user that this would help, *who would need a resource* to accomplish it.

So while it's well written etc, as usual, Stux, I'm not sure I'd have it as a resource.

But of course, I am an extremely strong believer that "more information" isn't necessarily "better", and I prefer to protect the user from himself, whenever possible.
 

m0nkey_

MVP
Joined
Oct 27, 2015
Messages
2,739
What @DrKK has said is quite fair. My concern is somebody applying this and then not being able to boot by either a typo or a copy/paste gone wrong.

Just an idea, maybe put a big red warning at the top of the resource saying something along the lines of: WARNING, this is an advanced how-to. Do not apply if you are not familiar with FreeBSD or FreeNAS. Advanced users only.
 
Last edited:

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
Just an idea, maybe put a big red warning
You know, Jordan taught me this:

If you have to put a big red sign, or a bunch of arrows, so the user does not F himself? The problem isn't the user, it's what you decided to expose to the user.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
If you have to put a big red sign, or a bunch of arrows, so the user does not F himself? The problem isn't the user, it's what you decided to expose to the user.
Can't agree here. "Unix was not designed to stop you from doing stupid things, because that would also stop you from doing clever things."
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
The procedure is actually relatively safe as far as these things go.

There are no permanent changes. Disabling/reverting is a GUI action.

The only dangerous thing is a dd command, and plenty of guides use dd in much more dangerous fashion.

The real risk is someone deciding to do this to their USB/SATADOM disk. And I warn against that.
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
I'm having an exceptionally difficult time envisioning the type of user that this would help, *who would need a resource* to accomplish it.

Btw, there is a lot of advise out there on how to do this, and most of the techniques are far more dangerous, have undisclosed side/effects, or don't actually accomplish the goal.

This does, has minimal side effects, almost zero chance of loss of data, and is a temporary re-enabled at boot time.

I believe it is better to have correct/critiqued instructions (go ahead) in one place than to just trust that people will know better than to follow random instructions found on random blogs.
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
"Unix was not designed to stop you from doing stupid things,
We're not UNIX. We're not BSD. At the level that this thing addresses, we are purveyors of an APPLIANCE.

But whatever, I think Stux has valid points, the risk of damage is minimal. My main argument is that there is a low probability that anyone that could even identify that they need to do this, would then need a "resource" for it; such a person would be able to figure it out without our critiqued instructions.
 

Marco Ertel

Dabbler
Joined
Apr 13, 2016
Messages
28
Hi,
I used your script as one or two times a week I am running out of RAM (16GB with 16TB Disks). My assumption is that happens during heavy load over samba from my windows machines. My boot device is a SSD so that should not be a problem. I created it with 24G
But now the machine crashes sometimes and in the messages I see the following:

...freenas swap_pager: indefinite wait buffer: bufobj: 0, blkno: 202914 size:8192

And directly before the machine goes down I see in the Physical memory utilization that the Wired and Inactive memory is going down very fast and slightly later the (before the reporting chart stops completely) Active memory goes down.
But swap seems to be completely unused.
Before I used your script to increase the swap I had the standard 8G of swap where I was able to see that the swap is sometimes used (which is now not longer the case)
This comes then in many lines with different sizes.
Do you have an idea?
Thanks and Kind Regards,
Marco
 
Last edited:

wblock

Documentation Engineer
Joined
Nov 14, 2014
Messages
1,506
This should be addressed with greater caution and a lot more warnings at the start. Like:

PLEASE DO NOT DO THIS UNLESS YOU CANNOT ADD MORE RAM.
PLEASE ADD MORE RAM INSTEAD OF DOING THIS.
If you think you need this, you almost certainly need more RAM instead.
This is not a cure, it is a work-around.
Doing this will make your system non-standard and could cause unexpected and mysterious, hard-to-debug problems later.
Even if you cannot add more RAM, please consider whether you have the ability to debug this non-standard configuration later when it jumps out and surprises you or someone else.


As far as the process, it might be possible to use truncate rather than dd, but I can't recall if it creates sparse files by default (sparse files as a swap file is a bad, bad idea).

Swap files rather than swap partitions have mixed value, too. A swap partition would be better, but that would be even more dangerous to the existing configuration on the boot device.
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
I'm really curious as to why anyone would need to do this?

IF swap even comes into play what's wrong with having it on the pool drives?

The argument about having swap space on the pool drives (to make up for slight differences in drive size if a drive needs to be replaced) was quite compelling.
 

SweetAndLow

Sweet'NASty
Joined
Nov 6, 2013
Messages
6,421
I'm really curious as to why anyone would need to do this?

IF swap even comes into play what's wrong with having it on the pool drives?

The argument about having swap space on the pool drives (to make up for slight differences in drive size if a drive needs to be replaced) was quite compelling.
If you have a disk failure and swap is being used it will bring down the whole system.
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
If you have a disk failure and swap is being used it will bring down the whole system.
Can you please expand?

If having the swap on the boot drive is a benefit to stability, why would the system distribute the swap area over multiple drives?
(Or is this an artefact of using USB drives as boot drives? It seems am SSD is now recommended with the switch to a ZFS boot drive)

If this does improve stability, are changes planned?
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Can you please expand?
What's to expand? If the system has swapped data out to a disk, and that disk fails, the system goes down the next time it tries to swap that data back into RAM.
why would the system distribute the swap area over multiple drives?
For the "quite compelling" reason you noted above--the purpose isn't really for the sake of having swap (though swap is a good thing to have), but to give a bit of a buffer to allow for replacement disks of slightly different capacities.
are changes planned?
Yes; IIRC, 11.1 is supposed to include mirrored swap, which should pretty much render this resource pointless. Though it's unclear if it will mirror swap on an existing pool, or only on newly-created pools.
 

NASbox

Guru
Joined
May 8, 2012
Messages
650
Yes; IIRC, 11.1 is supposed to include mirrored swap, which should pretty much render this resource pointless. Though it's unclear if it will mirror swap on an existing pool, or only on newly-created pools.
It would be great if someone from the dev team could comment. I'm going to have to recreate my main pool very soon, and if waiting for 11.1 would make a difference then I'd like to know.
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
Hi,
I used your script as one or two times a week I am running out of RAM (16GB with 16TB Disks). My assumption is that happens during heavy load over samba from my windows machines. My boot device is a SSD so that should not be a problem. I created it with 24G
But now the machine crashes sometimes and in the messages I see the following:

...freenas swap_pager: indefinite wait buffer: bufobj: 0, blkno: 202914 size:8192

And directly before the machine goes down I see in the Physical memory utilization that the Wired and Inactive memory is going down very fast and slightly later the (before the reporting chart stops completely) Active memory goes down.
But swap seems to be completely unused.
Before I used your script to increase the swap I had the standard 8G of swap where I was able to see that the swap is sometimes used (which is now not longer the case)
This comes then in many lines with different sizes.
Do you have an idea?
Thanks and Kind Regards,
Marco

The move swap to boot script or the page-in swap script?
 

Stux

MVP
Joined
Jun 2, 2016
Messages
4,419
Currently, on bootup, FreeNAS discovers all the pool swap partitions and then sets them up as striped swap.

It should work the same in future except as mirrored swap.

Ie, the swap type is not stored on the partition and is recreated imperitively each boot up.

</conjecture>
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
11.1 should indeed support mirrored swap.
 

Marco Ertel

Dabbler
Joined
Apr 13, 2016
Messages
28
The move swap to boot script or the page-in swap script?
Hi,
I moved the swap to boot.
Now I did some more tests with the "stress" tool. At first I used the default swap (2Gb per Disk for me which means 8GB at all).
I increased the "--vm-bytes" parameter each run to fill the 8GB swap. In the last run it was too much for the machine- I got something like:
swap_pager_getswapspace(16): failed
Then the machine was no longer reachable- which surprised my as my understanding of the alloc mechanism is that it will get memory as long as possible but if not possible it will not give the "stress" process any more. But here it was easy to stop the machine completely with that application in userspace (in a jail)
Then I did the same after creating the swap on my boot device (SSD). Here it took really long before it started with putting data on the swap and the machine had then very long response times but worked all the time. I only got then sometime the following messages:
swap_pager: indefinite wait buffer: bufobj: 0, blkno: 202914, size: 8192

So both not optimal (yes putting in more RAM might be the alternative but not right now because of the money ;-)) but the swap on the SSD seems to be slightly more stable. But even there sometimes the machine was no longer reacting.

Kind Regards,
Marco
PS Hardware:
MB Fujitsu 3417-B
16GB ECC RAM
4*4TB HD
256MB Boot SSD
Processor Intel Xeon E3-1225V5
 
Last edited:

LIGISTX

Guru
Joined
Apr 12, 2015
Messages
525
With 11.1, I assume this is a bit moot? I have this set up, but I am thinking I may want to revert it.

Thoughts?
 
Top