On 15/06/2025 21:16, Alexey Gladkov wrote:
On Mon, Jun 16, 2025 at 03:21:47AM +0800, Kang-Che Sung wrote:
Alexey has said that overlayfs won't touch the lower layer, and thus
in this case, deleting files from an overlayfs root might not free
memory that much as you would think. Here, it might be better to leave
the files alone and not 'rm -rf' them.

Typically overlayfs is used to temporarily modify read-only images such as
docker/podman. When the base image (lower layer) is left unchanged and all
changes are written to tmpfs and lost.

If you don't delete the data in switch_root, it will be a waste of memory
since you are not supposed to go back to root. This is a big difference
from rm -rf.

But Kang-Che Sung's point was that removing the data, even in switch_root, will not reclaim that memory. The situation you have got (correct me if I am wrong) is that you have a read-only image A, a tmpfs B, and an overlayfs C that uses A as the lower layer and B as the upper layer, where C is mounted as /. switch_root cannot modify A at all, and cannot modify B directly other than by modifying C. Removing the files from C will remove some files from B, but will also add new files to B to indicate that the files from A should be hidden from C. And the entire image A will be kept in memory regardless.

For this use case, in order to reclaim the memory, you would need to use pivot_root, not switch_root. pivot_root allows the old root to be remounted onto a subdirectory of the new root, and then allows it to be unmounted cleanly, freeing all resources.

Cheers,
Harald van Dijk
_______________________________________________
busybox mailing list
busybox@busybox.net
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to