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

add support for erofs as root filesystem format #379

Merged
merged 3 commits into from
Sep 24, 2024

Conversation

bcressey
Copy link
Contributor

Issue number:
N/A

Description of changes:
Add the erofs-root-partition image feature. This is still considered experimental, but using erofs for the root filesystem has shown significant improvements in overall boot time. I'd like to land this implementation, and the associated changes in the core kit, to facilitate further experiments.

I tried many different settings for mkfs.erofs and eventually settled on the ones here. The physical cluster size made the largest difference. I tested various extended options - dedupe, fragments, all-fragments, and ztailpacking - but left those out to simplify the initial implementation, and to avoid features that the 6.1 kernel labels as experimental.

Testing done:
Built aws-dev and aws-k8s-1.30 images with the new feature flag enabled. Confirmed that repack-variant also worked.

Using some tools provided by @cbgbt, I compared the boot times for aws-k8s-1.30 AMIs as of the v1.22.0 release, with the current ext4 root filesystem and the experimental erofs root filesystem.
erofs-boottime

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

erofs is a relatively new filesystem, especially when compared with
ext4. It shows promising results in terms of improved boot times, but
its behavior at runtime on fully loaded nodes is more difficult to
predict.

Mark the image feature as experimental for now. This allows it to be
enabled by downstream variants to facilitate additional experiments,
without immediately endorsing it for production use.

Signed-off-by: Ben Cressey <[email protected]>
Comment on lines +168 to +187
# shellcheck disable=SC2312 # mapfile is validated elsewhere
mapfile -t new_root_artifacts <<<"$(find "${ROOT_MOUNT}" -type f)"

# The reason we check index 0 rather than the mapfile length is if `find` fails
# to find an artifact the heredoc to mapfile will assign empty output to 0.
if [[ -z "${new_root_artifacts[0]}" ]]; then
echo "no new root artifacts found" >&2
exit 1
else
# Write files from the root mount to the root image.
ROOT_DEBUGFS_STDERR="${WORKDIR}/root.err"
for artifact in "${new_root_artifacts[@]}"; do
cat <<EOF | debugfs -w -f - "${ROOT_IMAGE}" 2>>"${ROOT_DEBUGFS_STDERR}"
rm ${artifact#"${ROOT_MOUNT}"}
write ${artifact} ${artifact#"${ROOT_MOUNT}"}
ea_set ${artifact#"${ROOT_MOUNT}"} security.selinux system_u:object_r:os_t:s0
EOF
done
check_debugfs_errors "${ROOT_DEBUGFS_STDERR}"
done
check_debugfs_errors "${ROOT_DEBUGFS_STDERR}"
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're just completely remaking the root filesystem if it's erofs, should we follow the same workflow for ext4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For erofs, extracting the filesystem is a supported feature of fsck.erofs. For ext4, I'm more confident that debugfs will do what we want, since I'm not aware of a way to do full filesystem extraction using tools from e2fsprogs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The erofs paper mentions support for "image patching" in 4.3, but I didn't find a way to do that with erofs-utils.

@arnaldo2792
Copy link
Contributor

One question tho, what was the final size of the root filesystem?

Copy link
Contributor

@yeazelm yeazelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

@bcressey
Copy link
Contributor Author

One question tho, what was the final size of the root filesystem?

For aws-k8s-1.30, it was 337 MiB with erofs and 700 MiB without. With some of the experimental options like dedupe, and a 1 MiB physical cluster size, I got the size below 300 MiB, though the image took quite a lot longer to build.

@bcressey bcressey merged commit e08172b into bottlerocket-os:develop Sep 24, 2024
1 check passed
@bcressey bcressey deleted the erofs-image-feature branch September 24, 2024 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants