COPY-ON-WRITE 原理

In short, not really in-memory copy when copying a copy object data of the original object to another address, but point to the same location with the original object in the new object memory mapping table, and put the block of memory Copy-On-Write bit is set to 1. When performing a read operation on this object, there is no change in the data memory, can be executed directly. At the time of writing, it really will be a copy of the original object to the new address, modify the memory map of the new object to the new location, and then to write here.
 
This technique requires the use with virtual memory and paging same time, its advantage is that when the replicated objects because does not really copy, but rather to build a "pointer", thus greatly improving performance. But this is not always established, provided that, after copying the new object, the write operation performed only on a small portion of memory paging, paging will not use most or just read. Or it will generate a lot of page fault, not worth the candle.
 
But for fork and exec, this is another matter. Because usually with a fork after exec, the process space completely replaced. So using Copy-On-Write, eliminating an unnecessary process will copy space on the fork

Reproduced in: https: //www.cnblogs.com/licheng/archive/2013/02/18/2916262.html

Guess you like

Origin blog.csdn.net/weixin_34248705/article/details/92628003