Memory sharing method and device, equipment, storage medium and program product

By partially copying the page table and using page missing processing, the problem of excessive page table occupies in the shared memory space of multiple processes is solved, efficient sharing of memory space and acceleration of process creation is achieved, and system stability is improved.

CN120336040APending Publication Date: 2025-07-18TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410065983.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-16
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

In the prior art, when multiple processes share memory space, the page table occupies too much memory space, resulting in excessive memory consumption, especially in scenarios with high connections, which affects system stability and process creation efficiency.

Method used

By responding to the child process creation request, the parent process partially replicates the first page table of the target memory shared space. The child process triggers a page missing exception and performs a page missing process during access, obtains the address mapping relationship and updates to the second page table, avoiding the replication of the complete page table.

Benefits of technology

It effectively reduces the memory space occupied by the page table, reduces process creation time, improves process creation efficiency, and reduces memory consumption in high connection scenarios, improving system stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120336040A_ABST
    Figure CN120336040A_ABST
Patent Text Reader

Abstract

The invention discloses a memory sharing method and device, equipment, a storage medium and a program product, relates to the technical field of memory management, and can be used for memory sharing of a cloud server. Partially copying a first page table of a target memory shared space maintained by the parent process to obtain a second page table; according to the second page table, accessing the target memory shared space through the sub-process to trigger a missing page exception; performing missing page processing through the sub-process to obtain a corresponding first address mapping relation; and updating the first address mapping relation to the second page table through the sub-process. Compared with the prior art, the memory space occupied by the page table for realizing the memory shared space can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of memory management, and in particular, to a memory sharing method, a memory sharing device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art

[0002] A memory sharing space refers to a memory space that can be accessed by multiple processes, and is usually used for communication between multiple processes. A page table is a data structure that stores the address mapping relationship between virtual addresses and physical addresses. Based on the address mapping relationship stored in the page table, a process can access the memory sharing space.

[0003] Currently, for the same memory sharing space, each process accessing the memory sharing space maintains its own page table. Thus, as the number of processes accessing the memory sharing space increases, the memory space occupied by the page table also increases. Taking the Linux system as an example, for a 2M-sized memory sharing space, each process needs to maintain at least a 4K-sized page table. If 1000 processes share it, a total of 4M-sized memory space is required to maintain the page tables. It can be seen that the memory space occupied by maintaining the page tables far exceeds the size of the memory sharing space. Therefore, how to reduce the memory space occupied by the page table for implementing the memory sharing space is an urgent problem to be solved currently. Summary of the Invention

[0004] Embodiments of this application provide a memory sharing method, a memory sharing device, an electronic device, a computer-readable storage medium, and a computer product, which can reduce the memory space occupied by the page table for implementing the memory sharing space.

[0005] In a first aspect, the memory sharing method provided by this application includes:

[0006] In response to a child process creation request by the parent process, during the process of creating the child process, partially copy the first page table of the target memory sharing space maintained by the parent process to obtain a second page table;

[0007] According to the second page table, trigger a page fault exception when the child process accesses the target memory sharing space;

[0008] Perform page fault handling by the child process to obtain a corresponding first address mapping relationship;

[0009] Update the first address mapping relationship to the second page table by the child process.

[0010] In a second aspect, the memory sharing device provided by this application includes:

[0011] A page table copying module, which is used for the parent process to respond to a child process creation request, and during the process of creating the child process, partially copy the first page table of the target memory shared space maintained by the parent process to obtain a second page table;

[0012] A page fault triggering module, which is used to trigger a page fault exception according to the second page table when the child process accesses the target memory shared space;

[0013] A page fault handling module, which is used for the child process to perform page fault handling to obtain a corresponding first address mapping relationship;

[0014] A page table updating module, which is used for the child process to update the first address mapping relationship to the second page table.

[0015] Optionally, in an embodiment, the memory sharing device provided in this application further includes a page table identification module, which is used to add a sharing identifier to the virtual memory space metadata corresponding to the memory sharing space during the process of the parent process performing memory mapping for the memory sharing space, and the sharing identifier is used to indicate that the memory sharing space requires page table sharing.

[0016] Optionally, in an embodiment, the page table copying module is used for the parent process to respond to a child process creation request, and during the process of creating the child process, copy the virtual memory space metadata of the target memory shared space maintained by the parent process to obtain copy virtual memory space metadata; if a sharing identifier is added to the copy virtual memory space metadata, then the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0017] Optionally, in an embodiment, the page fault handling module is used for the parent process to copy the virtual memory space metadata of the target memory shared space to obtain shadow virtual memory space metadata; and for the child process to perform page fault handling based on the shadow virtual memory space metadata to obtain a corresponding first address mapping relationship.

[0018] Optionally, in an embodiment, the page table updating module is further used for the parent process to update the first address mapping relationship to the first page table.

[0019] Optionally, in an embodiment, the page fault triggering module is further used to trigger a page fault exception according to the first page table when the parent process accesses the memory shared space; the page fault handling module is further used for the parent process to perform page fault handling based on the shadow virtual memory space metadata to obtain a corresponding second address mapping relationship; the page table updating module is further used for the parent process to update the second address mapping relationship to the first page table.

[0020] Optionally, in an embodiment, the page table updating module is further used for the child process to update the second address mapping relationship to the second page table.

[0021] Optionally, in one embodiment, the page table copying module is configured to, if a sharing identifier is added to the metadata of the copy virtual memory space and the child process belongs to the target child process set, partially copy, by the parent process, the first page table of the target memory sharing space maintained by the parent process to obtain a second page table.

[0022] Optionally, in one embodiment, the memory sharing device provided by the present application further includes a set determination module, configured to determine, by the parent process, the page table memory occupancy of the child process set sharing the same memory sharing space; if the page table memory occupancy reaches the space threshold, determine, by the parent process, the child process set as the target child process set.

[0023] Optionally, in one embodiment, the memory sharing device provided by the present application further includes an address alignment module, configured to align virtual addresses according to the page middle directory granularity during the process of memory mapping the memory sharing space by the parent process.

[0024] Optionally, in one embodiment, the page table copying module is configured to, in response to a child process creation request by the parent process, during the process of creating a child process, copy the page table above the page middle directory in the first page table of the target memory sharing space maintained by the parent process to obtain a second page table.

[0025] In a third aspect, the electronic device provided by the present application includes a memory and a processor. The memory stores a computer program, and the processor is configured to run the computer program in the memory to implement the steps in the memory sharing method provided by the present application.

[0026] In a fourth aspect, the computer-readable storage medium provided by the present application stores a computer program, and the computer program is suitable for running on a processor to implement the steps in the memory sharing method provided by the present application.

[0027] In a fifth aspect, the computer program product provided by the present application includes a computer program, and the computer program is suitable for running on a processor to implement the steps in the memory sharing method provided by the present application.

[0028] The memory sharing solution provided by this application is as follows: in response to a child process creation request from the parent process, during the creation of the child process, the first page table of the target memory sharing space maintained by the parent process is partially copied to obtain a second page table; according to the second page table, a page fault exception is triggered when the child process accesses the target memory sharing space; the child process performs page fault handling to obtain the corresponding first address mapping relationship; and the child process updates the first address mapping relationship to the second page table. In this way, when creating a child process, the page table of the parent process is not completely copied, but only a part of the parent process's page table is copied. For address mapping relationships that are not copied or do not exist, the corresponding address mapping relationships are obtained through page fault handling when actually accessing the memory sharing space. This not only enables the sharing of memory space but also effectively reduces the memory space occupied by maintaining the page table. Compared with the original memory consumption, the page table memory consumption can be reduced from dozens of gigabytes to less than dozens of megabytes at most. Especially in scenarios where multiple processes share a large amount, such as sharing an instance database, it can reduce approximately 90% of the page table memory consumption caused by a large number of connections (there is a possibility of 30,000 connections), thereby increasing the number of connections, avoiding memory overflow caused by memory consumption, and enhancing the stability of the database. Additionally, since only a part of the parent process's page table is copied when creating a child process, it can also reduce the time consumed in creating the child process, shortening the process creation time by about 40%, thereby improving the process creation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] To more clearly illustrate the technical solutions in the embodiments of this application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of this application. For those skilled in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0030] Figure 1a is a schematic diagram of the scenario of the memory sharing system provided by the embodiment of this application;

[0031] Figure 1b is a flowchart of the memory sharing method provided by the embodiment of this application;

[0032] Figure 1c is an example diagram of page fault handling in the embodiment of this application;

[0033] Figure 2a is another flowchart of the memory sharing method provided by the embodiment of this application;

[0034] Figure 2b is a schematic diagram of page table sharing in the embodiment of this application;

[0035] Figure 3 is a schematic structural diagram of a memory sharing device provided by the embodiment of this application;

[0036] Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0037] It should be noted that the principle of the present application is illustrated by being implemented in a suitable computing environment. The following description is based on the specific embodiments of the present application illustrated, and it should not be regarded as limiting other specific embodiments of the present application not detailed herein.

[0038] In the following description of the present application, reference is made to "some embodiments", which describe a subset of all possible embodiments. However, it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.

[0039] In the following description of the present application, the terms "first / second / third" are only used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first / second / third" can be interchanged with a specific order or sequence when allowed, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0040] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present application belongs. The terms used herein are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.

[0041] Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and networks within a wide area network or a local area network to achieve data computing, storage, processing, and sharing. It is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model, and can form a resource pool, which can be used on demand, flexibly and conveniently. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites, and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark and needs to be transmitted to the background system for logical processing. Data at different levels will be processed separately, and various industry data requires a powerful system support, which can only be achieved through cloud computing.

[0042] Cloud computing refers to the delivery and usage model of IT infrastructure, which means obtaining the required resources in a demand-driven and easily scalable manner through the network. Broadly speaking, cloud computing refers to the delivery and usage model of services, which means obtaining the required services in a demand-driven and easily scalable manner through the network. Such services can be related to IT and software, the Internet, or other services. Cloud computing is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balance.

[0043] With the development of the Internet, real-time data streams, and the diversification of connected devices, as well as the promotion of demands such as search services, social networks, mobile commerce, and open collaboration, cloud computing has developed rapidly. Different from previous parallel distributed computing, the emergence of cloud computing will drive a revolutionary change in the entire Internet model and enterprise management model conceptually.

[0044] In recent years, with the large-scale application of cloud computing, the use of memory has also increased, and the cost of high-speed memory has risen. More and more R & D personnel in the industry have begun to optimize memory from the perspective of business applications to achieve the purpose of cost reduction and efficiency improvement. Currently, in order to reduce the memory loss caused by the large occupation of page tables, the industry usually adopts the Hugetlb (Hugetlb represents a standard large page, usually about 2M for a large page, and it needs to be reserved from memory before use) optimization technology. However, Hugetlb has the following defects:

[0045] Hugetlb must be reserved before use, with low flexibility.

[0046] Hugetlb memory cannot be released and can only be released when it is no longer in use, and it cannot be shared with other business processes.

[0047] Hugetlb is usually 2M or larger in size, which is likely to cause memory waste for business with small data volumes.

[0048] Improper reservation of Hugetlb is likely to occur, resulting in memory waste, occupying system memory, and causing insufficient memory for other services.

[0049] Generally speaking, the Hugetlb optimization technology adopted in the related art can only be used as an avoidance means to solve the problem of excessive memory consumption by page tables. In actual use, its inconvenience is self-evident. For scenarios with high requirements for fine-grained support and scalability, it can no longer meet the needs at all. Based on this, the present application proposes an optimization design solution with finer granularity and high scalability, which can reduce the memory consumed by page tables without awareness, without the need to reserve memory, nor the need to use large pages of 2M or more. The saved memory can also be used without discrimination for other services in the system. In addition, it can also optimize the process creation time. The present application provides a memory sharing method, a memory sharing device, an electronic device, a computer-readable storage medium, and a computer program product. Among them, the memory sharing method can be executed by the memory sharing device, or by an electronic device integrated with the memory sharing device.

[0050] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the following described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative efforts belong to the scope of protection of the present application.

