Adguard Home crashes because of lack of memory. What can I do?

Hi,

I am very unexperienced in OpenWRT yet.

My adguard home regularly crashes on my Asus RT-AX53U, usually after 2-3 days of functionning. Here are my logs, maybe you could see some infos I missed:

I appears to be because of a lack of memory. I know RT-AX53U isn't a powerhouse, but what can I do ? I find strange that it crashes after so long instead of immediatly. Could there be a memory leak ? Is there something I can do ? Is there a way to use an usb storage as temporary RAM ? Can I limit the RAM it uses and still have it running ?

thanks in advance for any answer, have a great day

Blocklists for adblocking purposes are huge, if you add the further orchestration around it (either dnsmasq or the adguard services) even (much) larger than that, but your RT-AX53U gives you only 256 MB in total.

There are only two alternatives:

  • get a device with more RAM
  • reduce your blocklists
    • hope that plain luci-app-adblock has less overhead than adguard

Especially in combination with adguard, you really want >=1 GB RAM; 512 MB would still be marginal.

2 Likes

Swapping to adblock or adblock-lean might be an option?

I'd of course mention simple-adblock especially for resource-constrained models.

You can also run https-dns-proxy and point it to a filtering resolver to offload all the blocking to the resolver from your router and get an added benefit of encrypted DNS requests so your ISP can't resell them.

Just to clarify a bit further, handling large adblock lists is already quite a burden (you can easily OOM a 512 MB RAM device with extensive blocklists alone) - but adguard does add a considerable amount of 'fluff' beyond that, which needs even more RAM (it may add convenience and more features, but at the cost of significant overhead, re-implementing parts of the software stack that OpenWrt does provide anyways).

My Adguard Home process crashed a few minutes ago for the first time on an ER605v2 with 256MB of RAM as well. I only have three filter list for a total of about 200K rules. I found that when I add more than that it crashes as well. I also just attempted to disable logging and statistics. I noticed the default settings store those for a very long time which is completely unecessary. I just turned them off completely since I do know for a fact the filtering is working. I dont know how much of an impact it will have but if it crashes again I will definitely switch to simple-adblock.

Most likely none, since those would be stored on "disk", not RAM.

Okay, I will let it run for some prolonged time like this, and see what happens. My RAM is only at 50% usage so I don't even know if this is the culprit but maybe something else caused it to crash. Who knows...

@BobbyBoyGaming 256MiB of memory is way too little for AGH. There are native adblockers, designed specifically for OpenWrt, which functionally are more or less identical to AGH but way lighter on memory, storage and CPU. As a contributor to the adblock-lean project, I can recommend you to try it out - it is arguably the most efficient of all the available options, easiest to set up and very user-friendly. Make sure to uninstall other adblocking solutions before installing a new one.

2 Likes

I have an ER605v2 and it does not seem to have adblock-lean only adblock fast and adblock (regular). I'd imagine they are all much lighter than AdGuard Home anyway. The other thing I can do is offload all the heavy stuff to this thing I have called a NanoPi Neo 3 LTS, I had it in a box for 5 years and I guess now is the time to do something with it. It can run FriendlyWrt. The only reason I still need the ER605 is because of dual-WAN load balancing.

By default AGH logs and statistics are written to /var/lib/adguardhome, and /var is just a symlink to /tmp which is backed by tmpfs, i.e. stored in RAM. So you can either change workdir to point to some persistent storage, or reduce log retention. Stats take insignificant amount of space compared to logs.

1 Like

Space, not RAM, AFAIK /tmp size is fixed.

adblock-lean doesn't have a package but it's very easy to install anyway, you can find out how if you follow the link in my post above.

1 Like

For a router with a USB port you can add some storage with a flash drive or SD card plus USB adapter. Then make use of it for two things:

  1. Store files downloaded, processed and output by adguard/banip/etc on the flash drive freeing up RAM otherwise used to store them in /tmp.
  2. Create a swap file or partition so the OOM killer isn't triggered if you run out of physical RAM. It is much slower than RAM, especially over USB2, so have as little as possible in use.

Note /tmp by default will consume up to half of RAM on an as needed basis. As more files are placed there since the router was booted you will have less free RAM.

1 Like

There's also kmod-zram.

Again, I believe /tmp size is fixed.

Created with a fixed size but does not use a fixed amount of RAM.

By default /tmp is created as a volume 1/2 the size of RAM which limits how much can be stored on it. It uses RAM on an as needed basis to store what is placed on it.

Look at memory use before and after placing a largish file on it:

head -c 32m /dev/urandom > /tmp/sample.txt

Make sure to delete the file afterwards.

An update, the ER605v2 I have is currently running everything by itself without issue. It is doing DoQ DNS-proxy+DNSmasq, DNS sinkhole (AdBlock 200K rules), DHCP, load balancing 3 WANs (2 plus cellphone when plugged in occasionally). Everything is going well so far. The whole thing is at 59% memory...

Those swap file ideas are really cool ideas wouldn't have occurred to me, but I already spent like 2 hours turning my 1 and only USB port into a load-balanced tethering wan for the cellphone. I got it to work with iPhone, but it didn't work with android. I guess can only pick one, because it didn't seem to work with android once I installed the iPhone driver-specific packages.
Next I am gonna see if I can get IPv6 load-balanced properly and not just ipv4.

*I can confirm that USB tethering does work with both iPhone and Android without issue. It's just that the connection was flimsy on the android phone so it was actually not plugged in properly.