Hello, a simple question. I have an hAP ax³ with 1 GB memory. I have set up Pi-hole and Unbound containers. Now I am considering adding some others (Uptime-kuma, …). Of course the memory might saturate. So I have set up a swap space on my USB 3.2 thumbkey. Do you have any experience with the efficiency of the swap system ? Can it effectively be used or is it too slow in the real life ?
How well swap performs severely depends on the workload. When there is lots of memory that is allocated but not frequently used, it works well. In situations where all the memory is frequently used, it doesn’t.
There is not much that can be predicted, you need to try and find out. Remember on a demand-paged system there is not only the swapping of data memory, but also the reading of programs into memory isn’t “the entire program read and kept in memory” but only the parts of the program that are actually running are in memory, the rest can be discarded and read back as needed. So it may be that your swap isn’t really required but the performance still gets worse when you use more memory than you have.
Ok. I stop adding containers. I’m asking too much from that poor stressed router.
Is it already stressed? Did you check that?
I tried to install Uptime-kuma (in addition to Pi-Hole and Unbound) and it crashed twice before I could reach the UI. So I figured I would stop torturing it.
Yes for sure there is a limit to what you can do. If needed you can add a Raspberri Pi or similar SBC.
It's only 4core CPU.
Routing+firewall workload, containers workload ... I would not expect that everything would work smoothly.
Since I was giving a similar project a try, I thought I'd offer some feedback on the efficiency of the swap function.
So right now I'm running AdGuardHome+Redis+Unbound in a single container. I've initially used a flashdrive, but since I still had SSDs in NVMe enclosures lying around, I wanted to give the whole thing a proper chance.
So right now, with 1.1 million entries in my blocklist, Winbox shows me 431 MB free memory on my RB5009. This is what top insidie the container looks like:
Mem: 665000K used, 335500K free, 1000K shrd, 14656K buff, 221076K cached
CPU: 0% usr 0% sys 0% nic 99% idle 0% io 0% irq 0% sirq
Load average: 0.09 0.25 0.40 3/161 32
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
2 1 root S 1435m 146% 2 0% /opt/AdGuardHome/AdGuardHome -c /config/AdGuardHome/AdGuardHome.yaml -w /config
12 2 root S 25780 3% 1 0% redis-server 127.0.0.1:6379
13 2 unbound S 113m 12% 0 0% unbound -d -c /config/unbound/unbound.conf
30 0 root S 1760 0% 1 0% /bin/sh
32 30 root R 1688 0% 2 0% top
1 0 root S 836 0% 3 0% /sbin/tini -- /entrypoint.sh
For testing purposes, I've tripled the amount of entries in the blocklist to 3.0 million entries. Even with swap enabled as a partition on the flashdrive, the whole router would crash. Hell, even with 2.0 million entries, DNS lookup would become very slow and the whole WebUI would freeze and lag.
Now with everything on the SSD, AdGuardHome can handle even such a massive list without lagging in the WebUI (as it did before on the flashdrive) and WinBox reports free memory down to 387 MB. Top in the container looks like this:
Mem: 634980K used, 365520K free, 4K shrd, 2140K buff, 35488K cached
CPU: 0% usr 0% sys 0% nic 98% idle 0% io 0% irq 0% sirq
Load average: 0.56 0.51 0.48 3/161 32
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
2 1 root S 2025m 207% 2 0% /opt/AdGuardHome/AdGuardHome -c /config/AdGuardHome/AdGuardHome.yaml -w /config
12 2 root S 25780 3% 1 0% redis-server 127.0.0.1:6379
13 2 unbound S 113m 12% 0 0% unbound -d -c /config/unbound/unbound.conf
30 0 root S 1760 0% 1 0% /bin/sh
32 30 root R 1692 0% 1 0% top
1 0 root S 836 0% 3 0% /sbin/tini -- /entrypoint.sh
And this is what the swap partition looks like:
SLOT MOUNT-POINT MODEL SERIAL INTERFACE SIZE FREE USE FS FS-LABEL RAID-MASTER
0 B g usb2 JMicron USB 3.1 Storage Device DD56419885036 USB 2.10 480Mbps 256 060 514 304 - none
1 BSp usb2-swap JMicron USB 3.1 Storage Device @65'536-8'000'065'536 8 000 000 000 7 921 614 848 1% - none
2 BMp usb2-container usb2-container JMicron USB 3.1 Storage Device @8'000'110'592-256'060'424'192 248 060 313 600 242 792 648 704 0% ext4 usb2-container none
So from what I can tell, ROS has successfully outsorced about 100 MB to the SWAP partition.
EDIT:
This is what it looks now:
SLOT MOUNT-POINT MODEL SERIAL INTERFACE SIZE FREE USE FS FS-LABEL RAID-MASTER
0 B g usb2 JMicron USB 3.1 Storage Device DD56419885036 USB 2.10 480Mbps 256 060 514 304 - none
1 BSp usb2-swap JMicron USB 3.1 Storage Device @65'536-8'000'065'536 8 000 000 000 7 658 422 272 4% - none
2 BMp usb2-container usb2-container JMicron USB 3.1 Storage Device @8'000'110'592-256'060'424'192 248 060 313 600 242 792 648 704 0% ext4 usb2-container none
So we're now at about 350 MB in the swap partition.
So far, everything's working vastly better than when using the flashdrive.
You mean: NVMe SSDs in USB enclosures?
Exactly!