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
Devmapper snapshotter does not release disk space when a container exits #5691
Comments
Can you try that with non-loopback devices? I'd like to know whether the issue is depending on that or not. |
I'm not entirely sure how to perform the test without a loopback device. I have a setup with an LVM thin-pool backed by separate ssd attached to my EC2 instance, but I'm not sure how to check if exiting the container releases the physical disk sectors. The LVM tooling (lvs, pvs, vgs) shows me thin-pool information, but not information about the physical device. |
@Kern-- does containerd removes the snapshot when you exit container? (you should see a log message in debug mode about removal - https://github.com/containerd/containerd/blob/main/snapshots/devmapper/snapshotter.go#L274). |
Also have you tried any workarounds by calling dmsetup manually? (clear, pause/resume, etc) ? |
Yes, I do see the snapshot being removed:
Just now I tried suspend/resume and clear with no change. I expect Avail to go back to 5.0G if the space is freed. Is this what you meant?
What does consistently work is
It does seem that the thinpool is reusing the physical space before allocating more. E.g. The following will also recover the disk space:
|
dmsetup does not discard blocks when removing a thin device. The unused blocks are reused by the thin-pool, but will remain allocated in the underlying device indefinitely. For loop device backed thin-pools, this results in "lost" disk space in the underlying file system as the blocks remain allocated in the loop device's backing file. This change adds an option, discard_blocks, to the devmapper snapshotter which causes the snapshotter to issue blkdiscard ioctls on the thin device before removal. With this option enabled, loop device setups will see disk space return to the underlying filesystem immediately on exiting a container. Fixes containerd#5691 Signed-off-by: Kern Walster <walster@amazon.com>
dmsetup does not discard blocks when removing a thin device. The unused blocks are reused by the thin-pool, but will remain allocated in the underlying device indefinitely. For loop device backed thin-pools, this results in "lost" disk space in the underlying file system as the blocks remain allocated in the loop device's backing file. This change adds an option, discard_blocks, to the devmapper snapshotter which causes the snapshotter to issue blkdiscard ioctls on the thin device before removal. With this option enabled, loop device setups will see disk space return to the underlying filesystem immediately on exiting a container. Fixes containerd#5691 Signed-off-by: Kern Walster <walster@amazon.com>
dmsetup does not discard blocks when removing a thin device. The unused blocks are reused by the thin-pool, but will remain allocated in the underlying device indefinitely. For loop device backed thin-pools, this results in "lost" disk space in the underlying file system as the blocks remain allocated in the loop device's backing file. This change adds an option, discard_blocks, to the devmapper snapshotter which causes the snapshotter to issue blkdiscard ioctls on the thin device before removal. With this option enabled, loop device setups will see disk space return to the underlying filesystem immediately on exiting a container. Fixes containerd#5691 Signed-off-by: Kern Walster <walster@amazon.com>
Description
When using the devmapper snapshotter, any disk space used by a container during it's execution will remain allocated in the underlying device after the container exits. In development environments where the devmapper snapshotter docs suggest loopback devices, users will see what appears to be disk space leak in their root filesystem when space is not freed after exiting a container.
As an example, I ran a test where I launched a container, wrote 500MB of random data, and saw that the 500MB remained allocated after the container exited (details in steps to reproduce)
The underlying space does get reused by the thin pool - if I repeatedly launch a container, write 500MB, then exit the container, no additional space is allocated in the underlying device.
The space can be returned to the root filesystem by completely removing the thin-pool and loopback devices, but that means deleting all containerd data as well.
It looks like docker had this same issue in moby/moby#3182 which was tracked down to be that dmsetup does not issue discards to the underlying device when a thin device is removed (https://bugzilla.redhat.com/show_bug.cgi?id=1043527). The docker workaround was to issue BLKDISCARD ioctls to thin devices on removal. Would a similar approach be appropriate here?
Steps to reproduce the issue:
Describe the results you received:
The devmapper snapshotter did not release disk space when the container exited.
Describe the results you expected:
I expected the devmapper snapshotter to release disk space when the container exited.
What version of containerd are you using:
Any other relevant information (runC version, CRI configuration, OS/Kernel version, etc.):
runc --version
uname -a
The text was updated successfully, but these errors were encountered: