Method, apparatus, and electronic device for reclaiming shared memory
By introducing a shared memory recycling process in the multi-process shared large-page memory scenario, monitoring and recycling shared memory occupied by the exit process, the problem of shared large-page memory leaks is solved and the utilization and availability of system resources is improved.
Patent Information
- Application Number
- CN201910493738.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-06
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2039-06-06
AI Technical Summary
In the multi-process shared large page memory scenario, the shared large page memory occupied by a single process after exiting cannot be recycled in time, resulting in a leak of shared large page memory, which in turn leads to insufficient system resources and affects system availability.
Introduce a shared memory recycling process to monitor the operating status of the business process. When the business process exits, it releases the shared memory it occupies to the shared memory pool based on the shared memory information recorded previously.
By timely recycling shared memory occupied by exit processes, the shared large-page memory leak is avoided, the resource utilization rate of shared memory is improved, and the availability of the system is enhanced.
Smart Images

Figure CN112052085B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular, to a method, apparatus, and electronic device for recycling shared memory. Background Art
[0002] Virtual memory is an imaginary memory space. During the running of a program, the part of the virtual memory space that needs to be accessed will be mapped to the physical memory space, so as to access the data required for program running from the corresponding physical memory space. The kernel of the operating system will maintain an independent page mapping table for each process in the system. The basic principle of the page mapping table is to map a section of virtual memory space that needs to be accessed during the running of the program to a section of physical memory space through the page mapping table. In this way, when the CPU accesses the corresponding virtual memory address, it can access a corresponding address on the physical memory through this mechanism of looking up the page mapping table. A "page" is the basic unit for mapping the virtual memory space to the physical memory space.
[0003] Compared with the traditional 4K page memory, the Linux operating system supports memory with large pages above 2M, which is called large page memory. The use of large page memory can improve memory management and access efficiency.
[0004] Shared memory is one of the simplest ways of inter-process communication. Shared memory allows two or more processes to access the same piece of memory. In a scenario where multiple processes, such as processes A, B, and C, share large page memory, when process A exits, the shared large page memory resources occupied by this process are not released in the physical memory, resulting in a leakage of shared large page memory. If the processes in the system keep exiting, it will lead to a shortage of shared large page memory resources, resulting in the entire system being unable to run normally. It can only be solved by exiting all processes that occupy the shared large page memory and re-initializing the shared large page memory. This method has low efficiency and a great impact on system operation. Summary of the Invention
[0005] The present invention provides a method, apparatus, and electronic device for recycling shared memory, which can timely recycle the shared memory resources occupied by exited processes in a shared memory scenario and improve the resource utilization rate of the shared memory.
[0006] To achieve the above object, the embodiments of the present invention adopt the following technical solutions:
[0007] In a first aspect, a method for recycling shared memory is provided, including:
[0008] Recording the shared memory information allocated by a service process from a shared memory pool;
[0009] After the shared memory recycling process detects the exit of the service process, it releases the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information.
[0010] In a second aspect, a shared memory recycling device is provided, including:
[0011] A memory recording module, configured to record the shared memory information allocated by a service process from the shared memory pool;
[0012] A memory release module, configured to, after the shared memory recycling process detects the exit of the service process, release the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information.
[0013] In a third aspect, another shared memory recycling method is provided, including:
[0014] Recording the shared memory information allocated by a service process from the shared memory pool;
[0015] Selecting a service process from the currently running service processes as the shared memory recycling process, and through the shared memory recycling process, after detecting the exit of a service process, releasing the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information.
[0016] In a fourth aspect, another shared memory recycling device is provided, including:
[0017] A memory information recording module, configured to record the shared memory information allocated by a service process from the shared memory pool;
[0018] A memory information release module, configured to select a service process from the currently running service processes as the shared memory recycling process, and through the shared memory recycling process, after detecting the exit of a service process, release the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information.
[0019] In a fifth aspect, an electronic device is provided, including:
[0020] A memory, configured to store a program;
[0021] A processor, coupled to the memory, configured to execute the program, and when the program runs, execute the shared memory recycling method provided by the present invention.
[0022] The present invention provides a method, apparatus, and electronic device for reclaiming shared memory. By introducing a shared memory reclaiming process responsible for reclaiming shared (large page) memory. That is, after the shared memory reclaiming process detects that a service process has exited, according to the recorded information of the allocated shared memory, the shared memory allocated to the service process is released to the shared memory pool, thus solving the problem of shared (large page) memory leakage caused by the exit of a single service process, improving the resource utilization rate of shared memory, and further improving the availability of the system.
[0023] The above description is only an overview of the technical solution of the present application. In order to be able to understand the technical means of the present application more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features, and advantages of the present application more obvious and understandable, the following specifically illustrates the specific embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] By reading the detailed description of the preferred embodiments below, various other advantages and benefits will become clear to those of ordinary skill in the art. The drawings are only for the purpose of showing the preferred embodiments and are not considered to be a limitation of the present application. Moreover, throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:
[0025] Figure 1 is a schematic structural diagram of the shared memory and its management according to an embodiment of the present invention;
[0026] Figure 2 is a schematic diagram of the memory information management node according to an embodiment of the present invention;
[0027] Figure 3 is a schematic diagram of the shared memory reclaiming logic according to an embodiment of the present invention;
[0028] Figure 4 is the flow of the method for reclaiming shared memory according to an embodiment of the present invention Figure 1 ;
[0029] Figure 5 is the flow of the method for reclaiming shared memory according to an embodiment of the present invention Figure 2 ;
[0030] Figure 6 is the structure of the apparatus for reclaiming shared memory according to an embodiment of the present invention Figure 1 ;
[0031] Figure 7 is the structure of the apparatus for reclaiming shared memory according to an embodiment of the present invention Figure 2 ;
[0032] Figure 8 is the flow of the method for reclaiming shared memory according to an embodiment of the present invention Figure 3 ;
[0033] Figure 9 The structure of the shared memory recycling device according to the embodiment of the present invention Figure 3 ;
[0034] Figure 10 It is a schematic structural diagram of an electronic device according to an embodiment of the present invention. Detailed implementation manners
[0035] Hereinafter, exemplary embodiments of the present disclosure will be described in more detail with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be completely conveyed to those skilled in the art.
[0036] The embodiment of the present invention improves the problem in the prior art that in the scenario of multi-process shared memory, especially in the scenario of sharing large page memory, due to the exit of a single process, the large page memory occupied by it is not released, resulting in shared memory leakage. The core idea is to introduce a shared memory recycling process to monitor the running status of the processes that occupy the shared memory (hereinafter referred to as "business processes" for distinction from the shared memory recycling process). When a certain business process exits, the shared memory recycling process will release the shared memory occupied by it to the shared memory pool according to the shared memory information previously recorded for this business process, so that this part of the shared memory can be recycled in time and the utilization rate of the shared memory can be improved.
[0037] Figure 1 It is a schematic structural diagram of the shared memory and its management according to an embodiment of the present invention. As Figure 1 shown, the shared memory recycling process shares the shared memory with multiple business processes (Process A, B, C), and the shared memory recycling process is responsible for recycling the shared memory exclusively occupied by the business process after it exits. Figure 1 Among them, after each business process starts, it will create its own memory information management node in the shared memory to manage the memory information allocated to each business process. The memory information management nodes of all business processes are linked together.
[0038] As Figure 2 shown, it is a schematic diagram of the memory information management node according to an embodiment of the present invention. Each business process creates a memory information structure for the memory allocated to it from the shared memory and links all the memory information structures together to form a memory information management node. The memory information records the address of the shared memory allocated to the corresponding business process.
[0039] As Figure 3As shown in the figure, it is a schematic diagram of the shared memory recycling logic according to an embodiment of the present invention. In a multi-process shared memory scenario, when each business process starts, it creates its own memory information management node in the shared memory to maintain all the shared memory information allocated from the shared memory by the business process. The shared memory recycling process monitors the status of each business process. When it finds that a business process exits, it queries the memory information management node corresponding to the business process to obtain the allocated shared memory information, so as to recycle the memory allocated by the business process from the shared memory.
[0040] In the traditional multi-process shared memory scenario, after the available shared memory is allocated to the business process, when the business process exits, the corresponding occupied memory space (the memory space exclusive to the business process) is not recycled, resulting in that this part of the shared memory cannot be re-allocated to other business processes. Only after all the business processes using the shared memory exit, the shared memory can be initialized and recycled. However, in this solution, by setting up a shared memory recycling process, the shared memory occupied by the exited business process can be recycled in a timely manner, without waiting for the initialization and recycling after all business processes exit, thereby improving the utilization rate of the shared memory and the availability of the system.
[0041] The technical solution of the present application will be further described below through multiple embodiments.
[0042] Embodiment 1
[0043] Figure 4 It is a flowchart of the method for recycling the shared memory provided by the embodiment of the present invention, including the following steps:
[0044] S410, record the shared memory information allocated by the business process from the shared memory pool.
[0045] In a multi-process shared memory scenario, after each business process starts, through the mapping from the virtual memory address to the physical address, the business process can share the shared memory space in the physical memory. The business process can allocate available shared memory from the shared memory through a memory allocator for use.
[0046] Each shared memory space corresponds to a shared memory pool, which is used to record the available memory information in the shared memory space. Multiple business processes sharing the same shared memory can allocate shared memory resources from the corresponding shared memory pool. When a part of the shared memory in the shared memory pool is allocated to a certain business process, this part of the shared memory changes from the available state to the occupied state and is removed from the shared memory pool. If there is no special operation for the occupied shared memory (for example, the configuration information of the later-started business process indicates that it shares the memory space with the earlier-started business process), it will not be allocated to other processes until this part of the shared memory is released back to the shared memory pool.
[0047] After each business process is started, this solution records the shared memory information allocated by the business process from the shared memory pool, so as to facilitate the subsequent release of the corresponding shared memory space based on this recorded information. For example, after each business process is started, a memory information management node corresponding to the business process can be created in the specified memory space of the shared memory pool, and the shared memory information (such as the physical memory address) allocated to the business process can be stored in this memory information management node. For instance, the business process can create it by itself, or create the memory information management node corresponding to the business process through a memory allocator.
[0048] S420, after the shared memory recycling process detects that a business process has exited, according to the recorded allocated shared memory information, release the shared memory allocated to this business process to the shared memory pool.
[0049] In this solution, a shared memory recycling process is introduced to monitor the running status of each business process. When it detects that a certain business process has exited, this shared memory recycling process can promptly query the previously recorded allocated shared memory information, obtain the shared memory allocated to this business process, and release it to the shared memory pool, so that this part of the shared memory can be re-allocated and used again. Moreover, this shared memory recycling process will not affect the running status of other business processes.
[0050] Furthermore, when the allocated shared memory information is stored in the memory information management node, in order to facilitate the shared memory recycling process to query the allocated shared memory information, it can be set that the shared memory recycling process also shares the shared memory (especially the specified memory space where the memory information management node is located). In this way, the shared memory recycling process can complete the release of the shared memory by querying the memory information management node. The specific execution steps are as Figure 5 shown:
[0051] S510, query the memory information management node corresponding to this business process to determine the shared memory information allocated to this business process.
[0052] When the shared memory recycling process detects that a certain business process has exited, it will actively query the memory information management node corresponding to this business process, obtain the recorded information therein, to determine the shared memory information allocated to this business process.
[0053] S520, according to the determined shared memory information, release the shared memory allocated to this business process to the shared memory pool.
[0054] The shared memory recycling process releases the corresponding shared memory according to the shared memory information allocated to the exited business process, and puts the corresponding shared memory address back into the shared memory pool for re-allocation and utilization.
[0055] Further, in the scenario of multi-process shared memory, in many cases, there is an intersection between the shared memories allocated to business processes. After determining the shared memory information corresponding to a certain exited business process, it is also necessary to consider the shared memory information recorded by the memory information management nodes corresponding to other business processes in the above-mentioned specified memory space to complete the recycling process of the shared memory.
[0056] Specifically, it is possible to first query the memory information management nodes corresponding to other business processes in the specified memory space of the above-mentioned shared memory pool to determine whether there is any shared memory occupied by other processes in the determined shared memory; if so, release the unoccupied shared memory in the determined shared memory to the shared memory pool; if not, release the determined shared memory to the shared memory pool.
[0057] In this way, when recycling the shared memory of an exited business process, the status of other running business processes in the shared memory scenario will not be affected.
[0058] Further, after the shared memory allocated to a business process is released to the shared memory pool, the memory information management node corresponding to the business process can be deleted to recycle this part of the memory resources.
[0059] Further, the shared memory in this solution can be large page memory. Since the memory of each page of large page memory is large, adopting this solution to recycle the shared large page memory in a timely manner has a more obvious effect on improving the utilization rate of shared memory and improving system performance.
[0060] The method for recycling shared memory provided by the present invention is responsible for recycling shared (large page) memory by introducing a shared memory recycling process. That is, after the shared memory recycling process detects the exit of a business process, according to the recorded allocated shared memory information, the shared memory allocated to the business process is released to the shared memory pool, thereby solving the problem of shared (large page) memory leakage caused by the exit of a single business process, improving the resource utilization rate of shared memory, and further improving the availability of the system.
[0061] Further, by creating a memory information management node in the specified memory space of the shared memory pool and setting the shared memory recycling process to share the specified memory space, it is convenient for the shared memory recycling process to query the shared memory information allocated to business processes and recycle the shared memory information in a timely manner.
[0062] Embodiment 2
[0063] As Figure 6 shown, it is the structure diagram of the shared memory recycling device according to the embodiment of the present invention, which can control the execution of the method steps as Figure 4 shown therein, and it includes:
[0064] A memory recording module 610, configured to record the shared memory information allocated by a service process from a shared memory pool;
[0065] A memory release module 620, configured to, after a shared memory recycling process detects that a service process has exited, release the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information.
[0066] Furthermore, the above-mentioned memory recording module 610 may specifically be configured to, after a service process is started, create a memory information management node corresponding to the service process in a specified memory space of the shared memory pool, and store the shared memory information allocated to the service process in the memory information management node.
[0067] Furthermore, the above-mentioned shared memory recycling process shares the above-mentioned specified memory space;
[0068] Correspondingly, as Figure 7 shown, the above-mentioned memory release module 620 may include:
[0069] A record query unit 710, configured to control the shared memory recycling process to query the memory information management node corresponding to the service process to determine the shared memory information allocated to the service process;
[0070] A memory release unit 720, configured to control the shared memory recycling process to release the shared memory allocated to the service process to the shared memory pool according to the determined shared memory information.
[0071] Furthermore, the above-mentioned record query unit 710 may further be configured to control the shared memory recycling process to query the memory information management nodes corresponding to other service processes in the specified memory space to determine whether there is any shared memory occupied by other processes in the determined shared memory;
[0072] If so, trigger the memory release unit 720 to control the shared memory recycling process to release the unoccupied shared memory in the determined shared memory to the shared memory pool;
[0073] If not, trigger the memory release unit 720 to control the shared memory recycling process to release the determined shared memory to the shared memory pool.
[0074] Furthermore, the above-mentioned shared memory recycling device may further include:
[0075] A record deletion module, configured to delete the memory information management node corresponding to a service process after the shared memory allocated to the service process is released to the shared memory pool.
[0076] Furthermore, the above-mentioned shared memory is a large page memory.
[0077] The shared memory recycling device provided by the present invention is responsible for recycling shared (large page) memory by introducing a shared memory recycling process. That is, after the shared memory recycling process monitors the exit of a service process, it releases the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information, thereby solving the problem of shared (large page) memory leakage caused by the exit of a single service process, improving the resource utilization rate of shared memory, and further improving the availability of the system.
[0078] Furthermore, by creating a memory information management node in the specified memory space of the shared memory pool and setting the shared memory recycling process to share the specified memory space, it is convenient for the shared memory recycling process to query the shared memory information allocated to service processes and recycle the shared memory information in a timely manner.
[0079] Embodiment III
[0080] Figure 8 The flowchart of the shared memory recycling method provided by the embodiment of the present invention includes the following steps:
[0081] S810, record the shared memory information allocated by the service process from the shared memory pool.
[0082] S820, select a service process from the currently running service processes as the shared memory recycling process. After the shared memory recycling process monitors the exit of a service process, it releases the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information.
[0083] The method steps shown in this embodiment are generally similar to Figure 4 the method steps shown. The main difference is that the shared memory recycling process in this solution is selected from the currently running service processes.
[0084] For example, the first service process that allocates shared memory information from the shared memory pool can be selected as the shared memory recycling process to facilitate monitoring the running states of all processes that allocate shared memory information from the shared memory pool without omission (if a later-started service process is selected as the shared memory recycling process, the earlier-started service process may have exited and does not exist, thus unable to monitor the running state of the earlier-started service process).
[0085] Furthermore, during the execution of Figure 8 the method shown, if the service process serving as the shared memory recycling process exits, a service process is selected from the remaining running service processes as the shared memory recycling process to continue monitoring the states of the currently running service processes.
[0086] The shared memory occupied by the exited shared memory recycling process can be indicated to be released by the next selected shared memory recycling process.
[0087] In addition, on the basis of executing the method shown in this embodiment, the method processing procedure shown in Embodiment 1 can also be executed.
[0088] Based on the method shown in Embodiment 1, the shared memory recycling method provided by the present invention selects a service process from the currently running service processes as the shared memory recycling process to realize the recycling of the occupied shared memory, reducing the technical complexity of additionally setting up a shared memory recycling process.
[0089] Embodiment 4
[0090] As Figure 9 shown, it is the structural diagram of the shared memory recycling device of the embodiment of the present invention, which can control the execution of the method steps as shown in Figure 8 , and it includes:
[0091] The memory information recording module 910 is used to record the shared memory information allocated by the service process from the shared memory pool;
[0092] The memory information releasing module 920 is used to select a service process from the currently running service processes as the shared memory recycling process. Through the shared memory recycling process, after detecting that a service process exits, according to the recorded allocated shared memory information, the shared memory allocated to this service process is released to the shared memory pool.
[0093] Furthermore, the above-mentioned memory information releasing module 920 can be used to, if the service process serving as the shared memory recycling process exits, select a service process from the remaining running service processes as the shared memory recycling process.
[0094] In addition, in the shared memory recycling device shown in this embodiment, the functional modules shown in Embodiment 2 can also be included to execute the method steps shown in Embodiment 1.
[0095] Based on the functions of the device shown in Embodiment 2, the shared memory recycling device provided by the present invention selects a service process from the currently running service processes as the shared memory recycling process to realize the recycling of the occupied shared memory, reducing the technical complexity of additionally setting up a shared memory recycling process.
[0096] Embodiment 5
[0097] The previous embodiments describe the overall architecture of a shared memory recycling device, and the functions of this device can be realized by means of an electronic device, such as Figure 10As shown, it is a schematic structural diagram of an electronic device according to an embodiment of the present invention, specifically including: a memory 101 and a processor 102.
[0098] The memory 101 is used to store programs.
[0099] In addition to the above programs, the memory 101 can also be configured to store various other data to support operations on the electronic device. Examples of such data include instructions for any application program or method for operating on the electronic device, contact data, phone book data, messages, pictures, videos, etc.
[0100] The memory 101 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0101] The processor 102 is coupled to the memory 101 and is used to execute the programs in the memory 101. When the programs run, they perform the operation steps of the shared memory recycling method described in the foregoing embodiments.
[0102] In addition, the processor 102 can also include various modules described in the foregoing embodiments to perform the shared memory recycling operation, and the memory 101 can be used, for example, to store the data required for these modules to perform operations and / or the data output by them.
[0103] The above specific processing operations have been described in detail in the previous embodiments and will not be repeated here.
[0104] Furthermore, as Figure 10 shown, the electronic device may further include: other components such as a communication component 103, a power supply component 104, an audio component 105, a display 106, etc. Figure 10 Only some components are schematically shown in Figure 10 and it does not mean that the electronic device only includes
[0105] The communication component 103 is configured to facilitate communication between the electronic device and other devices in a wired or wireless manner. The electronic device can access a wireless network based on communication standards, such as WiFi, 2G, or 3G, or a combination thereof. In an exemplary embodiment, the communication component 103 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 103 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, Infrared Data Association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0106] The power supply component 104 provides power for various components of the electronic device. The power supply component 104 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device.
[0107] The audio component 105 is configured to output and / or input audio signals. For example, the audio component 105 includes a microphone (MIC). When the electronic device is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive external audio signals. The received audio signals can be further stored in the memory 101 or transmitted via the communication component 103. In some embodiments, the audio component 105 further includes a speaker for outputting audio signals.
[0108] The display 106 includes a screen, and the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can not only sense the boundaries of touch or swipe actions, but also detect the duration and pressure associated with the touch or swipe operation.
[0109] Those of ordinary skill in the art can understand that all or part of the steps to implement the above method embodiments can be completed by hardware related to program instructions. The foregoing program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps including the above method embodiments; and the foregoing storage medium includes: various media such as ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for reclaiming shared memory, comprising: Recording the shared memory information allocated by a service process from a shared memory pool; After the shared memory reclaiming process detects the exit of the service process, releasing the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information; Wherein, the recording of the shared memory information allocated by the service process from the shared memory pool includes: After the service process starts, creating a memory information management node corresponding to the service process in a specified memory space of the shared memory pool, and storing the shared memory information allocated to the service process in the memory information management node; wherein, the shared memory information includes the address of the shared memory allocated to the corresponding service process; the memory information management nodes of all service processes are linked together; The shared memory reclaiming process shares the specified memory space; The shared memory reclaiming process releasing the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information includes: Querying the memory information management node corresponding to the service process to determine the shared memory information allocated to the service process; and releasing the shared memory allocated to the service process to the shared memory pool according to the determined shared memory information; Wherein, the releasing of the shared memory allocated to the service process to the shared memory pool according to the determined shared memory information includes: Querying the memory information management nodes corresponding to other service processes in the specified memory space to determine whether there is shared memory occupied by other processes in the determined shared memory; if so, releasing the unoccupied shared memory in the determined shared memory to the shared memory pool; if not, releasing the determined shared memory to the shared memory pool.
2. The method according to claim 1, wherein The method further includes: After the shared memory allocated to the service process is released to the shared memory pool, deleting the memory information management node corresponding to the service process.
3. The method according to claim 1, wherein, The shared memory is large page memory.
4. A device for reclaiming shared memory, comprising: A memory recording module, configured to record the shared memory information allocated by a service process from a shared memory pool; A memory releasing module, configured to, after the shared memory reclaiming process detects the exit of the service process, release the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information; wherein, the shared memory information includes the address of the shared memory allocated to the corresponding service process; the memory information management nodes of all service processes are linked together; Wherein, the memory recording module is specifically configured to, after the service process starts, create a memory information management node corresponding to the service process in a specified memory space of the shared memory pool, and store the shared memory information allocated to the service process in the memory information management node; The shared memory recycling process shares the specified memory space; the memory release module includes: a record query unit, configured to control the shared memory recycling process to query the memory information management node corresponding to the service process to determine the shared memory information allocated to the service process; a memory release unit, configured to control the shared memory recycling process to release the shared memory allocated to the service process to the shared memory pool according to the determined shared memory information; Wherein, the record query unit is further configured to control the shared memory recycling process to query the memory information management nodes corresponding to other service processes in the specified memory space to determine whether there is shared memory occupied by other processes in the determined shared memory; If so, trigger the memory release unit to control the shared memory recycling process to release the shared memory not occupied by the other processes in the determined shared memory to the shared memory pool; If not, trigger the memory release unit to control the shared memory recycling process to release the determined shared memory to the shared memory pool.
5. The apparatus according to claim 4, wherein, The apparatus further includes: A record deletion module, configured to delete the memory information management node corresponding to the service process after the shared memory allocated to the service process is released to the shared memory pool.
6. The apparatus according to claim 4, wherein The shared memory is large page memory.
7. A method for recycling shared memory, including: Recording the shared memory information allocated by a service process from the shared memory pool; Selecting a service process from the currently running service processes as the shared memory recycling process, and through the shared memory recycling process, after detecting that a service process exits, releasing the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information; Wherein, recording the shared memory information allocated by a service process from the shared memory pool includes: after the service process starts, creating a memory information management node corresponding to the service process in the specified memory space of the shared memory pool, and storing the shared memory information allocated to the service process in the memory information management node; wherein, the shared memory information includes the address of the shared memory allocated to the corresponding service process; the memory information management nodes of all service processes are linked together; The shared memory recycling process shares the specified memory space; the shared memory recycling process releases the shared memory allocated to the service process to the shared memory pool according to the recorded allocated shared memory information, including: querying the memory information management node corresponding to the service process to determine the shared memory information allocated to the service process; releasing the shared memory allocated to the service process to the shared memory pool according to the determined shared memory information; Wherein, releasing the shared memory allocated to the service process to the shared memory pool according to the determined shared memory information includes: Query the memory information management nodes corresponding to other service processes in the specified memory space to determine whether there is shared memory occupied by other processes in the determined shared memory; if so, release the shared memory not occupied by the other processes in the determined shared memory to the shared memory pool; if not, release the determined shared memory to the shared memory pool.
8. The method according to claim 7, wherein, The method further includes: If the service process serving as the shared memory recycling process exits, select one service process from the remaining running service processes as the shared memory recycling process.
9. An electronic device, comprising: A memory for storing a program; A processor coupled to the memory for executing the program, and when the program runs, executing the shared memory recycling method according to any one of claims 1-3, 7, and 8.
Citation Information
Patent Citations
Sharing internal memory management method and apparatus
CN101470632A
Data transmission method between servers and servers
CN102340489A