Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3552

Troubleshooting • Re: Critical shortage of swap space - pi5

$
0
0
I have just set up two new Pi 5s headless. I plan to use them as DHCP/DNS servers, with one being an internal web site for building monitoring and nagios, and the other as a NAS server with an attached WD external drive.

unit 1 has DNSMasq,apache2, nagios, VNC
unit 2 has DNSMasq, apache2, NAS, VNC

After a week or two, I am getting 'SWAP CRITICAL - 1% free (0 MB out of 99 MB)' messages from nagios.

Here is the output of htop:

Code:

  0[                                                                                         0.0%] Tasks: 95, 121 thr, 125 kthr; 1 running    1[                                                                                         0.0%] Load average: 0.52 0.27 0.12    2[***************************************************************************************100.0%] Uptime: 11 days, 17:49:35    3[                                                                                         0.0%]  Mem[|||||||||||||||||||||||||||||||||||||||||||||                                      415M/3.95G]  Swp[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||86.7M/100.0M]  [Main] [I/O]    PID USER PRI  NI  VIRT   RES   SHR S  CPU%-MEM%   TIME+  Command 327727 root 20   0  8704  3584  2048 R  44.4  0.1  0:00.04 htop -C      1 root        20   0  165M 10384  6656 S   0.0  0.3  0:32.15 /sbin/init splash    308 root        20   0 83696 17232 16208 S   0.0  0.4  0:43.67 /lib/systemd/systemd-journald    344 root        20   0 26608  5072  3536 S   0.0  0.1  0:01.55 /lib/systemd/systemd-udevd    642 systemd-ti  20   0 90944  4608  4608 S   0.0  0.1  0:02.35 /lib/systemd/systemd-timesyncd    664 systemd-ti  20   0 90944  4608  4608 S   0.0  0.1  0:00.00 /lib/systemd/systemd-timesyncd    675 root        20   0  232M  6656  5120 S   0.0  0.2  0:07.93 /usr/libexec/accounts-daemon    685 avahi       20   0  7760  2560  2048 S   0.0  0.1  0:45.84 avahi-daemon: running [Pi-Master-2211.local]    688 root        20   0  6880  2048  2048 S   0.0  0.0  0:00.97 /usr/sbin/cron -f    689 messagebus  20   0 10144  3584  2560 S   0.0  0.1  0:07.63 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only    700 root        20   0 34016  6144  5120 S   0.0  0.1  0:01.25 /lib/systemd/systemd-logind    701 nobody      20   0  6032  2048  2048 S   0.0  0.0  0:03.33 /usr/sbin/thd --triggers /etc/triggerhappy/triggers.d/ --socket /run/thd.socket --user nobody --deviceglob /dev/input/event*    703 root        20   0  387M  7168  6144 S   0.0  0.2  0:00.83 /usr/libexec/udisks2/udisksd    707 avahi       20   0  7424  1536  1024 S   0.0  0.0  0:00.00 avahi-daemon: chroot helper    732 root        20   0  232M  6656  5120 S   0.0  0.2  0:07.65 /usr/libexec/accounts-daemon    800 root        20   0  387M  7168  6144 S   0.0  0.2  0:00.45 /usr/libexec/udisks2/udisksd    816 root        20   0  257M  9216  7680 S   0.0  0.2  1:00.24 /usr/sbin/NetworkManager --no-daemon    821 root        20   0  387M  7168  6144 S   0.0  0.2  0:00.01 /usr/libexec/udisks2/udisksd    823 root        20   0  232M  6656  5120 S   0.0  0.2  0:00.04 /usr/libexec/accounts-daemon    851 root        20   0  244M  6656  5632 S   0.0  0.2  0:00.08 /usr/sbin/ModemManager    855 root        20   0  244M  6656  5632 S   0.0  0.2  0:00.00 /usr/sbin/ModemManager    856 root        20   0  387M  7168  6144 S   0.0  0.2  0:00.00 /usr/libexec/udisks2/udisksd    858 root        20   0  244M  6656  5632 S   0.0  0.2  0:00.02 /usr/sbin/ModemManager    862 root        20   0  387M  7168  6144 S   0.0  0.2  0:00.00 /usr/libexec/udisks2/udisksd    864 root        20   0  257M  9216  7680 S   0.0  0.2  0:06.54 /usr/sbin/NetworkManager --no-daemon    865 root        20   0  257M  9216  7680 S   0.0  0.2  0:01.25 /usr/sbin/NetworkManager --no-daemon    886 root        20   0  300M  5632  4608 S   0.0  0.1  0:00.07 /usr/sbin/lightdm    902 root        20   0  300M  5632  4608 S   0.0  0.1  0:00.00 /usr/sbin/lightdm    904 root        20   0  300M  5632  4608 S   0.0  0.1  0:00.04 /usr/sbin/lightdm    988 dnsmasq     20   0 15296  2064  2048 S   0.0  0.0  0:44.31 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service --trust-anch   1014 root        20   0 16704  5120  4608 S   0.0  0.1  0:01.35 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups   1052 mysql       20   0 1256M 39456  4608 S   0.0  1.0  0:45.85 /usr/sbin/mariadbd   1511 colord      20   0  238M  9216  7168 S   0.0  0.2  0:00.23 /usr/libexec/colord   1534 root        20   0  158M  5120  5120 S   0.0  0.1  0:00.01 lightdm --session-child 10 14   1569 colord      20   0  238M  9216  7168 S   0.0  0.2  0:00.00 /usr/libexec/colord   1571 colord      20   0  238M  9216  7168 S   0.0  0.2  0:00.05 /usr/libexec/colord
Originally it had 93.4% swap, but I deleted apache2, polkitd, vncserver, and bluetooth since they are not currently being used, which brought it down to the above size.

Now, I really don't understand why it is using swap at all. Forgive me, I am an old mainframe man, but swap to me is virtual memory on disk that is use to page out unused threads when you run out of real memory. The system is using 415MB our of 3.95 GB so that is not happening.

Also, the swap is happening on the SD card, which is certainly not a good idea.

Any help appreciated!

cheers,
Nigel
I recommend disabling the 100MB swap file on Raspberry Pi OS and creating a swap partition that is 1.5 times the size of RAM. On a 8GB Pi 5 that would be a 12GB swap partition.

My opinion is swapping to a file is likely to cause filesystem corruption for the main reason that people tend to hard reset their systems if they start thrashing too much and it's a bad idea to hard reset a system that is doing lots of filesystem input and output.

While it's true that SD cards make poor swap devices, a swap partition also serves as a source of blocks for automatic flash-memory wear leveling. In particular, an unused 12GB swap partition is not a waste of space but rather a resource for wear leveling.

My preference is swap to an iSCSI network block device from a target on a NAS. If your Pi is wired to gigabit Ethernet that is faster than an SD card.

Statistics: Posted by ejolson — Thu Apr 18, 2024 11:41 pm



Viewing all articles
Browse latest Browse all 3552

Trending Articles