redis fork copy on write



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……

Recommended Today

Libp2p RS version 0.3.0 introduction

V0.3.0 released on 4.23, usingAsyncRead & AsyncWriteTo replace ourReadEx & WriteEx & SplitEx; SimplifiedKad/DHTImplementation logic. modify ReadEx & WriteEx & SplitEx: At first we tried to useasync-traitTo define their own IO operationsTraitFor more pure useasync/awaitTo write code. withReadExFor example, it is roughly as follows: #[async_trait] pub trait ReadEx { async fn read(&mut self, buf: &mut […]