Optimizing the copy-on-write mechanism of docker by dynamic prefetching

Yankun Jiang, Wei Liu, Xuanhua Shi, Weizhong QiangTsinghua 2020 · DOI

Abstract

Docker, as a mainstream container solution, adopts the Copy-on-Write (CoW) mechanism in its storage drivers to allow containers to share the same image layers. However, when a container modifies an image file, a duplicate is created in the upper read-write layer, introducing significant runtime overhead—especially for large files. This paper proposes Dynamic Prefetching Strategy Optimization (DPSO), which optimizes the CoW mechanism by predicting and pre-copying files during the container's startup idle time. Experimental results demonstrate that DPSO achieves an average prefetch accuracy of over 78% and effectively eliminates runtime CoW overhead.

Introduction: The "Copy-on-Write" Tax

Docker images are structured in layers to optimize storage efficiency. Multiple containers can share the same read-only image layers, but any modification to a file requires the storage driver (e.g., OverlayFS) to perform a "copy-up" operation. This operation duplicates the file from the read-only layer to the container's specific read-write layer.

While negligible for small configuration files, this "copy-up" tax becomes a performance bottleneck for large data files or high-volume file modifications. As shown in the performance analysis, the access overhead increases exponentially with file size, reaching nearly 100 seconds ($10^8 \mu s$) for a 4 GB file.

Access overhead increases exponentially with file size, highlighting the performance penalty of the standard CoW mechanism for large files.

Methodology: Dynamic Prefetching Strategy Optimization (DPSO)

The proposed DPSO system aims to hide this latency by exploiting the "idle gap" between container startup and application execution. The system consists of four primary modules:

  1. Metadata Collection: Hooks into the OverlayFS driver to record file copy-up events during runtime.
  2. Storage & Processing: Stores metadata (File ID, frequency, timestamps) in a host-side database.
  3. Probability Model: Ranks files based on their likelihood of being modified, leveraging the deterministic nature of container workloads.
  4. Pre-operation Module: A client-server architecture where the container client fetches high-probability file lists and triggers "pre-copy" operations during idle time.
The DPSO system architecture, illustrating the workflow from metadata collection during runtime to pre-copying files during the startup phase.

Key Insights

  • Exploiting Determinism: Container behavior is often predictable across multiple instances of the same image. DPSO leverages this to predict future file access patterns based on historical usage.
  • Latency Hiding: By shifting heavy I/O operations into the initialization window, the system ensures that the application experiences near-zero file system lag once it starts.
  • Efficiency Threshold: To minimize metadata overhead, the authors implemented a 256 KB filter, focusing prefetching efforts on files where the performance gains are most significant compared to the tracking cost.

Results and Performance

Evaluation using synthetic Ubuntu-based workloads showed that DPSO can reduce runtime overhead for a 4 GB file from approximately 70 seconds to just 0.067 ms, provided sufficient idle time is available to complete the pre-copy. Across complex scenarios, the system maintained a high prediction accuracy, averaging 78.6%. The system overhead for metadata management remained minimal, costing roughly 10 ms per 100 files—a negligible price for eliminating seconds or minutes of runtime lag.

Conclusion

DPSO effectively addresses the performance limitations of Docker's CoW mechanism. By intelligently prefetching files during startup, it eliminates runtime delays that would otherwise freeze applications. Future work will explore more advanced machine learning models to improve prediction accuracy for non-deterministic workloads and integrate the system as a native Docker plugin.

Summary updated

Abstract

Docker, as a mainstream container solution, adopts the Copy-on-Write (CoW) mechanism in its storage drivers. This mechanism satisfies the need of different containers to share the same image. However, when a single container performs operations such as modification of an image file, a duplicate is created in the upper read-write layer, which contributes to the runtime overhead. When the accessed image file is fairly large, this additional overhead becomes non-negligible. Here we present the concept of Dynamic Prefetching Strategy Optimization (DPSO), which optimizes the CoW mechanism for a Docker container on the basis of the dynamic prefetching strategy. At the beginning of the container life cycle, DPSO pre-copies up the image files that are most likely to be copied up later to eliminate the overhead caused by performing this operation during application runtime. The experimental results show that DPSO has an average prefetch accuracy of greater than 78% in complex scenarios and could effectively eliminate the overhead caused by the CoW mechanism.
BibTeX
@inproceedings{jiang2020optimizing,
  author = {Yankun Jiang and Wei Liu and Xuanhua Shi and Weizhong Qiang},
  title = {{Optimizing the copy-on-write mechanism of docker by dynamic prefetching}},
  booktitle = {Tsinghua},
  year = {2020},
  doi = {10.26599/tst.2019.9010034},
}
Figure