What's new

Is a USB swap file always recommended for merlin?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Morning all from Oz. Just wanted to say thanks to everyone for all the input and views. The key points I have taken are:

1. only use usb/swap/entware/scripts if you really need to
2. if you do need, do it properly (e.g. don't use a thumb drive)

I have got by fine without scripts for the last 2 months and have been really happy with network stability. I'd have to go and buy some kit to do it properly so i'm going to press the button to eject my USB thumb drive and not use a swap file. :)
1. True
2. Not true. Use a good USB2 thumb drive
3. Use a swap file or partition equal to or smaller than the device RAM.
 
Recommended swap size = router RAM or router RAM x 2
See docs:
This seems to point to not having a big swap file for these routers but maybe it is dated. Up to 1GB of RAM, it seems to be recommending 1x, and 2x if hibernation is enabled (which doesn't happen here).

I'm sort of coming around to the no-swapfile view. Or at least small swapfile.

Also, it isn't clear to me that the wear leveling algorithms kick in for an SSD, if the kernel is bypassing all the file allocation processes.
 
The above three posts are using outdated information and all coming to the wrong conclusions too.

We're talking here about how Asus routers with RMerlin firmware and using multiple/various amtm-enabled scripts.

2GB is the recommended minimum swap file size if you'll be trying the available scripts (and want to just set up the swap file, once). Regardless of the router's RAM.

Still haven't seen an answer from @ColinTaylor for why a bigger swap file is such 'bad advice' and what negative implications it has on a router.

Why? Because I believe, (via direct empirical evidence), that there are no such negative implications.




 
I'm a Linux kernel dev. I haven't used swapfiles or swap partitions on anything since the year 2004 or so, except as a target for "suspend-to-disk". Outdated concept IMHO.
 
I'm a Linux kernel dev. I haven't used swapfiles or swap partitions on anything since the year 2004 or so, except as a target for "suspend-to-disk". Outdated concept IMHO.
Personally I like to use them as an "overflow" for some production servers (particularly web servers), so rather than having system processes getting randomly killed by the OOM manager, things end up temporarily on swap. System runs like molasse, but it still runs, until the memory issue gets resolved, then things get back to normal.
 
Routers still crash with swap on USB, if pushed too far.
 
Routers still crash with swap on USB, if pushed too far.
That's a very different ballgame tho. We're talking USB here, and also potential core services ending up on it, not just child Apache processes.
 
Sorry to keep pushing at this, but as we move to routers with 1 and 2 GB of memory, I am still wondering if a swap file is necessary or advisable.

If I follow, 1 GB swap file is considered the minimum for 1) diversion, 2) skynet, and 3) unbound (in rare circumstances). I suspect it is really only necessary when processing large blocklists, and not for operation otherwise. But as noted the existing of a swap file may mean core services are ending up on it.

If I follow from post #7, the reasons for a swap file are:

1. Creating the swap file via amtm is a one time event. That just means it's easy; also using a file rather than a partition means it is easy to redo.
2. There have been instances where a script needed a bigger swap file, even when it was barely used. I'm not sure where exactly those instances are.
3. And, if I'm remembering correctly, a swap file was required when previously, it wasn't. Yes, so those three scripts test for a 1GB swap file (but I think, only at installation; they seem to run without it if the swap file is downsized), and I also recall the need for this was introduced a few years ago when no routers had 1GB memory, and few had 512mb memory. The 2GB, if I recall correctly, is a minimum only in Skynet where dns is cached locally.

So the reasons for a swap file are basically because these three scripts specify it, but I'm not sure if for more recent models it remains necessary for those scripts.
 
Last edited:
2. You'll have to search for those instances (sorry, can't remember them off-hand), looking at the links I've posted may give you more search terms in Better Search to guide you).

3. Wrong.

2GB is the minimum for today's scripts. Greater than 2GB is with specific Unbound setups.

1GB RAM routers were available (and in use) when amtm was introduced.

 
3. Wrong.

2GB is the minimum for today's scripts. Greater than 2GB is with specific Unbound setups.