[0051] Please refer to Figure 1a In addition, the present application also provides a memory sharing system, which includes an electronic device 100 for executing the memory sharing method provided by the present application. The electronic device 100 can be any device equipped with a processor and having processing capabilities, such as a server. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, and the present application does not make any restrictions here. Among them, in response to a child process creation request by the parent process, during the creation of the child process, a part of the first page table of the target memory sharing space maintained by the parent process is copied to obtain a second page table; according to the second page table, a page fault exception is triggered when the child process accesses the memory sharing space; the child process performs page fault handling to obtain a corresponding first address mapping relationship; the child process updates the first address mapping relationship to the second page table. In this way, the sharing of the memory space is realized through the method of page table sharing.

[0052] In addition, as Figure 1aAs shown in the figure, the memory sharing system may further include a memory 200 for storing relevant data during the memory sharing process, such as the second page table obtained by copying, the first address mapping relationship obtained by page fault handling, etc.

[0053] It should be noted that the memory sharing system described above is only an example, which is used to more clearly illustrate the technical solution of the embodiments of the present application, and does not constitute a limitation on the technical solution provided by the embodiments of the present application. Those of ordinary skill in the art know that with the evolution of the memory sharing system and the emergence of new business scenarios, the technical solution provided by the embodiments of the present application is also applicable to similar technical problems.

[0054] The following will be described in detail respectively. It should be noted that the serial numbers of the following embodiments do not limit the preferred order of the embodiments.

[0055] Please refer to Figure 1b , Figure 1b which is a schematic flowchart of the memory sharing method provided in this embodiment. As Figure 1b shown, the process of the memory sharing method may be as follows:

[0056] In 110, in response to a child process creation request by the parent process, during the process of creating the child process, the first page table of the target memory sharing space maintained by the parent process is partially copied to obtain the second page table.

[0057] A process is an execution activity of a computer program with respect to a certain data set. It is the basic unit of dynamic execution of the operating system. In traditional operating systems, a process is both the basic allocation unit and the basic execution unit. All processes except the process with process identifier 0 are created by other processes. Among them, for any process with a process identifier other than 0, the other process that creates this process is the parent process of this process, and the corresponding process is the child process of this other process. Therefore, the process with process identifier 0 has no parent process. Processes other than the process with process identifier 0 have only one parent process, but a parent process can have multiple child processes. For example, process A with process identifier 0 creates process B with process identifier 1, and process B creates process C with process identifier 23 and process D with process identifier 27. Among them, process A is the parent process of process B, and process B is the child process of process A; process B is the parent process of process C and process D, and process C and process D are the child processes of process B.

[0058] Generally, there are two common purposes for creating a child process. The parent process hopes to generate a copy of itself, allowing the child process to execute different code segments in the same program or execute a different program. In this embodiment, in response to a child process creation request, the parent process calls the fork function to create the child process. Different from the related art, in the process of creating the child process in this application, the first page table of the target memory shared space maintained by the parent process is not completely copied, but only partially copied to obtain a second page table, which is used by the created child process to access the target memory shared space. Here, the target memory shared space refers to the memory shared space that the parent process expects to share with the created child process.

[0059] The page table is a data structure used by the operating system kernel to manage system virtual memory. It stores the mapping relationship from virtual addresses to physical addresses, so that the conversion from virtual addresses to physical addresses can be achieved through the page table, enabling a process to access physical addresses through virtual addresses. Taking the Linux system as an example, its kernel uses a four-level page table structure, namely the Page Global Directory (PGD), Page Upper Directory (PUD), Page Middle Directory (PMD), and Page Table Entry (PTE). Among them, the next-level page table can be the page table entry of the upper-level page table. For example, the page table entry in the first-level page table, the Page Global Directory, can be the Page Upper Directory; the page table entry in the second-level page table, the Page Upper Directory, can be the Page Middle Directory, and so on.

[0060] Among them, the Page Global Directory manages the entire virtual address parameter and is the top-level page table, while the Page Upper Directory and Page Middle Directory are the intermediate-level page tables used to manage smaller virtual address parameters. The Page Table Entry is the last-level page table, which usually maintains the physical page frame number, etc.

[0061] In this embodiment, when copying the first page table, the parent process can copy the part of the page table above the Page Middle Directory in the first page table. That is, for the page table with a granularity below the Page Table Entry, page table sharing is performed and obtained through the page fault handling method.

[0062] It can be understood that the page table with the granularity of the Page Table Entry consumes the most memory in the entire page table. Sharing this part of the page table can maximize the savings of the memory space consumed by the page table.

[0063] It should be noted that the memory sharing solution provided in this application is executed in the kernel mode. To avoid affecting the kernel stability, in an optional embodiment, only partial memory sharing spaces are subject to page table sharing. Among them, in the process of creating a child process in response to a child process creation request by the parent process, before partially copying the first page table of the target memory sharing space maintained by the parent process to obtain the second page table, it further includes:

[0064] During the process of the parent process performing memory mapping for the memory sharing space, a sharing flag is added to the metadata of the virtual memory area (VMA) corresponding to the memory sharing space. The sharing flag is used to indicate that the memory sharing space requires page table sharing.

[0065] Taking the Linux system as an example, the memory mapping is implemented by the parent process by calling the mmap() interface provided by the kernel. In addition, during the memory mapping process, metadata of the virtual memory space will also be generated, that is, the vm_area_struct structure of the kernel, which is also called the process address space or the process linear region. The kernel uses this structure to define the virtual memory area and is the most basic management unit for the kernel to perform virtual memory management.

[0066] It can be understood that for a parent process, there may be multiple different memory sharing spaces. In this embodiment, not all of its memory sharing spaces are subject to page table sharing, but only the memory sharing spaces with page table sharing requirements are subject to page table sharing. To achieve this purpose, in this embodiment, the memory sharing spaces with page table sharing requirements are determined according to actual needs. During the process of the parent process performing memory mapping for the memory sharing spaces with page table sharing requirements, a sharing flag is added to the metadata of the virtual memory space corresponding to this memory sharing space. The sharing flag is used to indicate that this memory sharing space requires page table sharing.

[0067] It should be noted that this embodiment does not specifically limit the position where the sharing flag is added to the metadata of the virtual memory space, and it can be configured by those skilled in the art according to actual needs. For example, in this embodiment, the sharing flag can be added to the vm_flags field in the metadata of the virtual memory space.

