Process copying method and apparatus
By splitting the memory page table into two parts: storing page table information and physical address, the parent process first copying page table information and wakes up the child process, and the child process then copying the physical address, solving the problem of time-consuming process copying and improving efficiency.
Patent Information
- Application Number
- CN202111556431.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-12-17
AI Technical Summary
In the prior art process copying process, especially when large memory is occupied, copying the memory page table is severely time-consuming, resulting in the parent process being blocked and unable to process other requests.
The memory page table is split into the first child memory page table that stores the page table information and the second child memory page table that stores the physical address. The parent process first copy the first child memory page table and wakes up the child process, and the child process then copy the second child memory page table.
It avoids blockage caused by copying the physical address of the memory page table by the parent process, and improves process copying efficiency.
Smart Images

Figure CN114416425B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of computer technology, and particularly to a process copying method. This specification also relates to a process copying device, a computing device, a computer-readable storage medium, and a computer program. Background Art
[0002] With the development of computer technology, process copying technology has been widely applied. For example, memory snapshots, persistence, etc. can be achieved using process copying technology. Process copying refers to creating a new process by copying the called process. Among them, 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 of process copying, the memory spaces of the parent process and the child process have the same content.
[0003] However, process copying is an expensive operation. During the execution of process copying, the parent process needs to copy the entire memory page table. If the entire instance memory occupancy is large, then copying the memory page table will be very time-consuming. This process will consume a large amount of resources. Before the process copying is completed, the parent process will be blocked and unable to process any requests. Therefore, a faster process copying method is needed. Summary of the Invention
[0004] In view of this, the embodiments of this specification provide a process copying method. One or more embodiments of this specification also relate to a process copying 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 the first aspect of the embodiments of this specification, a process copying method is provided, including:
[0006] Obtain the memory page table corresponding to the parent process to be copied, where the memory page table includes multi-level page table entries;
[0007] 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, where 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;
[0008] Call the parent process to copy the first sub-memory page table, and create and wake up the child process;
[0009] Call the child process to copy the second sub-memory page table.
[0010] Optionally, calling the child process to copy the second sub-memory page table includes:
[0011] Obtain a second sub - memory page table according to the page table entry of the page table information stored in the first sub - memory page table;
[0012] Invoke a child process to copy the second sub - memory page table.
[0013] Optionally, before invoking the child process to copy the second sub - memory page table, it further includes:
[0014] Set the target page table entry in the first sub - memory page table to the read - only state, where the target page table entry stores the page table information of the second sub - memory page table.
[0015] Optionally, after setting the target page table entry in the first sub - memory page table to the read - only state, it further includes:
[0016] When it is detected that the memory page table corresponding to the parent process is modified, invoke the parent process to copy the memory page table before modification to the child process.
[0017] Optionally, based on multi - level page table entries, splitting the memory page table into a first sub - memory page table and a second sub - memory page table includes:
[0018] When it is detected that a preset switch is activated, split the memory page table into a first sub - memory page table and a second sub - memory page table based on multi - level page table entries.
[0019] Optionally, the multi - level page table entries include a page global directory, a page upper - level directory, a page middle - level directory, and a page table entry. Among them, the page global directory stores the page table information of the page upper - level directory, the page upper - level directory stores the page table information of the page middle - level directory, the page middle - level directory stores the page table information of the page table entry, and the page table entry stores the physical address;
[0020] Based on multi - level page table entries, splitting the memory page table into a first sub - memory page table and a second sub - memory page table includes:
[0021] Split the memory page table, take the page global directory, the page upper - level directory, and the page middle - level directory as the first sub - memory page table, and take the page table entry as the second sub - memory page table.
[0022] Optionally, invoking the parent process to copy the first sub - memory page table, creating and waking up the child process includes:
[0023] Invoke the parent process to copy the first sub - memory page table, and create a child process based on the copied first sub - memory page table;
[0024] Add the child process to the active running queue of the processor.
[0025] According to the second aspect of the embodiments of the present specification, a process copy device is provided, including:
[0026] An acquisition module, configured to acquire a memory page table corresponding to a parent process to be copied, where the memory page table includes multi-level page table entries;
[0027] A splitting module, configured to split the memory page table into a first sub-memory page table and a second sub-memory page table based on the multi-level page table entries, where 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;
[0028] A first calling module, configured to call the parent process to copy the first sub-memory page table and create and wake up a child process;
[0029] A second calling module, configured to call the child process to copy the second sub-memory page table.
[0030] Optionally, the copying module is further configured to obtain the second sub-memory page table according to the page table entries storing page table information in the first sub-memory page table; call the child process to copy the second sub-memory page table.
[0031] Optionally, the apparatus further includes: a setting module;
[0032] The setting module is configured to set target page table entries in the first sub-memory page table to a read-only state, where the target page table entries store page table information of the second sub-memory page table.
[0033] Optionally, the apparatus further includes: a detection module;
[0034] The detection module is configured to, when detecting that the memory page table corresponding to the parent process is modified, call the parent process to copy the memory page table before the modification to the child process.
[0035] Optionally, the splitting module is further configured to, when detecting that a preset switch is activated, split the memory page table into a first sub-memory page table and a second sub-memory page table based on the multi-level page table entries.
[0036] Optionally, the multi-level page table entries include a page global directory, a page upper directory, a page middle directory, and page table entries, where the page global directory stores page table information of the page upper directory, the page upper directory stores page table information of the page middle directory, the page middle directory stores page table information of the page table entries, and the page table entries store physical addresses;
[0037] The splitting module is further configured to split the memory page table, use the page global directory, the page upper directory, and the page middle directory as the first sub-memory page table, and use the page table entries as the second sub-memory page table.
[0038] Optionally, the first calling module is further configured to call the parent process, copy the first sub-memory page table, create a child process based on the copied first sub-memory page table, and add the child process to the active run queue of the processor.
[0039] According to a third aspect of the embodiments of the present specification, a computing device is provided, including:
[0040] A memory and a processor;
[0041] 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, the steps of the above process copying method are implemented.
[0042] According to a fourth aspect of the embodiments of the present specification, a computer-readable storage medium is provided, which stores computer-executable instructions. When the instructions are executed by the processor, the steps of the above process copying method are implemented.
[0043] According to a fifth aspect of the embodiments of the present specification, a computer program is provided. When the computer program is executed on a computer, the computer is made to execute the steps of the above process copying method.
[0044] In an embodiment of the present specification, by obtaining the memory page table corresponding to the parent process to be copied, where the memory page table includes multi-level page table entries; then based on the multi-level page table entries, the memory page table is split into a first sub-memory page table and a second sub-memory page table, where 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; calling the parent process, copying the first sub-memory page table, creating and waking up the child process; calling the child process, and copying the second sub-memory page table. By the above method, the memory page table is split into a first sub-memory page table storing page table entries with page table information and a second sub-memory page table storing page table entries with physical addresses. Since the parent process copying the second sub-memory page table storing page table entries with physical addresses will consume a lot of time, resulting in process blockage. Therefore, during the process copying, the parent process only needs to copy the first sub-memory page table storing page table entries with page table information, and then pass the second sub-memory page table storing page table entries with physical addresses to the child process and call the child process to copy the second memory page table. After the parent process passes the second memory page table to the child process, it directly calls and returns, so that the time-consuming operation of copying the second sub-memory page table storing page table entries with physical addresses can be delayed to the child process, avoiding the blockage of the parent process caused by the parent process copying the physical addresses in the memory page table, and improving the efficiency of process copying. Description of the Drawings
[0045] Figure 1 Shows a flowchart of a process copying method in the prior art;
[0046] Figure 2 shows a flowchart of a process copying method provided according to an embodiment of this specification;
[0047] Figure 3 shows a flowchart of another process copying method provided according to an embodiment of this specification;
[0048] Figure 4 shows a schematic structural diagram of a process copying apparatus provided according to an embodiment of this specification;
[0049] Figure 5 A structural block diagram of a computing device provided according to an embodiment of this specification. Detailed implementation manners
[0050] In the following description, numerous specific details are set forth in order to provide a thorough understanding of this specification. However, this specification can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the connotation of this specification. Therefore, this specification is not limited by the specific implementations disclosed below.
[0051] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a", "the", and "said" used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly dictates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and encompasses any or all possible combinations of one or more of the associated listed items.
[0052] It should be understood that although the terms first, second, etc. may be used in one or more embodiments of this specification to describe various information, such 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 can also be referred to as the second, and similarly, the second can also be referred to as the first. Depending on the context, the word "if" as used herein can be interpreted as "when" or "while" or "in response to determining".
[0053] First, the noun terms related to one or more embodiments of this specification are explained.
[0054] Process copy: Process copy refers to creating a new process by copying the calling process. Here, the calling 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 copy, the memory spaces of the parent process and the child process have the same content.
[0055] Memory snapshot: A memory snapshot is to record the data in memory at a certain moment and save it to the hard disk in the form of a file, so that the data still exists even if the system crashes. After the server restarts, only the recorded memory data needs to be restored.
[0056] Figure 1 The flowchart of a process copy method in the prior art is shown. During the current process copy, after the system kernel calls the process replication function, it starts to copy the parent process. When copying the parent process, it calls the copy process descriptor function to copy the data structures, file descriptors, etc. in the parent process to the child process, and then calls the page table copy function to copy the memory page table in the parent process to the child process; after the parent process copies the memory page table to the child process, it calls the wake-up function to wake up the child process and the system call returns; when the child process receives the child process scheduling function, it directly returns the system call. Among them, the process replication function can be the do_fork() function, the copy process descriptor function can be the copy_process() function, the page table copy function can be the copy_mm() function, the wake-up function can be the wake_up_new_task() function, and the child process scheduling function can be the ret_from_fork function.
[0057] In the above method, when performing a process copy, if the memory occupancy of the memory page table in the parent process is very large, then copying the memory page table will be very time-consuming. This process will consume a large amount of resources. Before the process copy is completed, the parent process will be blocked and unable to process any requests.
[0058] Therefore, based on the defects existing in the above process copying method, this specification further optimizes the page table copying function in the process copying process. Specifically, when copying the memory page table of the parent process, the original page table copying function is split into a page table fast path copying function and a page table slow path copying function. Then, the parent process calls the page table fast path copying function to replace the original page table copying function, and copies the first sub-memory page table containing virtual addresses in the parent process to the child process. Then, the wake-up function is called to wake up the child process and directly return through the system call. When the child process is woken up, the page table slow path copying function is called to copy the second sub-memory page table containing physical addresses in the parent process. After the child process finishes copying the second sub-memory page table, it directly returns through the system call. Among them, the page table fast path copying function can be the copy_mm_fastpath() function, and the page table slow path copying function can be the copy_mm_slowpath() function.
[0059] Through the above method, the memory page table is split into a first sub-memory page table storing page table information page entries and a second sub-memory page table storing physical address page entries. Since the parent process copying the second sub-memory page table storing physical address page entries consumes a lot of time, it causes process blockage. Therefore, during the process copying, the parent process only needs to copy the first sub-memory page table storing page table information page entries, and then passes the second sub-memory page table storing physical address page entries to the child process and calls the child process to copy the second memory page table. After the parent process passes the second memory page table to the child process, it directly calls and returns, so that the time-consuming operation of copying the second sub-memory page table storing physical address page entries can be delayed to the child process, avoiding the parent process blockage caused by the parent process copying the physical addresses in the memory page table and improving the efficiency of process copying.
[0060] In this specification, a process copying method is provided. This specification also relates to a process copying device, a computing device, and a computer-readable storage medium, which will be described in detail one by one in the following embodiments.
[0061] Figure 2 The flowchart of a process copying method provided according to an embodiment of this specification is shown, which specifically includes the following steps.
[0062] Step 202, obtain the memory page table corresponding to the parent process to be copied.
[0063] The memory page table is a data structure in a computer operating system. The memory page table records the correspondence between pages and page frames. Among them, paged storage management divides the virtual address of a process into a series of equally sized parts, called "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 non - contiguous partition allocation of memory, and based on the memory page table, the conversion from virtual address to physical address is realized.
[0064] In this embodiment, the execution entity for executing the process copy method provided in this specification can be the kernel in the operating system. The so - called kernel is the core of an operating system. It is responsible for managing the system's processes, memory, device drivers, files, and network systems, and determines the performance and stability of the system.
[0065] The memory page table includes multiple levels of page table entries, and each level of page table records different information. Generally, each level of page table entries records the query relationship between the first - level page table entries and the next - level page table entries in a way such as a directory. Usually, the actual physical address is recorded in the last - level page table entries. Through multiple levels of page table entries, the physical address corresponding to the process can be located more quickly. Taking a four - level memory page table as an example, the four - level page table entries include the Page Global Directory (PGD), Page Upper Directory (PUD), Page Middle Directory (PMD), and Page Table Entry (PTE). When the kernel as the execution entity copies a process, the actual main process is to copy the Page Global Directory, Page Upper Directory, Page Middle Directory, and Page Table Entry.
[0066] Each process will have its own independent memory space. Therefore, obtaining the memory page table corresponding to the parent process to be copied means that the system kernel as the execution entity obtains the corresponding memory page table from the memory space corresponding to the parent process to be copied.
[0067] In a possible implementation manner of the embodiment of this specification, also taking a four - level memory page table as an example, when the kernel in the operating system needs to copy a process to be copied, it takes the process to be copied as the parent process and obtains the global directory, page upper directory, page middle directory, and page table entry corresponding to the parent process.
[0068] Step 204: Based on multiple levels of page table entries, split the memory page table into a first sub - memory page table and a second sub - memory page table.
[0069] The page table entries storing page table information are stored in the first sub - memory page table, and the page table entries storing physical addresses are stored in the second sub - memory page table.
[0070] As a data structure in a computer operating system, the memory page table is placed in the page table area of the system space. The memory page table stores the corresponding relationship between pages and page frames, that is, the corresponding relationship between virtual addresses and physical addresses. Each process has its own page table, and there is a pointer in the process control block (PCB, Process Control Block) table pointing to the page table. Among them, 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 processes, describe the movement and change process of processes, and at the same time, the system can use the process control block to control and manage processes.
[0071] In the memory page table, there are multiple - level memory page table entries. Among them, each level of memory page table entries in the multiple - level memory page table entries stores the page table information of the next - level memory page table entries, and the last - level page table stores the physical address of a page. Among them, the physical address refers to the address in the memory address space of the CPU. The physical address is used for unit addressing at the memory chip level and corresponds to the address bus connected to the processor and the CPU.
[0072] Taking the three - level memory page table as an example, each entry of the first - level page table entries points to the second - level page table entries, each entry of the second - level page table entries points to the third - level page table entries, and each entry of the third - level page table entries points to the physical address of a page. Another example is taking the four - level memory page table as an example. Each entry of the first - level page table entries points to the second - level page table entries, each entry of the second - level page table entries points to the third - level page table entries, each entry of the third - level page table entries points to the fourth - level page table entries, and each entry of the fourth - level page table points to the physical address of a page.
[0073] In this embodiment, taking the four - level memory page table as an example, the four - level memory page table includes PGD, PUD, PMD, and PTE. Among them, 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. When the execution entity obtains the four - level memory page table corresponding to the parent process to be copied, the four - level memory page table is split.
[0074] In a possible implementation manner of the embodiment of this specification, step 204 can be specifically implemented in the following manner:
[0075] When it is detected that the preset switch is started, based on the multiple - level page table entries, the memory page table is split into a first sub - memory page table and a second sub - memory page table.
[0076] The preset switch refers to a dynamically controlled interface preset in the kernel. When the preset switch is detected to be in the activated state through this interface, the method flow of process copy provided in this specification starts to be implemented. Based on multi-level page table entries, the memory page table is split into a first sub-memory page table and a second sub-memory page table. Among them, the page table entries storing memory page table information are in the first sub-memory page table, and the page table entries storing physical addresses are in the second sub-memory page table.
[0077] In this embodiment, a "switch button" can be added to the display interface of the computer terminal. Among them, the "switch button" is a call function for the memory page table splitting instruction. When the user clicks the "switch button", the call function will be added to the system kernel. When the system kernel detects that the "switch button" is in the on state, the multi-level memory page table will be split into a first sub-memory page table and a second sub-memory page table based on the multi-level memory page table entries.
[0078] In the above implementation, the preset switch is detected. When it is detected that the preset switch is activated, the multi-level 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. Through the above method, when there is a need to accelerate the process copy, the preset switch can be turned on to split the multi-level memory page table, so as to achieve the effect of accelerating the process copy.
[0079] In another possible implementation manner of the embodiment of this specification, step 204 can be specifically implemented in the following way:
[0080] Split the memory page table, take the page global directory, page upper directory, and page middle directory as the first sub-memory page table, and take the page table entries as the second sub-memory page table.
[0081] 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. Among them, 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, in this four-level memory page table, there are four levels of page table entries, namely PGD, PUD, PMD, and PTE. Among them, PGD stores the address of PUD, PUD stores the address of PMD, PMD stores the address of PTE, and PTE stores the physical address corresponding to this process. Since the more levels of page tables in the memory page table, correspondingly, the more page table entries there are in the later stage, therefore, during the process copy, the time consumed for copying the PTE storing the physical address in the memory page table is the longest.
[0082] Therefore, in this embodiment, when the execution entity obtains the four-level memory page table corresponding to the parent process to be copied, the four-level memory page table is split. The PGD, PUD, and PMD in the four-level memory page table are used as the first sub-memory page table, and the PTE in the four-level memory page table is used as the second sub-memory page table.
[0083] Through the above method, only the first sub-memory page table storing page table information in the parent process can be copied, and the time-consuming operation of the second sub-memory page table storing physical address page table entries is delayed to the child process, avoiding the blockage of the parent process caused by the parent process copying the physical addresses in the memory page table and improving the efficiency of process copying.
[0084] Step 206: Invoke the parent process to copy the first sub-memory page table and create and wake up the child process.
[0085] The child process is obtained by the execution entity copying the first sub-memory page table. Therefore, except for the different process identifiers (PID, process ID), the child process is exactly the same as the parent process. The PID is a numerical value used by the kernel in the operating system to uniquely identify a process, and this value can be used as a parameter for many function calls to enable process control behaviors such as adjusting process priorities and commanding processes.
[0086] In a possible implementation manner of the embodiments of this specification, the system kernel as the execution entity starts to invoke the parent process to copy the first sub-memory page table based on the do_fork() function, and creates and wakes up the child process after the copying is completed.
[0087] Taking the four-level memory page table as an example, after splitting the memory page table into the first sub-memory page table containing PGD, PUD, and PMD and the second sub-memory page table containing PTE based on the four-level memory page table entries in the memory page table, the parent process is invoked to copy the first sub-memory page table, and the child process is created and woken up after the copying is completed.
[0088] In a possible implementation manner of the embodiments of this specification, step 206 can be specifically implemented in the following manner:
[0089] Invoke the parent process to copy the first sub-memory page table and create a child process based on the copied first sub-memory page table;
[0090] Add the child process to the active running queue of the processor.
[0091] Taking a four-level memory page table as an example, when the four-level memory page table in the memory page table is split into a first sub-memory page table and a second sub-memory page table based on the four-level memory page table entries, the system kernel as the execution entity will copy the parent process. When copying the parent process, the data copy function copy_mm() function will be decomposed, specifically into the copy_mm_fastpath() function and the copy_mm_slowpath() function, and then the original data copy function copy_mm() function will be replaced by the copy_mm_fastpath() function. The role of the copy_mm_fastpath() function is to copy the first sub-memory page table to the child process. When the copying of the first sub-memory page table by the parent process is completed, a new process will be created as the child process, and then the first sub-memory page table copied by the parent process will be sent to the child process. At this time, the child process has the same first sub-memory page table as the parent process. That is, the copy_mm_fastpath() function is called to copy the PGD, PUD, and PMD in the four-level memory page table, and then the system kernel creates a new process as the child process, and then the copied PGD, PUD, and PMD are sent to the child process.
[0092] After the child process obtains the same first sub-memory page table as the parent process, the parent process passes the relevant memory information of the PTE to the child process through the memory page table entries in the first sub-memory page table, and then the parent process will call the wake-up function to wake up the child process and is directly called back by the system kernel. For example, after the parent process passes the relevant memory information of the 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. Here, the CPU's run queue refers to the process task queue waiting for CPU processing when the process is in the running state.
[0093] In addition to calling the copy_mm_fastpath() function to copy the first sub-memory page table storing virtual addresses in the parent process, the execution entity will also call the copy_procress() function to copy the data structures, file descriptors, etc. in the parent process to the child process. The copy_procress() function will create a new child process with a copy of the current parent process and allocate a process id, but will not actually start this new child process.
[0094] In this embodiment, by calling the parent process, while copying the first sub-memory page table to the child process, data structures, file descriptors, etc. in the parent process are also copied, and the child process is awakened. Through the above method, only the first sub-memory page table in the parent process can be copied, and the time-consuming operation of the second sub-memory page table storing the physical address page table entries is delayed to the child process, avoiding the blockage of the parent process caused by copying the physical addresses in the memory page table of the parent process, and improving the efficiency of process copying.
[0095] In another possible implementation manner of the embodiment of this specification, before calling the child process to copy the second sub-memory page table, it further includes:
[0096] Set the target page table entry in the first sub-memory page table to the read-only state, where the target page table entry stores the page table information of the second sub-memory page table.
[0097] In a multi-level memory page table, the upper-level memory page table entry stores the page table information of the lower-level memory page table entry, and the last-level page table stores. Taking a four-level page table as an example, the four-level page table includes PGD, PUD, PMD, and PTE. Among them, PGD stores the page table information of PUD, PUD stores the page table information of PUD, PUD stores the page table information of PMD, PMD stores the page table information of PTE, and PTE stores the physical address of a page.
[0098] In this embodiment, the target page table entry storing the page table information of the second sub-memory page table in the first sub-memory page table can be PMD. Before calling the child process to copy the second sub-memory page table, first set the read-write permission of PMD to the read-only state.
[0099] There is a mapping relationship among PGD, PUD, and PMD in the first sub-memory page table. When any one of the page table entries is added, modified, or deleted, the mapping relationship among the page table entries at each level in the first sub-memory page table will change. Setting the read-write permission of PMD to the read-only state can prevent the change of PMD from causing the change of the mapping relationship among the entire memory page tables, thereby ensuring that the child process can completely copy the second sub-memory page table in the parent process.
[0100] In the above implementation manner, before calling the child process to copy the second sub-memory page table, setting the target page table entry in the first sub-memory page table to the read-only state can ensure that the child process can completely copy the second sub-memory page table in the parent process, avoiding the situation where the process copying fails due to the modification of the target page table entry in the parent process, and improving the efficiency of process copying.
[0101] In a possible implementation manner of the embodiments of this specification, after setting the target page table entry in the first sub-memory page table to the read-only state, the following steps are further included:
[0102] When it is detected that the memory page table corresponding to the parent process has been modified, call the parent process to copy the memory page table before the modification to the child process.
[0103] The modification of the memory page table corresponding to the parent process means that the memory page table corresponding to the parent process has been added, modified, or deleted.
[0104] In this embodiment, after setting the target page table entry in the first sub-memory page table to read-only, when the user needs to modify the target page table entry, that is, when a write operation needs to be performed on the target page table entry, the parent process needs to copy the memory page table before the modification to the child process. After the parent process copies the memory page table before the modification to the child process, the target page table entry is set to the writable state, and then the corresponding modification is made to the memory page table.
[0105] Alternatively, when it comes to the modification of virtual address information, the memory page table of the parent process will be modified. The situations of modifying virtual address information mainly include vma split, vma detach, numabalance, etc.; from the user's perspective, they are system calls such as mmap, munmap, mprotect, madvise, etc. When it is detected that the memory page table corresponding to the parent process has been modified, the parent process is called to copy the memory page table before the modification to the child process to prevent the modification of the virtual address information of the parent process from affecting the child process. After the parent process copies the memory page table before the modification to the child process, the corresponding modification is made to the memory page table.
[0106] In this embodiment, taking the memory page table in the parent process as a four-level memory page table as an example, in this memory page table, the first sub-memory page tables PGD, PUD, and PMD store the addresses of the next-level page tables, and the second sub-memory page table PTE stores the physical address of a page. If the data information of the first sub-memory page tables PGD, PUD, and PMD in this four-level memory page table is added, modified, or deleted, the mapping relationship between each level of page table address and physical address in the parent process may change. Therefore, when it is detected that the memory page table corresponding to the parent process has been modified, the parent process is called to copy the memory page table before the modification to the child process.
[0107] In a possible implementation manner of the embodiment of the present application, after setting the target page table entry in the first sub-memory page table to the read-only state, if the target page table entry needs to be added, modified, or deleted, that is, when the parent process needs to perform a write operation on the target page table entry, the parent process actively copies the PTE of the second sub-memory page table before modification to the child process according to the PGD, PUD, and PMD in the first sub-memory page table before modification. After the parent process copies the PTE of the second sub-memory page table before modification to the child process, the PTE of the second sub-memory page table is correspondingly modified according to the modified PGD, PUD, and PMD.
[0108] In practical applications, after the system kernel, as the execution entity, sets the read-write permission of the PMD in the first sub-memory page table to read-only, if the PMD needs to be added, modified, or deleted, that is, when the parent process needs to perform a write operation on the address corresponding to the PMD, it will be captured by the processor hardware, and then a page fault exception will occur. At this time, the parent process needs to actively copy the PTE of the second sub-memory page table corresponding to the PMD to the child process, then set the read-write permission of the PMD to writable, and then correspondingly modify the PTE of the second sub-memory page table according to the modified PMD.
[0109] In another possible implementation manner of the embodiment of this specification, the parent process actively detects whether the first sub-memory page table or the second sub-memory page table has been modified. For example, when it comes to the modification of virtual address information, the first sub-memory page table and the second sub-memory page table in the parent process will be modified. The situations of modifying virtual address information mainly include vmasplit, vma detach, numa balance, etc. From the user's perspective, they are system calls such as mmap, munmap, mprotect, and madvise. When the parent process detects that the first sub-memory page table and the second sub-memory page table have been modified, it copies the PTE of the second sub-memory page table before modification to the child process according to the first sub-memory page table before modification. After the parent process copies the PTE of the second sub-memory page table before modification to the child process, the PTE of the second sub-memory page table is correspondingly modified according to the modified first sub-memory page table.
[0110] In the above embodiments, after setting the target page table entry in the first sub-memory page table to the read-only state, when the user needs to modify the target page table entry, or when the parent process actively detects that the first sub-memory page table or the second sub-memory page table has been modified, the parent process needs to actively copy the memory page table before modification to the child process. After copying the memory page table before modification to the child process, the memory page table is then modified accordingly. Through the above method, it can be ensured that when the memory page table corresponding to the parent process is modified, the memory page table before modification is promptly copied to the child process, thereby avoiding the phenomenon of inconsistent data information between the child process and the parent process after the child process copies the second sub-memory page table.
[0111] Step 208, call the child process to copy the second sub-memory page table.
[0112] In this embodiment, the second sub-memory page table stores the physical address of the memory page table. When using do_fork() to copy the parent process, the data copy function copy_mm() function will be decomposed into the copy_mm_fastpath() function and the copy_mm_slowpath() function. After decomposing the data copy function copy_mm() function to obtain the copy_mm_fastpath() function and the copy_mm_slowpath() function, the child process will call the copy_mm_slowpath() function to copy the second sub-memory page table.
[0113] In a possible implementation manner of the embodiments of this specification, step 208 can be specifically implemented in the following manner:
[0114] Obtain the second sub-memory page table according to the page table entry of the page table information stored in the first sub-memory page table;
[0115] Call the child process to copy the second sub-memory page table.
[0116] When the child process obtains the PTE-related memory information passed from 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 sub-memory page table and the PTE-related memory information passed from the parent process to the child process. Among them, the physical address pointed to by the memory page table is stored in the PTE. 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 from 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.
[0117] In this embodiment, according to the page table entries of the page table information stored in the first sub-memory page table, a second sub-memory page table is obtained, and then a child process is called to copy the second sub-memory page table. Through the above method, the child process can only copy the second sub-memory page table storing the physical address, and combine it with the first sub-memory page table copied by the parent process to form a complete memory page table, avoiding the blockage of the parent process caused by the parent process copying the physical address in the memory page table and improving the efficiency of process copying.
[0118] In one embodiment of this specification, by obtaining the memory page table corresponding to the parent process to be copied, where the memory page table includes multi-level page table entries; then based on the multi-level page table entries, the memory page table is split into a first sub-memory page table and a second sub-memory page table, where 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; the parent process is called to copy the first sub-memory page table, create and wake up the child process; the child process is called to copy the second sub-memory page table. Through the above method, the memory page table is split into a first sub-memory page table with page table entries storing page table information and a second sub-memory page table with page table entries storing physical addresses. Since the parent process copying the second sub-memory page table with page table entries storing physical addresses will consume a lot of time, resulting in process blockage. Therefore, during the process copying, the parent process only needs to copy the first sub-memory page table with page table entries storing page table information, and then pass the second sub-memory page table with page table entries storing physical addresses 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, so that the time-consuming operation of copying the second sub-memory page table with page table entries storing physical addresses can be delayed to the child process, avoiding the blockage of the parent process caused by the parent process copying the physical address in the memory page table and improving the efficiency of process copying.
[0119] Figure 3 The flowchart of another process copying method provided according to an embodiment of this specification is shown.
[0120] After the system kernel call process as the execution entity copies the function, it starts to copy the parent process; when copying the parent process, it calls the copy process descriptor function to copy the data structure, file descriptor, etc. in the parent process to the child process, and then calls the page table fast path copy function to copy the first sub-memory page table storing the virtual address of the memory page table in the parent process to the child process; after copying the first sub-memory page table storing the virtual address of the memory page table in the parent process to the child process, it calls the wake-up function to wake up the child process, and then the parent process returns from the system call. When the child process receives the instruction of the child process scheduling function, it calls the page table slow path copy function to copy the second sub-memory page table storing the physical address of the memory page table passed from the parent process to the child process. When the child process finishes copying the second sub-memory page table, the system call returns. Among them, the process copy function can be the do_fork() function, the copy process descriptor function can be the copy_process() function, the page table fast path copy function can be the copy_mm_fastpath() function, the wake-up function can be the wake_up_new_task() function, the child process scheduling function can be the ret_from_fork function, and the page table slow path copy function can be the copy_mm_slowpath() function.
[0121] Through the above method, the memory page table is split into a first sub-memory page table storing page table information page table entries and a second sub-memory page table storing physical address page table entries. Since the parent process copying the second sub-memory page table storing physical address page table entries takes a lot of time, it causes process blockage. Therefore, during the process copy, the parent process only needs to copy the first sub-memory page table storing page table information page table entries, and then pass the second sub-memory page table storing physical address page table entries to the child process and call the child process to copy the second memory page table. After the parent process passes the second memory page table to the child process, it directly calls and returns, so that the time-consuming operation of copying the second sub-memory page table storing physical address page table entries can be delayed to the child process, avoiding the parent process blockage caused by the parent process copying the physical address in the memory page table and improving the efficiency of the process copy.
[0122] Corresponding to the above method embodiment, this specification also provides a process copy device embodiment. Figure 4 It shows a schematic structural diagram of a process copy device provided according to an embodiment of this specification. As Figure 4 shown, the device includes:
[0123] An acquisition module 402, configured to acquire the memory page table corresponding to the parent process to be copied, where the memory page table includes multiple levels of page table entries;
[0124] The splitting module 404 is configured to split the memory page table into a first sub-memory page table and a second sub-memory page table based on the multi-level page table entry, where 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;
[0125] The first calling module 406 is configured to call the parent process to copy the first sub-memory page table and create and wake up a child process;
[0126] The second calling module 408 is configured to call the child process to copy the second sub-memory page table.
[0127] Optionally, the copying module 408 is further configured to:
[0128] Obtain the second sub-memory page table according to the page table entries of the page table information stored in the first sub-memory page table;
[0129] Call the child process to copy the second sub-memory page table.
[0130] Optionally, the device further includes: a setting module;
[0131] The setting module is configured to set the target page table entry in the first sub-memory page table to a read-only state, where the target page table entry stores the page table information of the second sub-memory page table.
[0132] Optionally, the device further includes: a detection module;
[0133] The detection module is configured to call the parent process to copy the memory page table before modification to the child process when it detects that the memory page table corresponding to the parent process has been modified.
[0134] Optionally, the splitting module 404 is further configured to split the memory page table into a first sub-memory page table and a second sub-memory page table based on the multi-level page table entry when it detects that a preset switch is activated.
[0135] Optionally, the multi-level page table entry includes a page global directory, a page upper directory, a page middle directory, and a page table entry. Among them, the page global directory stores the page table information of the page upper directory, the page upper directory stores the page table information of the page middle directory, the page middle directory stores the page table information of the page table entry, and the page table entry stores the physical address;
[0136] The splitting module 404 is further configured to split the memory page table, use the page global directory, the page upper directory, and the page middle directory as the first sub-memory page table, and use the page table entry as the second sub-memory page table.
[0137] Optionally, the first call module 406 is further configured to call the parent process, copy the first child memory page table, create a child process based on the copied first child memory page table, and add the child process to the active run queue of the processor.
[0138] In one embodiment of this specification, by obtaining the memory page table corresponding to the parent process to be copied, where the memory page table includes multi-level page table entries, and then based on the multi-level page table entries, splitting the memory page table into a first child memory page table and a second child memory page table, where the first child memory page table includes page table entries storing page table information, and the second child memory page table includes page table entries storing physical addresses; calling the parent process to copy the first child memory page table, creating and waking up the child process; calling the child process to copy the second child memory page table. By the above method, the memory page table is split into a first child memory page table storing page table entries with page table information and a second child memory page table storing page table entries with physical addresses. Since the parent process copying the second child memory page table storing page table entries with physical addresses takes a lot of time, it causes process blockage. Therefore, during the process of process copying, the parent process only needs to copy the first child memory page table storing page table entries with page table information, and then pass the second child memory page table storing page table entries with physical addresses to the child process and call the child process to copy the second memory page table. After the parent process passes the second memory page table to the child process, it directly calls and returns, so that the time-consuming operation of copying the second child memory page table storing page table entries with physical addresses can be delayed to the child process, avoiding the blockage of the parent process caused by the parent process copying the physical addresses in the memory page table and improving the efficiency of process copying.
[0139] The above is a schematic solution of a process copying device in this embodiment. It should be noted that the technical solution of the process copying device and the technical solution of the above process copying method belong to the same concept. For the details not described in the technical solution of the process copying device, reference can be made to the description of the technical solution of the above process copying method.
[0140] Figure 5 The block diagram of a computing device 500 according to an embodiment of this specification is shown. The components of the computing device 500 include but are not limited to a memory 510 and a processor 520. The processor 520 is connected to the memory 510 through a bus 530, and a database 550 is used to store data.
[0141] The computing device 500 further includes an access device 540, which enables the computing device 500 to communicate via one or more networks 560. Examples of such networks include the Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of wired or wireless network interface (e.g., Network Interface Card (NIC)), such as an IEEE802.11 Wireless Local Area Network (WLAN) wireless interface, Worldwide Interoperability for Microwave Access (Wi-MAX) interface, Ethernet interface, Universal Serial Bus (USB) interface, cellular network interface, Bluetooth interface, Near Field Communication (NFC) interface, and so on.
[0142] In one embodiment of this specification, the above components of the computing device 500 and Figure 5 other components not shown therein may also be connected to each other, for example, via a bus. It should be understood that Figure 5 the block diagram of the computing device shown is for illustrative purposes only and is not a limitation on the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0143] The computing device 500 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 500 can also be a mobile or stationary server.
[0144] Wherein, the processor 520 is used to execute the following computer-executable instructions, and when the computer-executable instructions are executed by the processor, the steps of the above process copying method are implemented.
[0145] The above is a schematic solution of a computing device in this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the above process copying method belong to the same concept. For the details not described in detail in the technical solution of the computing device, reference can be made to the description of the technical solution of the above process copying method.
[0146] This specification also provides a computer-readable storage medium storing computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the above process copying method are implemented.
[0147] The above is a schematic solution of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium and the technical solution of the above process copying method belong to the same concept. For the detailed content not described in the technical solution of the storage medium, reference can be made to the description of the technical solution of the above process copying method.
[0148] An embodiment of this specification also provides a computer program. When the computer program is executed on a computer, the computer is made to execute the steps of the above process copying method.
[0149] The above is a schematic solution of a computer program according to this embodiment. It should be noted that the technical solution of this computer program and the technical solution of the above process copying method belong to the same concept. For the detailed content not described in the technical solution of the computer program, reference can be made to the description of the technical solution of the above method.
[0150] The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve the desired result. Additionally, the processes depicted in the figures do not necessarily require the particular order or sequential order shown to achieve the desired result. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0151] The computer instructions include computer program code, and the computer program code can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium can 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), electrical carrier signal, telecommunication signal, and software distribution medium, etc.
[0152] It should be noted that for the foregoing method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the embodiments of this specification are not limited by the described order of actions, because according to the embodiments of this specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential for the embodiments of this specification.
[0153] In the above embodiments, the descriptions of the respective embodiments each have their own emphasis. For parts not elaborated in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0154] The preferred embodiments of the present specification disclosed above are only used to help explain the present specification. The alternative embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and variations can be made according to the content of the embodiments of the present specification. The present specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of the present specification, so that those skilled in the art can understand and utilize the present specification well. The present specification is only limited by the claims and their full scope and equivalents.
Claims
1. A process copying method, comprising: Obtaining a memory page table corresponding to a parent process to be copied, where the memory page table includes multi-level 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, where 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; Invoking the parent process to copy the first sub-memory page table, creating and waking up a child process, where the memory page table entries in the first sub-memory page table are used to enable the parent process to transfer relevant memory information of the page table entries storing physical addresses to the child process; wherein, invoking the parent process to copy the first sub-memory page table, creating and waking up the child process includes: invoking the parent process to copy the first sub-memory page table, creating a child process after the copying is completed, sending the first sub-memory page table copied by the parent process to the child process, invoking a wake-up function to wake up the child process and directly returning from a system call; Invoking the child process to copy the second sub-memory page table.
2. The method according to claim 1, wherein invoking the child process to copy the second sub-memory page table includes: Obtaining the second sub-memory page table according to the page table entries storing page table information in the first sub-memory page table; Invoking the child process to copy the second sub-memory page table.
3. The method according to claim 1 or 2, before invoking the child process to copy the second sub-memory page table, further comprising: Setting target page table entries in the first sub-memory page table to a read-only state, where the target page table entries store page table information of the second sub-memory page table.
4. The method according to claim 1, after creating and waking up the child process, further comprising: When it is detected that the memory page table corresponding to the parent process is modified, determining the target page table entries that are modified; Invoking the parent process to copy the target page table entries to the child process.
5. The method according to claim 1, wherein 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 includes: When it is detected that a preset switch is started, 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.
6. The method according to any one of claims 1, 2, 4, and 5, wherein the multi-level page table entry includes a page global directory, a page upper directory, a page middle directory, and a page table entry, where The page global directory stores page table information of the page upper directory, the page upper directory stores page table information of the page middle directory, the page middle directory stores page table information of the page table entries, and the page table entries store physical addresses; 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 includes: Splitting the memory page table, taking the page global directory, the page upper directory, and the page middle directory as the first sub-memory page table, and taking the page table entries as the second sub-memory page table.
7. The method according to any one of claims 1, 2, 4, 5, wherein invoking the wake-up function to wake up the child process includes: Call the wake-up function to add the child process to the active run queue of the processor to wake up the child process.
8. A process copying device, comprising: An acquisition module, configured to acquire a memory page table corresponding to a parent process to be copied, the memory page table including multi-level page table entries; A splitting module, configured to split the memory page table into a first sub-memory page table and a second sub-memory page table based on the multi-level page table entries, the first sub-memory page table including page table entries storing page table information, and the second sub-memory page table including page table entries storing physical addresses; A first call module, configured to call the parent process to copy the first sub-memory page table, create and wake up a child process, and the memory page table entries in the first sub-memory page table are used to enable the parent process to transfer relevant memory information of the page table entries storing physical addresses to the child process; The first call module is further configured to call the parent process to copy the first sub-memory page table, create a child process after the copying is completed, send the copied first sub-memory page table of the parent process to the child process, call the wake-up function to wake up the child process and directly return from the system call; A second call module, configured to call the child process to copy the second sub-memory page table.
9. A computing device, comprising: A memory and a 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 copying method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the steps of the process copying method according to any one of claims 1 to 7 are implemented.
11. A computer program product, wherein, When the computer program in the computer program product is executed on a computer, the computer is made to execute the steps of the process copying method according to any one of claims 1 to 7.