[container]: add clean command#1949
Conversation
c9c01f4 to
65a1d09
Compare
2dcbb8b to
72be5b2
Compare
b6c6af6 to
083b3ec
Compare
jglogan
left a comment
There was a problem hiding this comment.
All looks good. I'm building locally to test. Only changes are to remove a probably-unneeded test and to ensure blocks are getting returned to the host OS.
| try waitForContainerRunning(name) | ||
|
|
||
| // Create some files to exercise the filesystem trim path | ||
| _ = try doExec(name: name, cmd: ["sh", "-c", "dd if=/dev/zero of=/test-file bs=1M count=10"]) |
There was a problem hiding this comment.
You could do a little white box testing at this point for both this test and for testCleanWithVolume:
- Use
/dev/urandomas your input to ensure blocks get allocated. With/dev/zerothe OS might optimize those writes. - Run a
synccommand in the guest after line 100. - Measure the number of allocated blocks in the block file on macOS after that.
- Run a
synccommand in the guest after the clean, just to be safe. - Measure the number of allocated blocks after the clean, and assert that the number has decreased within some margin of error (say 80%) of the number of blocks that the
ddcommand allocated.
There was a problem hiding this comment.
Note: updates to the test were made with the help of AI
jglogan
left a comment
There was a problem hiding this comment.
Are you missing a new route in Sources/Plugins/RuntimeLinux/RuntimeLinuxHelper+Start.swift?
I see:
% container clean d027f0a1-dfae-4c04-8e66-3687d511593b
Warning! Running debug build. Performance may be degraded.
Error: internalError: "failed to clean container" (cause: "internalError: "failed to clean container d027f0a1-dfae-4c04-8e66-3687d511593b (cause: "interrupted: "XPC connection error: Connection interrupted"")"")
Ensure container system service has been started with `container system start`.|
@saehejkang It looks like the root fs gets cleaned but not a mounted named volume? I'm testing your branch locally and doing this (the container volume create scratch
container run -it --rm --name clean-test --cap-add ALL -v scratch:/mnt/data ubuntu:nobleBaseline measurement from the host shell: du -sm ~/Library/Application\ Support/com.apple.container/containers/clean-test/rootfs.ext4
du -sm ~/Library/Application\ Support/com.apple.container/volumes/scratch/volume.imgIn the container: dd if=/dev/urandom of=/test.dat bs=65536 count=4096
dd if=/dev/urandom of=/mnt/data/test.dat bs=65536 count=4096
syncThe measured sizes of the files should be larger now. Then, in the container: rm /test.dat
rm /mnt/data/test.dat
syncMeasured sizes should not decrease yet. From the host: container clean clean-testAt this point the measured sizes should be close to the original (or less even, for the root volume). What I'm seeing is that the root fs decreases but the volume does not. If I run fstrim /mnt/data |
Type of Change
Motivation and Context
Closes #1763
Testing