doexcellence
doexcellence

Reputation: 11

Linux initrd optimization

I am investigating Linux initrd mechanism. I learned the following code:

bool __init initrd_load(void)
{
    if (mount_initrd) {
        create_dev("/dev/ram", Root_RAM0);
        /*
         * Load the initrd data into /dev/ram0. Execute it as initrd
         * unless /dev/ram0 is supposed to be our actual root device,
         * in that case the ram disk is just set up here, and gets
         * mounted in the normal path.
         */
        if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
            init_unlink("/initrd.image");
            handle_initrd();
            return true;
        }
    }
    init_unlink("/initrd.image");
    return false;
}

int __init rd_load_image(char *from)
{
    // ...
    out_file = filp_open("/dev/ram", O_RDWR, 0);
    in_file = filp_open(from, O_RDONLY, 0);
    // ...

    for (i = 0; i < nblocks; i++) {
        // ...
        kernel_read(in_file, buf, BLOCK_SIZE, &in_pos);
        kernel_write(out_file, buf, BLOCK_SIZE, &out_pos);
        // ...
    }

    // ...
}

Now I know ramdisk content read from device "/initrd.image" to device "/dev/ram" device (a RAM simulated disk?).

Here are my questions:

  1. Where is the implementation of file_operations for device "/dev/ram" and "/initrd.image"?
  2. How is the device "/dev/ram" used later? I didn't find anywhere else "/dev/ram" is used.
  3. From the above logic, file content is first READ from "/initrd.image", and the WRITE to "/dev/ram". That means there are 2 memory copies. I am wondering if it is possible to exclude one of the memory copy so as to improve the boot performance?

Thanks in advance for any reply!

Upvotes: 1

Views: 226

Answers (1)

stark
stark

Reputation: 13187

  1. /dev/ram has a block_device_operations struct in brd.c https://elixir.bootlin.com/linux/v5.4.210/source/drivers/block/brd.c#L327 while initrd.image depends on the filesystem that contains it.

  2. /dev/ram consists of blocks of memory starting at rd_image_start

  3. How do you know whether the /dev/ram area is an acceptable DMA target? How do you do decompress?

Upvotes: 1

Related Questions