Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not duplicate data when unpacking bootfs #977

Closed
wkozaczuk opened this issue Jun 8, 2018 · 0 comments
Closed

Do not duplicate data when unpacking bootfs #977

wkozaczuk opened this issue Jun 8, 2018 · 0 comments

Comments

@wkozaczuk
Copy link
Collaborator

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.

wkozaczuk pushed a commit to wkozaczuk/osv that referenced this issue Aug 23, 2018
This patch optimizes RAM utilization of bootfs by
eliminating unnecessary copy of data. It does so by
pointing created file nodes to existing data offset in memory
which is part of area where kernel is copied after decompression.

In essence we add new flag rn_owns_buf to RAMFS ramfs_node to track
if we can actually free memory wherever it happens. By default
rn_owns_buf is set to true but new function ramfs_set_file_data called
from unpack_bootfs() sets it to false.

The savings of RAM are equal to the size of build/release/bootfs.bin
which means we save around 700K with ZFS images, 0 with ROSF and
as much as application code size with RAMFS where the improvement
is most significant especially with for example Java images.

Please note that file data referenced by nodes created during
unpack_bootfs() would point to wherever bootfs.bin data is in
the uncompressed kernel area which means it is most likely not aligned
which possibly means slower access. This could be improved by
making individual files aligned in bootfs.bin.

Fixes cloudius-systems#977

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Message-Id: <[email protected]>
@nyh nyh closed this as completed in bf73b9a Aug 26, 2018
wkozaczuk added a commit to wkozaczuk/osv that referenced this issue Aug 27, 2018
This patch optimizes RAM utilization of bootfs by
eliminating unnecessary copy of data. It does so by
pointing created file nodes to existing data offset in memory
which is part of area where kernel is copied after decompression.

In essence we add new flag rn_owns_buf to RAMFS ramfs_node to track
if we can actually free memory whenever it happens. By default
rn_owns_buf is set to true but new function ramfs_set_file_data called
from unpack_bootfs() sets it to false.

The savings of RAM are equal to the size of build/release/bootfs.bin
which means we save around 700K with ZFS images, 0 with ROSF and
as much as application code size with RAMFS where the improvement
is most significant especially with Java images.

Please note that file data referenced by nodes created during
unpack_bootfs() would point to wherever bootfs.bin data is in
the uncompressed kernel area which means it is most likely not aligned
which possibly means slower access. This could be improved by
making individual files aligned in bootfs.bin.

Fixes cloudius-systems#977

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant