Process copying methods and devices

By pre-allocating the virtual address space before process copying and setting the recovery prohibition state, the lag problem caused by virtual address space modification during the memory database snapshot process is solved, and the efficiency of the memory database snapshot is improved.

CN114416426BActive Publication Date: 2024-09-10ALIBABA CLOUD COMPUTING CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202111556437.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-17
Publication Date
2024-09-10
Estimated Expiration
2041-12-17

AI Technical Summary

Technical Problem

When using process copy technology to take in-memory database snapshots, the parent process is often blocked due to modifications to the virtual address space, causing the in-memory database snapshot process to become stuck.

Method used

When receiving the process copy instruction, send an allocation instruction to the memory allocator to pre-allocate a virtual address space that meets the preset space size, and set the access status of the virtual address space to prohibit recycling before the process copy to avoid the virtual address space. Revise.

Benefits of technology

It effectively reduces the probability of blocking caused by insufficient virtual address space, improves the efficiency of memory database snapshots, and avoids blocking of the parent process during process copying.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416426B
    Figure CN114416426B
Patent Text Reader

Abstract

The embodiments of this specification provide a process copy method and device, wherein the process copy method includes: when a process copy instruction is received, sending an allocation instruction to a memory allocator; performing a copy operation on a parent process to create a child process; after the process copy is completed, calling the child process to perform a snapshot process on a memory database to generate snapshot information of the memory database. Through the above method, when a process copy instruction is received, sending an allocation instruction to a memory allocator can effectively reduce the probability of the virtual address space being modified due to insufficient virtual address space, and then performing a copy operation on the parent process to create a child process, and after the process copy is completed, calling the child process to perform a snapshot process on the memory database to generate snapshot information of the memory data, thereby effectively improving the efficiency of the memory database snapshot.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification relate to the field of computer technology, and more particularly to a process copy method. The specification also relates to a process copy device, a computing device, a computer-readable storage medium, and a computer program. Background Art

[0002] With the development of computer technology, process copy technology has been widely used, especially for in-memory database snapshots. Process copy refers to creating a new process by copying the called process, where the called process is called the parent process and the new process is called the child process. The parent process and the child process run in separate memory spaces. During the process copy, the memory spaces of the parent process and the child process have the same content. The so-called in-memory database snapshot refers to recording and storing the data in the in-memory database at a certain moment, so that even if the server crashes, the data still exists. After the server is restarted, you only need to restore the recorded memory data.

[0003] However, when using process copy technology to take in-memory database snapshots, the virtual address space is often modified because memory needs to be allocated after the process is copied, which causes the parent process to be blocked, causing the in-memory database snapshot process to be stuck. Therefore, a faster in-memory database snapshot method is needed. Summary of the invention

[0004] In view of this, the present specification provides a process copy method. One or more embodiments of the present specification also relate to a process copy device, a computing device, a computer-readable storage medium and a computer program to solve the technical defects existing in the prior art.

[0005] According to a first aspect of an embodiment of this specification, a process copy method is provided, including:

[0006] When receiving the process copy instruction, sending an allocation instruction to the memory allocator, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets a preset space size;

[0007] Copy the parent process and create a child process;

[0008] After the process copy is completed, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory database.

[0009] Optionally, before copying the parent process and creating the child process, the following steps are also included:

[0010] A first state setting instruction is sent to the memory allocator, wherein the first state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state.

[0011] Optionally, after calling the subprocess to perform snapshot processing on the memory database and generating snapshot information of the memory database, the method further includes:

[0012] A second state setting instruction is sent to the memory allocator, wherein the second state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a reclaimable state.

[0013] Optionally, before copying the parent process and creating the child process, the following steps are also included:

[0014] If there is an operation instruction of the preset type, a first permission setting instruction is sent to the database kernel, wherein the first permission setting instruction is used to instruct the database kernel to suspend execution of the operation instruction of the preset type.

[0015] Optionally, after calling the subprocess to perform snapshot processing on the memory database and generating snapshot information of the memory database, the method further includes:

[0016] A second permission setting instruction is sent to the database kernel, wherein the second permission setting instruction is used to instruct the database kernel to resume executing a preset type of operation instruction.

[0017] Optionally, a subprocess is called to perform snapshot processing on the memory database to generate snapshot information of the memory database, including:

[0018] Call the child process to read the data in the memory database;

[0019] Serialize the read data and write it to disk to generate snapshot information of the in-memory database.

[0020] Optionally, a copy operation is performed on the parent process to create a child process, including:

[0021] Obtain a memory page table corresponding to the parent process, wherein the memory page table includes multi-level page table entries;

[0022] Based on the multi-level page table entries, splitting the memory page table into a first sub-memory page table and a second sub-memory page table, wherein the first sub-memory page table includes page table entries storing page table information, and the second sub-memory page table includes page table entries storing physical addresses;

[0023] Call the parent process, copy the first child memory page table, create and wake up the child process;

[0024] Call the child process to copy the second child memory page table.

[0025] According to a second aspect of an embodiment of this specification, a process copying device is provided, including:

[0026] The allocation module is configured to send an allocation instruction to the memory allocator when receiving the process copy instruction, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets a preset space size;

[0027] A creation module is configured to copy the parent process and create a child process;

