What frees the `.init.ramfs` image after it is unpacked into the `rootfs`?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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.










share|improve this question




























    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.










    share|improve this question


























      1












      1








      1


      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.










      share|improve this question
















      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.







      linux-kernel initramfs arch-arm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 6 at 23:32







      Kaz

















      asked Feb 6 at 23:11









      KazKaz

      4,64811532




      4,64811532




















          1 Answer
          1






          active

          oldest

          votes


















          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.






          share|improve this answer
























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499180%2fwhat-frees-the-init-ramfs-image-after-it-is-unpacked-into-the-rootfs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            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.






            share|improve this answer





























              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.






              share|improve this answer



























                0












                0








                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.






                share|improve this answer















                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.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 7 at 20:43

























                answered Feb 7 at 0:09









                KazKaz

                4,64811532




                4,64811532



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499180%2fwhat-frees-the-init-ramfs-image-after-it-is-unpacked-into-the-rootfs%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?