Is a USB swap file always recommended for merlin?

jata

Senior Member
I'm on latest merlin 386.7_2 on my RT-AX86S (so only with 500MB ram).

I usually configure a good quality USB 3.x thumb drive with a swap file (and then install Entware to enable some scripts/addons).

One month ago I did a clean reset of my router/network and manually configured it. I did not add a USB so currently have no swap or entware.

My setup has been rock solid with no random restarts without the USB so i'm thinking that either the USB, swap, entware, nextDNS CLI script 'might' have been causing the instability (random restarts).

So - if I can live without Entware being installed and without heavy apps/services such as skynet/diversion, is there any point/benefit having a swap file?

Appreciate any view or thoughts from the community... Thanks.
 

bbunge

Part of the Furniture
Use of a swap usually depends on what other apps you run on your router, as you have discovered. RAM on the router is to be used and is usually adequate for "normal" router use. Some apps, as loaded via AMTM, recommend huge swap files. I have never used a swap larger than 1 GB and usually 512 MB or 256 MB. I also like to use swap partitions as I have had issues with swap files. Call me old school if you want. Now I am using Asus firmware and have no need for a swap. (Yes, it is possible to add a swap to the Asus firmware)
So, it is whatever you want to use. If you use the router to store files and transfer them via Samba you may want to add a swap.

Edit: the swap can be on a FAT, NTFS or EXT file system unless you use Entware and then it needs to be on EXT2, 3 or 4.
 

ColinTaylor

Part of the Furniture
If you don't install any addon scripts (e.g. skynet, diversion, etc.) then there is no point in having a swap file as there would be nothing running on the router that would require it.
 

jata

Senior Member
Thanks all. That is helpful.

So I could have a USB drive, install entware and addons/scripts that do not require a swap WITHOUT using a swap file
 

JT Strickland

Very Senior Member
Thanks all. That is helpful.

So I could have a USB drive, install entware and addons/scripts that do not require a swap WITHOUT using a swap file
OK. Hmm...... Why?
Just to be the swap file advocate.
 

L&LD

Part of the Furniture
Creating the swap file via amtm is a one time event. There have been instances where a script needed a bigger swap file, even when it was barely used. And, if I'm remembering correctly, a swap file was required when previously, it wasn't.

Makes no sense to not have it (and I would use the biggest option available, because again, why not), no matter which scripts you use.
 

jata

Senior Member
Thanks all.

I'm not advocating for using a swap file or not. I'm totally neutral but I am trying to see if I can find the route (pun intended) cause for my router random reboots.

No USB = no random reboots
USB formatted and mounted but no swap = currently being tested over next 2 weeks

After this I will add a swap file but not install any scripts and wait another 2 weeks

then i'll install entware etc...

I'm in no real hurry and who knows - maybe the random reboot issue has nothing to do with any of this :)
 

ColinTaylor

Part of the Furniture
OK. Hmm...... Why?
KISS

If you're not running anything that requires a swap file then you are introducing more complexity to your setup (modifying system scripts) and consuming disk space for zero benefit.
 

bbunge

Part of the Furniture
You could be having issues with the thumb drive. Try a USB2 drive and set the router to USB2 operation. I have done this for years and am still using old USB2 drives that just keep on trucking while newer USB3 drives have failed. Drive speed is not important for Entware apps.
 

bbunge

Part of the Furniture
I'm in no real hurry and who knows - maybe the random reboot issue has nothing to do with any of this :)
I have used Merlin 386.7_2 on my AX86U for a while and I remember the router rebooting for no apparent reason. Do not remember that it was related to Entware or USB use. Whatever it was I never figured it out. I was having some health and family issues and decided to go to Asus firmware just in case someone else had to work on my network. From time to time I load up Merlin just to see if I've missed anything but with the new Asus 388 code base I have been satisfied with the Asus firmware.
 

muffintastic

Senior Member
I have found using an SSD or NVME in a USB 3.0 caddy and at USB 3.0 setting never had an issue, and it's usually quicker to create. I used to have terrible problems running off a thumb drive at 2.0 or 3.0, random router reboots or hangs.
 

L&LD

Part of the Furniture
You're over-simplifying things by stating "No USB = no random reboots".

This is not what I would be testing for.

Because it's not just the addition of the USB drive causing problems, if it is, see what @muffintastic recommends as a solution (as do I).