[0028] The generation module is configured to call the child process to perform snapshot processing on the memory database after the process copy is completed, and generate snapshot information of the memory database.

[0029] Optionally, the device further comprises:

[0030] The first state setting instruction sending module is configured to send a first state setting instruction to the memory allocator, wherein the first state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state.

[0031] Optionally, the device further comprises:

[0032] The second state setting instruction sending module is configured to send a second state setting instruction to the memory allocator, wherein the second state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a reclaimable state.

[0033] Optionally, the device further comprises:

[0034] The first permission setting instruction sending module is configured to send the first permission setting instruction to the database kernel if there is an operation instruction of a preset type, wherein the first permission setting instruction is used to instruct the database kernel to suspend execution of the operation instruction of the preset type.

[0035] Optionally, the device further comprises:

[0036] The second permission setting instruction sending module is configured to send a second permission setting instruction to the database kernel, wherein the second permission setting instruction is used to instruct the database kernel to resume executing a preset type of operation instruction.

[0037] Optionally, the generation module is further configured to:

[0038] Call the child process to read the data in the memory database;

[0039] Serialize the read data and write it to disk to generate snapshot information of the in-memory database.

[0040] Optionally, the creation module is further configured to:

[0041] Obtain a memory page table corresponding to the parent process, wherein the memory page table includes multi-level page table entries;

[0042] Based on the multi-level page table entries, splitting the memory page table into a first sub-memory page table and a second sub-memory page table, wherein the first sub-memory page table includes page table entries storing page table information, and the second sub-memory page table includes page table entries storing physical addresses;

[0043] Call the parent process, copy the first child memory page table, create and wake up the child process;

[0044] Call the child process to copy the second child memory page table.

[0045] According to a third aspect of an embodiment of this specification, a computing device is provided, including:

[0046] Memory and processor;

[0047] The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the instructions are executed by the processor, any step of the process copy method is implemented.

[0048] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of any one of the process copy methods are implemented.

[0049] According to a fifth aspect of the embodiments of this specification, a computer program is provided, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned process copy method.

[0050] In the case of receiving a process copy instruction, the embodiment of the present specification sends an allocation instruction to the memory allocator, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets the preset space size; then the parent process is copied to create a child process; after the process copy is completed, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory database. Through the above method, when the process copy instruction is received, the allocation instruction is sent to the memory allocator, which can effectively reduce the probability of the virtual address space being modified due to insufficient virtual address space, and then the parent process is copied to create a child process. After the process copy is completed, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory data, thereby effectively improving the efficiency of the memory database snapshot. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1A flow chart of a process copy method in the prior art is shown;

[0052] Figure 2 A flow chart of another process copy method in the prior art is shown;

[0053] Figure 3 A flowchart of a process copy method provided according to an embodiment of this specification is shown;

[0054] Figure 4 A flowchart of another process copy method provided according to an embodiment of this specification is shown;

[0055] Figure 5 A flowchart of another process copy method provided according to an embodiment of this specification is shown;

[0056] Figure 6 A schematic diagram of the structure of a memory database provided according to an embodiment of this specification is shown;

[0057] Figure 7 A schematic diagram of the structure of a process copy device provided by an embodiment of this specification is shown;

[0058] Figure 8 A structural block diagram of a computing device provided according to an embodiment of the present specification is shown. DETAILED DESCRIPTION

[0059] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.

[0060] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0061] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0062] First, the terms involved in one or more embodiments of this specification are explained.

[0063] In-memory database: An in-memory database is a database that stores data in memory and operates it directly. Compared with disks, the data read and write speed of memory is much higher than that of disks. Storing data in memory can greatly improve application performance compared to accessing it from disk.

[0064] Remote Dictionary Server (Redis): is an open source, network-based, memory-based, and persistent log-based, Key-Value database written in ANSI C, and provides APIs in multiple languages.

[0065] Process copy: Process copy means creating a new process by copying the called process, where the called process is called the parent process and the new process is called the child process. The parent process and the child process run in separate memory spaces. After the process is copied, the memory spaces of the parent process and the child process have the same content.

[0066] In-memory database snapshot: The so-called in-memory database snapshot records the data in the in-memory database at a certain moment and saves it to the hard disk in the form of a file, so that the data still exists even if the server crashes. After the server is restarted, you only need to restore the recorded in-memory data.

[0067] Virtual address space (VMA, Virtual Memory Area): It is an area in the address space, also known as a linear area, which represents a linear interval.

[0068] In the current method of generating memory snapshots, a process copy technology is required. When the process copy function is called, the process is copied to generate a new process. The called process is called the parent process and the new process is called the child process.

[0069] Figure 1The flowchart of a process copy method in the prior art is shown. Before the process is copied, the parent process runs the database logic. The parent process runs the database logic means that the parent process runs the corresponding instructions according to a series of logic codes in the database. When the process copy function is called to start copying the parent process, the parent process will be in a state of suspending the operation of the database logic. Then the parent process copies the data structure, file descriptor, memory page table, etc. to the child process. When the parent process copies the data structure, file descriptor, memory page table, etc. to the child process, the parent process will continue to run the database logic.

