Memory leak detection method and device, equipment, medium and computer program product
By obtaining the memory allocation information of the memory page not counted by the operating system, determining the memory usage of the call path, the problem of low efficiency and complex memory leak detection in the prior art is solved, and online and real-time detection of memory leaks is realized.
Patent Information
- Application Number
- CN202411999087.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-02
AI Technical Summary
The prior art is difficult to realize memory leak detection on memory pages not counted by the operating system, resulting in low efficiency and complexity of memory leak detection.
By obtaining the second memory page that has not been counted by the operating system from the allocated first memory page, obtaining its memory allocation information, determining the memory usage of the calling path, and performing memory leak detection on the operating system based on this.
It realizes accurate determination of the memory usage of the driver call path, simplifies the memory leak detection process, improves the memory leak detection efficiency, and can conduct online and real-time detection.
Smart Images

Figure CN119917376A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, specifically cloud computing and other technical fields, and can be used in operating system operation monitoring scenarios, and in particular to a memory leak detection method, device, equipment, medium and computer program product. Background Art
[0002] Memory leak means that dynamically allocated memory is not released or cannot be released for some reason, resulting in a waste of system memory, and even causing problems such as slow program execution and system crash. In order to avoid the above problems, how to detect memory leaks is a technical problem that needs to be solved urgently. Summary of the invention
[0003] The present disclosure provides a memory leak detection method, apparatus, device, medium and computer program product.
[0004] According to a first aspect of the present disclosure, a memory leak detection method is provided, comprising:
[0005] Acquire at least one second memory page that is not counted by the operating system from the allocated first memory pages, wherein the second memory page is a memory page requested by the process that calls the driver program;
[0006] Obtaining memory allocation information corresponding to any of the second memory pages, wherein the memory allocation information is used to indicate a calling path of the driver;
[0007] Determine the memory usage of any call path based on the memory allocation information;
[0008] Based on the memory usage of any one of the calling paths, memory leak detection is performed on the operating system.
[0009] According to a second aspect of the present disclosure, a memory leak detection device is provided, comprising:
[0010] A first acquisition module is used to acquire at least one second memory page that is not counted by the operating system from the allocated first memory page, wherein the second memory page is a memory page requested by a process that calls the driver program;
[0011] A second acquisition module, used for acquiring memory allocation information corresponding to any of the second memory pages, wherein the memory allocation information is used for indicating a calling path of the driver program;
[0012] A determination module, used to determine the memory usage of any call path based on the memory allocation information;
[0013] A detection module is used to perform memory leak detection on the operating system based on the memory usage of any calling path.
[0014] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the memory leak detection method as described in the first aspect.
[0018] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the memory leak detection method as described in the first aspect.
[0019] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by a processor, implement the steps of the memory leak detection method as described in the first aspect.
[0020] The present disclosure provides a memory leak detection method, device, equipment, medium and computer program product, which have the following beneficial effects:
[0021] From the allocated first memory page, at least one second memory page that is not counted by the operating system is obtained, wherein the second memory page is a memory page requested by the process that calls the driver; memory allocation information corresponding to any second memory page is obtained, and the memory allocation information is used to indicate the calling path of the driver; the memory occupancy of any calling path is determined based on the memory allocation information; based on the memory occupancy of any calling path, memory leak detection is performed on the operating system. The present disclosure can utilize the memory allocation information of the second memory page that is not counted by the operating system to accurately determine the memory occupancy of the driver calling path, and then realize online and real-time detection of memory leaks based on the memory occupancy, without the need for the user to perform additional operations, thereby simplifying the memory leak detection process and improving the efficiency of memory leak detection.
[0022] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0024] Figure 1is a flowchart of a memory leak detection method provided according to an embodiment of the present disclosure;
[0025] Figure 2 is a flowchart of a memory leak detection method provided according to another embodiment of the present disclosure;
[0026] Figure 3 is a schematic diagram of a memory page screening process provided according to an embodiment of the present disclosure;
[0027] Figure 4 is a flowchart of a memory leak detection method provided according to another embodiment of the present disclosure;
[0028] Figure 5 is a flowchart of a memory leak detection method provided according to another embodiment of the present disclosure;
[0029] Figure 6 A schematic diagram of the structure of a memory leak detection device provided according to an embodiment of the present disclosure;
[0030] Figure 7 It is a block diagram of an electronic device used to implement the memory leak detection method of the embodiment of the present disclosure. DETAILED DESCRIPTION
[0031] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0032] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, comply with the relevant laws and regulations, and do not violate public order and good morals.
[0033] In the related art, memory leak detection is performed by tracking the allocation information of each memory page. The specific implementation schemes include the following two:
[0034] (1) Page owner: By extending the structure of the memory page, adding member variables to store the call stack information and flags of the allocated memory page, and then hacking the memory page allocation and release interface. When the memory page is allocated, save the call stack information and set the flags; when the memory page is released, clear the call stack information and flags, and then pass the call stack information of all allocated memory pages to the user state through a debugfs interface, and create a tool in the user state to count the call stack information. Then, the operation and maintenance personnel can locate the path of the memory leak and the corresponding process information through the statistical results of the call stack information.
[0035] (2) Tracepoint: Tracepoint is a static tracing mechanism. Tracepoint tracks page allocation information mainly by adding fixed declared hook points on the memory allocation path, manually calling the trace function to trigger a trace event, and then using perf to record the page allocation information generated by tracepoint and generate a report. By analyzing these reports, operation and maintenance personnel can obtain the system memory allocation status and then diagnose the system memory leak problem.
[0036] The above two solutions cannot realize online and real-time detection of memory leaks, and the operation is complicated and the real-time performance is poor. The operation and maintenance personnel need to use relevant tools to locate and analyze the failure after the service fails. Specifically:
[0037] The page owner tool counts the allocation information of all memory pages in the system and saves it in the corresponding debugfs interface. This method requires the operation and maintenance personnel to first confirm that the memory leak problem has occurred and then read the interface from the user state, and use the analysis tool to count the information of these call stacks.
[0038] Tracepoint is more complicated to track the allocation and release information of memory pages. This method not only requires operation and maintenance personnel to debug and read interfaces in advance, but also needs to continuously expand the tracking buffer during debugging to prevent information from being overwritten or lost before the information is exported. In addition, the buffer is constantly read and written when exporting memory page allocation information, which affects system performance and is not suitable for online environments.
[0039] In addition, for memory pages that can be counted by the operating system, when a memory leak occurs, the above two solutions can easily determine the source of the memory leak, while it is more difficult to detect memory leaks for memory pages that are not counted by the operating system.
[0040] In order to solve at least one technical problem existing in the above-mentioned related technologies, the present disclosure provides a memory leak detection method, apparatus, device, medium and computer program product.
[0041] The memory leak detection method, apparatus, device, medium, and computer program product of the embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0042] It should be noted that the execution subject of the memory leak detection method of this embodiment is a memory leak detection device, and the memory leak detection device can be implemented by software and / or hardware, and can be configured in an electronic device.
[0043] Figure 1 It is a flowchart of a memory leak detection method provided according to an embodiment of the present disclosure.
[0044] like Figure 1 As shown, the memory leak detection method includes:
[0045] Step 101: Obtain at least one second memory page that is not counted by the operating system from the allocated first memory pages, wherein the second memory page is a memory page requested by a process that calls a driver.
[0046] In the disclosed embodiment, the first memory page refers to the memory page that has been allocated / occupied in the operating system, and the second memory page refers to the memory page in the first memory page that will not be counted by the operating system; the operating system may refer to the operating system of the terminal or the cloud operating system. The operating system may refer to the Linux operating system.
[0047] Taking the Linux operating system as an example, the Linux operating system includes memory application interfaces such as Slab, Virtual Memory Allocation (vmalloc), Page Cache, alloc_pages and _get_free_pages. Among them, the memory pages applied for through the interfaces such as Slab, Vmalloc and Page Cache can be counted by the kernel in the operating system, and the memory pages applied for through the alloc_pages and _get_free_pages interfaces will not be counted by the kernel in the operating system. It can be seen that in the Linux operating system, the second memory page refers to the memory page applied for by the process calling the driver through the alloc_pages and _get_free_pages interfaces.
[0048] The memory capacity corresponding to the second memory page that is not counted by the operating system may be referred to as the capacity of lost memory (Lost Ram).
[0049] It should be noted that the memory pages that can be counted by the operating system can be used for memory leak detection through relevant technologies. The present disclosure filters the second memory page that is not counted by the operating system, reduces the amount of information to be processed during the memory leak detection process, and improves the efficiency of memory leak detection.
[0050] Step 102: Obtain memory allocation information corresponding to any second memory page, where the memory allocation information is used to indicate a calling path of the driver program.
[0051] The memory allocation information may include process information of the driver calling process, allocation time of the memory page, and other information.
[0052] It should be noted that if the memory allocation information is the same, the calling path is the same, and the memory allocation path corresponding to the corresponding second memory page is the same; if the memory allocation information is different, the corresponding calling path is different, and the memory allocation path corresponding to the corresponding second memory page is different.
[0053] Step 103: determine the memory usage of any calling path based on the memory allocation information.
[0054] As an example, the number of occurrences of memory allocation information is counted to obtain the number of occurrences of memory allocation information corresponding to any call path; based on the number of occurrences of any memory allocation information and the size of the second memory page, the memory usage of the corresponding call path is determined.
[0055] In a possible implementation, the number of occurrences of any memory allocation information and the size of the second memory page are multiplied to obtain the memory usage of the corresponding call path.
[0056] Step 104: Detect memory leaks on the operating system based on the memory usage of any calling path.
[0057] As an example, based on the memory usage of any calling path, the maximum memory usage is obtained; based on the calling path corresponding to the maximum memory usage, the memory leak source is determined.
[0058] In an embodiment of the present disclosure, at least one second memory page that is not counted by the operating system is obtained from the allocated first memory page, wherein the second memory page is a memory page requested by the process that calls the driver; memory allocation information corresponding to any second memory page is obtained, and the memory allocation information is used to indicate the calling path of the driver; the memory occupancy of any calling path is determined based on the memory allocation information; and the operating system is detected for memory leaks based on the memory occupancy of any calling path. The present disclosure can utilize the memory allocation information of the second memory page that is not counted by the operating system to accurately determine the memory occupancy of the driver calling path, and then realize online and real-time detection of memory leaks based on the memory occupancy, without the need for the user to perform additional operations, thereby simplifying the memory leak detection process and improving the efficiency of memory leak detection. In addition, the present disclosure can automatically detect memory leaks for memory pages that are not counted by the operating system.
[0059] Figure 2 It is a flowchart of a memory leak detection method provided according to another embodiment of the present disclosure.
[0060] like Figure 2 As shown, the memory leak detection method includes:
[0061] Step 201, obtaining a memory page status corresponding to a first memory page.
[0062] The memory page status is used to indicate the page usage or page attribute of the first memory page.
[0063] In the disclosed embodiment, the memory page status may be obtained through flags in a memory page structure (struct page).
[0064] As an example and not limitation, the memory page status includes reserved, slab, least recently used (Least Recently Used, LRU), vmalloc, compressed cache (zram) and other states.
[0065] Step 202: based on the memory page status, filter out the second memory page that is not counted by the operating system from the first memory page.
[0066] The memory page status reflects the usage or page attributes of the memory page. Based on the memory page status, the memory pages requested through interfaces such as Slab, Vmalloc, and Page Cache can be removed from the first memory page, and the second memory page that is not counted by the operating system can be accurately screened out, thereby improving the accuracy of memory leak detection.
[0067] As an example, according to the mapping relationship between the memory page status and whether it can be counted by the operating system, the second memory page that is not counted by the operating system is screened out from the first memory page.
[0068] As another example, determine whether the memory page status is the target status, wherein the memory page marked as the target status can be counted by the operating system; in response to the memory page status not being the target status, determine the first memory page whose memory page status is not the target status as the second memory page requested by the process calling the driver.
[0069] The target state is used to indicate whether the first memory page is a memory page requested through interfaces such as Slab, Vmalloc, Page Cache, etc. As an example but not a limitation, the target state is any state of reserved, slab, LRU, vmalloc, zram, etc.
[0070] like Figure 3 As shown, Figure 3 This is a schematic diagram of the memory page screening process. In response to the memory page status of the first memory page being the target state, it is determined that the first memory page is a memory page requested through interfaces such as Slab, Vmalloc, and Page Cache, wherein the memory page requested through interfaces such as Slab, Vmalloc, and Page Cache can also be called a page allocated by the kernel; in response to the memory page status of the first memory page being not the target state, it is determined that the first memory page is a memory page requested through alloc_pages and _get_free_pages interfaces by a process calling a driver, that is, a second memory page not counted by the operating system.
[0071] The second memory page is screened by directly comparing the memory page status with the target status, which simplifies the memory page screening process and improves the screening efficiency. In addition, compared with the method of screening memory pages based on the mapping relationship between the memory page status and whether it can be counted by the operating system, this method does not need to establish a mapping relationship first, and the memory page screening process is more direct and efficient.
[0072] Step 203: Obtain memory allocation information corresponding to any second memory page.
[0073] Step 204: determine the memory usage of any calling path based on the memory allocation information.
[0074] Step 205: Detect memory leaks on the operating system based on the memory usage of any calling path.
[0075] It should be noted that the explanation of steps 203 to 205 can be found in the relevant description in any embodiment of the present disclosure and will not be repeated here.
[0076] In the disclosed embodiment, a memory page status corresponding to a first memory page is obtained; based on the memory page status, a second memory page that is not counted by the operating system is screened out from the first memory page; memory allocation information corresponding to any second memory page is obtained; the memory occupancy of any call path is determined based on the memory allocation information; and memory leak detection is performed on the operating system based on the memory occupancy of any call path. The memory page status reflects the usage or page attributes of the memory page. Based on the memory page status, the second memory page that is not counted by the operating system can be accurately screened out from the first memory page, thereby improving the accuracy of memory leak detection.
[0077] Figure 4 It is a flowchart of a memory leak detection method provided according to another embodiment of the present disclosure.
[0078] like Figure 4 As shown, the memory leak detection method includes:
[0079] Step 401: Obtain at least one second memory page that is not counted by the operating system from the allocated first memory pages.
[0080] Step 402: Obtain memory allocation information corresponding to any second memory page.
[0081] Step 403: Obtain process information and call stack information in the memory allocation information corresponding to any second memory page.
[0082] The process information is used to identify the process that calls the driver program. For example, the process information includes the process name, process identifier, and other information. The call stack information is used to indicate the calling relationship and nesting level of the function when the process calls the driver program.
[0083] Among them, the page frame number (Page FrameNumber, PFN) line information in the memory allocation information corresponding to any second memory page can be eliminated, and the remaining lines (including process information and call stack information) can be placed in the specified cache area, so as to obtain the process information and call stack information in the memory allocation information corresponding to any second memory page.
[0084] Step 404: determine the memory usage of any call path based on the process information and the call stack information.
[0085] The process information and call stack information together indicate the calling path of the driver. In addition to the process information and call stack information, the memory allocation information may also include some information that is not related to the calling path. Therefore, compared with determining the memory usage based on the memory allocation information, determining the memory usage based on the process information and call stack information requires less computation and the statistical result is more accurate.
[0086] As an example, for any memory allocation information, the memory allocation information corresponding to each second memory page can be first filtered based on the process information included in the memory allocation information, and the memory allocation information with the same process information can be retained; then, based on the call stack information, the retained memory allocation information can be filtered, and the memory allocation information with the same call stack information can be retained; the number of memory allocation information finally retained can be counted, and the memory usage of the call path can be determined based on the counted number and the size of the second memory page.
[0087] As another example, hash processing is performed on the process information and call stack information corresponding to any second memory page to obtain a corresponding hash value; the number of occurrences of the hash value is counted to obtain the number of occurrences of the hash value corresponding to any call path; based on the number of occurrences of any hash value and the size of the second memory page, the memory usage of the corresponding call path is determined.
[0088] Compared with process information and call stack information, the hash value is a fixed-length value. When counting the number of occurrences based on the hash value, only numerical comparison is required, and the complexity is relatively low.
[0089] Step 405: Detect memory leaks on the operating system based on the memory usage of any calling path.
[0090] It should be noted that the explanation of step 401, step 402 and step 405 can be found in the relevant description in any embodiment of the present disclosure, and will not be repeated here.
[0091] In the disclosed embodiment, at least one second memory page that is not counted by the operating system is obtained from the allocated first memory page; memory allocation information corresponding to any second memory page is obtained; process information and call stack information in the memory allocation information corresponding to any second memory page are obtained; based on the process information and call stack information, the memory occupancy of any call path is determined; based on the memory occupancy of any call path, memory leak detection is performed on the operating system. The process information and call stack information together indicate the call path of the driver program. In addition to the process information and call stack information, the memory allocation information may also include some information that is not related to the call path. Therefore, compared with determining the memory occupancy based on the memory allocation information, determining the memory occupancy based on the process information and call stack information requires less computation and the statistical result is more accurate.
[0092] Figure 5 It is a flowchart of a memory leak detection method provided according to another embodiment of the present disclosure.
[0093] like Figure 5 As shown, the memory leak detection method includes:
[0094] Step 501, when a memory overflow occurs in the operating system, a process score of a target process selected by a process termination mechanism is obtained, where the process score is used to indicate a termination priority of the target process.
[0095] In the disclosed embodiment, if an operating system memory overflow (Out Of Memory, OOM) occurs, it means that the operating system memory is insufficient and a memory leak problem may have occurred. At this time, the operating system will perform process killing to release system memory.
[0096] In the disclosed embodiment, the target process may refer to a process to be terminated selected by the process termination mechanism or a process that has been terminated by the process termination mechanism; it should be noted that in order to release memory in a timely manner and ensure the normal operation of the system, the process score of the target process may be obtained after the target process is terminated.
[0097] In the disclosed embodiment, the process score may refer to oom_score_adj, or may refer to a score (points) calculated based on the process's oom_score_adj, physical memory occupation size (Resident Set Size, RSS), swap file and page table memory occupation. The larger the process score, the higher the process termination priority, and the more likely it is to be terminated by the process termination mechanism; the smaller the process score, the lower the process termination priority, and the lower the possibility of being terminated by the process termination mechanism.
[0098] Step 502: When the process score is less than or equal to the score threshold, determine a second memory capacity that is not counted by the operating system based on the total memory capacity and the first memory capacity counted by the operating system.
[0099] If the process score is less than or equal to the score threshold, it means that the operating system is in a serious memory shortage state, and there is a high probability that a memory leak or excessive memory usage has occurred. For example, the score threshold may be 0.
[0100] Among them, the second memory capacity is used to indicate whether a memory black hole type memory leak occurs in the operating system; a memory black hole type memory leak refers to a memory leak caused by a process failing to release the memory in time after applying for memory due to some reasons such as logical errors, pointer loss, etc.
[0101] In the disclosed embodiment, the difference between the total memory capacity and the first memory capacity is used as the second memory capacity.
[0102] As an example, the second memory capacity may be determined by the following formula:
[0103] Lost Ram=MemTotal–CurrentMemTotal
[0104] =MemTotal–(MemFree+MemKernel+MemLru)
[0105] =MemTotal–MemFree–(Slab+VmallocUsed+PageTables+KernelStack+Buffers+HardwareCorrupted+Bounce)–(Active+Inactive+Unevictable+
[0106] (HugePages_Total*Hugepagesize)
[0107] Among them, Lost Ram represents the second memory capacity, MemTotal represents the total memory capacity, and CurrentMemTotal represents the first memory capacity.
[0108] MemFree indicates the memory that has not been used by the operating system, MemKernel indicates the total memory occupied by the operating system kernel, MemLru indicates the total memory on the LRU list (lists), that is, the memory of the Page cache and all user processes, Slab indicates the memory allocated through slab, VmallocUsed indicates the size of the vmalloc memory used, PageTables indicates the total memory consumed by translating the virtual address of the memory into the physical address, KernelStack indicates the memory occupied by the kernel stack, Buffers indicates the temporary cache space used for raw disk blocks, HardwareCorrupted indicates the total size of the memory pages that the kernel has marked as damaged and deleted, Bounce indicates the memory consumed by copying the cache data of the high-end memory, Active indicates the memory pages that have not been accessed for a long time, Inactive indicates the memory pages that have been accessed recently, Unevictable indicates the memory pages that cannot be paged out (pageout) / swapout (swapout), HugePages_Total indicates the number of huge pages (HugePage) set by the system, and Hugepagesize indicates the size of a HugePage.
[0109] Step 503, when the second memory capacity is greater than or equal to the set value, obtain at least one second memory page that is not counted by the operating system from the allocated first memory pages.
[0110] If the second memory capacity is greater than or equal to the set value, it means that a memory black hole type memory leak has occurred in the operating system. In this case, it is necessary to obtain the second memory page to locate the memory leak.
[0111] Step 504: Obtain memory allocation information corresponding to any second memory page.
[0112] Step 505: determine the memory usage of any calling path based on the memory allocation information.
[0113] Step 506: Perform memory leak detection on the operating system based on the memory usage of any calling path.
[0114] As an example, the memory usage is sorted in descending order, and the memory leak location is determined based on the memory allocation information corresponding to the memory usage in the top N order; or the memory leak location is determined based on the memory allocation information corresponding to the memory usage that is greater than or equal to the usage threshold, where N is a positive integer.
[0115] For any memory occupancy in the top N memory occupancy, or for any memory occupancy in the memory occupancy that is greater than or equal to the occupancy threshold, obtain the process information and / or call stack information in the corresponding memory allocation information; based on the process information and / or call stack information, determine the memory leak location. It should be noted that the memory leak location may refer to the process or function call stack where the memory leak occurs.
[0116] Sorting the memory usage or comparing the memory usage with the usage threshold can quickly and accurately filter out abnormal call paths from various call paths, thereby quickly and accurately locating the memory leak location.
[0117] It should be noted that the explanation of step 504-step 505 can be found in the relevant description in any embodiment of the present disclosure, and will not be repeated here.
[0118] In an embodiment of the present disclosure, in the case of memory overflow in the operating system, the process score of the target process selected by the process termination mechanism is obtained, and the process score is used to indicate the termination priority of the target process; when the process score is less than or equal to the score threshold, the second memory capacity that is not counted by the operating system is determined based on the total memory capacity and the first memory capacity counted by the operating system; when the second memory capacity is greater than or equal to the set value, at least one second memory page that is not counted by the operating system is obtained from the allocated first memory page; the memory allocation information corresponding to any second memory page is obtained; the memory occupancy of any call path is determined based on the memory allocation information; based on the memory occupancy of any call path, the operating system is detected for memory leaks. The present disclosure can automatically trigger the acquisition of the second memory page from the allocated memory page when a serious memory leak occurs in the operating system according to the size relationship between the process score and the second memory capacity and the corresponding threshold, and analyze and count the memory allocation information of the second memory page, so as to realize automatic detection of memory leaks and directly locate the source of memory leaks.
[0119] Figure 6 It is a structural diagram of a memory leak detection device provided according to an embodiment of the present disclosure.
[0120] like Figure 6 As shown, the memory leak detection device includes:
[0121] A first acquisition module 601 is used to acquire at least one second memory page that is not counted by the operating system from the allocated first memory page, wherein the second memory page is a memory page requested by the process that calls the driver program;
[0122] A second acquisition module 602 is used to acquire memory allocation information corresponding to any second memory page, where the memory allocation information is used to indicate a calling path of the driver program;
[0123] A determination module 603 is used to determine the memory usage of any call path based on the memory allocation information;
[0124] The detection module 604 is used to perform memory leak detection on the operating system based on the memory usage of any calling path.
[0125] As a possible implementation of the embodiment of the present disclosure, the first acquisition module 601 is used to:
[0126] Get the memory page status corresponding to the first memory page;
[0127] Based on the memory page status, a second memory page that is not counted by the operating system is screened out from the first memory page.
[0128] As a possible implementation of the embodiment of the present disclosure, the first acquisition module 601 is used to:
[0129] Determine whether the memory page state is the target state, wherein the memory page marked as the target state can be counted by the operating system;
[0130] In response to the memory page state not being the target state, the first memory page whose memory page state is not the target state is determined as the second memory page requested by the process calling the driver.
[0131] As a possible implementation of the embodiment of the present disclosure, the determination module 603 is used to:
[0132] Obtaining process information and call stack information from memory allocation information corresponding to any second memory page;
[0133] Based on the process information and call stack information, determine the memory usage of any call path.
[0134] As a possible implementation of the embodiment of the present disclosure, the determination module 603 is used to:
[0135] Perform hash processing on the process information and call stack information corresponding to any second memory page to obtain a corresponding hash value;
[0136] Count the number of occurrences of the hash value to obtain the number of occurrences of the hash value corresponding to any call path;
[0137] According to the number of occurrences of any hash value and the size of the second memory page, the memory usage of the corresponding call path is determined.
[0138] As a possible implementation of the embodiment of the present disclosure, the detection module 604 is used to:
[0139] Sort the memory usage in descending order, and determine the memory leak location based on the memory allocation information corresponding to the top N memory usages in the sort;
[0140] Alternatively, the memory leak location is determined based on memory allocation information corresponding to a memory occupancy that is greater than or equal to an occupancy threshold.
[0141] As a possible implementation of the embodiment of the present disclosure, the first acquisition module 601 is used to:
[0142] Determine a second memory capacity that is not counted by the operating system based on the total memory capacity and the first memory capacity counted by the operating system;
[0143] When the second memory capacity is greater than or equal to the set value, the second memory page is obtained from the first memory page.
[0144] As a possible implementation of the embodiment of the present disclosure, the first acquisition module 601 is used to:
[0145] When a memory overflow occurs in the operating system, the process score of the target process selected by the process termination mechanism is obtained, and the process score is used to indicate the termination priority of the target process;
[0146] When the process score is less than or equal to the score threshold, the second memory capacity is determined according to the total memory capacity and the first memory capacity.
[0147] It should be noted that the above explanation of the memory leak detection method is also applicable to the memory leak detection device of this embodiment, and will not be repeated here.
[0148] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0149] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device 700 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0150] like Figure 7 As shown, the electronic device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 702 or a computer program loaded from a storage unit 708 to a RAM (Random Access Memory) 703. In the RAM 703, various programs and data required for the operation of the electronic device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An I / O (Input / Output) interface 705 is also connected to the bus 704.
[0151] Multiple components in the electronic device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the electronic device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0152] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, a DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as a memory leak detection method. For example, in some embodiments, the memory leak detection method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the memory leak detection method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute the memory leak detection method in any other appropriate manner (eg, by means of firmware).
[0153] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0154] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0155] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0156] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0157] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: LAN (Local Area Network), WAN (Wide Area Network), the Internet, and blockchain networks.
[0158] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0159] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.
[0160] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0161] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A memory leak detection method, comprising: Acquire at least one second memory page that is not counted by the operating system from the allocated first memory pages, wherein the second memory page is a memory page requested by the process that calls the driver program; Obtaining memory allocation information corresponding to any of the second memory pages, wherein the memory allocation information is used to indicate a calling path of the driver; Determine the memory usage of any call path based on the memory allocation information; Based on the memory usage of any one of the calling paths, memory leak detection is performed on the operating system.
2. The method according to claim 1, wherein: The step of obtaining a second memory page that is not counted by the operating system from the allocated first memory page includes: Obtaining a memory page status corresponding to the first memory page; Based on the memory page status, the second memory page that is not counted by the operating system is filtered out from the first memory page.
3. The method according to claim 2, wherein based on the memory page status, filtering out the second memory page that is not counted by the operating system from the first memory page comprises: Determining whether the memory page state is a target state, wherein the memory page marked as the target state can be counted by the operating system; In response to the memory page status not being the target status, a first memory page whose memory page status is not the target status is determined as the second memory page requested by the process calling the driver.
4. The method according to claim 1, wherein: The determining the memory usage of any calling path based on the memory allocation information includes: Obtaining process information and call stack information in the memory allocation information corresponding to any of the second memory pages; Based on the process information and the call stack information, the memory usage of any call path is determined.
5. The method according to claim 4, wherein: The determining the memory usage of any call path based on the process information and the call stack information includes: Performing hash processing on the process information and call stack information corresponding to any of the second memory pages to obtain a corresponding hash value; Counting the number of occurrences of the hash value to obtain the number of occurrences of the hash value corresponding to any call path; The memory usage of the corresponding call path is determined according to the number of occurrences of any of the hash values and the size of the second memory page.
6. The method according to claim 1, wherein: The performing memory leak detection on the operating system based on the memory usage of any one of the calling paths includes: Sorting the memory usage in descending order, and determining the memory leak location based on the memory allocation information corresponding to the top N memory usages in the sorting; Alternatively, the memory leak location is determined based on the memory allocation information corresponding to the memory occupancy that is greater than or equal to the occupancy threshold.
7. The method according to any one of claims 1 to 6, wherein: The step of obtaining at least one second memory page that is not counted by the operating system from the allocated first memory page comprises: Determine a second memory capacity that is not counted by the operating system based on the total memory capacity and the first memory capacity counted by the operating system; When the second memory capacity is greater than or equal to a set value, the second memory page is obtained from the first memory page.
8. The method according to claim 7, wherein: The determining, according to the total memory capacity and the first memory capacity counted by the operating system, a second memory capacity that is not counted by the operating system includes: In the case where a memory overflow occurs in the operating system, obtaining a process score of a target process selected by a process termination mechanism, wherein the process score is used to indicate a termination priority of the target process; When the process score is less than or equal to a score threshold, the second memory capacity is determined according to the total memory capacity and the first memory capacity.
9. A memory leak detection device, comprising: A first acquisition module is used to acquire at least one second memory page that is not counted by the operating system from the allocated first memory page, wherein the second memory page is a memory page requested by a process that calls the driver program; A second acquisition module, used for acquiring memory allocation information corresponding to any of the second memory pages, wherein the memory allocation information is used for indicating a calling path of the driver program; A determination module, used to determine the memory usage of any call path based on the memory allocation information; A detection module is used to perform memory leak detection on the operating system based on the memory usage of any calling path.
10. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.
11. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 8.
12. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 8.