1GB RAM routers were available (and in use) when amtm was introduced.
Before there was amtm, there was Diversion, and before Diversion, there was Ab-solution (and before that, when it didn't yet have a name, you and I were using it with an N66 with 256mb of memory without a swapfile!). I think about 6 years ago the swapfile was introduced when @thelonelycoder and @Adamm were working out sharing whitelists between their separate scripts, perhaps while both programs were processing their blocking lists at the same time.

In the post you link to, @thelonelycoder offers the idea that 2GB or smaller is sufficient in 99% of cases.

Both skynet and diversion have the same swapfile creation process, and offer 1GB with 2GB "recommended". After installation I think skynet only tests for the existence of a swapfile and not its size, except for this bit of alternative processing of the shared whitelists:
Code:
if [ "$(cat /jffs/addons/shared-whitelists/shared-*-whitelist | wc -l)" -gt "150" ] && [ "$swapsize" -lt "1048576" ] ||
            { [ "$(cat /jffs/addons/shared-whitelists/shared-*-whitelist | wc -l)" -gt "150" ] && [ "$swapsize" -lt "2097152" ] && [ "$(nvram get dns_local_cache)" = "1" ]; }; then
            Clean_Temp
            cwd="$(pwd)"
            cd /tmp/skynet/lists || exit 1
            grep -hvF "#" /jffs/addons/shared-whitelists/shared-*-whitelist | Strip_Domain | split -l 150
            for listname in *; do
                while IFS= read -r "domain"; do
                    for ip in $(Domain_Lookup "$domain" 2> /dev/null); do
                        echo "add Skynet-Whitelist $ip comment \"Shared-Whitelist: $domain\""
                    done &
                done < "$listname"
                wait
            done | ipset restore -!
            cd "$cwd" || exit 1
        else
            grep -hvF "#" /jffs/addons/shared-whitelists/shared-*-whitelist | Strip_Domain | while IFS= read -r "domain"; do
                for ip in $(Domain_Lookup "$domain" 2> /dev/null); do
                    echo "add Skynet-Whitelist $ip comment \"Shared-Whitelist: $domain\""
                done &
            done | ipset restore -!
        fi
That's the only place I see swapsize tested in Skynet.

EDIT: I'm pushing on this because it seems the swapfile is a vulnerability. Since we know USB drives fail, and we don't know, at any given moment, what has been swapped, it seems like there is a chance the swapfile could cause the router to crash without recovery. The router is a key part of my business, and at any given moment I might be anywhere from 50 to 5,000 miles away, so this is of concern. I have three fallbacks (one of which is also behind an Asus Merlin router) just in case.
 
Last edited:
I never used any scripts with my RT-N66U (from memory). At least none by @thelonelycoder. I'm not doubting they existed and were used back then. However, we're talking about current scripts, today, in 2022.

I don't set up routers for 99% of the cases. A 2GB swap file, or larger, is required to experiment with today's scripts. And once amtm, a USB drive (thumb or SSD based), and a script is installed, it always leads to experimenting with more scripts, IME.

What I'm stating is that it doesn't matter what script tests for a swap file (or not). There are posts where a too-small swap file was deemed the fix (and the cause is 'officially' unknown).

All our electronics are a vulnerability. Using a smaller swap file isn't a fix. Using an SSD in a solid enclosure is. And if you're worried about that failing, your best option is to drop these consumer approaches to your network needs.
 
I never used any scripts with my RT-N66U (from memory). At least none by @thelonelycoder. I'm not doubting they existed and were used back then. However, we're talking about current scripts, today, in 2022.

I don't set up routers for 99% of the cases. A 2GB swap file, or larger, is required to experiment with today's scripts. And once amtm, a USB drive (thumb or SSD based), and a script is installed, it always leads to experimenting with more scripts, IME.

What I'm stating is that it doesn't matter what script tests for a swap file (or not). There are posts where a too-small swap file was deemed the fix (and the cause is 'officially' unknown).

All our electronics are a vulnerability. Using a smaller swap file isn't a fix. Using an SSD in a solid enclosure is. And if you're worried about that failing, your best option is to drop these consumer approaches to your network needs.

The 2GB swap file was a solution to the “cannot fork” errors when doing ram/cpu intensive operations despite the swap rarely being utilized around the time of the AC86U
 
@Adamm, is that solution no longer needed then today? What changed, if it is not required any more?
 
Do not create "the largest swap file possible". This is very bad advice and shows a complete lack of understanding of how virtual memory is used and the implications for the router.
I agree with this statement. If you are already to the point of swapping more than you physically have in router memory, then you are probably doing waaayy too much on the ol'router there. The point of a swap is to have a preventative measure in place for OOM situations. Basically to save everything from crashing if the applications only require "alittle" bit more juice than you have available. It is there to supplement memory, not to supplant it.
 
Sorry to keep pushing at this, but as we move to routers with 1 and 2 GB of memory, I am still wondering if a swap file is necessary or advisable.

If I follow, 1 GB swap file is considered the minimum for 1) diversion, 2) skynet, and 3) unbound (in rare circumstances). I suspect it is really only necessary when processing large blocklists, and not for operation otherwise. But as noted the existing of a swap file may mean core services are ending up on it.

If I follow from post #7, the reasons for a swap file are:

1. Creating the swap file via amtm is a one time event. That just means it's easy; also using a file rather than a partition means it is easy to redo.
2. There have been instances where a script needed a bigger swap file, even when it was barely used. I'm not sure where exactly those instances are.
3. And, if I'm remembering correctly, a swap file was required when previously, it wasn't. Yes, so those three scripts test for a 1GB swap file (but I think, only at installation; they seem to run without it if the swap file is downsized), and I also recall the need for this was introduced a few years ago when no routers had 1GB memory, and few had 512mb memory. The 2GB, if I recall correctly, is a minimum only in Skynet where dns is cached locally.

So the reasons for a swap file are basically because these three scripts specify it, but I'm not sure if for more recent models it remains necessary for those scripts.
I highly recommend a swap for adguardhome as well. Specifically because the processes that are used in the go binary to update the filterlist are not memory friendly. Essentially it causes a spike in memory usage to complete the filter update process. If there are alot of filters being used, then it can easily cause an OOM situation when no swap is present.
 
I agree with this statement. If you are already to the point of swapping more than you physically have in router memory, then you are probably doing waaayy too much on the ol'router there. The point of a swap is to have a preventative measure in place for OOM situations. Basically to save everything from crashing if the applications only require "alittle" bit more juice than you have available. It is there to supplement memory, not to supplant it.

Yeah, I agree. The largest swap file size currently available in AMTM is 10GB. There's simply no sound technical reason to have a 10GB swap on routers with 256MB, 512MB, or 1GB RAM. Having a swap file that's 40x, 20x, or 10x larger than the total physical RAM is just an unnecessary waste of disk space.

The various "explanations" I've seen on this thread for such a large swap file are not really technical reasons at all. A reasonable technical explanation would sound like this (just for kicks): "There's a digital signal processing (DSP) module that's receiving 5 terabytes of data from a satellite linkup every 2 days. The DSP module must allocate a dozen arrays of data structures (100MB each) in RAM to analyze, filter & process the data."

Yes, that's far-fetched for a router. The point is that there must be a clear & valid technical reason why a process would allocate hundreds of MBytes of RAM to do its job, which may eventually lead to excessive memory paging in and out of swap when the amount of physical RAM is insufficient for the task.

A swap file on a router is essentially a stopgap measure, a crutch, for the system to handle sporadic out-of-memory conditions if/when needed due to the demands of the processes being run, but then the system should recover at some point, and RAM usage should return to "normal" conditions (< 90% usage). For those specific purposes, a 2GB swap is plenty for a router with 1GB RAM.

If a router is running one or more processes that are allocating excessive amounts of RAM which eventually requires a 10GB swap to do the work, you've got a flaw in your system, and you have to reconsider if the router is being pushed too far beyond its limits and going into thrashing mode.
 
The 2GB swap file was a solution to the “cannot fork” errors when doing ram/cpu intensive operations despite the swap rarely being utilized around the time of the AC86U
This reminds me, tangentially, that htop reports pixelserv uses an unremarkable amount of memory on my N66, AC56 and AC87, but an improbably large 973M on my AC86, returning to an unremarkable amount on my AX88.

I have a sense that a common thread might be the processing of blocking lists in diversion, skynet, unbound and adguardhome.

EDIT: I was mis-disremembering this. It was syslog-ng that spiked this way. Although on my ax88 syslog-ng is 11K resident and 345M virtual.
 
Last edited:
This reminds me, tangentially, that htop reports pixelserv uses an unremarkable amount of memory on my N66, AC56 and AC87, but an improbably large 973M on my AC86, ...
Are you sure there's not a typo in the amount of memory reported: 973MB?

Or, perhaps a typo in the router model: RT-AX86U (1GB RAM) vs. RT-AC86U (512MB RAM)?

I ask because 973MB is ~190% of 512MB total RAM for the RT-AC86U, and it would be an extremely large amount needed for just one process in a router.

Even if it were the RT-AX86U, 973MB is ~95% of 1GB total RAM which essentially leaves very little for anything else.

Just curious.
 
Yeah, I agree. The largest swap file size currently available in AMTM is 10GB. There's simply no sound technical reason to have a 10GB swap on routers with 256MB, 512MB, or 1GB RAM. Having a swap file that's 40x, 20x, or 10x larger than the total physical RAM is just an unnecessary waste of disk space.

The various "explanations" I've seen on this thread for such a large swap file are not really technical reasons at all. A reasonable technical explanation would sound like this (just for kicks): "There's a digital signal processing (DSP) module that's receiving 5 terabytes of data from a satellite linkup every 2 days. The DSP module must allocate a dozen arrays of data structures (100MB each) in RAM to analyze, filter & process the data."

Yes, that's far-fetched for a router. The point is that there must be a clear & valid technical reason why a process would allocate hundreds of MBytes of RAM to do its job, which may eventually lead to excessive memory paging in and out of swap when the amount of physical RAM is insufficient for the task.

A swap file on a router is essentially a stopgap measure, a crutch, for the system to handle sporadic out-of-memory conditions if/when needed due to the demands of the processes being run, but then the system should recover at some point, and RAM usage should return to "normal" conditions (< 90% usage). For those specific purposes, a 2GB swap is plenty for a router with 1GB RAM.

If a router is running one or more processes that are allocating excessive amounts of RAM which eventually requires a 10GB swap to do the work, you've got a flaw in your system, and you have to reconsider if the router is being pushed too far beyond its limits and going into thrashing mode.

I tried to push the limit to see how much it would take to fill the 2gb swap. Truth be told, once you are that deep in on swapping, there really is no saving grace. Either the process that is forcing that high of a usage must be killed, or crashing is inevitable. If anything, the 10gb swap might buy alittle extra time to find and kill the memory abusing processes, but that is about it. I don't think that is a valid enough point to flex out a 10gb swap.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top