[0070] In the above method, when the process is copied, the parent process will suspend the database logic. The time required for the process copy is the time the parent process suspends the database logic. If the memory page table in the parent process occupies a large amount of memory, copying the memory page table will be very time-consuming. Before the process copy is completed, the parent process will be blocked and can no longer process any requests, causing the process of generating the memory database snapshot to be stuck.

[0071] Figure 2 A flowchart of another process copy method in the prior art is shown. Before the process is copied, the parent process is in a state of running the database logic. When the process copy function is called to copy the parent process, the parent process will suspend the running of the database logic and copy part of the data in the parent process to the child process. After the parent process copies part of the data to the child process, it will continue to run the database logic; after receiving part of the data copied by the parent process, the child process will copy the remaining part of the parent process, thereby obtaining the complete data information of the parent process, thereby generating a complete child process.

[0072] In the above method, when copying a process, although the process copying speed is fast and the time consumption is small, when the child process copies the remaining part of the parent process data, the virtual address space modification is often triggered due to memory allocation and other reasons. The parent process performs process copying and the child process performs process copying to trigger the modification of the virtual address space, which will cause the parent process to suspend the operation of the database logic. The time required for the parent process to perform process copying and modify the virtual address space is the time for the parent process to suspend the operation of the database logic. The parent process suspends the operation of the database logic, which causes the parent process to be blocked and unable to process any requests. Only after the virtual address space modification is completed, the parent process can continue to run the database logic, which causes the process of generating the memory database snapshot to be stuck.

[0073] Therefore, based on the defects of the above-mentioned process copy method, this specification further optimizes the process copy process, so as to achieve faster process copying and solve the problem of freezing in the process of generating a snapshot of the memory database. Specifically, when a process copy instruction is received, an allocation instruction is first sent to the memory allocator, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets the preset space size. Then, the parent process is copied to create a child process; after the child process is copied, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory database.

[0074] Through the above method, when a process copy instruction is received, an allocation instruction is sent to the memory allocator, which can effectively reduce the probability of the virtual address space being modified due to insufficient virtual address space. Then, the parent process is copied to create a child process. After the process copy is completed, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory data, thereby effectively improving the efficiency of the memory database snapshot.

[0075] In this specification, a process copy method is provided. This specification also relates to a process copy device, a computing device, and a computer-readable storage medium, which are described in detail one by one in the following embodiments.

[0076] The execution subject of the process copy method provided in the embodiments of this specification may be a device having a process copy requirement, such as a device including a memory database, a device running a Linux system, etc. The process copy method provided in the embodiments of this specification may be implemented by at least one of software, hardware circuits, and logic circuits set in the execution subject.

[0077] Figure 3 A flowchart of a process copy method provided according to an embodiment of the present specification is shown, which specifically includes the following steps.

[0078] S302: When receiving the process copy instruction, send an allocation instruction to the memory allocator, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets a preset space size.

[0079] After a process is copied, the modification of the virtual address space is often triggered due to memory allocation and other reasons, which may cause the parent process to be blocked. Therefore, before using the process copy technology to take a memory database snapshot, it is necessary to pre-allocate sufficient virtual address space to avoid blocking the parent process during the process copy process, thereby accelerating the memory database snapshot.

[0080] In this embodiment, when a process copy instruction is received, the memory database calls the snapshot component to send an allocation instruction to the memory allocator, wherein the process copy instruction may be a do_fork() function, and the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets the preset space size. That is, when a process copy instruction is received, the memory database calls the snapshot component to send an allocation instruction to the memory allocator, and after the memory allocator receives the allocation instruction, the memory allocator calls the operating system kernel to allocate a virtual address space that meets the preset space size, wherein the virtual address space (VMA, Virtual Memory Area) is an area in an address space, also known as a linear area, which represents a linear interval.

[0081] In a possible implementation of the embodiments of the present specification, it is first necessary to preset a space threshold, which can characterize the space usage of each VMA segment. When receiving the process copy instruction do_fork(), the memory database calls the snapshot component to send an allocation instruction to the memory allocator. After the memory allocator receives the allocation instruction, it reads the percentage of the space used by each VMA segment to the currently available space. If the percentage of the used space to the currently available space is lower than the threshold, it is defined that the segment VMA meets the preset space size; or reads the percentage of the currently available space of each VMA segment to the used space. If the percentage of the target available space to the used space is higher than the threshold, it is defined that the segment VMA meets the preset space size. Then the memory allocator calls the operating system kernel to allocate a virtual address space that meets the preset space size.

[0082] In the above embodiment, when a process copy instruction is received, an allocation instruction is sent to the memory allocator to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets the preset space size. This can effectively reduce the probability of the virtual address space being modified due to insufficient virtual address space, thereby improving the efficiency of the memory database snapshot.

[0083] S304: Copy the parent process to create a child process.

[0084] After sending an allocation instruction to the memory allocator, so that the allocator calls the operating system kernel to allocate a virtual address space that meets the preset space size, it is necessary to respond to the process copy instruction, copy the parent process, and create a child process, so that the memory data can be snapshotted based on the child process and snapshot information of the memory database can be generated.

[0085] In a possible implementation of the embodiment of this specification, before the parent process is copied and the child process is created, the following is also included:

[0086] A first state setting instruction is sent to the memory allocator, wherein the first state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state.