What I would test is the following (preferably, with a new drive or better yet, an SSD in a USB enclosure). And be sure you have a notebook and pen handy to write down exactly what you did and in which order too, as a further troubleshooting measure if things go south again.
  • Do not insert any previously used USB drive into the router unless you first format it on a PC as NTFS.
  • Once installed into the router, use amtm to name, format (Ext4, with journalling), enable the DC disk checker, and create a swap file (I would use the maximum allowed via amtm, there is no downside here, storage is plentiful and cheap). Do all these steps in this order, first. Before adding any other scripts into the mix.
  • Reboot the router as needed when doing the steps above. Additionally, reboot the router one final time after an hour or so when you're done, also. Be sure you're checking the DC output to see if the drive is getting corrupted or comes up 'clean' each time.
  • With the above performing satisfactorily, use the router/network normally for as long as you need to verify the issue is effectively resolved for you.
  • If the reboots do start happening again at this point, a full reset of the router (and starting again with the post here), is in order.
  • Add a single script and again, reboot the router, verify that all you've set up to this point is working as expected, and use the network for the length of time you feel comfortable seeing this addition as 'solid' and the network reliable.
  • Continue doing this for each script you want to add. When/if a failure occurs, have your notes handy and create a new post on this thread to see if help is readily available for the issue then.
Using amtm, the largest swap file possible, an external SSD in a USB enclosure, and many, many scripts over the past few years, I would be shocked if the adequately large swap file, fully updated Entware or any properly installed/configured scripts were the reasons for the reboots.

My guess is the paltry 512MB of RAM of the router. And/or the specific USB drive used too.

What testing above will show you is which combination (and in which order) the setup fails (if it does again).

And if it does fail, while using an SSD in a quality USB enclosure (UGreen), and there is no applicable help available from the community here after the meticulous notes you've kept are shared, my next step would be a router with 1GB RAM or more.
 

Tech9

Part of the Furniture
is there any point/benefit having a swap file?

Not used and not needed, except for few custom scripts using it occasionally as workaround solution. With swap file on USB stick your router's warranty may expire before the swapping process ends.
 

L&LD

Part of the Furniture
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.

Please, do tell us why. I've already stated why it should be considered.

And I do understand how virtual memory is used. What further router implications are there?
 

elorimer

Very Senior Member
I've already stated why it should be considered.
Not to be argumentative here, but I think you said "why not".

I have wondered about this and would be interested in a fuller explanation as I am unclear on how exactly a swap file works. At the moment I have a 2GB swap file on a 16GB drive, formatted with ext4 and journalling. 1.5mb of it is used, while I have something like 350mb in cache and 50mb free. With that in mind:

1. When the router pages, does it read the whole file and then write the whole file? Or does it just access the necessary block portions of the file?
2. With journalling, does the router recalculate the checksum for the whole file?
3. With Ext4, does the swap file occupy pre-allocated space, so all of the writing is done to the same sectors?
4. Supposing RAM is faster than paging, is it faster to release some of the cache when necessary than do the paging.
5. If there is a read/write error, what happens?

I realize some of this may be kernel-dependent and model-dependent, so one size may not fit all ( :) ), but these might be reasons to choose the smallest swap file sufficient onto the purpose.
 

L&LD

Part of the Furniture
No one is being argumentative here, I hope we can share what we each know.

The 'why not', refers to the points made above it, in post 7 (for clarity).

1) If you're referring to the 'file' as the swap file, no. It only uses what it directly needs.

2) That, I don't know. But I wouldn't assume that to be the case. The 'whole file' is just a quick way to access storage, it really isn't a 'file', as we normally would see it.

3) It probably does, on an HDD. With an SSD or even a flash drive, there is no such thing. Wear leveling algorithms and all, to keep the nand cells healthy.

4) RAM is much faster than paging. But that is a moot point when the RAM is needed for multiple workloads/scripts, etc. (that is why the paging file exists).

5) That is why there are multiple layers of error correction available. If an error does surface without correction, the router would freeze, reboot, or give incorrect output in one form or another.

None of the above are reasons to choose a smaller swap file, IMO. And post 7 states why a larger swap file may be better. And, since that supposition hasn't been refuted by anyone, that is the side I choose to error on.
 

jata

Senior Member
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. :)
 

bartimeaus

Occasional Visitor
Since the main issues by OP seems to have resolved. Can I ask if scripts are automatically installed onto the USB? I kept on reading stuff about wearing out the router's built in NAND and I'm wondering how scripts like diversion are installed onto the USB drive.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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