CoW stands for (Copy On Write) in OS
- CoW is Use for Memory management and optimization For New GEN Modern OS
- Instead of creating a full copy of a resources (Memory ,CPU , Page) The OS delays copying until data is actually modified in (Written)
How it works on OS
- When you fork a process in Linux or Unix :
- Parents and child Process Initially Share the same physical resource
- Pages are as read-only
- When either process Tries to write to a shared pages
- Os Creates a Private copy of that page for the writing process
- Save the Ram and Speed !
Benifits
- Reduce memory usage
- Speed Up process creation.
- Allow LightWeight Snapshot data
Copy On Write in Docker
Docker utilizes a copy-on-write (CoW) strategy for efficient storage management and performance optimization, particularly with image layers and containers. This mechanism is central to how Docker shares and manages file system changes.
how it works:
- Image Layers: Docker images are composed of multiple read-only layers. When you build an image, each instruction in your Dockerfile creates a new layer on top of the previous one. These layers are shared across multiple images if they have common base layers, saving disk space.
- Container Writable Layer:When you run a container from an image, Docker adds a thin, writable layer on top of the image's read-only layers. All changes made within the running container occur in this writable layer.
CoW Actions:
- If a process inside a container needs to read a file, it accesses the file directly from the lower, read-only layers if it exists there.
- If a process needs to modify a file that exists in a lower, read-only layer, Docker does not modify the original file. Instead, it copies that file from the read-only layer into the container's writable layer.
Benefits of Copy-on-Write
- Efficient Storage
- Fast Container Startup
- Isolation
Written by Deepak Sen
Top comments (0)