[0087] Before copying the parent process and creating the child process, a first state setting instruction for instructing the memory allocator to set the access state of the virtual address space to a prohibited recycling state needs to be sent to the memory allocator.

[0088] In this embodiment, the memory allocator actively reclaims the virtual address space, that is, when the utilization rate of the virtual address space is low, the memory allocator actively sends a request to the operating system to reclaim part of the virtual address space, and the operating system reclaims this part of the virtual address space.

[0089] When the virtual address is recycled, the virtual address space will also be modified accordingly. After the virtual address space is modified, the process copy will cause the parent process to be blocked due to the modification of the virtual address space and will no longer be able to process any requests, causing the process of generating the memory database snapshot to be stuck.

[0090] Therefore, in this embodiment, before performing a copy operation on the parent process and creating a child process, it is also necessary to send a first state instruction to the memory allocator so that the memory allocator sets the access state of the virtual address space to a prohibited recycling state. Through the above method, it is possible to avoid the modification of the virtual address space due to virtual memory recycling, thereby avoiding the blocking of the parent process before the process copy is completed, thereby improving the efficiency of process copying and memory database snapshots.

[0091] In another possible implementation of the embodiment of the present specification, before the parent process is copied to create the child process, the following is further included:

[0092] If there is an operation instruction of the preset type, a first permission setting instruction is sent to the database kernel, wherein the first permission setting instruction is used to instruct the database kernel to suspend execution of the operation instruction of the preset type.

[0093] Before the parent process is copied and the child process is created, if there is an operation instruction of a preset type, a first permission setting instruction for instructing the database kernel to suspend execution of the operation instruction of the preset type is sent to the database kernel.

[0094] The preset type of operation instruction refers to the preset operation instruction that needs to modify the virtual address space. If there is a preset operation instruction that needs to modify the virtual address space, a first permission setting instruction is sent to the database kernel to instruct the database kernel to suspend execution of the preset operation instruction.

[0095] For example, when performing an output log operation, a virtual address space is applied for temporary storage of logs. Since applying for a virtual address space will modify the virtual address space, the output log operation instruction is set in advance as an operation instruction of a preset type. When an output log operation instruction exists, a first permission setting instruction for suspending the execution of the output log instruction is sent to the database kernel. By suspending the execution of the output log instruction, the modification of the virtual address space can be avoided during the process copy.

[0096] In the above implementation, if there is an operation instruction of a preset type, a first permission setting instruction is sent to the database kernel, wherein the first permission setting instruction is used to instruct the database kernel to suspend the execution of the operation instruction of the preset type. Through the above method, the modification of the virtual address space can be avoided before the parent process is copied and the child process is created, thereby avoiding blocking of the parent process before the process copy is completed, thereby improving the efficiency of process copying and memory database snapshots.

[0097] In a possible implementation of the embodiment of this specification, step S304 can be specifically implemented by Figure 4 to achieve this;

[0098] Figure 4 A flowchart of another process copy method provided according to an embodiment of the present specification is shown, which specifically includes the following steps:

[0099] S3042. Obtain a memory page table corresponding to the parent process, wherein the memory page table includes multiple levels of page table entries.

[0100] The memory page table is a data structure in the computer operating system. The memory page table records the correspondence between pages and page frames. The paging storage management divides the virtual address of a process into a series of equal-sized parts, called "pages" or "pages", and numbers each page, starting from 0, such as page 0, page 1, etc. Correspondingly, the available physical memory is also divided into continuous parts of the same size, called "blocks" or "page frames", and each "block" is also numbered, starting from 0#, such as block 0#, block 1#, etc. The memory page table is the basis for the allocation of non-contiguous memory partitions, and the conversion from virtual address to physical address is realized based on the memory page table.

[0101] The memory page table includes multiple levels of page table entries. Each level of the page table records different information. Generally, the page table entries at each level record the query relationship between the first-level page table entries and the next-level page table entries through, for example, directories. Usually, the actual physical address is recorded in the last-level page table entry. The physical address corresponding to the process can be located more quickly through multiple levels of page table entries. Taking the four-level memory page table as an example, the four-level memory page table entries include the page global directory (PGD, Page Global Directory), the page upper directory (PUD, Page Upper Directory), the page middle directory (PMD, Page Middle Directory), and the page table entry (PTE, Page Table Entry). To copy a process, the actual main process is to copy the page global directory, the page upper directory, the page middle directory, and the page table entry.

[0102] In a possible implementation of the embodiments of this specification, taking the four-level memory page table as an example, before obtaining the memory page table corresponding to the parent process so as to copy the memory page table in the process, it is also necessary to call the copy_procress() function to copy the data structure, file descriptor, etc. in the parent process to the child process. After the data structure, file descriptor, etc. in the parent process are copied to the child process, the global directory, page upper directory, page middle directory, and page table entry corresponding to the parent process are obtained.

[0103] S3044. Based on the multi-level page table entries, split the memory page table into a first sub-memory page table and a second sub-memory page table, wherein the first sub-memory page table includes page table entries storing page table information, and the second sub-memory page table includes page table entries storing physical addresses.

