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:
- Where is the implementation of file_operations for device "/dev/ram" and "/initrd.image"?
- How is the device "/dev/ram" used later? I didn't find anywhere else "/dev/ram" is used.
- 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!