[0068] In addition, since this embodiment realizes page table sharing at the page table entry granularity, during the process of the parent process performing memory mapping for the memory sharing space, the virtual addresses are also aligned according to the page middle directory granularity.

[0069] In this embodiment, in the process of creating a child process in response to a child process creation request by the parent process, partially copying the first page table of the target memory sharing space maintained by the parent process to obtain the second page table includes:

[0070] In response to a child process creation request, the parent process copies the virtual memory space metadata of the target memory shared space maintained by the parent process during the creation of the child process to obtain copy virtual memory space metadata.

[0071] If a sharing flag is added to the copy virtual memory space metadata, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0072] It should be noted that the virtual memory space of each process needs to be maintained through corresponding virtual memory space metadata. In this embodiment, the virtual memory space metadata of the child process is copied from the parent process. Among them, in response to a child process creation request, the parent process copies the virtual memory space metadata of the target memory shared space maintained by the parent process during the creation of the child process, and records the copied virtual memory space metadata as copy virtual memory space metadata, which is used to maintain the virtual memory space of the child process.

[0073] As described above, in this embodiment, page table sharing is not performed on all memory shared spaces, but only on memory shared spaces that require page table sharing. Correspondingly, since the copy virtual memory space metadata is copied from the virtual memory space metadata of the parent process, it can be identified whether a sharing flag is added to the copy virtual memory space metadata. If so, it means that the target memory shared space requires page table sharing. At this time, the parent process partially copies the first page table of the target memory shared space to obtain a second page table accordingly.

[0074] Optionally, in one embodiment, if a sharing flag is added to the copy virtual memory space metadata, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table, including:

[0075] If a sharing flag is added to the copy virtual memory space metadata and the child process belongs to the target child process set, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0076] In this embodiment, page table sharing can also be controlled at the process granularity. Among them, in addition to whether the target memory shared space itself described by the sharing flag requires page table sharing, the child processes that need to perform page table sharing are also controlled through a specific process set, denoted as the target child process set, which includes the child processes that need to perform page table sharing.

[0077] Correspondingly, when it is recognized that a shared identifier is added to the metadata of the copy virtual memory space, it is further recognized whether the created child process belongs to the target child process set. If so, it means that the child process requires page table sharing. At this time, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0078] It should be noted that the determination of the target child process set in this embodiment is not specifically limited and can be determined by those skilled in the art according to actual needs.

[0079] Optionally, in an embodiment, if a shared identifier is added to the metadata of the copy virtual memory space and the child process belongs to the target child process set, before the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table, it further includes:

[0080] The parent process determines the page table memory occupancy of the child process set sharing the same memory shared space;

[0081] If the page table memory occupancy reaches the space threshold, the parent process determines the child process set as the target child process set.

[0082] This embodiment provides an optional way to determine the target child process set. Among them, for a memory shared space, the parent process determines the total memory space occupied by the page table of its child process set due to sharing the memory shared space, which is recorded as the page table memory occupancy, and further determines whether the page table memory occupancy of the child process set reaches the space threshold. If so, the child process set is determined as the target child process set that requires page table sharing.

[0083] In 120, according to the second page table, when the child process accesses the target memory shared space, a page fault exception is triggered.

[0084] Among them, when the child process accesses a virtual address that does not have an address mapping relationship, a page fault exception will be triggered. It can be understood that since the second page table is only part of the content of the first page table, the second page table does not include the complete address mapping relationship corresponding to the target memory shared space. There may not be an address mapping relationship for a certain virtual address in the second page table, or there may not be an address mapping relationship for this virtual address in the first page table itself. Then, when the child process accesses a virtual address that does not have an address mapping relationship, a page fault exception will be triggered.

[0085] In 130, the child process performs page fault handling to obtain the corresponding first address mapping relationship.

[0086] In this embodiment, after a page fault exception is triggered, page fault handling is further performed through a child process to obtain the first address mapping relationship corresponding to this page fault. The process of page fault handling can be understood as determining the physical address corresponding to the virtual address accessed by the child process, and correspondingly obtaining the first address mapping relationship between the virtual address and the physical address.

[0087] Optionally, in one embodiment, in order to better perform page fault handling, this embodiment implements page fault handling through the metadata of the same virtual memory space. Before obtaining the address mapping relationship corresponding to the page fault exception through page fault handling by the child process, it further includes:

[0088] Copy the virtual memory space metadata of the target memory shared space through the parent process to obtain shadow virtual memory space metadata;

[0089] Performing page fault handling through the child process to obtain the corresponding first address mapping relationship includes:

[0090] Performing page fault handling through the child process based on the shadow virtual memory space metadata to obtain the corresponding first address mapping relationship.

[0091] In this embodiment, the parent process also creates a shadow mm_struct structure corresponding to the target shared memory space, and the parent process uses this shadow mm_struct structure to copy the virtual memory space metadata of the target memory shared space, and records the copied virtual memory space metadata as shadow virtual memory space metadata and stores it in the kernel state.

[0092] It should be noted that one or more fields of the virtual memory space metadata of the target memory shared space are used to store the pointers of each operation function in the relevant operation function set, for example, including the function pointers related to page fault handling. Since the shadow virtual memory space metadata is copied from the virtual memory space metadata of the target memory shared space, the two have exactly the same content, and it also stores the pointers of each operation function.

[0093] When performing page fault handling, according to the function pointers related to page fault handling stored in the shadow virtual memory space metadata, the child process can call the relevant functions of page fault handling to perform page fault handling in the kernel state to obtain the corresponding first address mapping relationship.

[0094] For example, please refer to Figure 1c, the page fault handling process is completed through the shadow virtual memory space metadata, such as operations like the creation of the page table entry page table and the filling of the page table entry page table. After completing the entire page fault process, the content filled in the page intermediate page table corresponding to the virtual memory space metadata to be accessed is filled with the content filled in the page intermediate page table after the shadow virtual memory space metadata processing, that is, the newly created lower-level page table: the page table entry sample, thus completing the handling of the page fault exception.

[0095] In 140, the first address mapping relationship is updated to the second page table through the child process.