[0104] The memory page table is a data structure in the computer operating system, which is placed in the page table area of ​​the system space. The memory page table stores the correspondence between pages and page frames, that is, the correspondence between virtual addresses and physical addresses. Each process has its own page table, and there is a pointer to the page table in the process control block (PCB). The process control block is a special data structure set by the operating system to manage processes. The system uses it to record the external characteristics of the process and describe the movement and change process of the process. At the same time, the system can use the process control block to control and manage the process.

[0105] The memory page table includes multiple levels of memory page table entries, wherein the multiple levels of memory page table entries store the page table information and the physical address of the memory page table, wherein the physical address refers to the address in the memory address space of the CPU, and the physical address is used for unit addressing at the memory chip level, and corresponds to the address bus connecting the processor and the CPU.

[0106] Taking the three-level memory page table as an example, each entry of the first-level page table entry points to the second-level page table entry, each entry of the second-level page table entry points to the third-level page table entry, and each entry of the third-level page table entry points to the physical address of a page. For another example, taking the four-level memory page table as an example, each entry of the first-level page table entry points to the second-level page table entry, each entry of the second-level page table entry points to the third-level page table entry, each entry of the third-level page table entry points to the fourth-level page table entry, and each entry of the fourth-level page table points to the physical address of a page.

[0107] In this embodiment, taking a four-level memory page table as an example, the four-level memory page table includes PGD, PUD, PMD and PTE, wherein each entry of PGD points to PUD, each entry of PUD points to PMD, each entry of PMD points to PTE, and each entry of PTE points to the physical address of a page. That is to say, the correspondence between the four-level memory page tables is stored in the memory page table, and the four-level memory page table includes four-level page table entries, namely PGD, PUD, PMD and PTE, wherein the page table information of PUD is stored in PGD, the page table information of PMD is stored in PUD, the page table information of PMD is stored in PMD, and the physical address corresponding to the process is stored in PTE. Since the more page table levels of the memory page table, the more page table entries there are, therefore, in the process of process copying, the longest time is spent on copying the PTE storing the physical address in the memory page table.

[0108] Therefore, in this embodiment, when the four-level memory page table corresponding to the parent process to be copied is obtained, the four-level memory page table is split, and the PGD, PUD and PMD containing the virtual address of the four-level memory page table are used as the first sub-memory page table; the PTE containing the physical address of the four-level memory page table is used as the second sub-memory page table.

[0109] S3046, calling the parent process, copying the first child memory page table, creating and waking up the child process;

[0110] The child process is obtained by copying the first child memory page table. Therefore, the child process and the parent process are exactly the same except for the process identifier (PID, processID). PID refers to a value used by the kernel in the operating system to uniquely identify a process. This value can be used as a parameter for many function calls to make it possible to adjust process priority, command processes and other process control behaviors.

[0111] In a possible implementation of the embodiments of this specification, taking a four-level memory page table as an example, after the memory page table is split into a first sub-memory page table and a second sub-memory page table based on the multi-level memory page table entries in the memory page table, the parent process is copied, which can be specifically implemented in the following manner:

[0112] First, the data copy function copy_mm() is decomposed into copy_mm_fastpath() and copy_mm_slowpath(). Then, the original data copy function copy_mm() is replaced with copy_mm_fastpath(), where the copy_mm_fastpath() function is used to copy the first child memory page table to the child process. That is, the copy_mm_fastpath() function is called to copy the PGD, PUD, and PMD in the four-level memory page table to the child process and pass the relevant memory information of PTE to the child process.

[0113] After the parent process passes the relevant memory information of PTE to the child process, the parent process will call the wake-up function to wake up the child process, and the operating system kernel will call and return directly. For example, after the parent process passes the relevant memory information of PTE to the child process, the parent process will call the wake-up function wake_up_new_task to add the created child process to the CPU's run queue to wake up the child process, where the CPU's run queue refers to the process task queue waiting for CPU processing when the process is in the running state.

[0114] S3048. Call the child process to copy the second child memory page table.

[0115] When the child process obtains the PTE-related memory information passed by the parent process, the child process will call the copy_mm_slowpath() function to copy the PTE according to the virtual addresses stored in the PGD, PUD, and PMD in the first child memory page table and the PTE-related memory information passed from the parent process to the child process, where the PTE stores the physical address pointed to by the memory page table. After the child process calls the copy_mm_slowpath() function to copy the PTE, the child process obtains the complete four-level memory page table of the parent process, that is, after the child process copies the PTE based on the PTE-related memory information passed by the parent process, combined with the PGD, PUD, and PMD copied by the parent process, a complete four-level memory page table is finally formed.

[0116] In the above implementation, by obtaining the memory page table corresponding to the parent process, wherein the memory page table includes multi-level page table items; then based on the multi-level page table items, the memory page table is split into a first sub-memory page table and a second sub-memory page table, wherein the first sub-memory page table includes a page table item storing page table information, and the second sub-memory page table includes a page table item storing a physical address; calling the parent process, copying the first sub-memory page table, creating and waking up the child process; calling the child process, copying the second sub-memory page table. Through the above method, the memory page table is split into a first sub-memory page table storing a page table item of page table information and a second sub-memory page table storing a physical address page table item. Since the parent process consumes a lot of time to copy the second sub-memory page table storing a physical address page table item, it causes process congestion. Therefore, in the process of process copying, the parent process only needs to copy the first sub-memory page table storing the page table item of page table information, and then pass the second sub-memory page table storing the physical address page table item to the child process and call the child process to copy the second memory page table. After passing the second memory page table to the child process, the parent process directly calls and returns, thereby delaying the time-consuming operation of copying the second child memory page table storing the physical address page table entry to the child process, avoiding the parent process from being blocked due to the parent process copying the physical address in the memory page table, and improving the efficiency of process copying.

