redis fork copy on write

Time:2021-4-21

fork

Fork creates a child process. The original process is called the parent process
A wonderful thing about fork() call is that it can only be called once, but it can return twice. It may have three different return values:

  • When the process is a parent process, the PID of the child process is returned
  • When the process is a child process, it returns 0
  • Fork execution failed, return – 1

Common modes:
redis  fork copy on write

There are two possible reasons for fork errors

  • The current number of processes has reached the upper limit specified by the system
  • The system is out of memory

Copy on write

Two processes after forkIt’s the same physical space(memory area), the code segment, data segment and stack of the child process all point to the physical space of the parent process, that is to say, the virtual space of the two processes is different, but the corresponding virtual space is differentPhysical space is the same

When father and son are in the processWhen the behavior of changing the corresponding segment occurs, againAllocate physical space for the corresponding segments of the subprocess

Implementation principle:
fork () After that, the kernel sets the permissions of all memory pages in the parent process to read – Then the address space of the child process points to the parent process. When the father and son processes are read-only memory, nothing happens. When one of the processes writes memory, the CPU hardware detects that the memory page is read – Only, and the page exception interrupt is triggered – Fault), an interrupt routine trapped in the kernel. In the interrupt routine, the kernel willMake a copy of the page that triggers the exceptionSo the father and son processes each hold an independent share.

reference resources

https://blog.csdn.net/qq_3455…
https://zhuanlan.zhihu.com/p/…

Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]