I have some code where I frequently copy a large block of memory, often after making only very small changes to it.
I have implemented a system which tracks the changes, but I thought it might be nice, if possible to tell the OS to do a 'copy-on-write' of the memory, and let it deal with only making a copy of those parts which change. However while Linux does copy-on-write, for example when fork()ing, I can't find a way of controlling it and doing it myself.
Copy-on-write pages are also used in the Linux kernel's same-page merging feature. Loading the libraries for an application is also a use of copy-on-write technique. The dynamic linker maps libraries as private like follows. Any writing action on the libraries will trigger a COW in virtual memory management.
Copy-on-write (or COW) is a technique to delay or altogether prevent copying of the data. Rather than duplicate the process address space, the parent and the child can share a single copy. The data, however, is marked in such a way that if it is written to, a duplicate is made and each process receives a unique copy.
Copy On Write (abbreviated as 'COW') is a trick designed to save memory. It is used more generally in software engineering. It means that PHP will copy the memory (or allocate new memory region) when you write to a symbol, if this one was already pointing to a zval.
Copy On Write (COW) is an optimization technique for maintaining a copy of a collection of data, handling resources when multiple tasks are using the same data. The aim of this journaling file system is to bring more efficient storage management and better data integrity features to Linux.
Your best chance is probably to mmap()
the original data to file, and then mmap()
the same file again using MAP_PRIVATE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With