[0117] S306: After the process copy is completed, the child process is called to perform snapshot processing on the memory data to generate snapshot information of the memory database.

[0118] After the process copy is completed, the child process is called to perform snapshot processing on the memory database, thereby generating memory database snapshot information. The memory database snapshot is the state of the Remote Dictionary Server (Redis) at a certain moment, saved on the disk in the form of a file. This snapshot file is the snapshot information of the generated memory database, saved in the form of an RDB (Redis Database) file.

[0119] After the state of Redis at a certain moment is saved on the disk in the form of an RDB file, even if a crash occurs, the data saved on the disk still exists. When recovering from the failure, it can be restored by simply reading the RDB file into the memory, and the recovery speed is very fast.

[0120] In a possible implementation of the embodiment of this specification, step S306 can be specifically implemented in the following manner:

[0121] Call the child process to read the data in the memory database.

[0122] Serialize the read data and write it to disk to generate snapshot information of the in-memory database.

[0123] In this embodiment, it is necessary to use the bgsave command to call a subprocess, and the subprocess performs snapshot processing on the memory database, thereby generating snapshot information of the memory database in the form of an RDB file.

[0124] In actual applications, when the child process is called using the basave command, the child process begins to read the data in the memory database and serializes the read data. The serialization operation refers to converting the memory database data into an RDB file that can be stored or transmitted. During serialization, the memory database data in the form of an RDB file is written to the disk, thereby generating a snapshot of the memory database. After that, the RDB file can be read directly from the disk to achieve a persistence effect.

[0125] Through the above method, the child process is called to read the data in the memory database, and then the read data is serialized and written to the disk to generate snapshot information of the memory data. Through the above method, the data in the memory database read by the child process can be permanently saved on the disk, thereby achieving the effect of data persistence.

[0126] In a possible implementation of the embodiment of this specification, after calling the subprocess to perform snapshot processing on the memory data and generating snapshot information of the memory database, it also includes:

[0127] A second state setting instruction is sent to the memory allocator, wherein the second state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a reclaimable state.

[0128] After the parent process is copied and the child process is created, the child process needs to send a notification of process copy completion to the main process, and the notification can be implemented by calling a function.

[0129] After the main process receives the notification that the copy of the subprocess is completed, the execution subject calls the main process to send a second state setting instruction to the operating system kernel for instructing the operating system kernel to set the access state of the virtual address space to a reclaimable state.

[0130] During the process copying, a first state setting instruction is sent to the memory allocator to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state. This may cause insufficient virtual address space after the process copying is completed.

[0131] Therefore, in this embodiment, after the parent process is copied and the child process is created, a second state instruction needs to be sent to the memory allocator so that the memory allocator sets the access state of the virtual address space to a reclaimable state. Through the above method, the phenomenon of insufficient virtual address space due to process copying can be avoided, thereby avoiding process jams, thereby improving the efficiency of process copying and memory database snapshots.

[0132] In another possible implementation of the embodiment of the present specification, after calling the subprocess to perform snapshot processing on the memory data and generating snapshot information of the memory database, it also includes:

[0133] A second permission setting instruction is sent to the database kernel, wherein the second permission setting instruction is used to instruct the database kernel to set an operation instruction to resume execution of a preset type.

[0134] After the parent process is copied and the child process is created, a second permission setting instruction for instructing the database kernel to set and restore the execution of a preset type of operation instruction needs to be sent to the database kernel.

[0135] During the process copying, a first state setting instruction for instructing the operating system kernel to suspend execution of a preset type of operation instruction is sent to the operating system kernel, which may cause insufficient virtual address space after the process copying is completed.

[0136] Therefore, in this embodiment, after the parent process is copied and the child process is created, a second permission setting instruction needs to be sent to the operating system kernel so that the operating system kernel can resume executing the preset type of operation instruction. Through the above method, the phenomenon of insufficient virtual address space due to process copying can be avoided, thereby avoiding process freezes, thereby improving the efficiency of process copying and memory database snapshots.

[0137] Figure 5 A flowchart of another process copy method provided according to an embodiment of the present specification is shown.

[0138] The execution subject of the process copy method provided in the embodiment of this specification may be a memory database. Figure 6 The schematic diagram of the structure of a memory database provided according to an embodiment of the present specification is shown. A memory database refers to a database that directly operates data in memory. Compared with a disk, the data reading and writing speed of the memory is much higher than the reading and writing speed of the disk. Storing data in memory can greatly improve the performance of the application compared to accessing it from a disk.

[0139] The in-memory database is built on the operating system kernel, which includes the in-memory database kernel, memory allocator, snapshot component and other parts. The database kernel, snapshot component and memory allocator directly call each other by calling functions (i.e. function calls); the memory allocator calls the operating system kernel by calling the interface in the operating system kernel (i.e. system calls). In addition, the memory allocator is responsible for the allocation and management of memory, and the snapshot component is responsible for generating database snapshots.

