Which segments are affected by a copy-on-write?

前端 未结 2 1921
猫巷女王i
猫巷女王i 2020-12-18 09:16

My understanding of copy-on-write is that \"Everyone has a single, shared copy of the same data until it\'s written, and then a copy is made\".

  1. Is a s
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 09:59

    To better understand, you should eliminate the term segment from your vocabulary. Most systems work on pages; not segments. In 64-bit Intel segments have finally gone away.

    You should be asking, "What pages are affected in copy on write."

    That would be pages that are writeable and shared by multiple processes when one process writes to it.

    This can happen after a fork. One way to implement forking is to create a complete copy of the parent process's address space. However, that could be a lot of effort, especially because most of the time one does an exec in the child right after the fork.

    An alternative is have the parent and children share the same memory. That works fine for read-only memory but has obvious problems if multiple processes can write to the same memory.

    This can be overcome by having the processes charge read/write memory until a process writes to it. In which case, that page becomes unshared by the writing process, the OS allocates a new page frame, maps that to the address space, copies the original data to that page, then allows the writing process to continue.

提交回复
热议问题