[Plugin] Swapfile for 6.9.1


Recommended Posts

Yeah, we actively encourage authors / maintainers to NOT publish the direct URLs and to instead install everything via Community Applications.  Then there are controls in place to ensure that you only wind up installing stuff that's compatible, works (bugs aside), and is secure.

Link to comment
4 minutes ago, tjb_altf4 said:

A general question about the filesystem swap sits on, as I need to enable this functionality very soon... as pools aren't useable for this, and I will probably add a dedicated drive for swap, is there an optimal filesystem to use for swap ?

I dont really know if one or the other filesystem performs better for swap. I am currently using btrfs and it has been working fine.

  • Thanks 1
Link to comment

I was wondering why the swap wasn't being used, seems the BTRFS file needs to have NOCOW attribute set.

This probably isn't an issue for many as they use existing share that happens to have NOCOW attribute set (and is then inherited), but might be worth explicitly setting for other cases.

 

It looks like NOCOW needs to be set on subvolume, before swapfile itself is added. ( i.e. chattr +C swapfile )

 

image.png.34982297ae003d32eb85d5c025027298.png

Edited by tjb_altf4
Link to comment
16 hours ago, tjb_altf4 said:

This probably isn't an issue for many as they use existing share that happens to have NOCOW attribute set (and is then inherited), but might be worth explicitly setting for other cases.

The plugin should already do this when creating a swapfile on a btrfs filesystem. It should create a new subvolume with the proper BTRFS attributes when the location is set to a BTRFS file system.

Link to comment
4 hours ago, primeval_god said:

The plugin should already do this when creating a swapfile on a btrfs filesystem. It should create a new subvolume with the proper BTRFS attributes when the location is set to a BTRFS file system.

Not sure what the problem was (PEBKAC probably).

I had problems initially when creating it as a subfolder of my pool, so I thought I could only create it at the root of the pool, thats where it couldn't set NOCOW.

I later created it as a subfolder again and is now working as expected.

Link to comment
4 minutes ago, wgstarks said:

Just wanted to ask, will this work on xfs? From what I'm reading it should really be a BTRFS formatted SSD but maybe I'm just not understanding the conversation.

Both this plugin and its precursor work just fine on xfs. The reason there is so much talk of BTRFS in this thread is that this newer plugin also supports BTRFS where the previous version did not. 

Edited by primeval_god
Link to comment
8 hours ago, primeval_god said:

Both this plugin and its precursor work just fine on xfs. The reason there is so much talk of BTRFS in this thread is that this newer plugin also supports BTRFS where the previous version did not. 

Does using an array share cause issues with read/write speeds? My easiest setup would be to just create a share on the unraid array but I could also attach an external drive via USB2. Both seem rather slow to me and I'm not sure if that would cause issues or not?

Link to comment
2 hours ago, wgstarks said:

Does using an array share cause issues with read/write speeds? My easiest setup would be to just create a share on the unraid array but I could also attach an external drive via USB2. Both seem rather slow to me and I'm not sure if that would cause issues or not?

Putting the swapfile on the array is not a recommended configuration. For one it will tend to keep the disk it is on spun up at all times (and thus also parity). I am not certain if the plugin code explicitly forbids the configuration but I would advise against it. I have used a USB2 flash drive for mine in the past, it works ok but the speed of the drive is not great. In such a configuration i recommend settings swappiness to very low or even zero so that the system will tend not to use swap unless memory pressure demands it. One other warning though, flash drives are not the highest quality flash memory and heavy swap usage on one will tend to wear it out fairly quickly (Not an issue with SSDs). 

  • Thanks 1
Link to comment
15 minutes ago, primeval_god said:

One other warning though, flash drives are not the highest quality flash memory and heavy swap usage on one will tend to wear it out fairly quickly (Not an issue with SSDs).

It wouldn’t be a flash but rather a spinner in an enclosure. I’ve got a bunch of old 3.5” drives and enclosures just laying around. Thanks for the info.

Link to comment
28 minutes ago, wgstarks said:

I’ve got this plugin setup and running. The delete swap file on stop is set to “No” by default so I left it that way. Just wanted to confirm that no is the best setting?

No is the settings that i use. As to what is the best, i am not really sure. I am not certain of the specific use-case of deleting the swapfile on stop. I am not the original author of the swapfile plugin and i am not completely familiar with the history of all of its options.

  • Thanks 1
Link to comment
  • 2 months later...

Hi there,

I've been using this and it's been working great, but I've tried to increase the size of my swap file and it just gets stuck loading.

Checking syslog, it looks like it times out after 3 minutes. 

Is there any way to increase the timeout?

 

Feb 13 11:39:32 NAS rc.swapfile[8110]: New swap file configuration is being implemented
Feb 13 11:39:32 NAS rc.swapfile[8123]: Restarting swap file with new configuration ...
Feb 13 11:41:10 NAS rc.swapfile[10902]: Swap file /mnt/cache/swap/swapfile stopped
Feb 13 11:41:10 NAS rc.swapfile[10904]: Swap file /mnt/cache/swap/swapfile removed
Feb 13 11:41:13 NAS rc.swapfile[11070]: Creating swap file /mnt/cache/swap/swapfile please wait ...
Feb 13 11:44:13 NAS nginx: 2022/02/13 11:44:13 [error] 19957#19957: *933134 upstream timed out (110: Connection timed out) while reading upstream, client: 10.8.0.2, server: , request: "POST /update.htm HTTP/2.0", upstream: "http://unix:/var/run/emhttpd.socket:/update.htm", host: "192.168.8.9", referrer: "https://192.168.8.9/Settings/swapfile"

 