[0140] When the memory database receives a process copy instruction, it calls the snapshot component to send an allocation instruction to the memory allocator. After receiving the allocation instruction, the memory allocator calls the operating system kernel to allocate a virtual address space that meets the preset space size.

[0141] Then, the memory database sends a first state setting instruction to the memory allocator. After receiving the first state setting instruction, the memory allocator sets the access state of the virtual address space to a prohibited recycling state.

[0142] When the memory database sends the first state setting instruction to the memory allocator, if there is a preset type of operation instruction, the first permission setting instruction is sent to the database kernel. After the database kernel receives the first permission setting instruction, it suspends the execution of the preset type of operation instruction.

[0143] After allocating a virtual address space that meets the preset space size, setting the access state of the virtual address space to a prohibited recycling state, and suspending the execution of preset type of operation instructions, the parent process is copied and a child process is created. After the first child memory page table storing the memory page table information in the parent process is copied to the child process, the parent process returns the call and continues to run the database logic. The child process continues to copy the second child memory page table. When the child process completes the copy of the second child memory page table, the child process has the complete memory page table data of the parent process. At this time, the child process is called to send a notification of the completion of the process copy to the parent process, and at the same time, the data of the memory database in the child process after the process copy is read, and then the read data is serialized and written to the disk to generate snapshot information of the memory database.

[0144] When the parent process receives the notification of process copy completion sent by the child process, the memory database calls the parent process to send a second state setting instruction to the memory allocator. When the memory allocator receives the second state setting instruction, it sets the access state of the virtual address space to a reclaimable state.

[0145] When the memory database calls the main process to send the second state setting instruction to the operating system kernel, it also needs to call the main process to send the second permission setting instruction to the database kernel. After the database kernel receives the second permission setting instruction, it resumes executing the preset type of operation instruction.

[0146] Through the above method, when a process copy instruction is received, an allocation instruction is sent to the memory allocator, which can effectively reduce the probability of the virtual address space being modified due to insufficient virtual address space. Then, the parent process is copied to create a child process. After the process copy is completed, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory data, thereby effectively improving the efficiency of the memory database snapshot.

[0147] Corresponding to the above method embodiment, this specification also provides a process copy device embodiment, Figure 7 FIG. 1 shows a schematic diagram of the structure of a process copying device provided by an embodiment of the present specification. Figure 7 As shown, the device comprises:

[0148] The allocation module 702 is configured to send an allocation instruction to the memory allocator when receiving the process copy instruction, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets a preset space size;

[0149] The creation module 704 is configured to copy the parent process and create a child process;

[0150] The generation module 706 is configured to call the child process to perform snapshot processing on the memory database after the process copy is completed, and generate snapshot information of the memory database.

[0151] Optionally, the device further comprises:

[0152] The first state setting instruction sending module is configured to send a first state setting instruction to the memory allocator, wherein the first state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state.

[0153] Optionally, the device further comprises:

[0154] The second state setting instruction sending module is configured to send a second state setting instruction to the memory allocator, wherein the second state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a reclaimable state.

[0155] Optionally, the device further comprises:

[0156] The first permission setting instruction sending module is configured to send the first permission setting instruction to the database kernel if there is an operation instruction of a preset type, wherein the first permission setting instruction is used to instruct the database kernel to set a pause in executing the operation instruction of the preset type.

[0157] Optionally, the device further comprises:

[0158] The second permission setting instruction sending module is configured to send a second permission setting instruction to the database kernel, wherein the second permission setting instruction is used to instruct the database kernel to resume executing a preset type of operation instruction.

[0159] Optionally, the generating module 706 is further configured to:

[0160] Call the child process to read the data in the memory database;

[0161] Serialize the read data and write it to disk to generate snapshot information of the in-memory database.

[0162] Optionally, the creation module 704 is further configured to:

[0163] Obtain a memory page table corresponding to the parent process, wherein the memory page table includes multi-level page table entries;

[0164] Based on the multi-level page table entries, splitting the memory page table into a first sub-memory page table and a second sub-memory page table, wherein the first sub-memory page table includes page table entries storing page table information, and the second sub-memory page table includes page table entries storing physical addresses;

[0165] Call the parent process, copy the first child memory page table, create and wake up the child process;

[0166] Call the child process to copy the second child memory page table.

[0167] The present specification provides a process copy device, which, upon receiving a process copy instruction, sends an allocation instruction to a memory allocator, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets a preset space size; then a copy operation is performed on the parent process to create a child process; after the process copy is completed, the child process is called to perform a snapshot process on the memory database to generate snapshot information of the memory database. Through the above method, upon receiving a process copy instruction, an allocation instruction is sent to the memory allocator, which can effectively reduce the probability of the virtual address space being modified due to insufficient virtual address space, and then a copy operation is performed on the parent process to create a child process, and after the process copy is completed, the child process is called to perform a snapshot process on the memory database to generate snapshot information of the memory data, thereby effectively improving the efficiency of the memory database snapshot.