[0096] As described above, after obtaining the first address mapping relationship through page fault handling, in this embodiment, the obtained first address mapping relationship is further updated to the second page table. In this way, the child process can access the corresponding physical address in the target memory shared space according to the first address mapping relationship in the updated second page table, achieving the purpose of memory sharing.

[0097] It can be understood that the first address mapping relationship obtained through the above page fault handling may not exist in the first page table of the parent process. Correspondingly, in an optional embodiment, after updating the first address mapping relationship to the second page table through the child process, it further includes:

[0098] Updating the first address mapping relationship to the first page table through the parent process.

[0099] In this embodiment, if the first page table does not have the first address mapping relationship, the first address relationship is updated to the first page table through the parent process.

[0100] For example, assume that the first page table does not have the first address mapping relationship. When the parent process accesses the virtual address corresponding to the first address mapping relationship, a page fault exception will be triggered. Since the first address mapping relationship has been obtained through page fault handling using the shadow virtual memory space metadata at this time, there is no need to perform page fault handling again, and the first address mapping relationship obtained through page fault handling can be directly updated to the first page table through the parent process. It can be understood that in other embodiments, when other child processes trigger a page fault exception for the corresponding virtual address, the first address mapping relationship can also be updated to their respective page tables without repeating page fault handling.

[0101] Optionally, in an embodiment, after updating the first address mapping relationship to the second page table through the child process, it further includes:

[0102] Accessing the memory shared space through the parent process according to the first page table triggers a page fault exception;

[0103] Performing page fault handling through the parent process based on the shadow virtual memory space metadata to obtain the corresponding second address mapping relationship;

[0104] The parent process updates the second address mapping relationship to the first page table.

[0105] Similarly, in addition to the child process accessing a virtual address for which there is no address mapping relationship, which will trigger a page fault exception, when the parent process accesses a virtual address that does not have an address mapping share, a page fault exception will also be triggered.

[0106] It can be understood that the first page table of the parent process may not have established a complete address mapping relationship yet. For some virtual addresses without an address mapping relationship, when the parent process accesses them, a page fault exception will also be triggered. In this embodiment, when the parent process triggers a page fault exception, the page fault is also processed through the shadow memory space metadata to obtain the second address mapping relationship corresponding to this page fault exception. Correspondingly, the parent process updates the second address mapping relationship obtained by the page fault handling to the first page table.

[0107] Optionally, in one embodiment, after the parent process updates the second address mapping relationship to the first page table, it further includes:

[0108] The child process updates the second address mapping relationship to the second page table.

[0109] It can be understood that the page table of the child process is copied from the parent process. For the second address mapping relationship that does not exist in the first page table itself, it will also not exist in the second page table copied from the first page table. In this embodiment, the child process also updates the second address mapping relationship to the second page table.

[0110] For example, when the child process accesses the virtual address corresponding to this second address mapping relationship, a page fault exception will be triggered. Since the second address mapping relationship has already been obtained through the page fault handling of the shadow virtual memory space metadata at this time, there is no need to perform page fault handling again. The second address mapping relationship obtained by the page fault handling can be directly updated to the second page table by the child process. It can be understood that in other embodiments, when other child processes trigger a page fault exception corresponding to this virtual address, the second address mapping relationship can also be updated to their respective page tables without repeating the page fault handling.

[0111] As can be seen from the above, in the memory sharing solution provided by this application, in response to a child process creation request from the parent process, during the process of creating the child process, the first page table of the target memory sharing space maintained by the parent process is partially copied to obtain the second page table; according to the second page table, a page fault exception is triggered when the child process accesses the target memory sharing space; the child process performs page fault handling to obtain the corresponding first address mapping relationship; the child process updates the first address mapping relationship to the second page table. In this way, when creating a child process, the page table of the parent process is not completely copied, but only a part of the page table of the parent process is copied. For the address mapping relationships that are not copied or do not exist, the corresponding address mapping relationships are obtained by means of page fault handling when actually accessing the memory sharing space. This can not only achieve the sharing of the memory space, but also effectively reduce the memory space occupied by maintaining the page table. Compared with the original memory consumption, the page table memory consumption can be reduced from dozens of gigabytes to less than dozens of megabytes at most. Especially in scenarios where some processes share too much, such as shared instance databases, it can reduce the page table memory consumption by about 90% brought by a large number of connections (the possibility of having 30,000 connections), so as to increase the number of connections, avoid memory overflow caused by memory consumption, and improve the stability of the database. In addition, since only a part of the page table of the parent process is copied when creating the child process, it can also reduce the time consumed in creating the child process, shortening the creation time of the process by about 40%, thereby improving the process creation efficiency.

[0112] Please refer to Figure 2a and Figure 2b , the process of this memory sharing method can also be as follows:

[0113] In 210, during the process of the parent process performing memory mapping for the memory sharing space, the virtual address is aligned according to the page middle directory granularity, and a sharing flag is added to the virtual memory space metadata corresponding to the memory sharing space to indicate that the memory sharing space requires page table sharing.

[0114] The memory mapping is implemented by the parent process by calling the mmap() interface provided by the kernel. In addition, virtual memory space metadata is generated during the memory mapping process, that is, the vm_area_struct structure of the kernel, which is also called the process address space or process linear area. The kernel uses this structure to define virtual memory areas and is the most basic management unit for the kernel to manage virtual memory.

[0115] It can be understood that for a parent process, there may be multiple different memory sharing spaces. In this embodiment, page table sharing is not performed for all its memory sharing spaces, but for the memory sharing spaces with page table sharing requirements. To achieve this purpose, this embodiment determines the memory sharing spaces with page table sharing requirements according to actual needs. During the process of the parent process performing memory mapping for the memory sharing spaces with page table sharing requirements, a sharing flag is added to the metadata of the virtual memory space corresponding to the memory sharing space. This sharing flag is used to indicate that the memory sharing space requires page table sharing.

[0116] In addition, it should also be noted that to implement page table sharing at the page table entry granularity in this embodiment, it is necessary to ensure that the page table sharing address is aligned at the page middle directory granularity. Correspondingly, the parent process also aligns the virtual address at the page middle directory granularity.