Link to comment

As a work around I've just run the commands from the script manually in the terminal.

 

dd if=/dev/zero of=/mnt/cache/swap/swapfile bs=1M count=32768
btrfs property set /mnt/cache/swap/swapfile compression none
mkswap -L swapfile /mnt/cache/swap/swapfile
chmod 600 /mnt/cache/swap/swapfile
swapon -v /mnt/cache/swap/swapfile

 

Link to comment
11 hours ago, gamerkonks said:

Is there any way to increase the timeout?

 

No.  It's hardcoded into the WebUI at 120seconds.  The next release is increasing the timeout to 5 minutes.  Any plugin where its possible for a request to take longer than the timeout has to account for that and program itself accordingly.

 

Note that even with the timeout the command(s) were still continuing while you are on that page.  IE: the script would have finished, but the spinner would never have disappeared

Link to comment
25 minutes ago, Squid said:

Note that even with the timeout the command(s) were still continuing while you are on that page.  IE: the script would have finished, but the spinner would never have disappeared

 

I would've thought so, and I did leave it for a while, but I saw that the activity on the cache drive stopped and the size of the swap file was no longer increasing, so something must've stopped.

Link to comment
6 minutes ago, Tjareson said:

Is there any way I can install this app directly via URL? Background is: I'm trying to get an old server up and running with unraid. But with this server I do not have enough memory to load the apps via the community app. So getting the app installed directly would be worth a try. 

https://raw.githubusercontent.com/dcflachs/swapfile_plugin/master/swapfile.plg

  • Thanks 1
Link to comment

Quick feedback about how it went with the plugin and swapfile in general on a really limited system (1GB, 1 SSD 400GB and 3 x 1,5TB)
Maybe it is useful for others trying to use unraid on really small/old systems.


- I had to install 6.9.1 as 6.9.2 already gets into memory deadlock when just booting first time. 
- I stopped docker and vm to release some additional memory during the swap setup, but: I wasn't able to generate the swapfile with the plugin unfortunately as somehow generating the swapfile alone is consuming so much memory that the process gets killed early. (not visible on the gui, it is just stuck in the apply situation...)
Also I wasn't able to use a swapfile on btrfs, because swapon always came back with wrong attributes error or similar. 

 

What I did to make swap work:
1.  Format ssd cache drive with xfs

2. fallocate  -l 4096M /mnt/cache/swapfile

3. mkswap /mnt/cache/swapfile

4. chmod 600 /mnt/cache/swapfile

5. swapon swapfile

 

As the swap is on an ssd it works quite well. Also docker containers (like logitech mediaserver) are running at sufficient speed. 

 

The only "issue" I would need to solve now, is to automatically issue a swapon command after the array starts and vice versa a swapoff before the array gets stopped. 

Any ideas where to implement that ideally? 

 

I think it would be great to somehow make it a bit easier to activate swap in Unraid in general. Maybe also in an early boot phase. (as it looks  this system is stuck with 6.9.1 due to memory requirements during boot already - does anyone know more details on that part?) That would reanimate a lot of existing hardware which cannot be used anymore because the vendors are not providing any updates anymore or it is outdated somehow otherwise. Personally I always feel bad to dispose otherwise well working hardware because of a software issue... It would be great if Unraid could further help to reduce that early hardware retirement trend.

 

Link to comment

The official minimum for any of the 6.9+ releases is 2GB RAM.  The functional minimum is 4GB.  You're just not going to be able to use the OS with 1GB as anything more than a pure file server (if it works at all), so I don't really get why you would require a swapfile to begin with.    This isn't a "software" issue, but rather a "hardware" issue.  You're not meeting the minimum requirements.

Link to comment
30 minutes ago, Squid said:

The official minimum for any of the 6.9+ releases is 2GB RAM.  The functional minimum is 4GB.  You're just not going to be able to use the OS with 1GB as anything more than a pure file server (if it works at all), so I don't really get why you would require a swapfile to begin with.    This isn't a "software" issue, but rather a "hardware" issue.  You're not meeting the minimum requirements.


Well, my experience here is just diffferent. It works at all and more than a pure file server.  Obviously linux brings along options to make Unraid fit on platforms below these minimum requirements. I don't get why insisting on hardware RAM if a swapfile is compensating for it with acceptable speed, as long as an SSD is used. 
Of course it  doesn't make a lot of sense to replace VM memory with swap files. But the ability to use docker containers (like logitech mediaserver here right now) is already good enough. And it is responsive. 
So why I would require a swapfile is clear: just to keep my old hardware longer deployed. Upside for Unraid is: I will buy another license for that box as well. And only the swapfile paves the way for that additional license revenue, as I cannot upgrade the onboard memory. Upside overall: We safe ressources on producing new hardware, as long as we can find smart solutions to continue using existing one.

 

Link to comment
10 minutes ago, Tjareson said:

So why I would require a swapfile is clear: just to keep my old hardware longer deployed.

May I ask about what hardware are we talking about?

I think every x64 CPU is capable of running 4GB of memory even really old ones...

 

Even if we are talking about DDR2 you can get a kit of 2x2GB on Amazon for about $20,-

The same applies for a single DDR2 4GB stick (but I'm not to sure if a single stick 4GB DDR2 will work on every motherboard from that time).

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.