- Status Unconfirmed Reopened
- Percent Complete
- Task Type Bug Report
- Category Base system
- Assigned To No-one
- Operating System All
- Severity Medium
- Priority Very Low
- Reported Version openwrt-19.07
- Due in Version Undecided
-
Due Date
Undecided
- Private
Attached to Project: OpenWrt/LEDE Project
Opened by Juliusz Chroboczek - 14.01.2020
Last edited by Jo-Philipp Wich - 15.01.2020
Opened by Juliusz Chroboczek - 14.01.2020
Last edited by Jo-Philipp Wich - 15.01.2020
FS#2734 - Opkg update fails although router has enough memory
19.07.0 running on WNDR3700v2, 32MB of memory. The machine is certainly not short on memory:
total used free shared buff/cache available Mem: 59560 26912 24108 956 8540 16564 Swap: 0 0 0
Running “opkg update” a first time works fine. However, if I run “opkg update” a second time, it reports:
Collected errors: * pkg_hash_add_from_file: Failed to open /var/opkg-lists/openwrt_routing: Out of memory.
After doing “rm /var/opkg-lists/openwrt_*”, everything works fine again.
Strace indicates that it's `fork` that fails:
Enabling memory overcommit (which I'm not recommending should be the default) successfully works around the issue:
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.
Same issue here with a x86-64 image in Virtualbox with 128MB Ram
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.
Sure, will reopen it if you prefer.
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:
Have the same problem. Only with Asus RT-N11P. Only with 19.07.X. 18.06 not affected.
Can confirm this on an WNDR3700v1 with 19.07.01
So 26M free. Not like it's out of memory. The contents of /var/opkg-lists decompressed totals some 3.6M :
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.
Confirmed on:
Mikrotik RB941-2nD (Atheros QCA9531), both 19.07.2 and 18.06.8 (except on 18.06.8, "opkg update" worked multiple times, but not "opkg list")
TP-Link TL-WR940N v6 (Atheros TP9343), 18.06.8
19.07.3 not fix this problem on Asus RT-N11P. Bug still there. Still "Out of memory" when opkg list-upgradable. Please pay attention to the one who leads MT7620N.
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 :
whereas
and
19.07.4 and ASUS RT-N11P.
"Out of memory" after opkg list-upgradable in terminal.
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 MBSecond
opkg update
takes 3.76 MBopkg list
takes 14.6 MBopkg list-upgradable
takes 56.3 MBopkg list-installed
takes 3.76 MBSo, jow's optimizations are quite good at reducing memory usage for
update
andlist
. Sincelist-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?
On D-Link DIR-869 with 19.07.5 same "Out of memory" after opkg list-upgradable in terminal. Opkg update works fine.
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 recommended, neither is it a 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:
Summary:
opkg update: 6.7MB
opkg list: 14MB
opkg list-upgradable: 44 - 50 MB (and then a crash)
opkg list-installed: 3.8MB
opkg upgrade: 49MB (and then a crash); presumably this is calling list-upgradable internally?
<details>
</details>
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?
<details>
</details>
Trying the "rm" solution doesn't help me because it comes back as soon as re-run opkg update.
<details>
</details>
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
* https://altermundi.net/ * http://firstmile.ca/ * https://www.giswatch.org/year/2018-community-networks * https://www.fastcompany.com/40540511/why-low-income-communities-are-building-their-own-internet-networks But I think we should remember that this is a community-run volunteer project that we're all benefitting from. Bugs are everywhere, and if they seem more prominent in free software that's more because there's not nearly as much funding for it; proprietary routers are also full of bugs, but they have the kind of money to patch over the most common ones, or pay for technical support teams to teach people how to work around them, that a project like OpenWRT just can't afford. Plus they can control exactly what is in their hardware which makes their job 100 times easier than the job of the OpenWRT volunteers. By dropping support for older models they are trying to reduce the amount of bugs they need to solve. But that same process makes cheaper models more prone to bugs because they're not getting tested as thoroughly anymore.
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.
And by "we" I mean "we", we're the ones having a problem, if we want it solved we can help out by getting into the code.