[0117] It should be noted that this embodiment does not specifically limit the position where the sharing flag is added to the metadata of the virtual memory space, which can be configured by those skilled in the art according to actual needs. For example, in this embodiment, the sharing flag can be added to the vm_flags field in the metadata of the virtual memory space.

[0118] In 220, in response to a child process creation request, during the process of creating a child process, the parent process copies the metadata of the virtual memory space of the target memory sharing space maintained by the parent process to obtain copy virtual memory space metadata, and copies the metadata of the virtual memory space of the target memory sharing space to obtain shadow virtual memory space metadata.

[0119] Generally, there are two common purposes for creating a child process. The parent process hopes to generate a copy of itself, allowing the child process to execute different code segments in the same program, or allowing the child process to execute a different program.

[0120] It should be noted that the virtual memory space of each process needs to be maintained through the corresponding metadata of the virtual memory space. In this embodiment, the metadata of the virtual memory space of the child process is copied from the parent process. Among them, in response to a child process creation request, during the process of creating a child process, the parent process copies the metadata of the virtual memory space of the target memory sharing space maintained by the parent process, and records the copied metadata of the virtual memory space as copy virtual memory space metadata. This copy virtual memory space metadata is used to maintain the virtual memory space of the child process.

[0121] In this embodiment, the parent process also creates a shadow mm_struct structure corresponding to the target shared memory space, and the parent process uses the shadow mm_struct structure to copy the virtual memory space metadata of the target memory shared space. The copied virtual memory space metadata is denoted as shadow virtual memory space metadata and is stored in the kernel mode.

[0122] In 230, if a shared flag is added to the copy virtual memory space metadata and the child process belongs to the target child process set, the parent process copies the page table above the page middle directory in the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0123] In this embodiment, page table sharing can also be controlled at the process granularity. Among them, in addition to whether the target memory shared space described by the shared flag itself requires page table sharing, a specific process set is also used to manage the child processes that need to perform page table sharing, denoted as the target child process set, and the target child process set includes the child processes that need to perform page table sharing.

[0124] Correspondingly, when it is recognized that a shared flag is added to the copy virtual memory space metadata, it is further recognized whether the created child process belongs to the target child process set. If so, it means that the child process needs page table sharing. At this time, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table. Among them, when copying the first page table, the parent process can copy the page table above the page middle directory in the first page table, that is, for the page table below the page table entry granularity, page table sharing is performed and obtained through the page fault handling method.

[0125] It can be understood that the page table at the page table entry granularity consumes the most memory in the entire page table. Sharing this part of the page table can maximize the savings of the memory space consumed by the page table.

[0126] It should be noted that the determination of the target child process set in this embodiment is not specifically limited and can be determined by those skilled in the art according to actual needs.

[0127] In 240, according to the second page table, when the child process accesses the target memory shared space, a page fault exception is triggered.

[0128] Among them, when the child process accesses a virtual address that does not have an address mapping relationship, a page fault exception will be triggered. It can be understood that since the second page table is only part of the content of the first page table, the second page table does not include the complete address mapping relationship corresponding to the target memory shared space. There may not be an address mapping relationship for a certain virtual address in the second page table, or there may not be an address mapping relationship for this virtual address in the first page table itself. Then, when the child process accesses a virtual address that does not have an address mapping relationship, a page fault exception will be triggered.

[0129] In 250, the child process performs page fault handling based on the shadow virtual memory space metadata to obtain the corresponding first address mapping relationship.

[0130] It should be noted that the virtual memory space metadata of the target memory shared space has one or more fields for storing pointers to each operation function in the relevant operation function set, for example, including function pointers related to page fault handling. Since the shadow virtual memory space metadata is copied from the virtual memory space metadata of the target memory shared space and the two have exactly the same content, it also stores pointers to each operation function.

[0131] When performing page fault handling, based on the function pointers related to page fault handling stored in the shadow virtual memory space metadata, the child process can call the relevant functions for page fault handling in the kernel mode to obtain the corresponding first address mapping relationship.

[0132] In 260, the child process updates the first address mapping relationship to the second page table.

[0133] As above, after obtaining the first address mapping relationship through page fault handling, this embodiment further updates the obtained first address mapping relationship to the second page table. In this way, the child process can access the corresponding physical address in the target memory shared space according to the first address mapping relationship in the updated second page table, achieving the purpose of memory sharing.

[0134] In 270, the parent process updates the first address mapping relationship to the first page table.

[0135] It can be understood that the first address mapping relationship obtained through the above page fault handling may not exist in the first page table of the parent process. Correspondingly, the first address mapping relationship is also updated to the first page table by the parent process.

[0136] For example, assume that the first address mapping relationship does not exist in the first page table. When the parent process accesses the virtual address corresponding to the first address mapping relationship, a page fault exception will be triggered. Since the first address mapping relationship has been obtained through page fault handling based on the shadow virtual memory space metadata at this time, there is no need to perform page fault handling again, and the first address mapping relationship obtained through page fault handling can be directly updated to the first page table by the parent process. It can be understood that in other embodiments, when other child processes trigger a page fault exception corresponding to the virtual address, the first address mapping relationship can also be updated to their respective page tables without repeating page fault handling.

[0137] In this embodiment, by replacing the page table consumption of a large number of parent and child processes sharing memory through the shared page table method, the page table consumption can be greatly reduced. In addition, compared with the traditional optimization scheme using Hugetlb, without the need for reservation, it can access memory in a more fine-grained manner, greatly reducing the impact of memory fragmentation and making memory expansion and contraction more flexible.

[0138] To better implement the above memory sharing method, the embodiment of the present application also provides a corresponding memory sharing device. The meanings of the nouns are the same as those in the above memory sharing method, and the specific implementation details can be referred to the description in the above method embodiments.

[0139] Please refer to Figure 3 , Figure 3 which is the structural schematic diagram of the memory sharing device provided by the embodiment of the present application. The memory sharing device may include a page table replication module 310, a page fault trigger module 320, a page fault handling module 330, and a page table update module 340. Among them,

[0140] The page table replication module 310 is configured to, in response to a child process creation request by the parent process, during the process of creating the child process, partially replicate the first page table of the target memory sharing space maintained by the parent process to obtain a second page table;

