Resource leakage detection method and system
By establishing a tracking list record resource allocation time stamp in Linux network packets, the problem of difficult detection of resource leakage in network packets is solved, efficient resource leakage detection and problem reproduction is achieved, and system stability is improved.
Patent Information
- Application Number
- CN202410175788.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-07
- Publication Date
- 2025-08-08
AI Technical Summary
The existing technology is difficult to efficiently detect and troubleshoot resource leakage problems in Linux network data packets, resulting in inefficient debugging, especially when resource leakage problems occur randomly.
By establishing a tracking list to record the resource allocation timestamps of network packets, combining the current timestamps, detect and evaluate network packets suspected of resource leakage, and use the processor to execute resource leakage detection program code to identify and reproduce leakage problems.
It improves the efficiency of resource leakage detection, can quickly identify and reproduce resource leakage problems, improves error debugging efficiency, and reduces the risk of system resource waste and crash.
Smart Images

Figure CN120448081A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to resource leakage detection, and in particular to a resource leakage detection method and system for detecting network data packets suspected of resource leakage by establishing a tracking list. Background Art
[0002] Generally speaking, computer programs occupy some resources (such as storage resources, such as memory) during operation. After the computer program completes its operation, the occupied resources must be released promptly. Resource leakage occurs when a computer program fails to release unused resources, resulting in the occupied resources being unable to be reused. As resources continue to leak, the available resources in the system decrease, leading to a decrease in system performance and even the inability of the system to provide services due to insufficient resources.
[0003] The Linux operating system is now widely used in network terminals and servers, and the network protocol stack module has long been an important component of the Linux kernel, making it widely used. Drivers and custom software developed based on the Linux network protocol stack architecture must use the Linux network packet management application programming interface (API) to process network packets. However, a common problem encountered during driver and custom software development is network packet resource leakage. This occurs when network packets are allocated resources but are not released, resulting in wasted resources. Over time, this can cause the system to crash due to insufficient resources. These problems are relatively hidden and often complex to troubleshoot.
[0004] Current methods for troubleshooting network packet resource leaks are limited, making it impossible to determine which network packets have not released resources. This results in low debugging efficiency. If the network packet resource leak occurs randomly, the debugging efficiency will be further reduced. Summary of the Invention
[0005] One of the objectives of the present invention is to provide a resource leakage detection method and system for detecting network data packets suspected of resource leakage by establishing a tracking list.
[0006] In one embodiment of the present invention, a resource leak detection method is disclosed. The resource leak detection method includes: when resources are allocated to a network packet, recording a resource allocation timestamp of the network packet in a tracking list; and detecting at least one network packet suspected of resource leak based on a current timestamp and at least one resource allocation timestamp currently recorded in the tracking list.
[0007] In one embodiment of the present invention, a resource leak detection system is disclosed. The resource leak detection system includes a storage device and a processor. The storage device is configured to store a resource leak detection program code. The processor is configured to load and execute the resource leak detection program code to perform the following operations: when a resource is allocated to a network packet, record a resource allocation timestamp of the network packet in a tracking list; and detect at least one network packet suspected of a resource leak based on a current timestamp and at least one resource allocation timestamp currently recorded in the tracking list.
[0008] In one embodiment of the present invention, a resource leak detection method is disclosed. The method includes: recording a resource allocation timestamp of a network data packet, the resource allocation timestamp indicating the time when resources were allocated to the network data packet; and, in response to a trigger signal, evaluating whether the network data packet is suspected of being a resource leak packet based on a current timestamp and the resource allocation timestamp.
[0009] Since network data packets have a certain life cycle, the present invention proposes a method for tracking the life cycle of network data packets to find network data packets suspected of resource leakage. For example, a tracking list is established to record the starting time point of the life cycle of the network data packet. When the network packet exceeds the life cycle without releasing the occupied resources, the network data packet can be regarded as a network data packet suspected of resource leakage. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 FIG. 1 is a schematic diagram of a resource leakage detection system according to an embodiment of the present invention.
[0011] Figure 2 Schematic diagram of a network data packet forwarding process according to an embodiment of the present invention.
[0012] Figure 3 FIG. 4 is a timing diagram of resource leak detection using a tracking list according to an embodiment of the present invention.
[0013]
Explanation of symbols
[0014] 100: Resource Leak Detection System
[0015] 102: Storage device
[0016] 104: Processor
[0017] 202: Data packet receiving driver module
[0018] 204: Kernel protocol module
[0019] 206: Data packet sending driver module
[0020] 302: Receive ring buffer
[0021] PROG: Resource leak detection program code
[0022] L_TR: Tracking List DETAILED DESCRIPTION
[0023] Certain words are used in the specification and claims to refer to specific components. Those skilled in the art will understand that hardware manufacturers may use different terms to refer to the same component. This specification and claims do not use differences in name as a way to distinguish components, but rather use differences in the functions of the components as the criterion for distinction. The terms "including" and "comprising" mentioned throughout the specification and claims are open-ended terms and should be interpreted as "including but not limited to". In addition, the term "coupled" or "coupled" includes any direct and indirect electrical connection means. Therefore, if the text describes a first device coupled to a second device, it means that the first device can be directly electrically connected to the second device, or indirectly electrically connected to the second device through other devices and connection means.
[0024] Figure 1 The diagram of a resource leak detection system according to an embodiment of the present invention is shown in FIG1 . The resource leak detection system 100 can be used to locate resource leaks in Linux network packets. After finding a network packet suspected of resource leakage, the resource leak problem can be reproduced by using the packet characteristics of the network packet suspected of resource leakage, thereby accelerating the sorting out of resource leakage problems. Figure 1As shown, the resource leak detection system 100 includes a storage device 102 and a processor 104. The storage device 102 is used to store resource leak detection program code PROG. For example, the storage device 102 can be a memory or any device with data storage capabilities. The processor 104 is coupled to the storage device 102 and is used to load and execute the resource leak detection program code PROG. For example, the processor 104 can be a central processing unit (CPU) or any device with instruction execution capabilities. In this embodiment, the processor 104 executes the resource leak detection program code PROG to perform at least the following operations: when resources are allocated to a network packet, record a resource allocation timestamp of the network packet in a tracking list L_TR; and detect network packets suspected of resource leaks based on a current timestamp (i.e., the current time point) and at least one resource allocation timestamp currently recorded in the tracking list L_TR (which indicates the start time of the corresponding network packet's lifecycle, i.e., the resource allocation timestamp indicates the time when the resource was allocated to the corresponding network packet). In addition, when the resources occupied by the network data packet are released (for example, the resources are released after the forwarding of the network data packet is completed), the processor 104 executes the resource leak detection program code PROG to delete the resource allocation timestamp of the network data packet from the tracking list L_TR, that is, the tracking list L_TR no longer needs to continue tracking the life cycle of this network data packet.
[0025] Generally speaking, network data packets are received from hardware (such as network cards), processed by software, and finally sent out through hardware. Therefore, network data packets have a certain life cycle. Figure 2 This is a schematic diagram of the network data packet forwarding process of one embodiment of the present invention. For a network data packet, its life cycle is roughly as follows. First, the data packet receiving driver module 202 in the driver program will be responsible for creating and allocating resources to this network data packet, which will involve allocating the network data packet API. The intermediate processing flow will perform some processing (such as the processing of the network communication protocol stack) through a software module (such as the kernel protocol module 204 in the Linux kernel). In addition, operations such as copying and releasing may also be performed, which will involve copying the network data packet API and releasing the network data packet API. When the network data packet is finally successfully sent out via the data packet sending driver module 206 in the driver program, the resources occupied by the network data packet will be released, which will involve releasing the network data packet API.
[0026] Since network data packets have a certain life cycle, the present invention proposes a method for tracking the life cycle of network data packets to find network data packets suspected of resource leakage. For example, a tracking list L_TR is established to record the starting time point of the life cycle of the network data packet. When the network data packet exceeds the life cycle without releasing the occupied resources, the network data packet can be regarded as a network data packet suspected of resource leakage.
[0027] Figure 3 This is a timing diagram of resource leak detection using the tracking list L_TR according to one embodiment of the present invention. The tracking list L_TR records relevant information (such as identification information, address in memory, resource allocation timestamp, etc.) of network data packets that have been allocated resources (such as memory resources). If the tracking list L_TR currently records relevant information (including resource allocation timestamp) of 4 data packets (including data packet No. 1, data packet No. 2, data packet No. 3, and data packet No. 4), when resources are allocated to the most recently received data packet No. 5 (or resources are allocated to data packet No. 5 generated by copying an existing data packet), the relevant information (including resource allocation timestamp) of data packet No. 5 will be added to the tracking list L_TR. In this embodiment, the resources occupied by data packet No. 4, data packet No. 3, and data packet No. 5 will be released in sequence. Figure 3 As shown, when the resources occupied by packet 4 are released, the relevant information of packet 4 (including the resource allocation timestamp) will be deleted from the tracking list L_TR. At this time, the tracking list L_TR only records the relevant information of packets 1, 2, 3, and 5 (including the resource allocation timestamp). Then, when the resources occupied by packet 3 are released, the relevant information of packet 3 (including the resource allocation timestamp) will be deleted from the tracking list L_TR. At this time, the tracking list L_TR only records the relevant information of packets 1, 2, and 5 (including the resource allocation timestamp). Finally, when the resources occupied by packet 5 are released, the relevant information of packet 5 (including the resource allocation timestamp) will be deleted from the tracking list L_TR. At this time, the tracking list L_TR only records the relevant information of packets 1 and 2 (including the resource allocation timestamp).
[0028] If the processor 104 determines that a resource leak may occur in the system based on some judgment rules (e.g., low available memory capacity), the processor 104 executes the resource leak detection program code PROG to detect a network packet suspected of a resource leak based on the current timestamp (i.e., the current time point) and at least one resource allocation timestamp currently recorded in the tracking list L_TR (i.e., the start time point of the network packet's life cycle). In other words, in response to a trigger signal indicating a possible resource leak, the processor 104 evaluates whether the network packet is a network packet suspected of a resource leak based on the current timestamp and the resource allocation timestamp. For example, the processor 104 executes the resource leak detection program code PROG to compare the current timestamp with the resource allocation timestamp of packet 1 to determine whether the difference between the current timestamp and the resource allocation timestamp of packet 1 exceeds a predetermined value (which may be greater than or equal to an expected value of the network packet's life cycle). If the difference exceeds the predetermined value, it indicates that packet 1 is highly likely to be a network packet suspected of a resource leak. Similarly, the processor 104 executes the resource leak detection program code PROG to compare the current timestamp and the resource allocation timestamp of data packet No. 2 to determine whether the difference between the current timestamp and the resource allocation timestamp of data packet No. 2 exceeds a predetermined value (which may be greater than or equal to the expected value of the life cycle of the network data packet). When the difference exceeds the predetermined value, it means that data packet No. 2 is very likely to be a network data packet with resource leak.
[0029] The packet receiving driver module 202 reads network packets received by the network card through the RX ring buffer 302. For example, the RX ring buffer 302 has a ring data structure for storing multiple packet descriptors, each of which points to multiple network packets. Due to the operating characteristics of the RX ring buffer 302 itself, network packets located in the RX ring buffer 302 (i.e., network packets corresponding to the packet descriptors recorded in the RX ring buffer 302) may remain unreleased for a long time. If such data is excluded from network packets suspected of resource leakage, the efficiency of resource leak detection can be further improved.
[0030] In some embodiments of the present invention, when the difference between the resource allocation timestamp and the current timestamp of packet 1 exceeds a predetermined value, the processor 104 further executes the resource leak detection program code PROG to determine whether packet 1 belongs to the network packet indicated by the receive ring buffer 302 accessed by the driver. If packet 1 does not belong to the network packet indicated by the receive ring buffer 302, the processor 104 determines that packet 1 is a network packet suspected of a resource leak. Otherwise, the processor 104 does not determine that packet 1 is a network packet suspected of a resource leak. Similarly, when the difference between the resource allocation timestamp and the current timestamp of packet 2 exceeds a predetermined value, the processor 104 further executes the resource leak detection program code PROG to determine whether packet 2 belongs to the network packet indicated by the receive ring buffer 302 accessed by the driver. If packet 2 does not belong to the network packet indicated by the receive ring buffer 302, the processor 104 determines that packet 2 is a network packet suspected of a resource leak. Otherwise, the processor 104 does not determine that packet 2 is a network packet suspected of a resource leak. However, this is merely an example and is not intended to limit the present invention. That is, any method of using the tracking list L_TR disclosed in the present invention to detect network data packets suspected of resource leakage falls within the scope of the present invention.
[0031] The cause of the resource leak problem is often related to a network packet with specific packet characteristics. If the packet characteristics of the network packet that triggers the resource leak are known, the problem of resource leak can be reproduced to accelerate the solution of the resource leak problem. Therefore, after detecting the network packet suspected of resource leak with the help of the tracking list L_TR, the processor 104 can reproduce the resource leak problem to accelerate the solution of the resource leak problem. For example, the processor 104 can also execute the resource leak detection program code PROG to read the message content of the network packet suspected of resource leak, and simulate the packet forwarding of the network packet suspected of resource leak to reproduce the resource leak problem, thereby accelerating the sorting out of the resource leak problem. In other words, since the resource leak problem can be reproduced continuously and no longer occurs randomly, the debugging efficiency can be improved. For example, through the packet characteristics of the network packet suspected of resource leak, combined with adding debugging information at the suspected point of the program code and inspecting the program code, the solution of the resource leak problem can be accelerated.
[0032] The above descriptions are merely preferred embodiments of the present invention. All equivalent changes and modifications made according to the claims of the present invention should fall within the scope of the present invention.
Claims
1. A resource leak detection method, comprising: When resources are allocated to a network data packet, recording the resource allocation timestamp of the network data packet into a tracking list; and At least one network data packet suspected of resource leakage is detected according to the current timestamp and at least one resource allocation timestamp currently recorded in the tracking list.
2. The resource leak detection method according to claim 1, further comprising: When the resources occupied by the network data packet are released, the resource allocation timestamp of the network data packet is deleted from the tracking list.
3. The resource leak detection method of claim 1 , wherein the operation of detecting the at least one network data packet suspected of resource leak based on the current timestamp and the at least one resource allocation timestamp currently recorded in the tracking list comprises: comparing a difference between the current timestamp and the resource allocation timestamp recorded in the tracking list with a predetermined value; and When the difference is greater than the predetermined value, it is determined that the network data packet corresponding to the resource allocation timestamp is a network data packet suspected of resource leakage.
4. The resource leakage detection method according to claim 3, wherein the operation of determining that the network data packet corresponding to the resource allocation timestamp is the network data packet suspected of resource leakage comprises: determining whether the network data packet corresponding to the resource allocation timestamp belongs to the network data packet indicated by the receive ring buffer accessed by the driver; and When the network data packet corresponding to the resource allocation timestamp does not belong to the network data packet indicated by the receiving ring buffer, the network data packet corresponding to the resource allocation timestamp is determined to be the network data packet suspected of resource leakage.
5. The resource leak detection method according to claim 1, further comprising: After a network data packet suspected of resource leakage is detected, data packet forwarding of the network data packet suspected of resource leakage is simulated to reproduce the resource leakage problem.
6. A resource leak detection system comprising: a storage device for storing resource leak detection program code; and The processor is configured to load and execute the resource leak detection program code to perform the following operations: When resources are allocated to a network data packet, recording the resource allocation timestamp of the network data packet into a tracking list; and At least one network data packet suspected of resource leakage is detected according to the current timestamp and at least one resource allocation timestamp currently recorded in the tracking list.
7. The resource leak detection system as claimed in claim 6, wherein the processor further executes the resource leak detection program code to perform the following operations: When the resources occupied by the network data packet are released, the resource allocation timestamp of the network data packet is deleted from the tracking list.
8. The resource leak detection system of claim 6 , wherein the operation of detecting the at least one network data packet suspected of resource leak according to the current timestamp and the at least one resource allocation timestamp currently recorded in the tracking list comprises: comparing a difference between the current timestamp and the resource allocation timestamp recorded in the tracking list with a predetermined value; and When the difference is greater than the predetermined value, it is determined that the network data packet corresponding to the resource allocation timestamp is a network data packet suspected of resource leakage.
9. The resource leakage detection system of claim 8, wherein the operation of determining that the network data packet corresponding to the resource allocation timestamp is the network data packet suspected of resource leakage comprises: determining whether the network data packet corresponding to the resource allocation timestamp belongs to the network data packet indicated by the receive ring buffer accessed by the driver; and When the network data packet corresponding to the resource allocation timestamp does not belong to the network data packet indicated by the receiving ring buffer, the network data packet corresponding to the resource allocation timestamp is determined to be the network data packet suspected of resource leakage.
10. The resource leak detection system as claimed in claim 6, wherein the processor further executes the resource leak detection program code to perform the following operations: After a network data packet suspected of resource leakage is detected, data packet forwarding of the network data packet suspected of resource leakage is simulated to reproduce the resource leakage problem.
11. A resource leak detection method, comprising: Recording a resource allocation timestamp of the network data packet, where the resource allocation timestamp indicates the time when resources are allocated to the network data packet; and In response to a trigger signal, the network data packet is evaluated according to the current timestamp and the resource allocation timestamp to determine whether the network data packet is a network data packet suspected of resource leakage.
12. The resource leakage detection method as claimed in claim 11, wherein the trigger signal indicates that a resource leakage problem may occur.
13. The resource leakage detection method of claim 11 , wherein in response to the trigger signal, the operation of evaluating whether the network data packet is a network data packet suspected of resource leakage according to the current timestamp and the resource allocation timestamp comprises: When the network data packet belongs to the network data packet indicated by the receiving ring buffer accessed by the driver, it is determined that the network data packet does not belong to the network data packet suspected of resource leakage.