FS#2734 - Opkg update fails although router has enough memory #7541
19.07.0 running on WNDR3700v2, 32MB of memory. The machine is certainly not short on memory:
Running "opkg update" a first time works fine. However, if I run "opkg update" a second time, it reports:
After doing "rm /var/opkg-lists/openwrt_*", everything works fine again.
The text was updated successfully, but these errors were encountered:
I don't see a solution to this. Opkg was already heavily patched and modified to use less RAM, even introducing a rather slow multi-pass list parsing algorithm to avoid keeping the entire dependency graph in memory. The lists are just big and keep growing, so devices with 64MB RAM and lower are nearing the end of their usefulness.
Jo-Philipp, may I suggest that you reopen this report? Just because we don't see a solution yet doesn't mean the bug should be closed.
There are two points I'd like to add.
First of all, "opkg install" and "opkg list-installable" work while "opkg update" fail. Is opkg perhaps keeping two copies (the old and the new one) in memory at the same time?
Second, the failure is not due to lack of memory -- it is due to fork failing due to the large amount of writeable pages. To me, this implies that either opkg should avoid forking (by linking with libz instead of running gzip -- see gzip_fdopen in libbb/gzip.c), or fork before it allocates the data structures (and keep the pipe around for later usage), or use a custom memory allocator that marks the pages as unwriteable using mprotect.
There might be a memory leak.
A first run of opkg update indicates all memory has been freed; running it a second time, though, indicates a leak of almost 4MB:
Can confirm this on an WNDR3700v1 with 19.07.01
If you are running "opkg update" for the first time, or if you delete /tmp/opkg-* , then it runs fine with only 2 Mb (or even less - I did not try beyond that). If there are already lists downloaded, then apparently no amount of memory will be enough (10M is certainly not enough). (We could just make it ignore previously downloaded lists, and that will fix it...)
"opkg list" should only list the names and not do anything more complex. It also runs fine when there are no downloaded lists; that could be attributed to having less text to display, but 10M being not enough to just display some text without any checking? That's unlikely.
19.07.3 has brought progress on my TP-Link re450v1 : No more Out of memory with opkg update
However as stated in the previous post, opkg list-upgradable fails with Out of memory
strace shows :
To get an idea of memory usage, run opkg with "time -v". Then look at "Maximum resident set size". That being said, I don't know if it accounts for forked processes.
Here is memory usage with 19.07.4 on a TL-WDR4300 v1 (ath79):
First ''opkg update'' takes 3.76 MB
Second ''opkg update'' takes 3.76 MB
''opkg list'' takes 14.6 MB
''opkg list-upgradable'' takes 56.3 MB
''opkg list-installed'' takes 3.76 MB
So, jow's optimizations are quite good at reducing memory usage for ''update'' and ''list''. Since ''list-upgradable'' has not been changed recently, it's not surprising it still takes a large amount of memory.
It's already been nine months since 19.07.0 was released. You have not done ANYTHING to fix the problem. Moreover, you have already started to drop support for 18.06, where this problem does not exist. When you completely stop supporting 18.06 what do we do then? Throw out fully working routers or become part of some kind of botnet network, without security updates? You understand that most people use budget models of routers with OpenWRT? Then why are you better than those technology companies that produce these routers and drop their support in 1.5-2 years? In some countries, people have wages of $ 100-200 per month (sometimes less) and they do not have money for good routers.
PS: Have you ever wondered why "free" operating systems have a market share within one percent? That's because of these things. Due to the large number of small and huge bugs in these OS. You have a huge list of supported devices. But how many routers on this list actually work without any bugs?
I'm seeing this too on on Archer C50 v4 (https://openwrt.org/toh/hwdata/tp-link/tp-link_archer_c50_v4), but only on list-upgradable. I can run update as many times as I want, but I actually getting updates done.
Weirdly, the luci interface doesn't seem to have a problem listing upgradable packages.
This router was manufactured just last year. Though it's not a 16/128 device like [[https://openwrt.org/toh/views/toh_available_16128|recommended]], neither is it a [[https://openwrt.org/supported_devices/openwrt_on_432_devices|banned 4/32]]. It's in the middle: a 8/64, and that's supposed to be powerful enough.
I'm running LuCI openwrt-19.07 branch (git-20.272.48698-9883bb3) / OpenWrt 19.07.4 r11208-ce6496d796.
I tried running Baptiste's experiment:
opkg update: 6.7MB
Turning on sysctl -w vm.overcommit_memory=1; allows the process to complete.
A side issue: why is opkg upgrade running list-upgradable if it's just going to stop when it notices I haven't told it what packages to upgrade?
Trying the "rm" solution doesn't help me because it comes back as soon as re-run opkg update.
I was finally able to get my system updated with
I share your anxiety, Karlito. Dropping support for older devices leaves a lot of perfectly good hardware sitting wasted, and people working on a budget out in the cold. The same thing happens with smartphones all the time; when the most common messenger apps your friends use decide your phone is too old then you're forced to buy a new one, or be cut off if you can't afford it. I imagine this turning out to be critical for hackers trying to network their communities in developing countries, like
I don't have a good solution. We need to get open source funded properly I guess!
I do hope we can extend the life of cheaper routers. We've identified list-upgradable as the problem here, so maybe we can pitch in by tracing the code and seeing if there's a way to make it process the data in more of a stream instead of a blob.