Process creation methods, devices, electronic devices, and computer-readable media
By sharing memory space with the child process only when the parent process's first page table entry does not support modification during child process creation, the problem of wasted memory space in the prior art is solved, and more efficient memory utilization is achieved.
Patent Information
- Application Number
- CN202211085599.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-06
- Publication Date
- 2026-11-10
- Estimated Expiration
- 2042-09-06
AI Technical Summary
Existing process creation methods result in wasted memory space, especially when directly copying page table entries from the parent process.
When creating a child process, it is only shared with the child process if the first page table entry of the parent process does not support modification, thus avoiding unnecessary memory space consumption.
This reduces the memory space occupied when child processes are created and avoids the impact of changes to shared page table entries on other processes.
Smart Images

Figure CN116302376B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a process creation method, apparatus, electronic device, and computer-readable medium. Background Technology
[0002] Currently, with the development of electronic information technology, electronic devices are being used more and more widely. While it's possible to create child processes by calling the parent process, thus spawning new child processes, existing methods of process creation result in unnecessary waste of memory space. Summary of the Invention
[0003] This application discloses a process creation method, apparatus, electronic device, and computer-readable medium.
[0004] In a first aspect, embodiments of this application provide a method for determining a memory region, applied to an electronic device. The method includes: responding to a child process creation request, determining a parent process executing the process creation request, wherein the child process creation request corresponds to a specified page table entry, the specified page table entry including a virtual address segment of the child process; obtaining a first page table entry of the parent process, wherein the physical address segment of the first page table entry is a target address segment; if the first page table entry does not support modification, pointing the virtual address segment of the child process to the target address segment to obtain a second page table entry; and creating a child process based on the second page table entry.
[0005] Secondly, embodiments of this application also provide a memory region determination apparatus, the apparatus comprising: a response unit, configured to, in response to a child process creation request, determine a parent process executing the process creation request, the child process creation request corresponding to a specified page table entry, the specified page table entry including a virtual address segment of the child process; an acquisition unit, configured to acquire a first page table entry of the parent process, the physical address segment of the first page table entry being a target address segment; a processing unit, configured to, if the first page table entry does not support modification, point the virtual address segment of the child process to the target address segment to obtain a second page table entry; and a creation unit, configured to, if the second page table entry is used, create a child process.
[0006] Thirdly, embodiments of this application also provide an electronic device, including: one or more processors; a memory; the one or more processors for executing instructions; the memory for providing physical addresses; the bus for providing data transmission; and the one or more processors for performing the above-described method.
[0007] Fourthly, embodiments of this application also provide a computer-readable medium storing processor-executable program code, which, when executed by the processor, causes the processor to perform the above-described method.
[0008] Fifthly, embodiments of this application also provide a computer program product, including a computer program / instructions that, when executed by a processor, implement the above-described method.
[0009] This application provides a process creation method, apparatus, electronic device, and computer-readable medium. In this method, the electronic device, in response to a child process creation request, determines the parent process executing the process creation request. The child process creation request corresponds to a specified page table entry, which includes a virtual address segment of the child process. Then, it obtains a first page table entry of the parent process, where the physical address segment of the first page table entry is a target address segment. If the first page table entry does not support modification, the virtual address segment of the child process is pointed to the target address segment to obtain a second page table entry. The child process is then created based on the second page table entry. Directly copying the parent process's first page table entry and then creating the child process based on the copied page table entry would consume a significant amount of memory. However, if the parent process's first page table entry is shared with the child process for creation, and the first page table entry is modified, the child process sharing the first page table entry may change its contents, thus affecting other child processes that share the first page table entry, and also affecting the parent process. Therefore, in the embodiments provided in this application, the first page table entry is shared with the child process only when it is not supported to be modified. The child process created based on the shared first page table entry will not have its corresponding page table entry occupy excessive memory space, thereby reducing the memory space occupied by the child process's page table entry when creating the child process.
[0010] Other features and advantages of the embodiments of this application will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the embodiments of this application. The objects and other advantages of the embodiments of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 A structural block diagram of the electronic device provided in an embodiment of this application is shown; Figure 2 A flowchart of the process creation method provided in an embodiment of this application is shown; Figure 3 A flowchart of a process creation method provided in another embodiment of this application is shown; Figure 4 A diagram illustrating one embodiment of step S230 is shown. Figure 5 A flowchart of a process creation method provided in another embodiment of this application is shown; Figure 6 This illustration shows a schematic diagram of the process for finding the target page provided in an embodiment of this application; Figure 7 This illustration shows a schematic diagram of the process for finding a target page according to another embodiment of this application; Figure 8 A diagram illustrating one embodiment of step S390 is shown. Figure 9 A flowchart of a process creation method provided in another embodiment of this application is shown; Figure 10 A unit block diagram of the process creation apparatus provided in an embodiment of this application is shown; Figure 11 A schematic diagram of an electronic device according to yet another embodiment of this application is shown; Figure 12 This paper shows a structural block diagram of a computer-readable storage medium provided in an embodiment of this application; Figure 13 A structural block diagram of a computer program product provided in an embodiment of this application is shown. Detailed Implementation
[0013] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, and not all of them. The components of the embodiments of the present application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without inventive effort are within the scope of protection of the present application.
[0014] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0015] Currently, with the development of electronic information technology, electronic devices are being used more and more widely. While it's possible to create child processes by calling a parent process, thereby spawning new child processes, existing methods of process creation lead to unnecessary waste of memory space. Therefore, how to save memory space when creating processes has become an urgent problem to be solved.
[0016] Currently, when an electronic device creates a new process, it can call a specified process as the parent process, and then create a child process based on that parent process. The calling process is called the parent process, and the new child process is called the child process. When creating a child process based on the parent process, the entire page table entry (PTE), data structures, and file descriptors from the parent process are typically copied to the child process as its PTE, thus completing the creation of the child process.
[0017] Specifically, a new child process can be created by copying the parent process. During the current process copying process, the system kernel begins copying the parent process after calling the process copy function. When copying the parent process, the process descriptor copy function is first called to copy the data structures and file descriptors from the parent process to the child process. Then, the page table copy function is called to copy the memory page table from 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 returns via a system call. When the child process receives the child process scheduling function, it directly returns via a system call. The process copy function can be `do_fork()`, the process descriptor copy function can be `copy_process()`, the page table copy function can be `copy_mm()`, the wake-up function can be `wake_up_new_task()`, and the child process scheduling function can be `ret_from_fork`.
[0018] However, the inventors discovered during their research that directly copying page table entries (PTEs) from the parent process to the child process could lead to unnecessary waste of memory space.
[0019] Therefore, to overcome the above-mentioned defects, this application provides a process creation method, apparatus, electronic device, and computer-readable medium. In this method, the electronic device can respond to a child process creation request by determining the parent process executing the process creation request. The child process creation request corresponds to a specified page table entry, which includes the virtual address segment of the child process. Then, the first page table entry of the parent process is obtained, where the physical address segment of the first page table entry is a target address segment. If the first page table entry does not support modification, the virtual address segment of the child process is pointed to the target address segment to obtain a second page table entry. The child process is then created based on the second page table entry. Directly copying the first page table entry of the parent process and then creating the child process based on the copied page table entry would consume a significant amount of memory. However, if the first page table entry of the parent process is shared with the child process, and the child process is then created, when the first page table entry can be modified, the child process sharing the first page table entry may change the content of the first page table entry, thereby affecting other child processes that share the first page table entry, and also affecting the parent process. Therefore, in the embodiments provided in this application, the first page table entry is shared with the child process only when it does not support modification. The child process created based on the shared first page table entry will not have its corresponding page table entry occupy excessive memory space, thereby reducing the memory usage when creating the child process.
[0020] Please see Figure 1 , Figure 1 This diagram illustrates a structural block diagram of an electronic device 100 according to an embodiment of this application. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130.
[0021] In some implementations, the processor 110 can be used to run system programs installed on the electronic device 100. These system programs can be of different types, such as system programs for portable electronic devices (e.g., smartphone system programs, in-vehicle computer system programs, or smart tablet system programs), desktop computer system programs, or server system programs. Furthermore, while the system program on the electronic device 100 is running, the electronic device 100 can also create new child processes. That is, an application or system program can issue a child process creation request, and the processor 110 in the electronic device can respond to the child process creation request, thereby creating a new child process. As an example, an application can initiate one child process creation request, and the processor 110 can respond to that request. As another example, an application can also initiate multiple child process creation requests, and the processor 110 can respond to each of these requests.
[0022] In some implementations, the processor 110 can first determine the process that needs to be copied, that is, create a new child process based on the process that needs to be copied, where the process being copied is the parent process. The processor 110 can call relevant functions to copy data structures, file descriptors, etc., from the parent process to the child process. Furthermore, the processor 110 can also obtain the first page table entry in the parent process and determine whether the first page table entry needs to be copied entirely to the child process based on whether the first page table entry can be modified. Since when the first page table entry does not support modification, it can be shared with the new child process, allowing the child process to access the first page table entry without needing to completely copy it, thus saving memory space. Specifically, the method for determining whether to copy the first page table entry entirely to the child process based on whether the first page table entry supports modification can be found in the following embodiments.
[0023] In some implementations, when executing a process, the electronic device 100 typically places the process in a virtual address space and then uses page table entries to map the virtual address space to the physical address space. This allows the process to access data stored in the physical address space through the virtual address space, or to store generated data in the physical address space. In other words, the page table entries store the mapping relationship from the virtual address space to the physical address space. Furthermore, the virtual address space can be divided into multiple segments of equal size, resulting in multiple virtual address segments, which can be called "pages". Each virtual address segment can be identified by a different address, for example, by numbering each page, starting from 0, such as page 0, page 1, etc. Similarly, the physical address space can be divided into multiple segments of equal size, resulting in multiple physical address segments, which can be called "blocks" or "page frames". Each physical address segment can be identified by a different address, for example, by numbering each "block", starting from 0#, such as block 0#, block 1#, etc. Page table entries can map virtual address segments to physical address segments, meaning that physical address segments can be determined through virtual address segments.
[0024] Optionally, since the number of virtual address segments and physical address segments is generally large, the page table entries store a large number of mapping relationships. Therefore, in some implementations, page table entries can be divided into multiple levels, with each level recording different information. For example, each level of page table entry can record the query relationship between that level and the next level page table entry in a directory-like manner. Typically, the last level page table entry records the actual physical address segment. Multi-level page table entries allow for faster location of the physical address segment corresponding to the process. Taking a four-level page table as an example, a four-level page table can include a first-level page table entry, a second-level page table entry, a third-level page table entry, and a fourth-level page table entry. If the first-level page table entry is set as the top level and the fourth-level page table entry as the bottom level, then the first-level page table entry can include multiple second-level page table entries, each second-level page table entry can include multiple third-level page table entries, each third-level page table entry can include multiple fourth-level page table entries, and each fourth-level page table entry can include the corresponding physical address segment number. In some implementations, the first-level page table entries can be the Page Global Directory (PGD), Page Upper Directory (PUD), Page Middle Directory (PMD), or Page Table Entry (PTE). When the processor 110 copies or shares page table entries from the parent process, it essentially copies or shares the Page Global Directory (PGD), Page Upper Directory (PUD), Page Middle Directory (PMD), and Page Table Entry (PTE).
[0025] The above analysis shows that page table entries, including those for storing query relationships between different levels and the mapping between virtual address segments and physical address segments, all require memory space. If the parent process's page table entries are directly copied to the child process each time a new child process is created, this would consume a significant amount of memory. However, in the embodiments provided in this application, if the first page table entry does not support modification, it can be shared with the new child process, allowing the child process to access the first page table entry without needing to copy the parent process's entry, thus saving memory space.
[0026] The processor 110 may include one or more processing cores. The processor 110 can connect to various parts within the electronic device 100 using various interfaces and lines, obtain different requests from system programs and application programs, and execute the processes corresponding to different requests. Then, based on the process's calls to the virtual address space, it searches for hot segments existing in the physical address space. Optionally, the processor 110 may be implemented using at least one of the following hardware forms: Microcontroller Unit (MCU), Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
[0027] In some implementations, the memory 120 may store the system program corresponding to the electronic device 100. For example, if the electronic device 100 is a smartphone, the memory 120 may store the smartphone system program; if the electronic device 100 is a desktop computer, the memory 120 may store the desktop computer system program. The electronic device 100 can run the system program stored in the memory 120, specifically through the processor 110. The memory 120 may also store different application programs, which can run within the system program running on the electronic device 100. The application program or system program may also initiate a subprocess creation request; details can be found in the foregoing description and will not be repeated here. In some implementations, the memory 120 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM.
[0028] In some implementations, memory 130 may include physical memory, which generally has a higher read speed, while the speed of memory 120 is generally lower than that of memory 130. Therefore, memory 130 can pre-read data stored in memory 120 and store it in memory 130. When processor 110 executes relevant processes of an application, it can directly interact with data through memory 130, thereby minimizing direct data exchange between processor 110 and memory 120 and affecting the overall operating speed of electronic device 100. Furthermore, since the physical memory in memory 130 is generally small, storing all application processes in the physical memory of memory 130 will affect the number of processes that can be executed simultaneously, and may also cause mutual interference between processes. Therefore, memory 130 may also include virtual memory space. Processes executed in electronic device 100 can be first placed in the virtual memory space of memory 130 by processor 110. This virtual memory space then accesses the corresponding physical memory space through a virtual physical address mapping table, specifically accessing data stored in the physical memory space or writing data generated during the process into the physical memory space. Virtual memory space can have a larger space than physical memory space, so the number of processes that can be executed simultaneously when placed in virtual memory space is greater than the number of processes that can be placed directly in physical memory space.
[0029] In some implementations, memory 130 may be synchronous dynamic random access memory (SDRAM) or double data rate synchronous dynamic random access memory (DDRSDRAM), etc.
[0030] Please see Figure 2 , Figure 2 This application illustrates a process creation method provided by an embodiment of the present application. This memory region determination method can be applied to the electronic device 100 in the aforementioned embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S110 to S140.
[0031] Step S110: In response to the child process creation request, determine the parent process that executes the process creation request, wherein the child process creation request corresponds to a specified page table entry, and the specified page table entry includes the virtual address segment of the child process.
[0032] In some implementations, the child process creation request can be initiated by a system program running in the electronic device, or by an application running on the system program. For example, launching a music playback application can initiate a child process creation request. In one implementation provided in this application, the child process creation request may further include a virtual address segment corresponding to the child process. Specifically, the virtual address segment corresponding to the child process may be included in a designated page table entry corresponding to the child process creation request. In one example, the designated page table entry may only store the virtual address segment of the child process; in another example, the designated page table entry may also store the virtual address segment and a physical address segment of the child process, where the physical address segment is a default value, for example, the default value could be 0x00000000, etc.
[0033] An electronic device can respond to a child process creation request, for example, through the `fork()` function. The `fork()` function can be a process, and it may include code, data, and resources allocated to the new child process to be created. When an application or system program initiates a child process creation request, the electronic device can call the `fork()` function to create a new child process. The electronic device can pre-allocate storage space for the new child process to store data and code. This storage space can also be used to store a specified page table entry corresponding to the child process creation request, and thus can also store the virtual address segment of the child process included in that specified page table entry. In some implementations, the `fork()` function can call the original process and create the child process based on the original process. Specifically, the relevant data of the original process can be copied to the storage space corresponding to the new child process. The original process used to create the child process is the parent process, i.e., the process used to execute the process creation request. The relevant data in the parent process may include data structures, file descriptors, and first page table entries, etc. However, directly copying page table entries from the parent process to each child process upon creation would consume a significant amount of memory. Therefore, we can determine whether it's possible to share page table entries with child processes instead of copying them, based on the attributes of the page table entries in the parent process.
[0034] Step S120: Obtain the first page table entry of the parent process, wherein the physical address segment of the first page table entry is the target address segment.
[0035] In some implementations, after determining the parent process corresponding to the process creation request, the first page table entry of that parent process can be obtained. This first page table entry includes virtual address segments, physical address segments, and the mapping relationship between the virtual and physical address segments, allowing processes stored in the virtual address space to access the physical address space. For example, the 0x0001 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space; the 0x0002 virtual address segment in the virtual address space can be mapped to the 0x0064 physical address segment in the physical address space; and the 0x0003 virtual address segment in the virtual address space can be mapped to the 0x00ea physical address segment in the physical address space. Another example is that different virtual address segments in the virtual address space can be mapped to the same physical address segments in the physical address space. For instance, the 0x0001 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space, while the 0x0002 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space; and the 0x0003 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space. The physical address segment in this first page table entry can serve as the target address segment.
[0036] Step S130: If the first page table entry does not support being modified, then the virtual address segment of the child process is pointed to the target address segment to obtain the second page table entry.
[0037] In some implementations, directly copying the first page table entry of the parent process and then creating a child process based on the copied page table entry consumes a significant amount of memory. However, if the parent process's first page table entry is shared with the child process, allowing the child process to determine the physical address segment based on the shared first page table entry, the child process sharing the first page table entry might modify its contents if the first page table entry can be changed. This could affect other child processes sharing the first page table entry, as well as the parent process. Therefore, it's crucial to first determine whether the first page table entry supports modification. Only if the first page table entry does not support modification should it be shared with the child process. Specifically, the child process's virtual address segment can be pointed to the target address segment, i.e., the physical address segment in the first page table entry, to obtain the second page table entry. Thus, the second page table entry retrieves data stored in the physical address segment based on the shared physical address segment of the first page table entry. Furthermore, since the first page entries do not support being updated, the child process will not modify the first page entries, meaning it will not affect other child processes that share the first page entries, nor will it affect the parent process.
[0038] Step S140: Create a child process based on the second page table entry.
[0039] In some implementations, after obtaining the second page table entry using the aforementioned method, a child process can be created based on the second page table entry. This child process can then use the second page table entry to obtain the mapping between its corresponding virtual address segment and physical address segment, thereby accessing the data in the physical address segment pointed to by the virtual address segment. Furthermore, the electronic device can also copy data structures and file descriptors from the parent process to the child process using a specified function.
[0040] This application provides a process creation method, apparatus, electronic device, and computer-readable medium. In this method, the electronic device, in response to a child process creation request, determines the parent process executing the process creation request. The child process creation request corresponds to a specified page table entry, which includes a virtual address segment of the child process. Then, it obtains a first page table entry of the parent process, where the physical address segment of the first page table entry is a target address segment. If the first page table entry does not support modification, the virtual address segment of the child process is pointed to the target address segment to obtain a second page table entry. The child process is then created based on the second page table entry. Directly copying the parent process's first page table entry and then creating the child process based on the copied page table entry would consume a significant amount of memory. However, if the parent process's first page table entry is shared with the child process for creation, and the first page table entry is modified, the child process sharing the first page table entry may change its contents, thus affecting other child processes that share the first page table entry, and also affecting the parent process. Therefore, in the embodiments provided in this application, the first page table entry is shared with the child process only when it does not support modification. The child process created based on the shared first page table entry will not have its corresponding page table entry occupy excessive memory space, thereby reducing the memory usage when creating the child process.
[0041] Please see Figure 3 , Figure 3 This application illustrates a process creation method provided by an embodiment of the present application. This memory region determination method can be applied to the electronic device 100 in the aforementioned embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S210 to S260.
[0042] Step S210: In response to the child process creation request, determine the parent process that executes the process creation request, wherein the child process creation request corresponds to a specified page table entry, and the specified page table entry includes the virtual address segment of the child process.
[0043] Step S220: Obtain the first page table entry of the parent process, wherein the physical address segment of the first page table entry is the target address segment.
[0044] For some implementation methods, steps S210 and S220 have been described in detail in the foregoing embodiments, and will not be repeated here.
[0045] Step S230: Obtain the attributes of the first page table item.
[0046] In some implementations, the ability to modify a page table entry can be determined by the attributes of the parent process's first page table entry. These page table entry attributes can include shared, read, write, and executable attributes, which can be combined. For example, a page table entry can have shared and read attributes; it can also have shared and executable read attributes; or it can have non-shared attributes, etc.
[0047] Furthermore, the attributes of the first page entries in the parent process can be controlled based on the parent process. That is, the parent process can change the attributes of the first page entries. Therefore, the attributes of the first page entries are not necessarily fixed and can be flexibly changed as needed.
[0048] In some implementations, a flag can be pre-defined at a specific location in the first page table entry corresponding to the parent process. The specific value of this flag can be agreed upon to represent different attributes. Therefore, by directly obtaining the value at the specified location in the first page table entry corresponding to the parent process, and combining it with the pre-agreed relationship between the flag value and the attributes, the attributes of the virtual address segment in the parent process's first page table entry can be determined. For example, the parent process can correspond to a virtual memory region structure (struct vm_area_struct, VMA), which may include a flag, the specific value of which can be agreed upon to represent different attributes. For example, when the flag is 0x00000001, it indicates that the attribute of the first page table entry is readable; when the flag is 0x00000002, it indicates that the attribute of the first page table entry is writable; when the flag is 0x00000004, it indicates that the attribute of the first page table entry is executable; and when the flag is 0x00000008, it indicates that the attribute of the first page table entry is shared. Therefore, the attributes of the parent process's first page table entry can be obtained by retrieving the value of the flag bit included in the Virtual Memory Region (VMA) structure.
[0049] Optionally, the parent process's identity information can also be obtained. The first page entries are shared with the child process only if the parent process's identity matches the specified identity. For details, please refer to [link to relevant documentation]. Figure 4 , Figure 4 A diagram illustrating one embodiment of step S230 is shown, specifically including steps S231 to S233.
[0050] Step S231: Obtain the identity information of the parent process.
[0051] Step S232: If the identity information of the parent process is a specified identity, obtain the attributes of the first page table entry.
[0052] Step S233: If the identity information of the parent process is not the specified identity, create a third page table entry and create a child process based on the third page table entry, wherein the second page table entry is obtained by copying the first page table entry.
[0053] Optionally, when creating a child process using some processes as parent processes, it may be necessary to completely copy the parent process to create the child process. In this case, it is not necessary to determine whether to share the first page table attributes with the child process based on the first page table attributes of the parent process. Therefore, before obtaining the attributes of the first page table entries of the parent process, the identity information of the parent process can also be obtained. The attributes of the first page table entries are only obtained if the identity information of the parent process is a specified identity.
[0054] The parent process's identity information can include the name of the parent process. In the implementation provided in this application, this designated identity can be a Zygote (incubator process). Therefore, if the parent process's identity information is a Zygote, the attributes of the first page table entry are retrieved.
[0055] Furthermore, if the parent process's identity information is not the specified identity, it is not necessary to obtain the attributes of the first page table entry. Instead, a third page table entry can be directly created, and a child process can be created based on the third page table entry. The second page table entry is obtained by copying the first page table entry; that is, the parent process's first page table entry is directly copied to obtain the third page table entry, and then the child process is created based on this third page table entry.
[0056] Step S240: If the attribute satisfies the target attribute, then it is determined that the first page table entry does not support being modified, wherein the target attribute includes any one of shared and read-only, shared and executable read.
[0057] In some implementations, after obtaining the attributes of the first page table, it can be determined whether the attribute satisfies the target attribute. If the attribute satisfies the target attribute, it is determined that the first page table entry does not support modification. Since if the attributes of the first page table entry include write-related attributes, it indicates that other processes sharing the first page table entry can modify it. Therefore, the target attributes can include read-only and executable read. Furthermore, as described above, when it is determined that the first page table entry does not support modification, it can be shared with child processes. Therefore, the attributes of the first page table entry should also include shared attributes, that is, the target attributes include any one of shared and read-only, or shared and executable read.
[0058] Step S250: If the first page table entry does not support being modified, then the virtual address segment of the child process is pointed to the target address segment to obtain the second page table entry.
[0059] Step S260: Create a child process based on the second page table entry.
[0060] In some implementations, if multiple child processes are created based on second page table entries, meaning these child processes all access physical address segments through a shared first page table entry, and if these processes need to execute simultaneously (i.e., all need to look up the corresponding physical address segment through the first page table entry), processes with higher priority can be prioritized to look up the corresponding physical address segment through the shared first page table entry. Different priorities can be pre-set for different processes, and this priority can be positively correlated with the user experience of the application or system program corresponding to the process. That is, the stronger the user's perception of the application or system program corresponding to the process, the higher the priority of the process; the weaker the user's perception of the application or system program, the lower the priority of the process. For example, if the application corresponding to the process is a video playback application, users generally have a strong perception of video playback applications, so a higher priority can be set for the process corresponding to the video playback application; if the system program corresponding to the process is a software background update, users generally do not pay much attention to background software updates, so a lower priority can be set for the process.
[0061] For a detailed description of steps S250 and S260, please refer to the description of the foregoing embodiments, which will not be repeated here.
[0062] Please see Figure 5 , Figure 5This application illustrates a process creation method provided by an embodiment of the present application. This memory region determination method can be applied to the electronic device 100 in the aforementioned embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S310 to S3100.
[0063] Step S310: In response to the child process creation request, determine the parent process that executes the process creation request, wherein the child process creation request corresponds to a specified page table entry, and the specified page table entry includes the virtual address segment of the child process.
[0064] Step S320: Obtain the first page table entry of the parent process, wherein the physical address segment of the first page table entry is the target address segment.
[0065] Step S330: Obtain the attributes of the first page table item.
[0066] Step S340: If the attribute satisfies the target attribute, it is determined that the first page table entry does not support being modified, wherein the target attribute includes any one of shared and read-only, shared and executable read.
[0067] Step S350: If the first page table entry does not support being modified, then the virtual address segment of the child process is pointed to the target address segment to obtain the second page table entry.
[0068] Step S360: Create a child process based on the second page table entry.
[0069] Steps S310 to S360 can be referred to the description in the foregoing embodiments, and will not be repeated here.
[0070] Step S370: In response to the page recycling request, determine the target page corresponding to the page recycling request.
[0071] In some implementations, when an electronic device needs to reclaim a page, that page is a physical address segment. For example, it can be a single physical address segment or multiple physical address segments. The system program in the electronic device can initiate this page reclamation request. One rational approach is when loading a large-space process, and the existing physical address segments do not provide sufficient space for that process. In this case, a page reclamation request can be initiated to provide more physical address segments, i.e., more space, for the process. Another rational approach is to initiate page reclamation requests at pre-set, specified periods. The electronic device can then respond to this page reclamation request, for example, through its processor. Specifically, the target page corresponding to the page reclamation request can be determined, where the target page is the page that the page reclamation request needs to reclaim, i.e., the physical address segment that needs to be reclaimed.
[0072] Step S380: Obtain a first type of page table entry and a second type of page table entry corresponding to the target page, wherein the first type of page table entry includes either the first page table entry or the second page table entry, and the second type of page table entry includes the third type of page table entry.
[0073] Step S390: Based on the first type of page table entry and the second type of page table entry, determine the target process corresponding to the target page.
[0074] Step S3100: Disconnect the correspondence between the target process and the target page, and reclaim the target page.
[0075] In some implementations, to reclaim the physical address segment, it is necessary to first update the page table entries that have a mapping relationship with the target page and delete the corresponding target page from the page table entries. Therefore, it is necessary to first determine the page table entries corresponding to the target page. In one implementation provided in this application, all page table entries pointing to the same physical address segment can be located through the reverse mapping (RMAP) mechanism, that is, all target page table entries corresponding to the target page can be obtained.
[0076] Furthermore, it is necessary to determine the target page table entry and the process corresponding to it. If the child process is created by copying a third page table entry from the parent process's first page table entry, then this page table entry corresponds to a unique process, and this page table entry can be used as a second-type page table entry. If the child process is created by copying a second page table entry from the parent process's shared first page table entry, then all child processes created through the second page table entry can be found through the first page table entry, and this page table entry can be used as a first-type page table entry. That is, first-type page table entries include either the first page table entry or the second page table entry, and second-type page table entries include the third-type page table entry. Further, the target page table corresponds to... In some implementations, the page table entries determined by the target page may include both first-type and second-type page table entries. Therefore, it is necessary to determine the target process corresponding to the target page based on both the first-type and second-type page table entries. That is, the target process may include processes corresponding to the first-type page table entries or processes corresponding to the second-type page table entries. Specifically, the process corresponding to the first-type page table entry can be a first-type process, and the process corresponding to the second-type page table entry can be a second-type process; in other words, the target process may include both first-type and second-type processes.
[0077] Please see Figure 6 ,in Figure 6 This illustration shows a schematic diagram of a process for finding a target page according to an embodiment of this application. Specifically, Figure 6 This includes a target page 610, second-type page table entries 620, and second-type processes 630. The second-type page table entries 620 specifically include page table entries A1, A2, and so on up to AN, totaling N page table entries, where N is a natural number greater than or equal to 1. Correspondingly, processes 630 specifically include processes B1, B2, and so on up to BN. Figure 6 All page table entries in the process are type 2 page table entries 620. Therefore, processes 630 are created by copying the third page table entry obtained from the first page table entry of the parent process. Thus, when traversing the type 2 page table entry 620 corresponding to the target page 610 through reverse mapping, it is necessary to traverse N times, and the corresponding time complexity is O(N).
[0078] Please see Figure 7 ,in Figure 7 This illustration shows a process for finding a target page according to another embodiment of this application. Specifically, Figure 7 This includes a target page 710, a first-type page table entry 720, and a first-type process 730. The first-type page table entry 720 specifically includes page table entry C. Correspondingly, the process 730 specifically includes processes D1, D2, and so on up to process DM, where M is a natural number greater than or equal to 1. Figure 7 All page table entries in the process are type 1 page table entries 720. Therefore, processes 730 are all created by sharing the second page table entry obtained from the first page table entry of the parent process. Thus, different processes can correspond to type 1 page table entries 720. That is, when traversing the type 1 page table entries 720 corresponding to the target page 710 through reverse mapping, only one traversal is needed, resulting in a time complexity of O(1). Figure 6 and Figure 7It can be seen that the time complexity o(1) of obtaining the first type of page table entry by traversing the target page through reverse mapping is less than the time complexity o(N) of obtaining the second type of page table entry by traversing the target page through reverse mapping; the computational resources consumed by obtaining the first type of page table entry by traversing the target page through reverse mapping are less than the computational resources consumed by obtaining the second type of page table entry.
[0079] For further details, please refer to Figure 8 , Figure 8 The diagram illustrates an implementation of step S390, which specifically includes steps S391 to S393.
[0080] Step S391: Determine the first type of process based on any one of the page table entries in the first type of page table entries.
[0081] Step S392: Determine the second type of process based on each page table entry in the second type of page table entries.
[0082] Step S393: Determine the target process based on the first type of process and the second type of process.
[0083] pass Figure 7 As described above, processes of the first type all share the first page table entry of their parent process. Therefore, a process of the first type can be identified simply by using any one of the page table entries of the first type. For example, if the first page table entry belongs to the first type, then all child processes that share that first page table entry—that is, processes of the first type—can be identified by using the first page table entry of the parent process.
[0084] Furthermore, through Figure 6 As the introduction states, the second type of processes are all created by copying the third page table entry obtained from the first page table entry. Therefore, it is necessary to determine each corresponding second type of process through each second type of page table entry, that is, to determine the second type of process based on each page table entry in the second type of page table entry.
[0085] As can be seen from the above introduction, the target process includes both the first type of process and the second type of process. Therefore, after determining the first type of process and the second type of process, the target process can be determined.
[0086] Furthermore, before reclaiming the target page, the mapping between the target process and the target page needs to be broken. Specifically, the target process and the target page are generally established through page table entries corresponding to the target process. Therefore, the page table entries of the target process can be updated so that they do not include the physical address segment corresponding to the target page. For example, the original target page in the page table entry can be deleted; or, for example, the physical address segment of the target page corresponding to the virtual address segment in the original page table entry can be remapped to another physical address segment different from the physical address segment corresponding to the target page table. Further, after breaking the mapping between the target process and the target page, the target page can be reclaimed. The reclaimed target page can be reassigned to other processes for data storage, for example, by establishing a mapping relationship with the virtual address segments of other processes, thereby providing that process with data interaction with the physical address segment corresponding to the target page.
[0087] Optionally, before reclaiming the target page, it can be detected whether any process within the target process is still accessing data in the physical address segment corresponding to the target page, such as reading or writing data. One example is to wait until all processes within the target process have completed their data interactions with the physical address segment corresponding to the target page before reclaiming the target page. Another example is to temporarily store the data in the target page in another physical address segment, modify the target page mapped by the target process to the other physical address segment that temporarily stores the data, and then reclaim the target page.
[0088] This application provides a process creation method, apparatus, electronic device, and computer-readable medium. In this method, the electronic device, in response to a child process creation request, determines the parent process executing the process creation request. The child process creation request corresponds to a specified page table entry, which includes the virtual address segment of the child process. Then, it obtains a first page table entry of the parent process, where the physical address segment of the first page table entry is a target address segment. If the first page table entry does not support modification, the virtual address segment of the child process is pointed to the target address segment to obtain a second page table entry. The child process is then created based on the second page table entry. In the embodiments provided in this application, the first page table entry is shared with the child process only if it does not support modification. The child process created based on the shared first page table entry will not occupy excessive memory space for its corresponding page table entry, thereby reducing the memory space occupied when creating the child process. The method further includes responding to a page reclamation request by determining the target page corresponding to the page reclamation request; obtaining a first type page table entry and a second type page table entry corresponding to the target page; determining the target process corresponding to the target page from the first type page table entry and the second type page table entry; disconnecting the correspondence between the target process and the target page; and reclaiming the target page. Since traversing the second type page table entry 620 corresponding to the target page 0 via reverse mapping requires N traversals, the corresponding time complexity is O(N). However, for the first type page table entry 720, traversing the first type page table entry 720 corresponding to the target page via reverse mapping only requires 1 traversal, resulting in a time complexity of O(1). Therefore, in this application, the computational resources consumed by traversing the target page to obtain the first type page table entry via reverse mapping are less than those consumed by obtaining the second type page table entry. Thus, by sharing a portion of the first page table with the child process, this application can also improve the efficiency of finding the target process corresponding to the target page through the reverse mapping mechanism when reclaiming pages, thereby improving the overall efficiency of page reclamation.
[0089] Please see Figure 9 , Figure 9 This application illustrates a process creation method provided by an embodiment of the present application. This memory region determination method can be applied to the electronic device 100 in the aforementioned embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S410 to S460.
[0090] Step S410: In response to the child process creation request, determine the parent process that executes the process creation request, wherein the child process creation request corresponds to a specified page table entry, and the specified page table entry includes the virtual address segment of the child process.
[0091] Step S420: Obtain the first page table entry of the parent process, wherein the physical address segment of the first page table entry is the target address segment.
[0092] Step S430: If the first page table entry does not support being modified, then the virtual address segment of the child process is pointed to the target address segment to obtain the second page table entry.
[0093] Step S440: Create a child process based on the second page table entry.
[0094] Steps S410 to S440 have been described in detail in the foregoing embodiments and will not be repeated here.
[0095] Step S450: Update the number of child processes corresponding to the first page table entry.
[0096] In some implementations, a designated space can be allocated to store the number of child processes created based on the second page entry obtained from the shared first page entry. For example, if 1000 child processes are created using the second page entry obtained from the shared first page entry, then this designated space can store 1000 data items.
[0097] Step S460: If the first page table entry supports being modified, create a fourth page table entry and create a subprocess based on the fourth page table entry, wherein the fourth page table entry is obtained by copying the first page table entry.
[0098] As described above, in some implementations, if the first page entry can be modified, sharing it with a child process may result in changes to the data in the first page entry, thus affecting the parent process or other child processes that have shared the first page entry. Therefore, when the first page entry can be modified, a fourth page entry is created, and a child process is created based on the fourth page entry, wherein the fourth page entry is obtained by copying the first page entry.
[0099] Similar to the embodiments described above, the properties of the first page table entry can be used to determine whether the first page table supports modification. For example, when the first page table's property is shared writable, indicating that the first page table supports modification, a fourth page table entry can be created, and a child process can be created based on the fourth page table entry.
[0100] Please see Figure 10 The diagram illustrates a structural block diagram of a process creation device 1000 provided in an embodiment of this application, which is applied to an electronic device. The device includes a response unit 1010, an acquisition unit 1020, a processing unit 1030, and a creation unit 1040.
[0101] The response unit 1010 is configured to respond to a child process creation request by determining the parent process that executes the process creation request, wherein the child process creation request corresponds to a specified page table entry, and the specified page table entry includes the virtual address segment of the child process.
[0102] The acquisition unit 1020 is used to acquire the first page table entry of the parent process, wherein the physical address segment of the first page table entry is the target address segment.
[0103] The processing unit 1030 is configured to, if the first page table entry does not support being modified, point the virtual address segment of the subprocess to the target address segment to obtain the second page table entry.
[0104] Furthermore, the processing unit 1030 is also used to obtain the attributes of the first page table entry; if the attributes satisfy the target attributes, it is determined that the first page table entry does not support being modified, wherein the target attributes include any one of shared and read-only, shared and executable read.
[0105] Furthermore, the processing unit 1030 is also used to obtain the identity information of the parent process; if the identity information of the parent process is a specified identity, the attributes of the first page table entry are obtained.
[0106] Furthermore, the processing unit 1030 is also configured to create a third page table entry if the parent process's identity information is not a specified identity, and create a child process based on the third page table entry, wherein the second page table entry is obtained by copying the first page table entry. The specified identity includes the incubation process.
[0107] Furthermore, the processing unit 1030 is also configured to respond to a page recycling request by: determining the target page corresponding to the page recycling request; obtaining a first type of page table entry and a second type of page table entry corresponding to the target page, wherein the first type of page table entry includes either the first page table entry or the second page table entry, and the second type of page table entry includes the third type of page table entry; determining the target process corresponding to the target page based on the first type of page table entry and the second type of page table entry; disconnecting the correspondence between the target process and the target page, and recycling the target page.
[0108] Furthermore, the processing unit 1030 is also configured to determine the first type of process based on any one page table entry in the first type of page table entries; determine the second type of process based on each page table entry in the second type of page table entries; and determine the target process based on the first type of process and the second type of process.
[0109] Furthermore, the processing unit 1030 is also configured to create a fourth page entry if the first page entry is modified, and to create a subprocess based on the fourth page entry, wherein the fourth page entry is obtained by copying the first page entry.
[0110] Creation unit 1040 is used to create a subprocess based on the second page table entry.
[0111] Furthermore, the creation unit 1040 is also used to update the number of child processes corresponding to the first page table entry.
[0112] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the above-described apparatus and unit can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0113] In the several embodiments provided in this application, the coupling between the units can be electrical, mechanical or other forms of coupling.
[0114] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0115] Please refer to Figure 11 This document illustrates a structural block diagram of an electronic device 100 provided in an embodiment of this application. The electronic device 100 can be a smartphone, tablet computer, e-reader, or other electronic device capable of running applications. The electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications can be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.
[0116] Processor 110 may include one or more processing cores. Processor 110 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets, or instruction sets stored in memory 120, and by calling data stored in memory 120. Optionally, processor 110 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 110 may integrate one or more of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 110 and may be implemented separately using a communication chip.
[0117] The memory 120 may include random access memory (RAM) or read-only memory (ROM). The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the electronic device 100 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0118] Please refer to Figure 12 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 1200 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0119] The computer-readable storage medium 1200 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 1200 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 1200 has storage space for program code 1210 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 1210 may, for example, be compressed in a suitable form.
[0120] Please refer to Figure 13 The diagram illustrates a structural block diagram 1300 of a computer program product provided in an embodiment of this application. The computer program product 1300 includes a computer program / instructions 1310, which, when executed by a processor, implements the steps of the aforementioned method.
[0121] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A process creation method, characterized in that, Applied to electronic devices, including: In response to a child process creation request, the parent process that executes the child process creation request is determined, the child process creation request corresponds to a specified page table entry, the specified page table entry includes the virtual address segment of the child process; Obtain the first page table entry of the parent process, where the physical address segment of the first page table entry is the target address segment; Obtain the attributes of the first page table entry, wherein the attributes of the first page table entry are represented by flag bits in the virtual memory region structure corresponding to the parent process; If the attribute satisfies the target attribute, it is determined that the first page table entry does not support being modified. The target attribute includes any one of shared and read-only, or shared and executable read. If the first page table entry does not support being modified, then the virtual address segment of the child process is pointed to the target address segment to obtain the second page table entry; A child process is created based on the entries in the second page.
2. The method according to claim 1, characterized in that, The step of obtaining the attributes of the first page table entry includes: Obtain the identity information of the parent process; If the parent process's identity information is a specified identity, obtain the attributes of the first page table entry.
3. The method according to claim 2, characterized in that, Also includes: If the parent process's identity information is not the specified identity, a third page table entry is created, and a child process is created based on the third page table entry, wherein the third page table entry is obtained by copying the first page table entry.
4. The method according to claim 2 or 3, characterized in that, The designated identity includes the incubation process.
5. The method according to claim 3, characterized in that, Also includes: In response to a page recycling request, determine the target page corresponding to the page recycling request; Obtain a first type of page table entry and a second type of page table entry corresponding to the target page, wherein the first type of page table entry includes either the first page table entry or the second page table entry, and the second type of page table entry includes the third page table entry; Based on the first type of page table entry and the second type of page table entry, the target process corresponding to the target page is determined; Disconnect the mapping between the target process and the target page, and reclaim the target page.
6. The method according to claim 5, characterized in that, The target process includes a first type of process and a second type of process. Determining the target process corresponding to the target page based on the first type of page table entry and the second type of page table entry includes: The first type of process is determined based on any one of the page table entries of the first type; The second type of process is determined based on each page table entry in the second type of page table entries; The target process is determined based on the first type of process and the second type of process.
7. The method according to claim 1, characterized in that, Also includes: If the first page entry supports modification, a fourth page entry is created, and a subprocess is created based on the fourth page entry, wherein the fourth page entry is obtained by copying the first page entry.
8. The method according to claim 1, characterized in that, After creating the subprocess based on the second page table entry, the process further includes: Update the number of child processes corresponding to the first page table entry.
9. A process creation apparatus, characterized in that, Applied to electronic devices, including: A response unit is configured to respond to a child process creation request and determine the parent process that executes the child process creation request, wherein the child process creation request corresponds to a specified page table entry, and the specified page table entry includes the virtual address segment of the child process; The acquisition unit is configured to acquire the first page table entry of the parent process, wherein the physical address segment of the first page table entry is a target address segment; acquire the attributes of the first page table entry, wherein the attributes of the first page table entry are characterized by flag bits in the virtual memory region structure corresponding to the parent process; if the attributes satisfy the target attributes, it is determined that the first page table entry does not support being modified, wherein the target attributes include any one of shared and read-only, shared and executable read; The processing unit is configured to, if the first page table entry does not support being modified, point the virtual address segment of the subprocess to the target address segment to obtain the second page table entry; A creation unit is used to create a subprocess based on the second page table entry.
10. An electronic device, characterized in that, include: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications being configured to perform the method as described in any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-8.
12. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the method described in any one of claims 1-8.
Citation Information
Patent Citations
System and method for creating snapshot of subset of database
CN109643276A
Process copying method and device
CN114416426A
