You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
4.19: ext4_inode_cache slab memory usage, doesn't get reclaimed #2829
i tried out the next branch of https://github.com/raspberrypi/firmware/ with "sudo BRANCH=next rpi-update". this gave me kernel version 4.19.16. i had no issues with it until i noticed that the memory usage was going up and up.
after executing "sudo slabtop", ext4_inode_cache was using ~170 MB. normally this would get reclaimed when the rest of the memory is getting full, however this was not the case here. even when the memory was fully used up by userspace programs, and the kernel was agressively swapping, the ext4_inode_cache would not go down. increasing "vm.vfs_cache_pressure" and "echo 3 > /proc/sys/vm/drop_caches" did not help. i've since went back to the older 4.14 kernel and the issue doesn't appear there.
Which model of Raspberry Pi? e.g. Pi3B+, PiZeroW
Pi3B+
Which OS and version (cat /etc/rpi-issue)?
Raspbian Stretch with desktop
Additional context
I'm not using a microSD card: the system is on a USB attached SSD drive. Let me know if you need more info to reproduce this issue.
No idea if it's the same bug, but this seems similar to an issue I have been wrangling recently with the 4.19.16 and 4.19.20 Linux kernels on some non-Raspberry Pis.
In my case it turned out that the kernel was leaking memory associated with cgroups - and over time it grew to a large size because we had some faulty systemd services restarting over and over (creating and removing a cgroup each time, but the kernel leaked).
Here's an LKML thread discussing backporting the patches: https://lkml.org/lkml/2018/11/2/160
And a bug in Ubuntu: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1792349
I upgraded to 4.19.25 (not 4.19.16) via rpi-update, thats all. After a reboot it took 5-10 minutes (with running node processes) until the whole ram was used and the Pi got unresponsive.
What do you mean by running node process? I got 4.19.27 running here with no memory problems that I can see, so trying to understand specifically what you are doing that is soaking up the RAM.
Just node.js processes with some memory/disk io, nothing heavy. As you can see ext4_inode_cache is eating up all the memory. There were no processes in top/htop that had more than a couple of Megabytes ram usage. Then I checked with slabtop which finally led me here.
The easiest way to reproduce it for me is to run e4defrag on ext4 eternal disk (but it also happens when doing tar or even du on folders with many entries).
I use external disk to make my Pi backups with rclone - so backup folder contains 1m+ files (about 10 full backups)
Now when I start some operations on this folder (e4dfrag, tar or du) I can see ext4_inode_cache grwoing - when I CTRL-C it does not truncate. When I start something else it grows again. If I let it go it grows until my Pi crashes. All of these worked perfectly well with 4.14.98
example of slabtop -s c just before Pi becomes unresponsive
and also in 4.19.27 case "echo 3 | sudo tee /proc/sys/vm/drop_caches "does not truncate ext4_inode_cache which is the case in 4.14.98
It always grows until RPi is dead - the pace depends on number of ext4 disk operations - fair amount is required to eat all memory.
4.19.29 no change. I can kill my raspberry pi in reproducible way by simply copying big folder few times (copy -R source A; copy -R source B; copy -R source C) With 10GB of source code files I can do it after three copy commands . After few more tests I can see that none of caches are released not just ext4_inode_cache - but this one is the largest in size so fills all memory first.
When not using heavy file operations system seems to be stable as caches are within manageable size. They grow forever though as well so the end comes just much later.
Having swap file does not help as caches are not swappable
This is looking more and more like an upstream bug that has been reported, and we are currently awaiting a fix - there is some argument, apparently, over the proposed fix.
The "big" folder full of files doesn't even need files with any sensible contents - 0 byte files created by "touch" are sufficient to trigger the leak.
in case of ext4_inode_cache any filesystem access which requires inode information not already in cache adds new info to cache which only grows until there is no memory. From user perspective nothing to do at the moment but wait for upstream fix. 4.14 is fully usable,
My script still crashes on downstream versions 4.19.36 through to 5.1.0-rc6, taking the top of each of rpi-4.19.y, rpi-5.0.y, rpi-5.1.y branches. I suppose the next step is to replicate it on an upstream config and start making noise in bug trackers.
I've been unable to get an upstream kernel to crash in the same fashion. Reverting this commit cd6ce4d causes the issue to disappear. If we have the commit applied but pass cgroup_enable=memory on the commandline, the issue disappears.
commit beb0cc781b8e07d4bf89b6be2bf6e7ff7fe8b7ff
Author: Yang Shi <yang.shi@linux.alibaba.com>
Date: Fri Aug 2 21:48:44 2019 -0700
mm: vmscan: check if mem cgroup is disabled or not before calling memcg slab shrinker
commit fa1e512fac717f34e7c12d7a384c46e90a647392 upstream.
Shakeel Butt reported premature oom on kernel with
"cgroup_disable=memory" since mem_cgroup_is_root() returns false even
though memcg is actually NULL. The drop_caches is also broken.
It is because commit aeed1d325d42 ("mm/vmscan.c: generalize
shrink_slab() calls in shrink_node()") removed the !memcg check before
!mem_cgroup_is_root(). And, surprisingly root memcg is allocated even
though memory cgroup is disabled by kernel boot parameter.
Add mem_cgroup_disabled() check to make reclaimer work as expected.
So latest upstream kernel should work correctly regardless of cgroup_enable=memory / cgroup_disable=memory commandline parameters. (Same fix was applied to all affected stable kernels in upstream.)
Activity
DrJosh9000 commentedon Mar 1, 2019
No idea if it's the same bug, but this seems similar to an issue I have been wrangling recently with the 4.19.16 and 4.19.20 Linux kernels on some non-Raspberry Pis.
In my case it turned out that the kernel was leaking memory associated with cgroups - and over time it grew to a large size because we had some faulty systemd services restarting over and over (creating and removing a cgroup each time, but the kernel leaked).
Here's an LKML thread discussing backporting the patches: https://lkml.org/lkml/2018/11/2/160
And a bug in Ubuntu: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1792349
Pmant commentedon Mar 6, 2019
I think I'm experiencing the same issue on my Pi 3.
System info:
DrJosh9000 commentedon Mar 8, 2019
What does
cat /proc/cgroupssay?Pmant commentedon Mar 8, 2019
I'm sorry, I had to switch back to 4.14 since the Pi was almost unusable
JamesH65 commentedon Mar 8, 2019
@Pmant What specifically are you doing that caused the issue on 4.19.16
Note we have some of the cgroup patches referenced above, in our latest 4.19.27 tree, so it might be worth trying that.
Pmant commentedon Mar 8, 2019
I upgraded to 4.19.25 (not 4.19.16) via rpi-update, thats all. After a reboot it took 5-10 minutes (with running node processes) until the whole ram was used and the Pi got unresponsive.
JamesH65 commentedon Mar 8, 2019
What do you mean by running node process? I got 4.19.27 running here with no memory problems that I can see, so trying to understand specifically what you are doing that is soaking up the RAM.
Pmant commentedon Mar 8, 2019
Just node.js processes with some memory/disk io, nothing heavy. As you can see ext4_inode_cache is eating up all the memory. There were no processes in top/htop that had more than a couple of Megabytes ram usage. Then I checked with slabtop which finally led me here.
Pmant commentedon Mar 8, 2019
here is what it looks like on 4.14.98 if that helps
kapitainsky commentedon Mar 12, 2019
I have similar issue with 4.19.27
The easiest way to reproduce it for me is to run e4defrag on ext4 eternal disk (but it also happens when doing tar or even du on folders with many entries).
I use external disk to make my Pi backups with rclone - so backup folder contains 1m+ files (about 10 full backups)
Now when I start some operations on this folder (e4dfrag, tar or du) I can see ext4_inode_cache grwoing - when I CTRL-C it does not truncate. When I start something else it grows again. If I let it go it grows until my Pi crashes. All of these worked perfectly well with 4.14.98
example of slabtop -s c just before Pi becomes unresponsive
kapitainsky commentedon Mar 12, 2019
and also in 4.19.27 case "echo 3 | sudo tee /proc/sys/vm/drop_caches "does not truncate ext4_inode_cache which is the case in 4.14.98
It always grows until RPi is dead - the pace depends on number of ext4 disk operations - fair amount is required to eat all memory.
kapitainsky commentedon Mar 21, 2019
4.19.29 no change. I can kill my raspberry pi in reproducible way by simply copying big folder few times (copy -R source A; copy -R source B; copy -R source C) With 10GB of source code files I can do it after three copy commands . After few more tests I can see that none of caches are released not just ext4_inode_cache - but this one is the largest in size so fills all memory first.
When not using heavy file operations system seems to be stable as caches are within manageable size. They grow forever though as well so the end comes just much later.
Having swap file does not help as caches are not swappable
JamesH65 commentedon Mar 21, 2019
This is looking more and more like an upstream bug that has been reported, and we are currently awaiting a fix - there is some argument, apparently, over the proposed fix.
P33M commentedon Mar 21, 2019
The "big" folder full of files doesn't even need files with any sensible contents - 0 byte files created by "touch" are sufficient to trigger the leak.
kapitainsky commentedon Mar 21, 2019
in case of ext4_inode_cache any filesystem access which requires inode information not already in cache adds new info to cache which only grows until there is no memory. From user perspective nothing to do at the moment but wait for upstream fix. 4.14 is fully usable,
17 remaining items
popcornmix commentedon Apr 19, 2019
From earlier in this issue:
defconfigs: disable memory and IO cgroups (#2908)
P33M commentedon Apr 23, 2019
My script still crashes on downstream versions 4.19.36 through to 5.1.0-rc6, taking the top of each of rpi-4.19.y, rpi-5.0.y, rpi-5.1.y branches. I suppose the next step is to replicate it on an upstream config and start making noise in bug trackers.
P33M commentedon Apr 23, 2019
For reference, this script on an ext4 filesystem (with cgroups enabled) will crash a Pi in about 2 minutes:
Note that you need a filesystem with enough free inodes to leak enough memory to crash.
P33M commentedon Apr 24, 2019
I've been unable to get an upstream kernel to crash in the same fashion. Reverting this commit cd6ce4d causes the issue to disappear. If we have the commit applied but pass cgroup_enable=memory on the commandline, the issue disappears.
defconfigs: disable memory and IO cgroups (#2908)
defconfigs: disable memory and IO cgroups (#2908)
defconfigs: disable memory and IO cgroups (#2908)
defconfigs: disable memory and IO cgroups (#2908)
defconfigs: disable memory and IO cgroups (#2908)
defconfigs: disable memory and IO cgroups (#2908)
hadrava commentedon Aug 9, 2019
I think, that this issue was fixed in kernel 4.19.65. https://cdn.kernel.org/pub/linux/kernel/v4.x/ChangeLog-4.19.65:
So latest upstream kernel should work correctly regardless of
cgroup_enable=memory/cgroup_disable=memorycommandline parameters. (Same fix was applied to all affected stable kernels in upstream.)popcornmix commentedon Aug 12, 2019
@hadrava thanks - that's good to know there has been a fix.
JamesH65 commentedon Sep 19, 2019
Please update to the latest kernel which contains a fix for this issue.