Snapshots in Linux Userspace -- Design and Application of a Copy-on-Write Memory Allocation Scheme


Modern operating systems leverage the copy-on-write technique to efficiently manage their memory resources. Copy-on-write can significantly reduce the demand on the memory management system, avoiding copies of entire data blocks whenever memory should be duplicated. Instead, the process is delayed until a modification is made.

The Linux kernel applies copy-on-write in its fork() system call. There are also many other appearances of copy-on-write, for example, for persistence in database systems, for snapshots of file systems or even for reducing memory usage in interpreted languages. However, even though there are many use cases of copy-on-write, the Linux kernel does not provide a dedicated interface to create such mappings. Either, the application developer has to implement a copy-on-write concept, or as many applications do, the application exploits fork() for its copy-on-write.

As a last resort many applications even modify their system's kernel. This work proposes a solution to the lack of such a dedicated mechanism by extending the mremap() system call with a new flag. This new flag lets users of mremap() create a new copy-on-write protected memory mapping from an existing one. Thus, allowing users of mremap() to only snapshot selected data instead of all data.

Additionally, this work also explores and evaluates existing mechanisms in the field of memory snapshots based on quantitative methods. The results show that an inclusion in the Linux kernel can also discourage applications from modifying the kernel, perhaps introducing severe security risks. Therefore, the extension of the Linux kernel with a new mremap() flag enhances the operating system by providing a dedicated interface for users to create efficient page-granular memory snapshots.