-
-
Notifications
You must be signed in to change notification settings - Fork 606
Description
When booting OSv initially mounts so called bootfs (ramfs at /) based on the data located in the kernel itself. It does it in unpack_bootfs which is essence copies the data from one place in memory to another (write).
In order to avoid this extra copy we could instead pass bootfs_start as the 'data' argument to sys_mount (https://github.com/cloudius-systems/osv/blob/master/fs/vfs/main.cc#L2191) which then could be used in ramfs_mount to populate ramfs flesystem is a similar way unpack_bootfs does it. Obviously unpack_bootfs does it through VFS and ramfs_mount would do it using native ramfs construct and do NOT copy file data instead simply set ramfs_node->rn_buf to the original address in the kernel.
The only caveat is that bootfs is read-write and a write to any file would result in at attempt of freeing the original data that is part of kernel which would be bad. One way to prevent it would be to mount bootfs as read-only (when calling sys_mount) so that VFS would not allow for any write operation. It actually makes a lot of sense given that bootfs typically contains executable code and possibly immutable data. If anybody wanted ramfs based OSv image with possibility of writing data (logs) it could mount read-write ramfs at different mountpoint.
This change would significantly improve memory utilization of ram disk based images of OSv especially when application code is pretty big.