1

Under the old initrd system, Linux used to free the initrd image. This was traced on the console:

 Freeing initrd memory: xxxxk freed.

What this referred to was actually releasing the memory occupied by the original compressed image. The live, mounted filesystem was released via unmounting (via pivot_root to the replacement root).

Under initramfs, the filesystem is released by a recursive removal using some utility like switch_root, and is never unmounted. I understand that, but where is the original image (the compressed .cpio archive) freed?

I'm looking at init/initramfs.c (populate_rootfs) and see that in fact initramfs can unpack data from either __initramfs_start or initrd_start, or even both! The initrd area is freed by free_initrd(), but there is no logic here for doing the analogous freeing for the memory starting at __initramfs_start.

Can someone shed some light on how this memory is freed? Or else confirm that it's not freed? Is it in a section that gets discarded along with other unused memory?

I added some diagnostics which show that __initramfs_start is outside of the unused memory that is freed. This is on an ARM embedded system:

[    1.241857] Freeing unused kernel memory: 3240K [c0c01000, c0f2b000)
[    1.241874] Initramfs image starts at: e7fddef0

But then, if I look at the linker script, I see that the INITRAMFS is placed between __init_start and __init_end symbols, so maybe this discrepancy is due to some run-time relocation? The size is about right: the original compressed image is 2958550 bytes, which could reasonably account for the bulk of this reported 3240K.

0

Well, I've confirmed that the memory gets freed by the following experiment. I added a few megabytes of random junk into the initramfs, built the kernel and booted. The Freeing unused kernel memory reported size increased by about the size of that junk. Furthermore, this bloat made no difference to the free memory seen just after boot via free and /proc/meminfo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.