[swapper] Virtual Memory

Black Hole

May contain traces of nut
This package doesn't seem to have an existing dedicated topic, so here it is! Note: introductory post updated to reflect later discussion.

swapper
provides HDR-FOX with virtual memory to supplement the existing (limited) RAM. This is of general benefit for WebIF processing options, but particularly youtube-dl / qtube users, where the processing chain is likely to crash because of the RAM limitations. swapper invokes a swap file on the HDD (HDR-FOX). swapper is installed automatically, as an indirect dependency of web-if.

swapper is not currently compatible with HD-FOX (despite being installed automatically). However, it can be tweaked for HD-FOX – see post 2.

If you find a process is still running out of RAM, the swap space (128MB as standard) can be permanently increased by another tweak – see post 5.
 
Last edited:
The youtube-dl package runs into trouble if the download is too large, particularly on HD-FOX, because the ffmpeg clean-up runs out of memory. swapper is useful here, by making virtual memory available, but is not (in original form) compatible with the HD-FOX (due to any available disk space being external on USB). Instructions for manual set-up have been provided:
Code:
humax# free -m
humax# dd if=/dev/zero of=/media/drive1/.swap0 bs=1M count=128
humax# mkswap /media/drive1/.swap0
humax# swapon /media/drive1/.swap0
humax# free -m
and to get rid of it again:
Code:
humax# swapoff /media/drive1/.swap0
humax# rm /media/drive1/.swap0

...but a modification to the swapper package itself has been proposed, which will make manual set-up on the HD-FOX (repeated after every reboot) unnecessary:
Permanent fix:
Code:
--- /mod/etc/init.d/S00swapper~
+++ /mod/etc/init.d/S00swapper
@@ -1,8 +1,7 @@
#!/bin/sh

-[ "`cat /etc/model`" = "HDR" ] || exit 0
-
swapfile=/mnt/hd3/.swap0
+[ "`cat /etc/model`" = "HD" ] && swapfile=/media/drive1/.swap0

case "$1" in
     start)

My question is: has this been incorporated into the package yet?
 
A recent indication that ffmpeg was running out of memory when patching up a youtube-dl download, even with swapper installed, led me to investigate increasing the size of the swap file:
The swapper package sets up swap space each boot (128MB), but equally the swapper thread demonstrates how to set up a 128MB swap manually, which can be adapted to to 256MB or whatever you like (but needs turning on again after boot). So, to make it double (I guess that will be enough, considering the crash is near the end of the processing):
Code:
swapoff /mnt/hd3/.swap0
rm /mnt/hd3/.swap0
dd if=/dev/zero of=/mnt/hd3/.swap0 bs=1M count=256
mkswap /mnt/hd3/.swap0
swapon /mnt/hd3/.swap0

Google "linux help dd" for dd command explanation (like wot I just did), and you'll see that:
  • "if" means "Input File", so "=/dev/zero" means it is just sourcing a string of zero bytes;
  • "of" means "Output File", creating the .swap0 file;
  • "bs" is the number of bytes in a block;
  • "count" is the number of blocks
...in other words, it creates a 256MB empty .swap0 file on hd3 by copying that many bytes across from a null source.

The rm... command might not be strictly necessary, but I preferred to start with a clean slate.

The swapper package instates swap space each boot, but uses whatever size /mnt/hd3/.swap0 happens to be, so setting the size (as above) is a one-off operation (the default is 128MB). Just change "count=" in the commands above to however many megabytes you want.

Without swapper installed, the above commands can be used to create swap space, but the swapon command will be needed to make the swap space available after each boot.
 
In the swapper update just published, you can now set the size of the swap file by writing the desired number of MB into /mod/boot/swapsize
e.g.
Code:
humax# echo 256 >/mod/boot/swapsize
which will take effect the next time the machine is booted, or you can run /mod/etc/init.d/S00swapper stop followed by /mod/etc/init.d/S00swapper start.
If you want to go back to the default (128), then just delete the file.
 
Last edited:
Back
Top