A memory leak detection processing method and device for a storage system
By using inter-process communication between the main process and auxiliary processes and utilizing slot arrays to record memory usage information, the problem of difficult-to-locate memory leaks in storage systems is solved, achieving rapid location and improved system stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INSPUR SUZHOU INTELLIGENT TECH CO LTD
- Filing Date
- 2023-11-30
- Publication Date
- 2026-06-23
Smart Images

Figure CN117743005B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of storage system technology, specifically to a method and apparatus for detecting and processing memory leaks in a storage system. Additionally, it also relates to an electronic device and a processor-readable storage medium. Background Technology
[0002] In the storage industry, multiple processes run concurrently in a storage system. Some of these processes allocate memory using `malloc`, typically requesting only the amount of memory they need. However, this method makes it difficult to pinpoint the cause of memory leaks, and can even negatively impact system performance. Therefore, finding a way to effectively and quickly locate the responsible process when a memory leak occurs is a pressing issue. Summary of the Invention
[0003] Therefore, this application provides a memory leak detection and processing method and apparatus for a storage system to solve the defects of existing memory leak detection and processing schemes, which have high limitations and result in poor actual detection accuracy and efficiency.
[0004] In a first aspect, this application provides a memory leak detection and processing method for a storage system, comprising: responding to a memory request initiated by a secondary process in the storage system to a main process, determining whether the secondary process has a memory leak based on memory usage information recorded in a slot array corresponding to the main process; wherein, the secondary process is one or more predefined processes in the storage system for implementing external functional operations, the main process is a predefined process in the storage system for implementing internal memory usage management and monitoring, and the main process and the secondary process interact with each other through inter-process communication; each array element in the slot array is used to obtain a corresponding memory page according to the memory request;
[0005] If a memory leak is determined in the auxiliary process, the target function operation with the memory leak is determined based on the application record information corresponding to the slot array.
[0006] Furthermore, in response to a memory request initiated by a secondary process from the main process in the storage system, based on the memory usage information recorded in the slot array corresponding to the main process, it is determined whether the secondary process has a memory leak, specifically including:
[0007] In response to a memory request initiated by a secondary process to the main process in the storage system, it is determined whether the unused array elements in the slot array corresponding to the main process meet the preset memory allocation conditions. If the preset memory allocation conditions are met, the main process selects the corresponding unused target array element for the secondary process and obtains the corresponding memory page based on the target array element and allocates it to the secondary process.
[0008] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is determined that the memory usage information has reached or exceeded a preset memory usage amount. If the memory usage information has reached or exceeded the preset memory usage amount and no target array element is detected to be released within a preset time period, it is determined that the auxiliary process has a memory leak.
[0009] Furthermore, after obtaining the corresponding memory page based on the target array element and allocating it to the auxiliary process, the method further includes: recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array, and storing the mapping relationship between the memory request and the actual functional operation as request record information;
[0010] The step of recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array specifically includes: setting a corresponding flag bit for the auxiliary process to send a memory request based on the preset marking module in the slot array, and recording the actual functional operation corresponding to the memory request through the flag bit.
[0011] Furthermore, after allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is judged whether the memory usage information reaches or exceeds a preset memory usage amount, specifically including:
[0012] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the unused and used array elements in the slot array are recorded. Unused array elements are marked as memory free, and used array elements are marked as memory used. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, the current remaining memory usage information in the slot array is determined. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, it is determined that the memory usage information has reached or exceeded a preset memory usage amount.
[0013] Furthermore, the step of determining whether the memory usage information reaches or exceeds a preset memory usage amount based on the number of array elements in the memory free state and the number of array elements in the memory usage state specifically includes:
[0014] The number of array elements in the memory free state or the number of array elements in the memory used state are compared and analyzed with preset steady-state values to obtain comparison and analysis results. According to the comparison and analysis results, if the number of array elements in the memory free state and the number of array elements in the memory used state reach or exceed the corresponding steady-state values, it is determined that the memory usage information reaches or exceeds the preset memory usage amount; if the number of array elements in the memory free state and the number of array elements in the memory used state do not reach or exceed the corresponding steady-state values, it is determined that the memory usage information does not reach or exceed the preset memory usage amount.
[0015] Furthermore, after determining that the memory usage information has not reached or exceeded the preset memory usage amount, the method further includes: if the number of array elements in the memory idle state decreases to 0, and if the auxiliary process continues to receive memory requests from the main process, the main process generates an error message indicating that the memory usage amount has been exceeded, and triggers the auxiliary process to restart.
[0016] Furthermore, before comparing and analyzing the number of array elements in the memory free state or the number of array elements in the memory used state with the preset steady-state value, the method further includes: determining the steady-state value corresponding to the slot array of the main process based on the input reservation ratio value; wherein, the steady-state value is the number of array elements that can request memory.
[0017] Secondly, this application also provides a memory leak detection and processing device for a storage system, comprising:
[0018] A memory leak detection unit is used to respond to a memory request initiated by a secondary process to the main process in the storage system. Based on the memory usage information recorded in the slot array corresponding to the main process, it determines whether the secondary process has a memory leak. The secondary process is one or more predefined processes in the storage system used to implement external functional operations. The main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the secondary process interact with each other through inter-process communication. Each element in the slot array is used to obtain the corresponding memory page according to the memory request.
[0019] The memory leak location unit is used to determine the target function operation with memory leak in the auxiliary process based on the application record information corresponding to the slot array when it is determined that there is a memory leak in the auxiliary process.
[0020] Furthermore, the memory leak detection unit is specifically used for:
[0021] In response to a memory request initiated by a secondary process to the main process in the storage system, it is determined whether the unused array elements in the slot array corresponding to the main process meet the preset memory allocation conditions. If the preset memory allocation conditions are met, the main process selects the corresponding unused target array element for the secondary process and obtains the corresponding memory page based on the target array element and allocates it to the secondary process.
[0022] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is determined that the memory usage information has reached or exceeded a preset memory usage amount. If the memory usage information has reached or exceeded the preset memory usage amount and no target array element is detected to be released within a preset time period, it is determined that the auxiliary process has a memory leak.
[0023] Furthermore, after obtaining the corresponding memory page based on the target array element and allocating it to the auxiliary process, the system further includes: an application record information obtaining unit, used to record the actual functional operation corresponding to the memory application request based on the preset marking module in the slot array, and to store the mapping relationship between the memory application request and the actual functional operation as application record information;
[0024] The step of recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array specifically includes: setting a corresponding flag bit for the auxiliary process to send a memory request based on the preset marking module in the slot array, and recording the actual functional operation corresponding to the memory request through the flag bit.
[0025] Furthermore, after allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is judged whether the memory usage information reaches or exceeds a preset memory usage amount, specifically including:
[0026] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the unused and used array elements in the slot array are recorded. Unused array elements are marked as memory free, and used array elements are marked as memory used. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, the current remaining memory usage information in the slot array is determined. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, it is determined that the memory usage information has reached or exceeded a preset memory usage amount.
[0027] Furthermore, the step of determining whether the memory usage information reaches or exceeds a preset memory usage amount based on the number of array elements in the memory free state and the number of array elements in the memory usage state specifically includes:
[0028] The number of array elements in the memory free state or the number of array elements in the memory used state are compared and analyzed with preset steady-state values to obtain comparison and analysis results. According to the comparison and analysis results, if the number of array elements in the memory free state and the number of array elements in the memory used state reach or exceed the corresponding steady-state values, it is determined that the memory usage information reaches or exceeds the preset memory usage amount; if the number of array elements in the memory free state and the number of array elements in the memory used state do not reach or exceed the corresponding steady-state values, it is determined that the memory usage information does not reach or exceed the preset memory usage amount.
[0029] Furthermore, after determining that the memory usage information has not reached or exceeded the preset memory usage amount, the system further includes: an error prompting unit, which is used to generate an error prompting message indicating that the memory usage amount has exceeded the preset limit based on the main process, and trigger the auxiliary process to restart if the number of array elements in the memory idle state decreases to 0 and the auxiliary process continues to receive memory requests from the main process.
[0030] Furthermore, before comparing and analyzing the number of array elements in the memory free state or the number of array elements in the memory used state with the preset steady-state value, the system further includes: a steady-state value determination unit, used to determine the steady-state value corresponding to the slot array of the main process based on the input reservation ratio value; wherein, the steady-state value is the number of array elements that can request memory.
[0031] Thirdly, this application also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the memory leak detection and processing method of the storage system as described in any of the above claims.
[0032] Fourthly, this application also provides a processor-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the memory leak detection and processing method of the storage system as described in any of the above claims.
[0033] The memory leak detection and processing method for a storage system provided in this application determines whether a memory leak exists in a secondary process based on memory usage information recorded in the slot array corresponding to the main process, in response to a memory request initiated by a secondary process to the main process in the storage system. The secondary process is one or more predefined processes in the storage system used to implement external functional operations. The main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the secondary process interact via inter-process communication. Each element in the slot array is used to obtain the corresponding memory page according to the memory request. If a memory leak is determined in the secondary process, the target functional operation causing the memory leak is identified based on the request record information corresponding to the slot array. This method effectively improves the efficiency of memory leak detection and processing in the storage system and quickly locates the functional operation in the secondary process that causes the memory leak. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 This is a flowchart illustrating the memory leak detection and processing method for a storage system provided in an embodiment of this application;
[0036] Figure 2 This is a schematic diagram of the slot array and its memory pages provided in an embodiment of this application;
[0037] Figure 3 This is a schematic flowchart illustrating the memory leak detection and processing method for a storage system provided in this application embodiment;
[0038] Figure 4 This is a schematic diagram of the structure of the memory leak detection and processing device for the storage system provided in the embodiments of this application;
[0039] Figure 5 This is a schematic diagram of the hardware environment for the memory leak detection and processing method of the storage system provided in the embodiments of this application;
[0040] Figure 6 This is a schematic diagram of the physical structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0042] The following section first describes in detail the embodiments of the memory leak detection and processing method for the storage system described in this application. For example... Figure 1 The diagram shown is a flowchart illustrating the memory leak detection and processing method for a storage system provided in this application embodiment. The specific process includes the following steps:
[0043] Step 101: In response to a memory request initiated by a secondary process in the storage system to the main process, determine whether the secondary process has a memory leak based on the memory usage information recorded in the slot array corresponding to the main process; wherein, the secondary process is one or more predefined processes in the storage system used to implement external functional operations, and the main process is a predefined process in the storage system used to implement internal memory usage management and monitoring, and the main process and the secondary process interact with each other through inter-process communication; each array element in the slot array is used to obtain the corresponding memory page according to the memory request.
[0044] In this embodiment of the invention, in response to a memory request initiated by a secondary process to the primary process in the storage system, it is determined whether the unused array elements in the slot array corresponding to the primary process meet preset memory allocation conditions. If the preset memory allocation conditions are met, the primary process selects a corresponding unused target array element for the secondary process, and obtains and allocates the corresponding memory page to the secondary process based on the target array element. After allocating the corresponding memory page to the secondary process based on the target array element, the remaining memory usage information in the slot array is determined, and it is determined that the memory usage information reaches or exceeds a preset memory usage amount. If the memory usage information reaches or exceeds the preset memory usage amount and no target array element is detected to be released within a preset time period, it is determined that the secondary process has a memory leak.
[0045] It should be noted that the main process maintains a slot array. Each element of the slot array acquires different memory pages based on the memory requests of auxiliary processes. The slot array records the number of memory pages used. The main process can reserve a certain proportion of the slot array elements used by auxiliary processes to limit the number of array elements used, preventing unlimited memory allocation that could lead to memory leaks and ultimately cause a main process dump, resulting in even greater problems. Auxiliary processes can request memory from the head and release it to the tail. When an auxiliary process requests memory from the main process, the main process allocates one array element for it, and the slot array count is decremented by 1 (i.e., the number of idle array elements is decremented by 1). When an auxiliary process releases memory, the slot array count is incremented by 1 (i.e., the number of idle array elements is incremented by 1). The slot array can report the number of used and idle array elements to determine the usage status and mitigate memory shortage problems early. After the storage system has been running for a period of time, the number of used array elements and the number of idle array elements in the slot array should reach a steady state. If the number of array elements in the main process's slot array decreases to 0, and if a secondary process requests memory, the main process will send an error message indicating that memory usage has exceeded the limit. The secondary process will then restart itself because it cannot request memory. During the restart, the main process will release the memory. When the secondary process requests memory, different flag bits are used at different points (i.e., different functional operations) to indicate which functional operation requested the memory. When a secondary process cannot request memory, it is determined that there is a memory leak in the secondary process. This method facilitates the location of memory shortage problems and improves the functional stability of the storage system without causing any impact on the storage system. It avoids the continuous memory leak that leads to insufficient memory and reduced stability of the storage system. In other words, in this embodiment of the invention, when a secondary process requests memory from the main process, it also records which functional operation of the secondary process requested the memory, which facilitates troubleshooting when problems occur later. When a secondary process requests memory, the main process records the functions that use that memory. This allows the main process to easily identify which functions are consuming memory and, in case of insufficient memory, to pinpoint which function is consuming excessive memory. For example... Figure 2 As shown, this embodiment of the invention can be divided into two parts: recording the number of idle array elements in the slot array; and recording the content requested by which function operation. The slot array will show the usage of different pages (i.e., memory pages), and the number of pages can be different depending on the size of the memory requested by the auxiliary process. As above... Figure 2The slot[0] is allocated 1 page, the slot[1] is allocated 2 pages, the slot[2] is allocated 3 pages, and so on. Here, slot[0], slot[1] and slot[2] are array elements in the slot array.
[0046] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the actual functional operation corresponding to the memory request can be recorded based on the preset marking module in the slot array, and the mapping relationship between the memory request and the actual functional operation can be stored as request record information. That is, based on the preset marking module in the slot array, a corresponding flag is set for the auxiliary process to send a memory request, and the actual functional operation corresponding to the memory request is recorded through the flag.
[0047] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the unused and used array elements in the slot array are recorded. Unused array elements are marked as memory free, and used array elements are marked as memory used. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, the current remaining memory usage information in the slot array is determined. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, it is determined that the memory usage information has reached or exceeded a preset memory usage amount.
[0048] The specific implementation process of determining whether the memory usage information reaches or exceeds a preset memory usage amount based on the number of array elements in the memory free state and the number of array elements in the memory used state includes: comparing and analyzing the number of array elements in the memory free state or the number of array elements in the memory used state with preset steady-state values to obtain comparison and analysis results; based on the comparison and analysis results, if the number of array elements in the memory free state and the number of array elements in the memory used state reach or exceed the corresponding steady-state values, determining that the memory usage information reaches or exceeds the preset memory usage amount; if the number of array elements in the memory free state and the number of array elements in the memory used state do not reach or exceed the corresponding steady-state values, determining that the memory usage information does not reach or exceed the preset memory usage amount.
[0049] After determining that the memory usage information has not reached or exceeded the preset memory usage limit, if the number of array elements in the memory free state decreases to 0, and if the auxiliary process continues to receive memory requests from the main process, the main process generates an error message indicating that memory usage has exceeded the limit and triggers the auxiliary process to restart. Before comparing and analyzing the number of array elements in the memory free state or the number of array elements in the memory used state with preset steady-state values, the steady-state value corresponding to the slot array of the main process can also be determined based on the input reservation ratio value. The steady-state value is the number of array elements that can request memory.
[0050] Step 102: If it is determined that there is a memory leak in the auxiliary process, based on the application record information corresponding to the slot array, determine the target function operation in the auxiliary process that has a memory leak.
[0051] In this embodiment of the invention, the request record information includes a mapping relationship between the memory request and the actual functional operation. When the memory usage information reaches or exceeds the preset memory usage amount and no target array element is detected to be released within a preset time period, and the auxiliary process cannot allocate memory, it is determined that the auxiliary process has a memory leak. When the auxiliary process initiates a memory request, the main process records the functional operations using memory based on the marker module in the slot array, to facilitate checking which functional operation is using memory. If memory shortage occurs, it is easy to identify which functional operation consumes excessive memory, i.e., the target functional operation with a memory leak.
[0052] In a specific implementation of this invention, the main process sets up a slot array. Each element of the slot array can acquire different memory pages as needed, and the slot array records the number of memory pages used. The main process reserves a certain proportion of the slot array elements used by the auxiliary processes to limit the number of array elements used, thus preventing unlimited memory allocation and continuous memory leaks that could lead to a main process dump and cause even bigger problems. Auxiliary processes allocate memory from the head and release it to the tail. In this embodiment of the invention,
[0053] The `slot` array records the number of array elements in a used state and the number of array elements in a free state, i.e., it records the total number of `slot` array elements, categorized as free and used. It also marks and records which functional operations requested memory. Specifically, an array, labeled `slot`, is initialized in the main process to fix the maximum amount of memory the process can use. For example, this value is `n`, where `n` is a positive integer greater than or equal to 1. This value can be changed based on the memory usage of the storage system. By analyzing the memory usage information in the `slot` array (such as the number of array elements in a used state and the number of array elements in a free state), it is analyzed whether the usage is normal. If abnormalities are found, the functional operations causing memory leaks are identified based on the abnormal usage. For example, a `slot` array is set based on the main process, with a size of 10240 elements. Each element in this array will acquire different memory pages as needed. Simultaneously, limiting the number of array elements that can be requested in the `slot` array prevents unlimited memory allocation, memory leaks, and potential main process dumps, causing even greater problems. In the auxiliary process, memory is requested from the head and released to the tail. The number of slots recorded is decremented by 1 when a memory request is made and incremented by 1 when a slot is released. After the auxiliary process has been running for a period of time, the number of slots used will stabilize at a stable value. The specific operation within the auxiliary process that requested the memory can be recorded to facilitate troubleshooting in case of problems.
[0054] This invention proposes a method for detecting and handling memory leaks in a storage system. In this method, auxiliary processes in the storage system obtain memory from the main process via shared memory, facilitating the monitoring of overall memory usage. The main process can limit the memory usage of auxiliary processes and easily pinpoint problems. A flag slot is set in the main process to record the number of array elements in the slot array (the number of array elements that auxiliary processes can request memory from). When an auxiliary process requests memory (e.g., greater than or equal to 4KB, which can be considered a relatively large memory structure, generally a few bytes), the number of slots in the main process's slot array decreases by one. When an auxiliary process releases memory, the number of slots in the main process's slot array increases by one. As the program runs, the number of slots in the slot array remains stable and does not continuously decrease. If the number of slots in the main process's slot array decreases to 0, and if an auxiliary process still requests memory, the main process sends an error message indicating that memory usage has exceeded the limit. The auxiliary process, unable to obtain memory, will automatically restart. Upon restarting, the main process will release the memory. When a secondary process requests memory, different flags are used at different points to indicate which function is requesting the memory. When a secondary process fails to allocate memory, it indicates a memory leak within the secondary process. This method facilitates locating memory shortages and can also improve system performance.
[0055] The memory leak detection and processing method for a storage system described in this application determines whether a memory leak exists in a secondary process based on memory usage information recorded in the slot array corresponding to the main process, in response to a memory request initiated by a secondary process to the main process in the storage system. The secondary process is one or more predefined processes in the storage system used to implement external functional operations. The main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the secondary process interact via inter-process communication. Each element in the slot array is used to obtain the corresponding memory page according to the memory request. If a memory leak is determined in the secondary process, the target functional operation causing the memory leak is identified based on the request record information corresponding to the slot array. This effectively improves the efficiency of memory leak detection and processing in the storage system and quickly locates the functional operation in the secondary process that causes the memory leak.
[0056] Corresponding to the memory leak detection and processing method for a storage system provided above, this application also provides a memory leak detection and processing apparatus for a storage system. Since the embodiments of this apparatus are similar to the method embodiments described above, the description is relatively simple. For relevant details, please refer to the description in the method embodiment section above. The embodiments of the memory leak detection and processing apparatus for a storage system described below are merely illustrative. Please refer to... Figure 4 As shown, it is a schematic diagram of the structure of a memory leak detection and processing device for a storage system provided in an embodiment of this application.
[0057] The memory leak detection and processing device for the storage system described in this application includes the following parts:
[0058] The memory leak detection unit 401 is used to respond to a memory request initiated by a secondary process to the main process in the storage system, and to determine whether the secondary process has a memory leak based on the memory usage information recorded in the slot array corresponding to the main process. The secondary process is one or more predefined processes in the storage system used to implement external functional operations, and the main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the secondary process interact with each other through inter-process communication. Each element in the slot array is used to obtain the corresponding memory page according to the memory request.
[0059] The memory leak location unit 402 is used to determine, based on the application record information corresponding to the slot array, the target function operation in the auxiliary process that has a memory leak when it is determined that there is a memory leak in the auxiliary process.
[0060] Furthermore, the memory leak detection unit is specifically used for:
[0061] In response to a memory request initiated by a secondary process to the main process in the storage system, it is determined whether the unused array elements in the slot array corresponding to the main process meet the preset memory allocation conditions. If the preset memory allocation conditions are met, the main process selects the corresponding unused target array element for the secondary process and obtains the corresponding memory page based on the target array element and allocates it to the secondary process.
[0062] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is determined that the memory usage information has reached or exceeded a preset memory usage amount. If the memory usage information has reached or exceeded the preset memory usage amount and no target array element is detected to be released within a preset time period, it is determined that the auxiliary process has a memory leak.
[0063] Furthermore, after obtaining the corresponding memory page based on the target array element and allocating it to the auxiliary process, the system further includes: an application record information obtaining unit, used to record the actual functional operation corresponding to the memory application request based on the preset marking module in the slot array, and to store the mapping relationship between the memory application request and the actual functional operation as application record information;
[0064] The step of recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array specifically includes: setting a corresponding flag bit for the auxiliary process to send a memory request based on the preset marking module in the slot array, and recording the actual functional operation corresponding to the memory request through the flag bit.
[0065] Furthermore, after allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is judged whether the memory usage information reaches or exceeds a preset memory usage amount, specifically including:
[0066] After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the unused and used array elements in the slot array are recorded. Unused array elements are marked as memory free, and used array elements are marked as memory used. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, the current remaining memory usage information in the slot array is determined. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, it is determined that the memory usage information has reached or exceeded a preset memory usage amount.
[0067] Furthermore, the step of determining whether the memory usage information reaches or exceeds a preset memory usage amount based on the number of array elements in the memory free state and the number of array elements in the memory usage state specifically includes:
[0068] The number of array elements in the memory free state or the number of array elements in the memory used state are compared and analyzed with preset steady-state values to obtain comparison and analysis results. According to the comparison and analysis results, if the number of array elements in the memory free state and the number of array elements in the memory used state reach or exceed the corresponding steady-state values, it is determined that the memory usage information reaches or exceeds the preset memory usage amount; if the number of array elements in the memory free state and the number of array elements in the memory used state do not reach or exceed the corresponding steady-state values, it is determined that the memory usage information does not reach or exceed the preset memory usage amount.
[0069] Furthermore, after determining that the memory usage information has not reached or exceeded the preset memory usage amount, the system further includes: an error prompting unit, which is used to generate an error prompting message indicating that the memory usage amount has exceeded the preset limit based on the main process, and trigger the auxiliary process to restart if the number of array elements in the memory idle state decreases to 0 and the auxiliary process continues to receive memory requests from the main process.
[0070] Furthermore, before comparing and analyzing the number of array elements in the memory free state or the number of array elements in the memory used state with the preset steady-state value, the system further includes: a steady-state value determination unit, used to determine the steady-state value corresponding to the slot array of the main process based on the input reservation ratio value; wherein, the steady-state value is the number of array elements that can request memory.
[0071] The memory leak detection and processing device for a storage system described in this application determines whether a memory leak exists in a secondary process based on memory usage information recorded in the slot array corresponding to the main process, in response to a memory request initiated by a secondary process to the main process in the storage system. The secondary process is one or more predefined processes in the storage system used to implement external functional operations. The main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the secondary process interact via inter-process communication. Each element in the slot array is used to obtain a corresponding memory page according to the memory request. If a memory leak is determined in the secondary process, the target functional operation causing the memory leak is identified based on the request record information corresponding to the slot array. This effectively improves the efficiency of memory leak detection and processing in the storage system and quickly locates the functional operation in the secondary process that causes the memory leak.
[0072] The methods and embodiments provided in this application can be executed on a computer terminal, device terminal, or similar computing device. Taking running on a computer terminal as an example, Figure 5 This is a schematic diagram of the hardware environment for a memory leak detection and processing method for a storage system according to an embodiment of this application. Figure 5 As shown, a computer terminal may include one or more ( Figure 5 Only one is shown in the diagram. A processor 502 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 504 for storing data are also shown. In one exemplary embodiment, the computer terminal may further include a transmission device 506 for communication functions and an input / output device 508. Those skilled in the art will understand that... Figure 5The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 5 The array shown is more or less than the array shown, or has the same as Figure 5 Equivalent functions or ratios shown Figure 5 The illustrated functionality includes various configurations. Memory 504 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the memory leak detection processing method of the storage system in this embodiment. Processor 502 executes various functional applications and data processing by running the computer program stored in memory 504, thus implementing the aforementioned method. Memory 504 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, memory 504 may further include memory remotely located relative to processor 502, which can be connected to the computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Transmission device 506 is used to receive or send data via a network. Specific examples of such networks may include wireless networks provided by the computer terminal's communication provider. In one example, transmission device 506 includes a Network Interface Controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 506 can be a radio frequency (RF) module, used for wireless communication with the Internet. This embodiment provides a memory leak detection and processing method for a storage system, applied to the aforementioned computer terminal.
[0073] Alternatively, corresponding to the memory leak detection and processing method for the storage system provided above, this application also provides an electronic device. Since the embodiment of this electronic device is similar to the above method embodiment, it is described simply. For relevant details, please refer to the description in the above method embodiment section. The electronic device described below is merely illustrative. Figure 6The diagram shown is a schematic representation of the physical structure of an electronic device disclosed in an embodiment of this application. The electronic device may include a processor 601, a memory 602, and a communication bus 603. The processor 601 and the memory 602 communicate with each other via the communication bus 603 and communicate with external devices via a communication interface 604. The processor 601 can invoke logical instructions in the memory 602 to execute a memory leak detection and processing method for the storage system. This method includes: responding to a memory request initiated by a secondary process to a main process in the storage system, determining whether the secondary process has a memory leak based on memory usage information recorded in the slot array corresponding to the main process; wherein the secondary process is one or more predefined processes in the storage system used to implement external functional operations, and the main process is a predefined process in the storage system used to implement internal memory usage management and monitoring; the main process and the secondary process interact with each other through inter-process communication; each array element in the slot array is used to obtain a corresponding memory page according to the memory request; if it is determined that the secondary process has a memory leak, determining the target functional operation with the memory leak in the secondary process based on the request record information corresponding to the slot array.
[0074] Furthermore, the logical instructions in the aforementioned memory 602 can be implemented as software functional modules and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as memory chips, USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0075] On the other hand, this application also provides a computer program product, which includes a computer program stored on a processor-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute the memory leak detection and processing method for the storage system provided in the above-described method embodiments. The method includes: responding to a memory request initiated by a secondary process to a main process in the storage system, determining whether the secondary process has a memory leak based on memory usage information recorded in a slot array corresponding to the main process; wherein the secondary process is one or more predefined processes in the storage system for implementing external functional operations, the main process is a predefined process in the storage system for implementing internal memory usage management and monitoring, and the main process and the secondary process interact with each other through inter-process communication; each array element in the slot array is used to obtain a corresponding memory page according to the memory request; if it is determined that the secondary process has a memory leak, determining the target functional operation with the memory leak in the secondary process based on the request record information corresponding to the slot array.
[0076] In another aspect, embodiments of this application also provide a processor-readable storage medium storing a computer program, which, when executed by a processor, implements the memory leak detection and processing method for the storage system provided in the above embodiments. The method includes: responding to a memory request initiated by a secondary process in the storage system to a main process, determining whether the secondary process has a memory leak based on memory usage information recorded in a slot array corresponding to the main process; wherein the secondary process is one or more predefined processes in the storage system for implementing external functional operations, the main process is a predefined process in the storage system for implementing internal memory usage management and monitoring, and the main process and the secondary process interact via inter-process communication; each array element in the slot array is used to obtain a corresponding memory page according to the memory request; if it is determined that the secondary process has a memory leak, determining the target functional operation with the memory leak in the secondary process based on the request record information corresponding to the slot array.
[0077] The processor-readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic memory (e.g., floppy disk, hard disk, magnetic tape, magneto-optical disk (MO)), optical memory (e.g., CD, DVD, BD, HVD), and semiconductor memory (e.g., ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)).
[0078] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0079] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for detecting and handling memory leaks in a storage system, characterized in that, include: In response to a memory request initiated by a secondary process in the storage system, the system determines whether the secondary process has a memory leak based on the memory usage information recorded in the slot array corresponding to the main process. The secondary process is one or more predefined processes in the storage system used to implement external functional operations, and the main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the secondary process interact via inter-process communication. Each element in the slot array is used to obtain a corresponding memory page according to the memory request. The secondary process obtains memory from the main process through shared memory. If it is determined that there is a memory leak in the auxiliary process, the target function operation with the memory leak is determined based on the application record information corresponding to the slot array. In response to a memory request initiated by a secondary process from the main process in the storage system, based on the memory usage information recorded in the slot array corresponding to the main process, it is determined whether the secondary process has a memory leak, specifically including: In response to a memory request initiated by a secondary process to the main process in the storage system, it is determined whether the unused array elements in the slot array corresponding to the main process meet the preset memory allocation conditions. If the preset memory allocation conditions are met, the main process selects the corresponding unused target array element for the secondary process and obtains the corresponding memory page based on the target array element and allocates it to the secondary process. After allocating the corresponding memory page to the auxiliary process based on the target array element, the remaining memory usage information in the slot array is determined, and it is determined that the memory usage information reaches or exceeds the preset memory usage amount. If the memory usage information reaches or exceeds the preset memory usage amount and no target array element is detected to be released within a preset time period, it is determined that the auxiliary process has a memory leak. After obtaining the corresponding memory page based on the target array element and allocating it to the auxiliary process, the method further includes: recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array, and storing the mapping relationship between the memory request and the actual functional operation as request record information; The step of recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array specifically includes: setting a corresponding flag bit for the auxiliary process to send a memory request based on the preset marking module in the slot array, and recording the actual functional operation corresponding to the memory request through the flag bit.
2. The memory leak detection and processing method for a storage system according to claim 1, characterized in that, After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the remaining memory usage information in the slot array is determined, and it is judged whether the memory usage information reaches or exceeds a preset memory usage amount, specifically including: After allocating the corresponding memory pages to the auxiliary process based on the target array elements, the unused and used array elements in the slot array are recorded. Unused array elements are marked as memory free, and used array elements are marked as memory used. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, the current remaining memory usage information in the slot array is determined. Based on the number of array elements in the memory free state and the number of array elements in the memory used state, it is determined that the memory usage information has reached or exceeded a preset memory usage amount.
3. The memory leak detection and processing method for a storage system according to claim 2, characterized in that, The step of determining whether the memory usage information reaches or exceeds a preset memory usage amount based on the number of array elements in the memory free state and the number of array elements in the memory usage state specifically includes: The number of array elements in the memory free state or the number of array elements in the memory used state are compared and analyzed with preset steady-state values to obtain comparison and analysis results. According to the comparison and analysis results, if the number of array elements in the memory free state and the number of array elements in the memory used state reach or exceed the corresponding steady-state values, it is determined that the memory usage information reaches or exceeds the preset memory usage amount; if the number of array elements in the memory free state and the number of array elements in the memory used state do not reach or exceed the corresponding steady-state values, it is determined that the memory usage information does not reach or exceed the preset memory usage amount.
4. The memory leak detection and processing method for a storage system according to claim 3, characterized in that, After determining that the memory usage information has not reached or exceeded the preset memory usage amount, the method further includes: if the number of array elements in the memory free state decreases to 0, and if the auxiliary process continues to receive memory requests from the main process, the main process generates an error message indicating that the memory usage amount has been exceeded, and triggers the auxiliary process to restart.
5. The memory leak detection and processing method for a storage system according to claim 3, characterized in that, Before comparing and analyzing the number of array elements in the memory free state or the number of array elements in the memory used state with the preset steady-state value, the method further includes: determining the steady-state value corresponding to the slot array of the main process based on the input reservation ratio value; wherein, the steady-state value is the number of array elements that can request memory.
6. A memory leak detection and processing device for a storage system, characterized in that, include: A memory leak detection unit is used to respond to memory requests initiated by auxiliary processes in the storage system to the main process, and to determine whether the auxiliary process has a memory leak based on memory usage information recorded in the slot array corresponding to the main process. The auxiliary processes are one or more predefined processes in the storage system used to implement external functional operations, and the main process is a predefined process in the storage system used to implement internal memory usage management and monitoring. The main process and the auxiliary processes interact with each other through inter-process communication. Each element in the slot array is used to obtain a corresponding memory page according to the memory request. The auxiliary process obtains memory from the main process through shared memory. The memory leak location unit is used to determine the target function operation with memory leak in the auxiliary process based on the application record information corresponding to the slot array when it is determined that there is a memory leak in the auxiliary process. In response to a memory request initiated by a secondary process from the main process in the storage system, based on the memory usage information recorded in the slot array corresponding to the main process, it is determined whether the secondary process has a memory leak, specifically including: In response to a memory request initiated by a secondary process to the main process in the storage system, it is determined whether the unused array elements in the slot array corresponding to the main process meet the preset memory allocation conditions. If the preset memory allocation conditions are met, the main process selects the corresponding unused target array element for the secondary process and obtains the corresponding memory page based on the target array element and allocates it to the secondary process. After allocating the corresponding memory page to the auxiliary process based on the target array element, the remaining memory usage information in the slot array is determined, and it is determined that the memory usage information reaches or exceeds the preset memory usage amount. If the memory usage information reaches or exceeds the preset memory usage amount and no target array element is detected to be released within a preset time period, it is determined that the auxiliary process has a memory leak. After obtaining the corresponding memory page based on the target array element and allocating it to the auxiliary process, the method further includes: recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array, and storing the mapping relationship between the memory request and the actual functional operation as request record information; The step of recording the actual functional operation corresponding to the memory request based on the preset marking module in the slot array specifically includes: setting a corresponding flag bit for the auxiliary process to send a memory request based on the preset marking module in the slot array, and recording the actual functional operation corresponding to the memory request through the flag bit.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the memory leak detection and processing method for the storage system as described in any one of claims 1 to 5.
8. A processor-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the memory leak detection and processing method for the storage system as described in any one of claims 1 to 5.