[0168] The above is a schematic scheme of a process copy device of this embodiment. It should be noted that the technical scheme of the process copy device and the technical scheme of the process copy method described above are of the same concept, and the details not described in detail in the technical scheme of the process copy device can be found in the description of the technical scheme of the process copy method described above.

[0169] Figure 8 The block diagram of a computing device 800 according to an embodiment of the present specification is shown. The components of the computing device 800 include but are not limited to a memory 810 and a processor 820. The processor 820 is connected to the memory 810 via a bus 830, and a database 850 is used to store data.

[0170] The computing device 800 also includes an access device 840 that enables the computing device 800 to communicate via one or more networks 860. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 840 may include one or more of any type of network interface (e.g., a network interface card (NIC)) that is wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.

[0171] In one embodiment of the present specification, the above components of the computing device 800 and Figure 8 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 8 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0172] The computing device 800 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 800 may also be a mobile or stationary server.

[0173] The processor 820 is used to execute the following computer executable instructions, which implement the steps of the above-mentioned process copy method when executed by the processor.

[0174] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the process copy method described above are of the same concept, and the details not described in detail in the technical scheme of the computing device can be found in the description of the technical scheme of the process copy method described above.

[0175] An embodiment of the present specification also provides a computer-readable storage medium storing computer-executable instructions, which implement the steps of the above-mentioned process copy method when executed by a processor.

[0176] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the process copy method described above are of the same concept, and the details not described in detail in the technical scheme of the storage medium can be found in the description of the technical scheme of the process copy method described above.

[0177] An embodiment of the present specification further provides a computer program, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned process copy method.

[0178] The above is a schematic scheme of a computer program of this embodiment. It should be noted that the technical scheme of the computer program and the technical scheme of the process copy method described above are of the same concept, and the details not described in detail in the technical scheme of the computer program can be found in the description of the technical scheme of the process copy method described above.

[0179] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0180] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.

[0181] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.

[0182] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0183] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is only limited by the claims and their full scope and equivalents.

Claims

1. A process copy method, comprising: When receiving the process copy instruction, sending an allocation instruction to the memory allocator, wherein the allocation instruction is used to instruct the memory allocator to call the operating system kernel to allocate a virtual address space that meets a preset space size; Performing a copy operation on the parent process to create a child process, wherein before performing the copy operation on the parent process to create the child process, it also includes: sending a first state setting instruction to the memory allocator, the first state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state; After the process copy is completed, the child process is called to perform snapshot processing on the memory database to generate snapshot information of the memory database, wherein after calling the child process to perform snapshot processing on the memory database to generate snapshot information of the memory database, it also includes: sending a second state setting instruction to the memory allocator, and the second state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a reclaimable state.

2. The method according to claim 1, before copying the parent process to create the child process, further comprises: If there is an operation instruction of the preset type, a first permission setting instruction is sent to the database kernel, where the first permission setting instruction is used to instruct the database kernel to suspend execution of the operation instruction of the preset type.

3. The method according to claim 2, after calling the subprocess to perform snapshot processing on the memory database and generating snapshot information of the memory database, further comprises: A second permission setting instruction is sent to the database kernel, where the second permission setting instruction is used to instruct the database kernel to resume executing the operation instruction of the preset type.

4. According to the method of claim 1, the calling of the subprocess to perform snapshot processing on the memory database to generate snapshot information of the memory database comprises: Calling the subprocess to read the data in the memory database; The read data is serialized and written to the disk to generate snapshot information of the memory database.

5. According to the method of claim 1, the step of copying the parent process to create a child process comprises: Obtain a memory page table corresponding to the parent process, wherein the memory page table includes multiple levels of page table entries; Based on the multi-level page table entries, splitting the memory page table into a first sub-memory page table and a second sub-memory page table, wherein the first sub-memory page table includes a page table entry storing page table information, and the second sub-memory page table includes a page table entry storing a physical address; Calling the parent process, copying the first child memory page table, and creating and waking up a child process; The child process is called to copy the second child memory page table.

6. A memory database snapshot device, comprising: An allocation module is configured to send an allocation instruction to a memory allocator when receiving a process copy instruction, wherein the allocation instruction is used to instruct the memory allocator to call an operating system kernel to allocate a virtual address space that meets a preset space size; A creation module is configured to copy the parent process to create a child process, wherein the creation module further includes: a first state setting instruction sending module, configured to send a first state setting instruction to the memory allocator, the first state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a prohibited recycling state; a second state setting instruction sending module, configured to send a second state setting instruction to the memory allocator, the second state setting instruction is used to instruct the memory allocator to set the access state of the virtual address space to a recycling state; The generation module is configured to call the subprocess to perform snapshot processing on the memory database after the process copy is completed, and generate snapshot information of the memory database.

7. A computing device comprising: Memory and processor; The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the process copy method described in any one of claims 1 to 5 are implemented.

8. A computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the process copy method according to any one of claims 1 to 5.

9. A computer program product, comprising a computer program, which, when executed in a computer, causes the computer to execute the steps of the process copy method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for achieving real-time operation on data base

    CN103593485A

  • Method and device for backing up and restoring database data

    CN109426585A

  • Process processing method and device and electronic equipment

    CN112084058A

  • Data backup method and device, data recovery method and device and electronic equipment

    CN112114999A

  • Process creation method and device and electronic equipment

    CN112231121A