[0141] The page fault trigger module 320 is configured to, according to the second page table, trigger a page fault exception by the child process accessing the target memory sharing space;

[0142] The page fault handling module 330 is configured to perform page fault handling by the child process to obtain a corresponding first address mapping relationship;

[0143] The page table update module 340 is configured to update the first address mapping relationship to the second page table by the child process.

[0144] Optionally, in an embodiment, the memory sharing device provided by the present application further includes a page table identification module, which is configured to add a sharing identifier to the virtual memory space metadata corresponding to the memory sharing space during the process of the parent process performing memory mapping for the memory sharing space. The sharing identifier is used to indicate that the memory sharing space requires page table sharing.

[0145] Optionally, in an embodiment, the page table replication module 310 is configured to, in response to a child process creation request by the parent process, during the process of creating the child process, replicate the virtual memory space metadata of the target memory sharing space maintained by the parent process to obtain a copy of the virtual memory space metadata; if a sharing identifier is added to the copy of the virtual memory space metadata, then the parent process partially replicates the first page table of the target memory sharing space maintained by the parent process to obtain a second page table.

[0146] Optionally, in one embodiment, the page fault handling module 330 is configured to copy, by the parent process, the virtual memory space metadata of the target memory shared space to obtain shadow virtual memory space metadata; and perform page fault handling by the child process based on the shadow virtual memory space metadata to obtain a corresponding first address mapping relationship.

[0147] Optionally, in one embodiment, the page table update module 340 is further configured to update the first address mapping relationship to the first page table by the parent process.

[0148] Optionally, in one embodiment, the page fault trigger module 320 is further configured to, according to the first page table, trigger a page fault exception by the parent process when accessing the memory shared space; the page fault handling module 330 is further configured to perform page fault handling by the parent process based on the shadow virtual memory space metadata to obtain a corresponding second address mapping relationship; the page table update module 340 is further configured to update the second address mapping relationship to the first page table by the parent process.

[0149] Optionally, in one embodiment, the page table update module 340 is further configured to update the second address mapping relationship to the second page table by the child process.

[0150] Optionally, in one embodiment, the page table copying module 310 is configured to, if a sharing identifier is added to the copy virtual memory space metadata and the child process belongs to the target child process set, partially copy, by the parent process, the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0151] Optionally, in one embodiment, the memory sharing device provided in this application further includes a set determination module, configured to determine, by the parent process, the page table memory occupancy of the child process set sharing the same memory shared space; if the page table memory occupancy reaches the space threshold, determine, by the parent process, the child process set as the target child process set.

[0152] Optionally, in one embodiment, the memory sharing device provided in this application further includes an address alignment module, configured to align virtual addresses according to the page middle directory granularity during the process of performing memory mapping on the memory shared space by the parent process.

[0153] Optionally, in one embodiment, the page table copying module 310 is configured to, in response to a child process creation request by the parent process, during the process of creating a child process, copy the page table above the page middle directory in the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

[0154] For the specific implementation of each of the above modules, reference may be made to the previous embodiments and will not be elaborated here.

[0155] In this embodiment, the page table copying module 310 partially copies the first page table of the target memory shared space maintained by the parent process in response to the child process creation request during the creation of the child process, to obtain the second page table; the page fault triggering module 320 triggers a page fault exception through the child process accessing the target memory shared space according to the second page table; the page fault handling module 330 performs page fault handling through the child process to obtain the corresponding first address mapping relationship; the page table updating module 340 updates the first address mapping relationship to the second page table through the child process. In this way, when creating a child process, the page table of the parent process is not completely copied, but only a part of the page table of the parent process is copied. For the address mapping relationships that are not copied or do not exist themselves, the corresponding address mapping relationships are obtained by means of page fault handling when actually accessing the memory shared space. This can not only achieve the sharing of the memory space, but also effectively reduce the memory space occupied by maintaining the page table. Compared with the original memory consumption, the page table memory consumption can be reduced from dozens of gigabytes to less than dozens of megabytes at most. Especially in scenarios where some processes share too much, such as shared instance databases, it can reduce about 90% of the page table memory consumption brought by a large number of connections (the possibility of having 30,000 connections), so as to increase the number of connections, avoid memory overflow caused by memory consumption, and improve the stability of the database. In addition, since only a part of the page table of the parent process is copied when creating a child process, it can also reduce the time consumed for creating the child process, shortening the creation time of the process by about 40%, thereby improving the process creation efficiency.

[0156] An embodiment of the present application further provides an electronic device, including a memory and a processor. The processor is configured to execute the steps in the memory sharing method provided in the above embodiment by calling a computer program stored in the memory.

[0157] Please refer to Figure 4 , Figure 4 which is a schematic structural diagram of the electronic device provided in the embodiment of the present application.

[0158] The electronic device may include a processor 101 with one or more processing cores, a memory 102 with one or more computer-readable storage media, a power supply 103, an input unit 104, and other components. Those skilled in the art can understand that Figure 4 the structural diagram of the electronic device shown in

[0159] The processor 101 is the control center of the electronic device, connecting various parts of the entire electronic device through various interfaces and circuits. By running or executing software programs and / or modules stored in the memory 102, and by invoking the data stored in the memory 102, it executes various functions of the electronic device and processes data. Optionally, the processor 101 may include one or more processing cores; optionally, the processor 101 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor may not be integrated into the processor 101 either.

[0160] The memory 102 can be used to store software programs and modules. The processor 101 executes various functional applications and data processing by running the software programs and modules stored in the memory 102. The memory 102 mainly includes a program storage area and a data storage area. Among them, the program storage area can store the operating system, application programs required for at least one function (such as the sound playback function, image playback function, etc.); the data storage area can store the data created according to the use of the electronic device. In addition, the memory 102 may include high-speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid-state storage devices. Correspondingly, the memory 102 may also include a memory controller to provide the processor 101 with access to the memory 102.

[0161] The electronic device further includes a power supply 103 for powering each component. Optionally, the power supply 103 can be logically connected to the processor 101 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system. The power supply 103 may also include any components such as one or more DC or AC power supplies, a recharge system, a power failure detection circuit, a power converter or inverter, and a power status indicator.

[0162] The electronic device may further include an input unit 104, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.

[0163] Although not shown, the electronic device may further include a display unit, an image acquisition component, etc., which will not be elaborated here. Specifically, in this embodiment, the processor 101 will load the executable code corresponding to one or more computer programs into the memory 102, and the processor 101 will execute the steps in the memory sharing method provided in this application, such as:

[0164] In response to a child process creation request by the parent process, during the process of creating a child process, a first page table of a target memory shared space maintained by the parent process is partially copied to obtain a second page table;

[0165] According to the second page table, a page fault exception is triggered when the child process accesses the target memory shared space;

[0166] The child process performs page fault handling to obtain a corresponding first address mapping relationship;

[0167] The child process updates the first address mapping relationship to the second page table.

[0168] It should be noted that the electronic device provided in the embodiments of the present application and the memory sharing method in the above embodiments belong to the same concept. The specific implementation process is detailed in the above related embodiments and will not be repeated here.

[0169] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program stored thereon is executed by a processor of the electronic device provided in the embodiments of the present application, the processor of the electronic device implements the steps in the memory sharing method provided by the present application. Among them, the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0170] The present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor of the electronic device provided in the embodiments of the present application, the processor of the electronic device implements the steps in the memory sharing method provided by the present application.

[0171] The memory sharing method, memory sharing device, electronic device, computer-readable storage medium, and computer program product provided by the present application have been introduced in detail above. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present application.

[0172] It should be noted that when the above embodiments of the present application are applied to specific products or technologies, involving relevant user data, user permission or consent needs to be obtained, and the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards of relevant countries and regions.

Claims

1. A memory sharing method, characterized in that, including: When the parent process responds to a child process creation request and creates a child process, partially copy the first page table of the target memory shared space maintained by the parent process to obtain a second page table; According to the second page table, trigger a page fault exception when the child process accesses the target memory shared space; Perform page fault handling through the child process to obtain a corresponding first address mapping relationship; Update the first address mapping relationship to the second page table through the child process.

2. The memory sharing method according to claim 1, wherein Before the step of when the parent process responds to a child process creation request and creates a child process, and partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table, it further includes: When the parent process performs memory mapping for the memory shared space, add a sharing identifier to the virtual memory space metadata corresponding to the memory shared space, and the sharing identifier is used to indicate that the memory shared space requires page table sharing.

3. The memory sharing method according to claim 2, wherein The step of when the parent process responds to a child process creation request and creates a child process, and partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table includes: When the parent process responds to a child process creation request and creates a child process, copy the virtual memory space metadata of the target memory shared space maintained by the parent process to obtain a copy of the virtual memory space metadata; If the sharing identifier is added to the copy of the virtual memory space metadata, then partially copy the first page table of the target memory shared space maintained by the parent process by the parent process to obtain a second page table.

4. The memory sharing method according to claim 3, wherein Before the step of performing page fault handling through the child process to obtain an address mapping relationship corresponding to the page fault exception, it further includes: Copy the virtual memory space metadata of the target memory shared space by the parent process to obtain shadow virtual memory space metadata; The step of performing page fault handling through the child process to obtain a corresponding first address mapping relationship includes: Perform page fault handling based on the shadow virtual memory space metadata through the child process to obtain a corresponding first address mapping relationship.

5. The memory sharing method according to claim 4, wherein After the step of updating the first address mapping relationship to the second page table through the child process, it further includes: Update the first address mapping relationship to the first page table through the parent process.

6. The memory sharing method according to claim 4, wherein After the step of updating the first address mapping relationship to the second page table through the child process, it further includes: According to the first page table, trigger a page fault exception when the parent process accesses the memory shared space; Perform page fault handling based on the shadow virtual memory space metadata through the parent process to obtain a corresponding second address mapping relationship; Update the second address mapping relationship to the first page table through the parent process.

7. The memory sharing method according to claim 6, wherein After the step of updating the second address mapping relationship to the first page table through the parent process, it further includes: Update the second address mapping relationship to the second page table through the child process.

8. The memory sharing method according to claim 3, wherein The step of if the sharing identifier is added to the copy of the virtual memory space metadata, then partially copy the first page table of the target memory shared space maintained by the parent process by the parent process to obtain a second page table includes: If the shared identifier is added to the metadata of the copy virtual memory space, and the child process belongs to the target child process set, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

9. The memory sharing method according to claim 8, wherein Before the step of "If the shared identifier is added to the metadata of the copy virtual memory space, and the child process belongs to the target child process set, the parent process partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table", the method further includes: The parent process determines the page table memory occupancy of the child process set sharing the same memory shared space; If the page table memory occupancy reaches the space threshold, the parent process determines the child process set as the target child process set.

10. The memory sharing method according to claim 2, wherein The method further includes: During the process of the parent process performing memory mapping for the memory shared space, the virtual address is aligned according to the page middle directory granularity.

11. The memory sharing method according to claim 10, characterized in that, The step of "The parent process responds to a child process creation request, and during the process of creating a child process, partially copies the first page table of the target memory shared space maintained by the parent process to obtain a second page table" includes: The parent process responds to a child process creation request, and during the process of creating a child process, copies the page table above the page middle directory in the first page table of the target memory shared space maintained by the parent process to obtain a second page table.

12. A memory sharing device, characterized in that, The method includes: A page table copying module, configured to, when the parent process responds to a child process creation request, during the process of creating a child process, partially copy the first page table of the target memory shared space maintained by the parent process to obtain a second page table; A page fault triggering module, configured to, according to the second page table, trigger a page fault exception when the child process accesses the target memory shared space; A page fault handling module, configured to perform page fault handling by the child process to obtain a corresponding first address mapping relationship; A page table updating module, configured to update the first address mapping relationship to the second page table by the child process.

13. An electronic device, characterized in that, The device includes a memory and a processor, the memory stores a computer program, and the processor executes the computer program in the memory to implement the steps in the memory sharing method according to any one of claims 1 to 11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program is suitable for being executed by a processor to implement the steps in the memory sharing method according to any one of claims 1 to 11.

15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps in the memory sharing method according to any one of claims 1 to 11.