WO2023284793A1 - 内存泄露处理方法、装置和电子设备 - Google Patents
内存泄露处理方法、装置和电子设备 Download PDFInfo
- Publication number
- WO2023284793A1 WO2023284793A1 PCT/CN2022/105496 CN2022105496W WO2023284793A1 WO 2023284793 A1 WO2023284793 A1 WO 2023284793A1 CN 2022105496 W CN2022105496 W CN 2022105496W WO 2023284793 A1 WO2023284793 A1 WO 2023284793A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- state
- memory
- target memory
- leak
- usage
- Prior art date
Links
- 230000015654 memory Effects 0.000 title claims abstract description 366
- 238000003672 processing method Methods 0.000 title claims abstract description 18
- 238000000034 method Methods 0.000 claims abstract description 48
- 230000005039 memory span Effects 0.000 claims abstract description 18
- 238000004891 communication Methods 0.000 claims abstract description 9
- 238000012545 processing Methods 0.000 claims description 47
- 238000001514 detection method Methods 0.000 claims description 40
- 238000012423 maintenance Methods 0.000 claims description 21
- 238000012546 transfer Methods 0.000 claims description 14
- 239000003795 chemical substances by application Substances 0.000 claims description 7
- 238000004590 computer program Methods 0.000 claims 2
- 238000005259 measurement Methods 0.000 abstract 1
- 238000010586 diagram Methods 0.000 description 11
- 230000006870 function Effects 0.000 description 8
- 230000002159 abnormal effect Effects 0.000 description 7
- 230000003111 delayed effect Effects 0.000 description 3
- 230000000694 effects Effects 0.000 description 3
- 238000012544 monitoring process Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 241000699670 Mus sp. Species 0.000 description 1
- 230000005856 abnormality Effects 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 229910001423 beryllium ion Inorganic materials 0.000 description 1
- 230000001010 compromised effect Effects 0.000 description 1
- 238000004883 computer application Methods 0.000 description 1
- 230000001186 cumulative effect Effects 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000007599 discharging Methods 0.000 description 1
- 238000007689 inspection Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 230000004044 response Effects 0.000 description 1
- 238000011895 specific detection Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/366—Software debugging using diagnostics
Definitions
- the present application belongs to the technical field of communications, and in particular relates to a memory leak processing method, device and electronic equipment.
- Memory leak refers to the heap memory that has been dynamically allocated in the program is not released or cannot be released for some reason, resulting in a waste of system memory, resulting in serious consequences such as slowing down the running speed of the program and even system crashes. Memory leak defects are concealed and cumulative, and are more difficult to detect than other memory illegal access errors. With the increasing demand for computer applications, the design and development of application programs have also become increasingly complex, and the number of variables that developers deal with in the process of program implementation has also increased significantly. How to effectively allocate and release memory and prevent memory leaks becomes a problem. become more and more prominent.
- the slub memory leak detection method mainly includes the kmemleak method, which records the call stack of the memory application function and starts a kernel thread to periodically scan whether the requested memory is referenced, so as to determine whether there is a suspected memory leak.
- this method detects an increased load on the electronics, as well as memory consumption.
- the purpose of the embodiments of the present application is to provide a memory leak processing method, device, and electronic equipment, which can solve the problems that the existing memory leak detection increases the burden on the electronic equipment and consumes memory.
- the embodiment of the present application provides a memory leak processing method, including:
- the preset frequency is the memory span corresponding to the usage state of the target memory.
- the embodiment of the present application provides a memory leak processing device, including:
- a detection module configured to detect the size of unreclaimable memory in the target memory according to a preset frequency
- the first processing module is configured to adjust the usage state of the target memory according to the detection result
- the second processing module is configured to dump the stack information of all current mirror pools to the target memory when it is determined according to the usage status that the target memory leaks;
- the preset frequency is associated with the memory span corresponding to the usage status of the target memory.
- an embodiment of the present application provides an electronic device, the electronic device includes a processor, a memory, and a program or instruction stored in the memory and operable on the processor, and the program or instruction is The processor implements the steps of the method described in the first aspect when executed.
- an embodiment of the present application provides a readable storage medium, on which a program or an instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented .
- the embodiment of the present application provides a chip, the chip includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is used to run programs or instructions, so as to implement the first aspect the method described.
- the usage state of the target memory is adjusted according to the detection result, so that when it is determined based on the usage state that the target memory leaks
- the stack information of all current mirror pools is transferred to the target memory, without repeated detection, which greatly reduces the loss of electronic equipment caused by the detection of memory leaks.
- FIG. 1 is a schematic flow diagram of a memory leak processing method in an embodiment of the application
- Figure 2 is a schematic diagram of the memory structure of the object
- Fig. 4 is a schematic diagram of state changes
- Fig. 5 is a schematic diagram of the operation of entering the early warning state
- Fig. 6 is the processing schematic diagram in the early warning state waiting state change process
- Fig. 7 is a schematic diagram of the operation of entering the leakage state
- Fig. 8 is a schematic diagram of processing in the process of waiting for a state change in a leakage state
- FIG. 9 is a schematic structural diagram of a memory leak processing device according to an embodiment of the present application.
- FIG. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
- Fig. 11 is a schematic structural diagram of an electronic device according to another embodiment of the present application.
- a memory leak processing method in the embodiment of the present application includes steps 101 to 103 , which are specifically as follows.
- Step 101 detecting the association of the unreclaimable memory size in the target memory according to a preset frequency.
- the preset frequency is the memory span corresponding to the usage status of the target memory.
- the preset frequency is a detection frequency of an unreclaimable memory size in the target memory.
- the preset frequency is associated with the memory span corresponding to the usage status of the target memory, that is, for the usage status of the target memory, a frequency is preset based on its memory span, and the non-reclaimable memory size in the target memory is detected with this frequency , to reflect the dynamic use of the target memory and adapt to the needs of different usage states. It can be understood that different usage states correspond to different memory spans, that is, different detection frequencies.
- the non-reclaimable memory size in the target memory will be detected according to the preset frequency.
- Step 102 adjusting the usage state of the target memory according to the detection result.
- the usage state of the target memory can be adjusted, so as to deal with the memory leak later.
- Step 103 if it is determined according to the usage status that the target memory leaks, dump the stack information of all current mirror pools to the target memory.
- the stack information of all the current mirror pools can be transferred to the target memory when the target memory leaks.
- the electronic device after the electronic device detects the size of the non-reclaimable memory in the target memory according to the preset frequency, it adjusts the usage state of the target memory based on the detection result, so that the target memory is determined based on the usage state.
- the stack information of all current mirror pools is transferred to the target memory, without repeated detection, which greatly reduces the loss of electronic equipment caused by memory leak detection.
- the target memory may be a slub memory, and the method of the embodiment of the present application is used to handle the slub memory leak.
- the target memory can also be ion memory, virtual memory, etc., and the method of the embodiment of the present application can also be applied to other memory leaks (such as ion memory leaks, virtual memory leaks, etc.).
- the application of the method in the embodiment of the present application will be described in detail by taking the target memory as an example of the slub memory, and other memories are also applicable, and will not be listed here.
- the usage status of the target memory is divided into three types: normal status, warning status and leak status.
- an early warning threshold and a leak threshold are set.
- the warning threshold and/or leakage threshold are configured according to the target memory size of the electronic device, and the warning threshold is higher than the maximum value reached by the electronic device using the target memory normally, and the leakage threshold needs to be higher than the warning threshold.
- the warning threshold can be set to 1.5GB, and the leakage threshold can be set to 1.8GB (that is, the maximum increment of warning is 300MB).
- the preset frequency follows a criterion: in a corresponding use state, the larger the memory span, the lower the detection frequency.
- this criterion is used to determine the proportional coefficient of each usage status detection frequency, and the specific detection frequency can be adjusted according to the performance requirements of the project.
- the memory span in the normal state is 1200MB, and the corresponding preset frequency is 1200 seconds;
- the memory span in the warning state is 300MB, and the corresponding preset frequency is 300 seconds;
- the leak state is 200MB, and the corresponding The preset frequency is 200 seconds each time.
- step 102 includes:
- the usage state of the target memory is kept in the normal state.
- the electronic device will detect the value of Sunreclaim (that is, the size of non-recyclable memory) for the slub memory that is currently in a normal state, and switch the usage state of the slub memory to the warning state when the value of Sunreclaim is greater than the warning threshold; And when the value of Sunreclaim is less than or equal to the warning threshold, the usage state of the slub memory is kept in a normal state.
- Sunreclaim that is, the size of non-recyclable memory
- detecting the value of Sunreclaim is regularly detected at a first frequency, and the first frequency is a preset frequency corresponding to the memory span of the normal state of the slub memory.
- the slub memory is in a normal state waiting for a state change. In this way, in a normal state, except for one more monitoring process (or kernel thread) in the system, no other consumption will be brought to the system.
- step 102 includes:
- the target memory When the target memory is currently in an early warning state and a preset condition is met, switch the usage state of the target memory to a leakage state; wherein, the preset condition is: the maintenance time of the early warning state is less than the first A period of time, and the size of the non-reclaimable memory is greater than the leak threshold; or, the maintenance time of the warning state is greater than or equal to the first period of time;
- the target memory when the target memory is currently in the warning state, and the size of the non-reclaimable memory drops to less than the warning threshold before the maintenance time of the warning state reaches the first duration, the The usage state of the target memory switches to normal.
- the electronic device will detect the value of Sunreclaim and/or obtain the maintenance time of the warning state for the slub memory currently in the warning state, and when the maintenance time of the warning state is less than the first duration, and the value of Sunreclaim is greater than the leakage threshold , or, when the maintenance time of the warning state is greater than or equal to the first duration, switch the usage state of the slub memory to the leakage state; and before the maintenance time of the warning state reaches the first duration, the value of Sunreclaim drops to less than the warning threshold , switch the usage state of the slub memory to the normal state.
- detecting the value of Sunreclaim is regularly detected at a second frequency, and the second frequency is a preset frequency corresponding to the memory span of the warning state of the slub memory. At this point, the slub is in an early warning state waiting for the state to change.
- the method of entering the leak state by reaching the leak threshold is applicable to the case of a relatively fast leak, for example, a specific scene triggers a continuous memory leak. If the leakage threshold is not reached at this time, and the state is switched after waiting for the first time period, oom (out of memory) may occur before the state changes, causing the system to crash or restart.
- the method of entering the leak state by reaching the first duration is applicable to the case of slow leak, or the case of not much leaked memory. Since the mirror pool of top m is in the working state in the warning state, the memory requested by them will bring additional memory consumption, so at this time it is not expected that the target memory will remain in the warning state for a long time. Therefore, even if the leak threshold is not reached, the The first time the target memory also enters the leak state, even though the leak may have stopped at this point.
- this embodiment also includes:
- the use state of the target memory When the use state of the target memory is switched to a first state, obtain the use information of each buffer pool in the target memory, where the first state includes the warning state or the leak state;
- the mark is used to record application information and release information
- the usage information of each buffer pool includes the current usage information of each buffer pool; when the first state is the leakage state The usage information of each cache pool includes usage information changed within a second duration of each cache pool.
- the usage information of each cache pool can be obtained from slabinfo in the system memory information.
- slabinfo includes the name, setting size, usage size and usage times of each cache pool, etc. Therefore, the usage information can be the usage size and usage times of the buffer pool, or the cache obtained by calculating the product of usage size and usage times The total occupancy of the pool (total memory occupancy).
- mark and add the mirror pool After determining the target cache pool, mark and add the mirror pool, and record the application information and whether information through the mark. For example, adding the flag SLAB_STORE_USER enables the mirror pool to record the stack of each object. After adding the mark, the memory structure of each object is shown in Figure 2. Applying for memory in the mirror pool will increase the memory overhead, and the alloc/free track is used to store the corresponding object (the memory actually allocated to the applicant) Application information (application stack information) and release information (release stack information).
- the target cache pool is based on the usage information of each cache pool, and determines the m cache pools with the largest leakage suspicion, that is, the top m cache pools with the largest total usage.
- slabinfo data is not implemented in the system, you can traverse each slab_cache (slab cache pool) by yourself, and filter out the top m cache pools with the largest total occupancy.
- the target cache pool is based on the usage information of each cache pool, and determines the m cache pools with the largest leakage suspicion, that is, the top m cache pools with the largest increment.
- step 103 includes:
- step 103 includes:
- the leak state is a fast leak state or a low-speed leak state according to a leak increment threshold and a third duration; wherein, the third duration is determined by the The preset frequency and preset detection times corresponding to the leakage state are determined;
- the leak state is a fast leak state
- revoke the proxy allocation memory right of the mirror pool and immediately traverse all current mirror pools, and transfer the acquired stack information to the target memory;
- the leak state is a low-speed leak state
- revoke the proxy allocation memory right of the mirror pool and traverse all current mirror pools when the preset conditions are met, and transfer the obtained stack information to the target memory.
- the leak increment threshold can also be understood as the maximum leak increment threshold, and the warning threshold and the leak threshold are configured according to the target memory size of the electronic device.
- the electronic device will detect the value of Sunreclaim for the slub memory currently in the leak state and combine it with the third time length to determine Determines whether the leak state is a fast leak state or a slow leak state.
- detecting the value of Sunreclaim is periodically detected at a third frequency
- the third frequency is a preset frequency corresponding to the memory span of the leaked state of the slub memory.
- the third frequency can be adjusted according to the performance requirements of the project. For example, if the value of Sunreclaim is 300MB when the electronic device is turned on, and the value of Sunreclaim fluctuates between 300MB and 1GB during normal use, the leakage increment threshold may be set to 200MB. Based on the change of the leak increment threshold, if the memory span of the leak state, that is, the leak increment threshold changes, the third frequency will change accordingly.
- the system may quickly oom, resulting in a crash or restart, then revoke the agent allocation memory rights of all current mirror pools, and immediately traverse all current mirror pools to obtain the stack information Dump to target memory, such as memory ROM, to avoid data loss after restart.
- target memory such as memory ROM
- For low-speed leaked target memory compared to fast leaks, which lack the urgency of dumping, revoke the proxy memory allocation rights of all current mirror pools, and traverse all current mirror pools when the preset requirements are met, and obtain the stack
- the information is transferred to the target memory, such as memory ROM.
- the time to meet the preset requirements can be the time when the system load is less than the corresponding load threshold, so as to achieve staggered use of system resources, and because it will not traverse immediately, the memory normally used in the mirror pool may be released, and the new memory application It will not be in the mirror pool, so the stack information stored in the mirror pool is more likely to be the real leaked stack information.
- determining that the leakage state is a fast leakage state or a low speed leakage state includes:
- the current leak state is fast leak state; if the size of unreclaimable memory before reaching the third time length is less than or equal to the leak threshold, the current leak state is low speed leaked state.
- the stack information may be application information and release information of each object.
- revoking the proxy allocation memory right of the mirror pool will clear the mirror flag of the corresponding buffer pool, and the target memory will return to the normal state.
- the proxy memory allocation right of the mirror pool is revoked, and the normal state is returned.
- the value of Sunreclaim drops below the warning threshold before the third time period reaches, that is, the leakage does not actually occur, and the proxy allocation memory right of the mirror pool can be revoked, returning to the normal state.
- step 103 after step 103, it also includes:
- step 103 after step 103, it also includes:
- the user triggers the restart or exits the restart by displaying a restart reminder message.
- the system will be reset.
- Memory leaks will not immediately cause problems to the system. Generally, it will take a period of time for the leaks to gradually show problems. For example, if the user uses a mobile phone with a memory leak, if the leak is relatively slow, there may be no problem with normal use for a week. Suppose that the leaked memory will reach a relatively large amount after two weeks of continuous use, causing the system to freeze. Dayton, even oom occurs.
- restarting the device will clear the created mirror pool, which also saves a small amount of memory.
- restarting the device will not affect the saving and uploading of exception logs. It can effectively prevent the game from getting stuck in the middle of the game, or getting stuck when editing important files without saving them.
- the restart reminder information can be "abnormal log collection completed, we hope you restart the device once, thank you for your support to xx, the abnormal information collected this time is, xxx, xxx.
- the abnormal log does not involve any private information of yours, Are you willing to upload the exception log to xx for analysis?"
- a pop-up window reminder or a status bar notification can be performed to remind the user that there may be an exception in the system, solicit the user's opinion, and whether to allow recording of the abnormal log, after the user agrees Perform follow-up processing. If the user does not agree, no follow-up processing will be performed.
- the content to remind users can be roughly set as: "System prompt: There may be abnormalities in the current system. In order to ensure the user experience of you and other xx brands, we hope that your device can collect no more than x hours (x is the maximum duration of the warning) and) the system memory usage information of the maximum leakage time. After the collection is complete, you will be reminded again. In order to thank you for your support in creating better products, we will also give you points/coupons... ".
- the warning threshold can be set to 1.5GB and the leakage threshold to 1.8GB (that is, the maximum increment of warning is 300MB), with the leak increment set to 200MB.
- the detection frequency can be respectively positioned every time of 1200 seconds (first frequency), every time of 300 seconds (second frequency), and every time of 200 seconds (third frequency). In this example, the relationship between the Sunreclaim value and each usage status and detection frequency is shown in Figure 3.
- step 1 the state changes of the slub memory are shown in Figure 4.
- step 1 enter the normal state, and wait for the state to change in the normal state.
- the electronic device regularly detects the value of Sunreclaim in the system memory information according to the first frequency, and judges whether the Sunreclaim is greater than the warning threshold, and if so, enters the warning state, otherwise remains in this state.
- the slabinfo in the current system memory information is obtained, and the m cache pools with the largest current leak suspicions are determined. After that, check whether the m buffer pools have corresponding mirror pools one by one. If not, add a mirror tag to the current buffer pool, create a corresponding mirror pool and add a tag to the mirror pool; if it exists, directly add a tag to the current buffer pool The mirror pool of the cache pool is tagged.
- Step 2 enter the early warning state, and wait for the state to change in the early warning state.
- the value of Sunreclaim in the system memory information is periodically detected according to the second frequency, if the value of the Sunreclaim is greater than the leakage threshold before the first time length is reached (that is, the maintenance time of the warning state is less than the first time length, and the value of Sunreclaim is greater than the leakage threshold), or, when the time to enter the early warning state is greater than or equal to the first duration (that is, the maintenance time of the early warning state is greater than or equal to the first duration), enter the leakage state; if the value of the Sunreclaim reaches the first duration A long time ago, it dropped below the warning threshold and returned to normal.
- the slabinfo in the current system memory information is obtained, and the m buffer pools with the largest increment are determined by determining the increment of the slabinfo obtained in the early warning state. After that, check whether the m buffer pools have corresponding mirror pools one by one. If not, add a mirror tag to the current buffer pool, create a corresponding mirror pool and add a tag to the mirror pool; if it exists, directly add a tag to the current buffer pool The mirror pool of the cache pool is tagged.
- Step 3 enter the leakage state, and wait for the state change in the leakage state.
- the stack information of all current mirror pools is transferred to the memory ROM.
- the value of Sunreclaim in the system memory information is periodically detected according to the third frequency, and if the value of Sunreclaim falls below the warning threshold before reaching the third time length, the proxy allocation memory right of the mirror pool is revoked.
- the target memory in the fast leaking state revoke the agent allocation memory rights of all current mirror pools, and immediately traverse all the current mirror pools, and transfer the obtained stack information to the storage ROM;
- the target memory in the low-speed leaking state revoke The agents of all current mirror pools allocate memory rights, and traverse all current mirror pools when the preset requirements are met, and transfer the obtained stack information to the memory ROM.
- the dump choose an opportunity to upload and delete the log information. After the upload is complete, it will continue to maintain the leaking state until it detects that the value of Sunreclaim drops below the warning threshold, and returns to the normal state.
- the method of the embodiment of the present application only dumps the mirror pool stack information when a leak occurs, and only detects the slab cache pool with the largest leak suspicion, instead of detecting all cache pools, which greatly reduces the impact of detecting memory leaks. system losses.
- two rounds of cache pool selection will be performed, and a mirror image will be created for it, taking into account not only the overall memory usage, but also the memory increment during the abnormal period, so as to ensure that no important sources of suspicious leaks are missed.
- the method of timing dump/uploading is adopted, and system resources are used at staggered peaks. Since the dump is the memory that is normally applied in the mirror buffer pool after clearing the mirror flag will be released, so delayed dumping can reduce the number of suspected leak sources in the log, which is convenient for developers to troubleshoot problems, and can also reduce the memory required for dumping.
- the memory leak processing method provided in the embodiment of the present application may be executed by a memory leak processing device, or a control module in the memory leak processing device for executing the memory leak processing method.
- the method for processing the memory leak by the memory leak processing apparatus is taken as an example to illustrate the memory leak processing device provided in the embodiment of the present application.
- a memory leak processing device includes:
- a detection module 910 configured to detect the size of unreclaimable memory in the target memory according to a preset frequency
- the first processing module 920 is configured to adjust the usage state of the target memory according to the detection result
- the second processing module 930 is configured to dump the stack information of all current mirror pools to the target memory when it is determined according to the usage status that the target memory leaks;
- the preset frequency is associated with the memory span corresponding to the usage state of the target memory.
- the first processing module includes:
- the first processing submodule is used to switch the use state of the target memory to the warning state when the target memory is currently in a normal state and the size of the non-recyclable memory is greater than the warning threshold;
- the second processing submodule is configured to keep the usage state of the target memory at the normal state when the target memory is currently in a normal state and the size of the non-reclaimable memory is less than or equal to the warning threshold state.
- the first processing module includes:
- the third processing sub-module is configured to switch the use state of the target memory to a leakage state when the target memory is currently in an early warning state and meets a preset condition; wherein the preset condition is: The maintenance time of the warning state is less than the first duration, and the size of the non-recoverable memory is greater than the leakage threshold; or, the maintenance time of the warning state is greater than or equal to the first duration;
- the fourth processing submodule is configured to reduce the target memory to less than the warning threshold before the maintenance time of the warning state reaches the first duration when the target memory is currently in the warning state and the size of the non-recyclable memory In the case, the usage state of the target memory is switched to a normal state.
- the device also includes:
- An acquisition module configured to acquire usage information of each cache pool in the target memory when the usage status of the target memory is switched to a first status, where the first status includes the warning status or the leak status ;
- a determining module configured to determine a target cache pool according to the usage information of each cache pool
- a third processing module configured to add a mark to the mirror pool of the target cache pool, where the mark is used to record application information and release information;
- the usage information of each buffer pool includes the current usage information of each buffer pool; when the first state is the leakage state The usage information of each cache pool includes usage information changed within a second duration of each cache pool.
- the second processing module is also used for:
- the second processing module includes:
- the determining submodule is configured to determine that the leak state is a fast leak state or a low speed leak state according to a leak increment threshold and a third duration when the usage state of the target memory is switched to a leak state; wherein, the The third duration is determined by the preset frequency and the preset detection times corresponding to the leakage state;
- the fifth processing sub-module is used to revoke the agent allocation memory right of the mirror pool when the leak state is a fast leak state, and immediately traverse all current mirror pools, and transfer the acquired stack information to the the target memory;
- the sixth processing sub-module is used to revoke the agent allocation memory right of the mirror pool when the leak state is a low-speed leak state, and traverse all current mirror pools when the preset conditions are met, and obtain the The stack information is dumped to the target memory.
- the device also includes:
- the fourth processing module is configured to upload and delete log information, wherein the log information includes stack information of all current mirror pools.
- the device of the embodiment of the present application only transfers the mirror pool stack information when a leak occurs, and only detects the slab buffer pool with the largest leak suspicion, instead of detecting all buffer pools, which greatly reduces the impact of detecting memory leaks on the system. loss.
- two rounds of cache pool selection will be performed, and a mirror image will be created for it, taking into account not only the overall memory usage, but also the memory increment during the abnormal period, so as to ensure that no important sources of suspicious leaks are missed.
- the method of timing dump/uploading is adopted, and system resources are used at staggered peaks. Since the dump is the memory that is normally applied in the mirror buffer pool after clearing the mirror flag will be released, so delayed dumping can reduce the number of suspected leak sources in the log, which is convenient for developers to troubleshoot problems, and can also reduce the memory required for dumping.
- the memory leak processing apparatus in the embodiment of the present application may be a device, or may be a component, an integrated circuit, or a chip in an electronic device.
- the device may be a mobile electronic device or a non-mobile electronic device.
- the mobile electronic device may be a mobile phone, a tablet computer, a notebook computer, a handheld computer, a vehicle electronic device, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant).
- non-mobile electronic devices can be servers, network attached storage (Network Attached Storage, NAS), personal computer (personal computer, PC), television (television, TV), teller machine or self-service machine, etc., this application Examples are not specifically limited.
- Network Attached Storage NAS
- personal computer personal computer, PC
- television television
- teller machine or self-service machine etc.
- the memory leak handling device in the embodiment of the present application may be a device with an operating system.
- the operating system may be an Android (Android) operating system, an ios operating system, or other possible operating systems, which are not specifically limited in this embodiment of the present application.
- the memory leak processing device provided by the embodiment of the present application can realize various processes realized by the method embodiments in FIG. 1 to FIG. 8 , and details are not repeated here to avoid repetition.
- the embodiment of the present application further provides an electronic device 1000, including a processor 1001, a memory 1002, and programs or instructions stored in the memory 1002 and operable on the processor 1001,
- the program or instruction is executed by the processor 1001
- the various processes of the above-mentioned memory leak processing method embodiment can be achieved, and the same technical effect can be achieved. In order to avoid repetition, details are not repeated here.
- the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
- FIG. 11 is a schematic diagram of a hardware structure of an electronic device implementing an embodiment of the present application.
- the electronic device 1100 includes, but is not limited to: a radio frequency unit 1101, a network module 1102, an audio output unit 1103, an input unit 1104, a sensor 1105, a display unit 1106, a user input unit 1107, an interface unit 1108, a memory 1109, and a processor 1110, etc. part.
- the electronic device 1100 can also include a power supply (such as a battery) for supplying power to various components, and the power supply can be logically connected to the processor 1110 through the power management system, so that the management of charging, discharging, and function can be realized through the power management system. Consumption management and other functions.
- a power supply such as a battery
- the structure of the electronic device shown in FIG. 11 does not constitute a limitation to the electronic device.
- the electronic device may include more or fewer components than shown in the figure, or combine some components, or arrange different components, and details will not be repeated here. .
- processor 1110 is used for:
- the preset frequency is associated with the memory span corresponding to the usage state of the target memory.
- the electronic device After the electronic device detects the size of the unreclaimable memory in the target memory of the electronic device according to the preset frequency, it adjusts the use state of the target memory based on the detection result, so that when it is determined that the target memory leaks based on the use state, the The stack information of all current mirror pools is transferred to the target memory, without repeated detection, which greatly reduces the loss of electronic equipment caused by the detection of memory leaks.
- processor 1110 is also used for:
- the usage state of the target memory is kept in the normal state.
- processor 1110 is also used for:
- the target memory When the target memory is currently in an early warning state and a preset condition is met, switch the usage state of the target memory to a leakage state; wherein, the preset condition is: the maintenance time of the early warning state is less than the first A period of time, and the size of the non-reclaimable memory is greater than the leak threshold; or, the maintenance time of the warning state is greater than or equal to the first period of time;
- the target memory when the target memory is currently in the warning state, and the size of the non-reclaimable memory drops to less than the warning threshold before the maintenance time of the warning state reaches the first duration, the The usage state of the target memory switches to normal.
- processor 1110 is also used for:
- the use state of the target memory When the use state of the target memory is switched to a first state, obtain the use information of each buffer pool in the target memory, where the first state includes the warning state or the leak state;
- the usage information of each buffer pool includes the current usage information of each buffer pool; when the first state is the leakage state The usage information of each cache pool includes usage information changed within a second duration of each cache pool.
- the processor 1110 is further configured to revoke the proxy memory allocation right of the mirror pool when the usage state of the target memory switches to the leaked state, and immediately traverse all current mirror pools, and obtain the Stack information is dumped to the target memory.
- processor 1110 is also used for:
- the leak state is a fast leak state or a low-speed leak state according to a leak increment threshold and a third duration; wherein, the third duration is determined by the The preset frequency and preset detection times corresponding to the leakage state are determined;
- the leak state is a fast leak state
- revoke the proxy allocation memory right of the mirror pool and immediately traverse all current mirror pools, and transfer the acquired stack information to the target memory;
- the leak state is a low-speed leak state
- revoke the proxy allocation memory right of the mirror pool and traverse all current mirror pools when the preset conditions are met, and transfer the obtained stack information to the target memory.
- the radio frequency unit 1101 is configured to upload log information
- the processor 1110 is configured to delete log information, where the log information includes stack information of all current mirror pools.
- detecting the slab cache pool with the largest leak suspicion rather than detecting all the cache pools, greatly reduces the loss of the system caused by the detection of memory leaks.
- two rounds of cache pool selection will be performed, and a mirror image will be created for it, taking into account not only the overall memory usage, but also the memory increment during the abnormal period, so as to ensure that no important sources of suspicious leaks are missed.
- the method of timing dump/uploading is adopted, and system resources are used at staggered peaks. Since the dump is the memory that is normally applied in the mirror buffer pool after clearing the mirror flag will be released, so delayed dumping can reduce the number of suspected leak sources in the log, which is convenient for developers to troubleshoot problems, and can also reduce the memory required for dumping.
- the input unit 1104 may include a graphics processor (Graphics Processing Unit, GPU) 11041 and a microphone 11042, and the graphics processor 11041 is used for the image capture device (such as the image data of the still picture or video obtained by the camera) for processing.
- the display unit 1106 may include a display panel 11061, and the display panel 11061 may be configured in the form of a liquid crystal display, an organic light emitting diode, or the like.
- the user input unit 1107 includes a touch panel 11071 and other input devices 11072 . Touch panel 11071, also called touch screen.
- the touch panel 11071 may include two parts, a touch detection device and a touch controller.
- Other input devices 11072 may include, but are not limited to, physical keyboards, function keys (such as volume control keys, switch keys, etc.), trackballs, mice, and joysticks, which will not be repeated here.
- Memory 1109 can be used to store software programs as well as various data, including but not limited to application programs and operating systems.
- Processor 1110 may integrate an application processor and a modem processor, wherein the application processor mainly processes operating systems, user interfaces, and application programs, and the modem processor mainly processes wireless communications. It can be understood that the foregoing modem processor may not be integrated into the processor 1110 .
- the embodiment of the present application also provides a readable storage medium, the readable storage medium stores a program or an instruction, and when the program or instruction is executed by the processor, each process of the above-mentioned memory leak processing method embodiment is implemented, and can achieve The same technical effects are not repeated here to avoid repetition.
- the processor is the processor in the electronic device described in the above embodiments.
- the readable storage medium includes computer readable storage medium, such as computer read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk, etc.
- the embodiment of the present application further provides a chip, the chip includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the above embodiment of the memory leak processing method Each process, and can achieve the same technical effect, in order to avoid repetition, will not repeat them here.
- chips mentioned in the embodiments of the present application may also be called system-on-chip, system-on-chip, system-on-a-chip, or system-on-a-chip.
- the term “comprising”, “comprising” or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or apparatus comprising a set of elements includes not only those elements, It also includes other elements not expressly listed, or elements inherent in the process, method, article, or device. Without further limitations, an element defined by the phrase “comprising a " does not preclude the presence of additional identical elements in the process, method, article, or apparatus comprising that element.
- the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved. Functions are performed, for example, the described methods may be performed in an order different from that described, and various steps may also be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Debugging And Monitoring (AREA)
Abstract
一种内存泄露处理方法、装置和电子设备,属于通信技术领域。该方法包括:根据预设频率检测目标内存中不可回收的内存大小(101);根据检测的结果,调整所述目标内存的使用状态(102);在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器(103);其中,所述预设频率与所述目标内存的使用状态对应的内存跨度相关联。
Description
相关申请的交叉引用
本申请要求享有于2021年07月16日提交的名称为“内存泄露处理方法、装置和电子设备”的中国专利申请202110805414.1的优先权,该申请的全部内容通过引用并入本文中。
本申请属于通信技术领域,具体涉及一种内存泄露处理方法、装置和电子设备。
内存泄漏(Memory Leak)是指程序中已动态分配的堆内存由于某种原因程序未释放或无法释放,造成系统内存的浪费,导致程序运行速度减慢甚至系统崩溃等严重后果。内存泄漏缺陷具有隐蔽性、积累性的特征,比其他内存非法访问错误更难检测。随着计算机应用需求的日益增加,应用程序的设计与开发也相应的日趋复杂,开发人员在程序实现的过程中处理的变量也大量增加,如何有效进行内存分配和释放,防止内存泄漏的问题变得越来越突出。
目前,slub内存泄漏检测的方法主要有kmemleak方法,通过记录内存申请函数的调用堆栈,并启动一个内核线程周期性地扫描已申请的内存是否被引用,以此判断是否有内存泄漏嫌疑。然而,该方法检测出会增加电子设备的负担,以及内存的消耗。
发明内容
本申请实施例的目的是提供一种内存泄露处理方法、装置和电子设备,能够解决现有内存泄露检测增加电子设备的负担以及内存的消耗的问 题。
第一方面,本申请实施例提供了一种内存泄露处理方法,包括:
根据预设频率检测目标内存中不可回收的内存大小;
根据检测的结果,调整所述目标内存的使用状态;
在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器;
其中,所述预设频率与所述目标内存的使用状态对应的内存跨度。相关联
第二方面,本申请实施例提供了一种内存泄露处理装置,包括:
检测模块,用于根据预设频率检测目标内存中不可回收的内存大小;
第一处理模块,用于根据检测的结果,调整所述目标内存的使用状态;
第二处理模块,用于在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器;
其中,所述预设频率与所述目标内存的使用状态对应的内存跨度相关联。
第三方面,本申请实施例提供了一种电子设备,该电子设备包括处理器、存储器及存储在所述存储器上并可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如第一方面所述的方法的步骤。
第四方面,本申请实施例提供了一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如第一方面所述的方法的步骤。
第五方面,本申请实施例提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如第一方面所述的方法。
在本申请实施例中,在根据预设频率检测目标内存中不可回收的内存大小之后,由检测的结果来调整该目标内存的使用状态,从而在基于该使用状态确定该目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息 转存到目标存储器,无需重复多次的检测,极大地降低了检测内存泄漏对电子设备带来的损耗。
图1是申请实施例的内存泄露处理方法的流程示意图;
图2是object的内存结构示意图;
图3是Sunreclaim值与各个使用状态及检测频率的关系;
图4是状态变化示意图;
图5是进入预警状态的操作示意图;
图6是预警状态等待状态变化过程中的处理示意图;
图7是进入泄露状态的操作示意图;
图8是泄露状态等待状态变化过程中的处理示意图;
图9是本申请实施例的内存泄露处理装置的结构示意图;
图10是本申请实施例的电子设备的结构示意图;
图11是本申请另一实施例的电子设备的结构示意图。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员获得的所有其他实施例,都属于本申请保护的范围。
本申请的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。
下面结合附图,通过具体的实施例及其应用场景对本申请实施例提供 的内存泄露处理方法进行详细地说明。
如图1所示,本申请实施例的一种内存泄露处理方法,包括步骤101至103,具体如下所示。
步骤101,根据预设频率检测目标内存中不可回收的内存大小相关联。其中,所述预设频率与所述目标内存的使用状态对应的内存跨度。
这里,预设频率是目标内存中不可回收的内存大小的检测频率。预设频率与目标内存的使用状态对应的内存跨度相关联,也就是,对于目标内存的使用状态,会基于其内存跨度预先设置一频率,以该频率来检测该目标内存中不可回收的内存大小,来反映目标内存的动态使用,适应不同使用状态的需求。可以理解的,不同的使用状态对应的内存跨度是不同的,即,检测频率也不同。
如此,本步骤中,会根据该预设频率来检测目标内存中不可回收的内存大小。
步骤102,根据检测的结果,调整所述目标内存的使用状态。
这里,基于上述步骤101检测的结果,能够调整该目标内存的使用状态,以便后续针对内存泄露进行处理。
步骤103,在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器。
这里,基于步骤102调整的目标内存的使用状态,就可以进一步在目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器。
这样,本申请实施例的方法,电子设备在根据预设频率检测目标内存中不可回收的内存大小之后,由检测的结果来调整该目标内存的使用状态,从而在基于该使用状态确定该目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器,无需重复多次的检测,极大地降低了检测内存泄漏对电子设备带来的损耗。
应该知道的是,该实施例中,目标内存可以是slub内存,应用本申请实施例的方法对slub内存泄漏进行处理。当然,目标内存还可以是ion内存、虚拟内存等,对于其他内存泄漏(例如ion内存泄漏,虚拟内存泄 漏等)也可应用本申请实施例的方法。下面,将以目标内存是slub内存为例对本申请实施例的方法的应用进行具体说明,其他内存也同样适用,在此不再一一列举。
还应该知道的是,本申请实施例中,基于泄露的发生可能,目标内存的使用状态分为三种:正常状态、预警状态和泄露状态。其中,为明确目标内存的使用状态,设置了预警阈值和泄露阈值。预警阈值和/或泄露阈值是根据电子设备的目标内存大小配置,并且,预警阈值比电子设备正常使用目标内存达到的最高值高,泄漏阈值需要比预警阈值高。例如,电子设备开机时Sunreclaim的值在300MB,正常使用过程中Sunreclaim的值会在300MB~1GB之间波动,则可以将预警阈值设置为1.5GB,泄漏阈值设置为1.8GB(即预警最大增量为300MB)。
此外,该实施例中,预设频率遵循一个准则:对应的使用状态下,内存跨度越大,检测频率越低。当然,该准则用于确定各个使用状态检测频率的比例系数,具体检测频率可以根据项目对性能的要求做调整。例如,正常状态的内存跨度是1200MB,其对应的预设频率为1200秒每次;预警状态的内存跨度是300MB,其对应的预设频率为300秒每次;泄漏状态是200MB,其对应的预设频率为200秒每次。
可选地,该实施例中,步骤102包括:
在所述目标内存当前处于正常状态,且所述不可回收的内存大小大于预警阈值的情况下,将所述目标内存的使用状态切换至预警状态;
或者,在所述目标内存当前处于正常状态,且所述不可回收的内存大小小于或等于所述预警阈值的情况下,将所述目标内存的使用状态保持在所述正常状态。
也就是说,电子设备会针对当前处于正常状态的slub内存,通过检测Sunreclaim的值(即不可回收的内存大小),在Sunreclaim的值大于预警阈值时,将slub内存的使用状态切换至预警状态;而在Sunreclaim的值小于或等于预警阈值时,将slub内存的使用状态保持在正常状态。
其中,检测Sunreclaim的值是以第一频率定期检测的,该第一频率是与slub内存的正常状态的内存跨度对应的预设频率。此时,slub内存 在正常状态等待状态变化。这样,在正常状态,除了系统中多了一个监控进程(或内核线程),不会给系统带来其他消耗。
可选地,步骤102包括:
在所述目标内存当前处于预警状态,且满足预设条件的情况下,将所述目标内存的使用状态切换至泄露状态;其中,所述预设条件为:所述预警状态的维持时间小于第一时长,且所述不可回收的内存大小大于泄露阈值;或者,所述预警状态的维持时间大于或等于所述第一时长;
或者,在所述目标内存当前处于预警状态,且所述不可回收的内存大小在所述预警状态的维持时间达到所述第一时长之前,下降至小于所述预警阈值的情况下,将所述目标内存的使用状态切换至正常状态。
也就是说,电子设备会针对当前处于预警状态的slub内存,通过检测Sunreclaim的值和/或获取预警状态的维持时间,在预警状态的维持时间小于第一时长,且Sunreclaim的值大于泄露阈值时,或者,在预警状态的维持时间大于或等于第一时长时,将slub内存的使用状态切换至泄露状态;而在Sunreclaim的值在预警状态的维持时间达到第一时长之前,下降至小于预警阈值时,将slub内存的使用状态切换至正常状态。
其中,检测Sunreclaim的值是以第二频率定期检测的,该第二频率是与slub内存的预警状态的内存跨度对应的预设频率。此时,slub内存在预警状态等待状态变化。
这里,第一时长也称为预警最大时长,是预警状态下,第一次检测到第n+1次检查的时间间隔。例如,如果n为36,第二频率为300秒每次,则第一时长为300*36=10800秒=3小时。
其中,由达到泄漏阈值进入泄漏状态的方式适用于泄漏速度较快的情况,例如某个特定场景触发了一个连续泄漏内存的情况。此时如果没有达到泄漏阈值,而等待第一时长到达再切换状态,有可能还没等到状态变化就出现oom(out of memory),导致系统死机或重启。
由达到第一时长进入泄漏状态的方式适用于泄漏较慢的情况,或者泄漏内存不多的情况。由于预警状态下top m的镜像池是处于工作状态的,通过他们申请的内存会带来额外的内存消耗,所以此时不希望目标内存长 时间保持预警状态,因此,即使未达到泄露阈值,达到第一时长目标内存也会进入泄漏状态,即使此时泄漏可能已经停止。
应该了解的是,该实施例中,目标内存进入预警状态,即有可能存在泄漏,而泄露状态,即泄漏已发生。故,可选地,该实施例还包括:
在所述目标内存的使用状态切换至第一状态的情况下,获取所述目标内存中各个缓存池的使用信息,所述第一状态包括所述预警状态或者所述泄露状态;
根据所述各个缓存池的使用信息,确定目标缓存池;
对所述目标缓存池的镜像池添加标记,所述标记用于记录申请信息和释放信息;
其中,在所述第一状态为所述预警状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池的当前使用信息;在所述第一状态为所述泄露状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池在第二时长内变化的使用信息。
这里,各个缓存池(slab_cache)的使用信息可由系统内存信息中的slabinfo得到。其中,slabinfo包括每个缓存池的名称、设置大小、使用大小和使用次数等,故,使用信息可为缓存池的使用大小和使用次数,也可为计算使用大小和使用次数的乘积所得的缓存池的占用总量(内存占用总量)。
确定目标缓存池后,对其镜像池进行标记添加,通过标记记录申请信息和是否信息。例如,加上SLAB_STORE_USER这个标记(flag),使得镜像池能够记录每一个对象(object)的堆栈。添加标记后,每个object的内存结构如图2所示,在镜像池申请内存是会增加内存开销的,alloc/free track用来存储对应的object(分配出去实际给申请方使用的内存)的申请信息(申请堆栈信息)及释放信息(释放堆栈信息)。
当然,电子设备的目标内存第一次进入预警状态时,是没有创建任何镜像池的。所以第一次进入预警状态会对目标缓存池添加镜像标记,同时创建对应的镜像缓池。原本在被添加镜像标记后的缓存池里申请的内存会被镜像池所代理,代理分配内存的同时将申请内存的申请信息记录。
目标内存进入预警状态时,仅需获取各个缓存池的当前使用信息,如获取一次slabinfo。对应的,目标缓存池则是基于各个缓存池的使用信息,确定的泄露嫌疑最大的m个缓存池,即使用总量最大的前m个缓存池。当然,如果系统中没有实现slabinfo数据,可以自行遍历一遍每一个slab_cache(slab缓存池),筛选出占用总量最大的前m个的缓存池。
目标内存进入泄露状态时,需要获取的是各个缓存池在第二时长内变化的使用信息,如之前预警状态的使用信息和进入泄露状态时的使用信息之间的变化,或者,进入泄露状态时的使用信息和进入泄露状态后某一时间的使用信息之间的变化。对应的,目标缓存池则是基于各个缓存池的使用信息,确定的泄露嫌疑最大的m个缓存池,即增量最大的前m个缓存池。
还应该了解的是,对于目标内存进入泄露状态,可理解为目标内容发生泄露,因此,可选地,步骤103包括:
在所述目标内存的使用状态切换至泄露状态时,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
也就是说,一旦目标内存进入泄露状态,就撤销所有镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到目标存储器。
此外,该实施例中,目标内存进入泄露状态,不同场景可能具有不同的泄露程度,所以,可选地,步骤103包括:
在所述目标内存的使用状态切换至泄露状态的情况下,根据泄露增量阈值和第三时长,确定所述泄露状态为快速泄露状态或者低速泄露状态;其中,所述第三时长由所述泄露状态对应的预设频率和预设检测次数确定;
在所述泄露状态为快速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器;
在所述泄露状态为低速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并在满足预设条件的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
这里,泄露增量阈值也可理解为泄露最大增量阈值,同预警阈值和泄露阈值是根据电子设备的目标内存大小配置。在根据泄露增量阈值和第三时长,确定泄露状态为快速泄露状态或者低速泄露状态的步骤中,电子设备会针对当前处于泄露状态的slub内存,通过检测Sunreclaim的值,并结合第三时长来确定泄露状态是快速泄露状态还是低速泄露状态。
其中,检测Sunreclaim的值是第三频率定期检测的,第三频率是与slub内存的泄露状态的内存跨度对应的预设频率。第三频率可以根据项目对性能的要求做调整。例如,电子设备开机时Sunreclaim的值在300MB,正常使用过程中Sunreclaim的值会在300MB~1GB之间波动,则可以将泄露增量阈值设置为200MB。基于泄露增量阈值的变化,泄露状态的内存跨度也就是泄露增量阈值发生了变化,则第三频率会随之变化。
对于快速泄露状态的目标内存,如果继续泄漏,系统可能会很快oom,导致死机或重启,则撤销当前所有镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到目标存储器,如存储器ROM,避免重启后数据丢失。对于低速泄露的目标内存,相对于快速泄露缺少转存的急迫性,则撤销当前所有镜像池的代理分配内存权,并在满足预设要求的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到目标存储器,如存储器ROM即可。
其中,满足预设要求的时机可以是系统负载小于对应负载阈值的时机,以实现错峰使用系统资源,而且由于不会立即遍历,镜像池中正常使用的内存可能会被释放,新的内存申请也不会在镜像池中,所以镜像池中存储的堆栈信息为真实泄露的堆栈信息的概率更大。
具体的,根据所述泄露增量阈值和第三时长,确定所述泄露状态为快速泄露状态或者低速泄露状态,包括:
若达到第三时长前不可回收的内存大小大于该泄漏阈值,则当前的泄露状态为快速泄露状态;若达到第三时长前不可回收的内存大小小于或等 于泄漏阈值,则当前的泄露状态为低速泄露状态。
该实施例中,堆栈信息可以是每个object的申请信息和释放信息。当然,撤销镜像池的代理分配内存权,会清除对应的缓存池的镜像标记,目标内存将返回正常状态。
可选地,该实施例中,还包括:
在所述目标内存进入泄露状态时,若检测到所述不可回收的内存大小在所述第三时长到达之前下降至小于所述预警阈值,则撤销镜像池的代理分配内存权,返回正常状态。
由于进入泄露状态后,Sunreclaim的值在第三时长到达之前下降至小于预警阈值,即泄露实际未发生,则能够撤销镜像池的代理分配内存权,返回正常状态。
可选地,该实施例中,步骤103之后,还包括:
上传并删除日志信息,其中所述日志信息包括当前所有镜像池的堆栈信息。
具体的,可择机上传并删除日志信息,例如监控进程检测到系统空闲且连接WiFi时上传并删除日志,当然开发人员也可以随时从设备中拉取日志文件。
而上传完成后,可继续保持该状态,直至检测到Sunreclaim的值降到预警阈值之下,重新回到正常状态。
可选地,该实施例中,步骤103之后,还包括:
显示所述电子设备的重启提醒信息;
响应于用户基于所述重启提醒信息的输入,执行重启或退出重启。
这里,在当前所有镜像池的堆栈信息转存到目标存储器之后,通过显示重启提醒信息,由用户触发重启或退出重启。重启后,会重置系统,内存泄漏并不会马上给系统带来问题,一般是需要持续一段时间的泄漏才会慢慢显现出问题。举个例子,用户使用一部存在内存泄漏的手机,泄漏得比较慢的话,正常使用一周可能不会出问题,假设在连续使用两周时泄漏的内存会达到一个比较大的量,使得系统卡顿,甚至发生oom。这种情况下只要用户在发生严重卡顿或者oom前重启设备,也就是由于内存泄漏带 来的问题还没有出现就重启了系统,需要再等两周才会出现该问题。而且,重启设备会清除所创建的镜像池,也节约了一小部分内存。另外,由于已经完成了转储,重启设备并不影响异常日志的保存和上传。可有效避免游戏打到一半卡死了,或者正在编辑重要文件未保存时卡死。
具体的,该重启提醒信息可以是“异常日志采集完成,我们希望您重启一次设备,感谢您对xx的支持,本次采集的异常信息为,xxx,xxx。异常日志不涉及您任何隐私信息,是否愿意将异常日志上传给xx分析?”
当然,可以输入触发重启的用户,即积极配合提供日志信息的用户,还可进行回馈操作,例如发放优惠券、商城积分等,鼓励用户以后继续配合采集日志,分析问题。
此外,该实施例中,在目标内存的使用状态切换至预警状态时,可进行弹窗提醒或状态栏通知,提醒用户系统可能存在异常,征求用户意见,是否允许记录异常日志,在用户同意后执行后续处理,若用户未同意,则不再执行后续处理。其中,提醒用户的内容大致可以设置为:“系统提示:当前系统可能存在异常,为保证您和其他xx品牌的用户体验,我们希望能够通过你的设备采集不超过x小时(x为预警最大时长与泄漏最大时长的和)的系统内存使用信息。采集完成后会再次提醒您,为感谢您对我们创造更好的产品的支持,我们也将赠送您积分/优惠券…”。
同样的,在由其他状态重返正常状态时,还能够提醒用户本次异常日志记录完成,是否上传异常日志。
下面,结合8GB内存的电子设备,说明本申请实施例的方法的应用:
假设电子设备开机时Sunreclaim的值在300MB,正常使用过程中Sunreclaim的值会在300MB~1GB之间波动,则可以将预警阈值设置为1.5GB,泄漏阈值设置为1.8GB(即预警最大增量为300MB),泄漏增量设置为200MB。检测频率可以分别定位1200秒每次(第一频率),300秒每次(第二频率),200秒每次(第三频率)。本例中,Sunreclaim值与各个使用状态及检测频率的关系如图3所示。
系统初始化后,slub内存的状态变化如图4所示。首先,如步骤1,进入正常状态,在正常状态等待状态变化。这里,电子设备按照第一频率 定期检测系统内存信息中Sunreclaim的值,判断Sunreclaim是否大于预警阈值,是则进入预警状态,否则保持在该状态。其中,进入预警状态时,如图5所示,获取当前系统内存信息中的slabinfo,确定当前泄露嫌疑最大的m个缓存池。之后,逐个检查这m个缓存池是否有对应的镜像池,若不存在,则将当前缓存池添加镜像标记,同时创建对应的镜像池以及对该镜像池添加标记;若存在,则直接对当前缓存池的镜像池添加标记。
步骤2,进入预警状态,在预警状态等待状态变化。等待过程中,如图6所示,按照第二频率定期检测系统内存信息中Sunreclaim的值,若该Sunreclaim的值在第一时长达到之前大于泄露阈值(即预警状态的维持时间小于第一时长,且Sunreclaim的值大于泄露阈值),或者,进入预警状态的时间大于或等于第一时长(即预警状态的维持时间大于或等于第一时长)时,进入泄露状态;若该Sunreclaim的值在达到第一时长之前下降至该预警阈值之下,重返正常状态。其中,进入泄露状态时,如图7所示,获取当前系统内存信息中的slabinfo,通过确定相较于预警状态获取的slabinfo的增量,确定增量最大的m个缓存池。之后,逐个检查这m个缓存池是否有对应的镜像池,若不存在,则将当前缓存池添加镜像标记,同时创建对应的镜像池以及对该镜像池添加标记;若存在,则直接对当前缓存池的镜像池添加标记。
步骤3,进入泄露状态,在泄露状态等待状态变化。等待过程中,根据泄露状态为快速泄露状态还是低速泄露状态,进行当前所有镜像池的堆栈信息转存到存储器ROM中。具体地,如图8所示,按照第三频率定期检测系统内存信息中Sunreclaim的值,若在达到第三时长前该Sunreclaim的值降至预警阈值之下,则撤销镜像池的代理分配内存权,返回正常状态;若Sunreclaim的值在达到第三时长前大于泄露增量阈值,则当前的泄漏状态为快速泄露状态;若该Sunreclaim的值在达到第三时长前未大于该泄露增量阈值,则当前的泄漏状态为低速泄露状态。
其中,对于快速泄露状态的目标内存,撤销当前所有镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到存储 器ROM;对于低速泄露状态的目标内存,撤销当前所有镜像池的代理分配内存权,并在满足预设要求的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到存储器ROM。转存完成后,择机上传并删除日志信息。上传完成后继续保持泄露状态,直到检测到Sunreclaim的值降到预警阈值之下,重新回到正常状态。
综上,本申请实施例的方法,只在泄漏发生时进行镜像池堆栈信息转存,且只检测泄漏嫌疑最大的slab缓存池,而不是检测所有的缓存池,极大地降低了检测内存泄漏对系统带来的损耗。另外,会进行两轮缓存池的选择,对它标记并创建镜像,既考虑了整体内存用量,又考虑了异常时期的内存增量,确保不遗漏重要的可疑泄漏源。最后在慢速泄漏转储以及日志上传时机的选择上,采用择机转储/择机上传的方式,错峰使用系统资源,由于转储是在清除镜像标记之后,在镜像缓存池中正常申请的内存会被释放掉,因此延时转储能够减少日志中可疑泄漏源的数量,方便开发人员排查问题,同时还能够减少转储所需内存。
需要说明的是,本申请实施例提供的内存泄露处理方法,执行主体可以为内存泄露处理装置,或者该内存泄露处理装置中的用于执行内存泄露处理方法的控制模块。本申请实施例中以内存泄露处理装置执行内存泄露处理的方法为例,说明本申请实施例提供的内存泄露处理的装置。
如图9所示,本申请实施例的一种内存泄露处理装置,包括:
检测模块910,用于根据预设频率检测目标内存中不可回收的内存大小;
第一处理模块920,用于根据检测的结果,调整所述目标内存的使用状态;
第二处理模块930,用于在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器;
其中,所述预设频率与所述目标内存的使用状态对应的内存跨度相关联。
可选地,所述第一处理模块包括:
第一处理子模块,用于在所述目标内存当前处于正常状态,且所述不 可回收的内存大小大于预警阈值的情况下,将所述目标内存的使用状态切换至预警状态;
第二处理子模块,用于在所述目标内存当前处于正常状态,且所述不可回收的内存大小小于或等于所述预警阈值的情况下,将所述目标内存的使用状态保持在所述正常状态。
可选地,所述第一处理模块包括:
第三处理子模块,用于在所述目标内存当前处于预警状态,且满足预设条件的情况下,将所述目标内存的使用状态切换至泄露状态;其中,所述预设条件为:所述预警状态的维持时间小于第一时长,且所述不可回收的内存大小大于泄露阈值;或者,所述预警状态的维持时间大于或等于所述第一时长;
第四处理子模块,用于在所述目标内存当前处于预警状态,且所述不可回收的内存大小在所述预警状态的维持时间达到所述第一时长之前,下降至小于所述预警阈值的情况下,将所述目标内存的使用状态切换至正常状态。
可选地,所述装置还包括:
获取模块,用于在所述目标内存的使用状态切换至第一状态的情况下,获取所述目标内存中各个缓存池的使用信息,所述第一状态包括所述预警状态或者所述泄露状态;
确定模块,用于根据所述各个缓存池的使用信息,确定目标缓存池;
第三处理模块,用于对所述目标缓存池的镜像池添加标记,所述标记用于记录申请信息和释放信息;
其中,在所述第一状态为所述预警状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池的当前使用信息;在所述第一状态为所述泄露状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池在第二时长内变化的使用信息。
可选地,所述第二处理模块还用于:
在所述目标内存的使用状态切换至泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息 转存到所述目标存储器。
可选地,所述第二处理模块包括:
确定子模块,用于在所述目标内存的使用状态切换至泄露状态的情况下,根据泄露增量阈值和第三时长,确定所述泄露状态为快速泄露状态或者低速泄露状态;其中,所述第三时长由所述泄露状态对应的预设频率和预设检测次数确定;
第五处理子模块,用于在所述泄露状态为快速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器;
第六处理子模块,用于在所述泄露状态为低速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并在满足预设条件的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
可选地,所述装置还包括:
第四处理模块,用于上传并删除日志信息,其中所述日志信息包括当前所有镜像池的堆栈信息。
本申请实施例的装置,只在泄漏发生时进行镜像池堆栈信息转存,且只检测泄漏嫌疑最大的slab缓存池,而不是检测所有的缓存池,极大地降低了检测内存泄漏对系统带来的损耗。另外,会进行两轮缓存池的选择,对它标记并创建镜像,既考虑了整体内存用量,又考虑了异常时期的内存增量,确保不遗漏重要的可疑泄漏源。最后在慢速泄漏转储以及日志上传时机的选择上,采用择机转储/择机上传的方式,错峰使用系统资源,由于转储是在清除镜像标记之后,在镜像缓存池中正常申请的内存会被释放掉,因此延时转储能够减少log中可疑泄漏源的数量,方便开发人员排查问题,同时还能够减少转储所需内存。
本申请实施例中的内存泄露处理装置可以是装置,也可以是电子设备中的部件、集成电路、或芯片。该装置可以是移动电子设备,也可以为非移动电子设备。示例性的,移动电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备、可穿戴设备、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本或者个人数字助理 (personal digital assistant,PDA)等,非移动电子设备可以为服务器、网络附属存储器(Network Attached Storage,NAS)、个人计算机(personal computer,PC)、电视机(television,TV)、柜员机或者自助机等,本申请实施例不作具体限定。
本申请实施例中的内存泄露处理装置可以为具有操作系统的装置。该操作系统可以为安卓(Android)操作系统,可以为ios操作系统,还可以为其他可能的操作系统,本申请实施例不作具体限定。
本申请实施例提供的内存泄露处理装置能够实现图1至图8的方法实施例实现的各个过程,为避免重复,这里不再赘述。
可选地,如图10所示,本申请实施例还提供一种电子设备1000,包括处理器1001,存储器1002,存储在存储器1002上并可在所述处理器1001上运行的程序或指令,该程序或指令被处理器1001执行时实现上述内存泄露处理方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
需要说明的是,本申请实施例中的电子设备包括上述所述的移动电子设备和非移动电子设备。
图11为实现本申请实施例的一种电子设备的硬件结构示意图。
该电子设备1100包括但不限于:射频单元1101、网络模块1102、音频输出单元1103、输入单元1104、传感器1105、显示单元1106、用户输入单元1107、接口单元1108、存储器1109、以及处理器1110等部件。
本领域技术人员可以理解,电子设备1100还可以包括给各个部件供电的电源(比如电池),电源可以通过电源管理系统与处理器1110逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。图11中示出的电子设备结构并不构成对电子设备的限定,电子设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置,在此不再赘述。
其中,处理器1110,用于:
根据预设频率检测目标内存中不可回收的内存大小;
根据检测的结果,调整所述目标内存的使用状态;
在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器;
其中,所述预设频率与所述目标内存的使用状态对应的内存跨度相关联。
电子设备在根据预设频率检测电子设备目标内存中不可回收的内存大小之后,由检测的结果来调整该目标内存的使用状态,从而在基于该使用状态确定该目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器,无需重复多次的检测,极大地降低了检测内存泄漏对电子设备带来的损耗。
可选地,处理器1110,还用于:
在所述目标内存当前处于正常状态,且所述不可回收的内存大小大于预警阈值的情况下,将所述目标内存的使用状态切换至预警状态;
或者,在所述目标内存当前处于正常状态,且所述不可回收的内存大小小于或等于所述预警阈值的情况下,将所述目标内存的使用状态保持在所述正常状态。
可选地,处理器1110,还用于:
在所述目标内存当前处于预警状态,且满足预设条件的情况下,将所述目标内存的使用状态切换至泄露状态;其中,所述预设条件为:所述预警状态的维持时间小于第一时长,且所述不可回收的内存大小大于泄露阈值;或者,所述预警状态的维持时间大于或等于所述第一时长;
或者,在所述目标内存当前处于预警状态,且所述不可回收的内存大小在所述预警状态的维持时间达到所述第一时长之前,下降至小于所述预警阈值的情况下,将所述目标内存的使用状态切换至正常状态。
可选地,处理器1110,还用于:
在所述目标内存的使用状态切换至第一状态的情况下,获取所述目标内存中各个缓存池的使用信息,所述第一状态包括所述预警状态或者所述泄露状态;
根据所述各个缓存池的使用信息,确定目标缓存池;
对所述目标缓存池的镜像池添加标记,所述标记用于记录申请信息和 释放信息;
其中,在所述第一状态为所述预警状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池的当前使用信息;在所述第一状态为所述泄露状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池在第二时长内变化的使用信息。
可选地,处理器1110,还用于在所述目标内存的使用状态切换至泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
可选地,处理器1110,还用于:
在所述目标内存的使用状态切换至泄露状态的情况下,根据泄露增量阈值和第三时长,确定所述泄露状态为快速泄露状态或者低速泄露状态;其中,所述第三时长由所述泄露状态对应的预设频率和预设检测次数确定;
在所述泄露状态为快速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器;
在所述泄露状态为低速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并在满足预设条件的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
可选地,射频单元1101,用于上传日志信息,处理器1110,用于删除日志信息,其中所述日志信息包括当前所有镜像池的堆栈信息。
这样,检测泄漏嫌疑最大的slab缓存池,而不是检测所有的缓存池,极大地降低了检测内存泄漏对系统带来的损耗。另外,会进行两轮缓存池的选择,对它标记并创建镜像,既考虑了整体内存用量,又考虑了异常时期的内存增量,确保不遗漏重要的可疑泄漏源。最后在慢速泄漏转储以及日志上传时机的选择上,采用择机转储/择机上传的方式,错峰使用系统资源,由于转储是在清除镜像标记之后,在镜像缓存池中正常申请的内存会被释放掉,因此延时转储能够减少日志中可疑泄漏源的数量,方便开发人员排查问题,同时还能够减少转储所需内存。
应理解的是,本申请实施例中,输入单元1104可以包括图形处理器(Graphics Processing Unit,GPU)11041和麦克风11042,图形处理器11041对在视频捕获模式或图像捕获模式中由图像捕获装置(如摄像头)获得的静态图片或视频的图像数据进行处理。显示单元1106可包括显示面板11061,可以采用液晶显示器、有机发光二极管等形式来配置显示面板11061。用户输入单元1107包括触控面板11071以及其他输入设备11072。触控面板11071,也称为触摸屏。触控面板11071可包括触摸检测装置和触摸控制器两个部分。其他输入设备11072可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆,在此不再赘述。存储器1109可用于存储软件程序以及各种数据,包括但不限于应用程序和操作系统。处理器1110可集成应用处理器和调制解调处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等,调制解调处理器主要处理无线通信。可以理解的是,上述调制解调处理器也可以不集成到处理器1110中。
本申请实施例还提供一种可读存储介质,所述可读存储介质上存储有程序或指令,该程序或指令被处理器执行时实现上述内存泄露处理方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
其中,所述处理器为上述实施例中所述的电子设备中的处理器。所述可读存储介质,包括计算机可读存储介质,如计算机只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等。
本申请实施例另提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现上述内存泄露处理方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
应理解,本申请实施例提到的芯片还可以称为系统级芯片、系统芯片、芯片系统或片上系统芯片等。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他 变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。此外,需要指出的是,本申请实施方式中的方法和装置的范围不限按示出或讨论的顺序来执行功能,还可包括根据所涉及的功能按基本同时的方式或按相反的顺序来执行功能,例如,可以按不同于所描述的次序来执行所描述的方法,并且还可以添加、省去、或组合各种步骤。另外,参照某些示例所描述的特征可在其他示例中被组合。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以计算机软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台电子设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本申请的保护之内。
Claims (19)
- 一种内存泄露处理方法,包括:根据预设频率检测目标内存中不可回收的内存大小;根据检测的结果,调整所述目标内存的使用状态;在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器;其中,所述预设频率与所述目标内存的使用状态对应的内存跨度相关联。
- 根据权利要求1所述的方法,其中,所述根据检测的结果,调整所述目标内存的使用状态,包括:在所述目标内存当前处于正常状态,且所述不可回收的内存大小大于预警阈值的情况下,将所述目标内存的使用状态切换至预警状态;或者,在所述目标内存当前处于正常状态,且所述不可回收的内存大小小于或等于所述预警阈值的情况下,将所述目标内存的使用状态保持在所述正常状态。
- 根据权利要求1所述的方法,其中,所述根据检测的结果,调整所述目标内存的使用状态,包括:在所述目标内存当前处于预警状态,且满足预设条件的情况下,将所述目标内存的使用状态切换至泄露状态;其中,所述预设条件为:所述预警状态的维持时间小于第一时长,且所述不可回收的内存大小大于泄露阈值;或者,所述预警状态的维持时间大于或等于所述第一时长;或者,在所述目标内存当前处于预警状态,且所述不可回收的内存大小在所述预警状态的维持时间达到所述第一时长之前,下降至小于所述预警阈值的情况下,将所述目标内存的使用状态切换至正常状态。
- 根据权利要求1所述的方法,其中,所述根据检测的结果,调整所述目标内存的使用状态之后,还包括:在所述目标内存的使用状态切换至第一状态的情况下,获取所述目标内存中各个缓存池的使用信息,所述第一状态包括所述预警状态或者所述泄露状态;根据所述各个缓存池的使用信息,确定目标缓存池;对所述目标缓存池的镜像池添加标记,所述标记用于记录申请信息和释放信息;其中,在所述第一状态为所述预警状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池的当前使用信息;在所述第一状态为所述泄露状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池在第二时长内变化的使用信息。
- 根据权利要求4所述的方法,其中,所述在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器中,包括:在所述目标内存的使用状态切换至泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
- 根据权利要求4所述的方法,其中,所述在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器,包括:在所述目标内存的使用状态切换至泄露状态的情况下,根据泄露增量阈值和第三时长,确定所述泄露状态为快速泄露状态或者低速泄露状态;其中,所述第三时长由所述泄露状态对应的预设频率和预设检测次数确定;在所述泄露状态为快速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器;在所述泄露状态为低速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并在满足预设条件的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
- 根据权利要求1所述的方法,其中,所述在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器之后,还包括:上传并删除日志信息,其中所述日志信息包括当前所有镜像池的堆栈信息。
- 一种内存泄露处理装置,包括:检测模块,用于根据预设频率检测目标内存中不可回收的内存大小;第一处理模块,用于根据检测的结果,调整所述目标内存的使用状态;第二处理模块,用于在根据所述使用状态确定所述目标内存发生泄漏的情况下,将当前所有镜像池的堆栈信息转存到目标存储器;其中,所述预设频率与所述目标内存的使用状态对应的内存跨度相关联。
- 根据权利要求8所述的装置,其中,所述第一处理模块包括:第一处理子模块,用于在所述目标内存当前处于正常状态,且所述不可回收的内存大小大于预警阈值的情况下,将所述目标内存的使用状态切换至预警状态;第二处理子模块,用于在所述目标内存当前处于正常状态,且所述不可回收的内存大小小于或等于所述预警阈值的情况下,将所述目标内存的使用状态保持在所述正常状态。
- 根据权利要求8所述的装置,其中,所述第一处理模块包括:第三处理子模块,用于在所述目标内存当前处于预警状态,且满足预设条件的情况下,将所述目标内存的使用状态切换至泄露状态;其中,所述预设条件为:所述预警状态的维持时间小于第一时长,且所述不可回收的内存大小大于泄露阈值;或者,所述预警状态的维持时间大于或等于所述第一时长;第四处理子模块,用于在所述目标内存当前处于预警状态,且所述不可回收的内存大小在所述预警状态的维持时间达到所述第一时长之前,下降至小于所述预警阈值的情况下,将所述目标内存的使用状态切换至正常状态。
- 根据权利要求8所述的装置,还包括:获取模块,用于在所述目标内存的使用状态切换至第一状态的情况 下,获取所述目标内存中各个缓存池的使用信息,所述第一状态包括所述预警状态或者所述泄露状态;确定模块,用于根据所述各个缓存池的使用信息,确定目标缓存池;第三处理模块,用于对所述目标缓存池的镜像池添加标记,所述标记用于记录申请信息和释放信息;其中,在所述第一状态为所述预警状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池的当前使用信息;在所述第一状态为所述泄露状态的情况下,所述各个缓存池的使用信息包括所述各个缓存池在第二时长内变化的使用信息。
- 根据权利要求11所述的装置,其中,所述第二处理模块还用于:在所述目标内存的使用状态切换至泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
- 根据权利要求11所述的装置,其中,所述第二处理模块包括:确定子模块,用于在所述目标内存的使用状态切换至泄露状态的情况下,根据泄露增量阈值和第三时长,确定所述泄露状态为快速泄露状态或者低速泄露状态;其中,所述第三时长由所述泄露状态对应的预设频率和预设检测次数确定;第五处理子模块,用于在所述泄露状态为快速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并立即遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器;第六处理子模块,用于在所述泄露状态为低速泄露状态的情况下,撤销所述镜像池的代理分配内存权,并在满足预设条件的时机下遍历当前所有镜像池,将获取到的堆栈信息转存到所述目标存储器。
- 根据权利要求8所述的装置,还包括:第四处理模块,用于上传并删除日志信息,其中所述日志信息包括当前所有镜像池的堆栈信息。
- 一种电子设备,其特征在于,包括处理器,存储器及存储在所述存储器上并可在所述处理器上运行的程序或指令,所述程序或指令被所述 处理器执行时实现如权利要求1-7任一项所述的内存泄露处理方法的步骤。
- 一种电子设备,被配置为用于执行如权利要求1-7中任一项所述的内存泄露处理方法的步骤。
- 一种可读存储介质,其特征在于,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如权利要求1-7任一项所述的内存泄露处理方法的步骤。
- 一种计算机程序产品,所述计算机程序产品被处理器执行以实现如权利要求1-7中任一项所述的内存泄露处理方法的步骤。
- 一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如权利要求1-7中任一项所述的内存泄露处理方法的步骤。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110805414.1A CN113448735A (zh) | 2021-07-16 | 2021-07-16 | 内存泄露处理方法、装置和电子设备 |
CN202110805414.1 | 2021-07-16 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023284793A1 true WO2023284793A1 (zh) | 2023-01-19 |
Family
ID=77816425
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/105496 WO2023284793A1 (zh) | 2021-07-16 | 2022-07-13 | 内存泄露处理方法、装置和电子设备 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN113448735A (zh) |
WO (1) | WO2023284793A1 (zh) |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115242462A (zh) * | 2022-06-30 | 2022-10-25 | 北京华顺信安科技有限公司 | 一种数据泄露检测方法 |
CN115794045A (zh) * | 2023-02-07 | 2023-03-14 | 山东信息职业技术学院 | 基于大数据的软件开发应用数据处理方法 |
CN116578424A (zh) * | 2023-07-11 | 2023-08-11 | 麒麟软件有限公司 | 基于hmat的内存回收方法 |
CN117112193A (zh) * | 2023-04-10 | 2023-11-24 | 荣耀终端有限公司 | 内存资源管理方法及电子设备 |
CN117112192A (zh) * | 2023-04-10 | 2023-11-24 | 荣耀终端有限公司 | 内存资源管理方法及电子设备 |
CN117687820A (zh) * | 2023-06-20 | 2024-03-12 | 荣耀终端有限公司 | 内存泄露检测方法及电子设备 |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113448735A (zh) * | 2021-07-16 | 2021-09-28 | 维沃移动通信有限公司 | 内存泄露处理方法、装置和电子设备 |
CN114296986B (zh) * | 2021-12-31 | 2024-05-10 | 北京字节跳动网络技术有限公司 | 内存泄漏定位方法、装置、介质和电子设备 |
CN115794476B (zh) * | 2023-02-01 | 2023-07-18 | 荣耀终端有限公司 | 内核图形系统层内存的处理方法和终端设备 |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20090037687A1 (en) * | 2007-07-04 | 2009-02-05 | International Business Machines Corporation | Partition-based method and apparatus for diagnosing memory leak in java systems |
CN101615143A (zh) * | 2008-06-27 | 2009-12-30 | 国际商业机器公司 | 用于内存泄漏诊断的方法和装置 |
CN104991847A (zh) * | 2015-07-03 | 2015-10-21 | 厦门美图移动科技有限公司 | 一种内存泄露自动化检测方法、装置及移动终端 |
CN107346285A (zh) * | 2017-05-26 | 2017-11-14 | 郑州云海信息技术有限公司 | 一种内存泄露检测方法及装置 |
CN111143100A (zh) * | 2019-12-09 | 2020-05-12 | 北京小米移动软件有限公司 | 内存泄露检测方法、装置、设备及存储介质 |
CN111858112A (zh) * | 2019-04-26 | 2020-10-30 | 腾讯科技(深圳)有限公司 | 一种检测内存泄露的方法、客户端及服务器 |
CN113448735A (zh) * | 2021-07-16 | 2021-09-28 | 维沃移动通信有限公司 | 内存泄露处理方法、装置和电子设备 |
Family Cites Families (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102681938B (zh) * | 2012-05-15 | 2015-02-18 | 青岛海信移动通信技术股份有限公司 | 一种内存泄漏检测方法及装置 |
CN106802861A (zh) * | 2015-11-26 | 2017-06-06 | 大唐移动通信设备有限公司 | 一种检测内存泄露的方法和装置 |
CN106502880B (zh) * | 2016-09-20 | 2019-05-17 | 东软集团股份有限公司 | 一种内存泄漏调试方法及装置 |
CN109213539B (zh) * | 2016-09-27 | 2021-10-26 | 华为技术有限公司 | 一种内存回收方法及装置 |
CN109344011B (zh) * | 2018-10-22 | 2022-03-08 | 郑州云海信息技术有限公司 | 一种数据备份方法及装置 |
CN112416733B (zh) * | 2019-08-20 | 2023-12-29 | 深圳市优必选科技股份有限公司 | 一种内存检测方法、内存检测装置及智能设备 |
CN110553686A (zh) * | 2019-10-12 | 2019-12-10 | 重庆四标精密零部件制造有限公司 | 一种冷镦机运行状态监测系统 |
CN112035314B (zh) * | 2020-07-31 | 2024-04-30 | 北京达佳互联信息技术有限公司 | 内存泄漏的监控方法、装置及电子设备 |
CN112084024B (zh) * | 2020-08-31 | 2024-02-02 | 北京字节跳动网络技术有限公司 | 一种内存监控方法、装置、介质和电子设备 |
CN112162893A (zh) * | 2020-10-30 | 2021-01-01 | 新华三大数据技术有限公司 | 一种内存泄漏定位方法、装置及电子设备 |
-
2021
- 2021-07-16 CN CN202110805414.1A patent/CN113448735A/zh active Pending
-
2022
- 2022-07-13 WO PCT/CN2022/105496 patent/WO2023284793A1/zh active Application Filing
Patent Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20090037687A1 (en) * | 2007-07-04 | 2009-02-05 | International Business Machines Corporation | Partition-based method and apparatus for diagnosing memory leak in java systems |
CN101615143A (zh) * | 2008-06-27 | 2009-12-30 | 国际商业机器公司 | 用于内存泄漏诊断的方法和装置 |
CN104991847A (zh) * | 2015-07-03 | 2015-10-21 | 厦门美图移动科技有限公司 | 一种内存泄露自动化检测方法、装置及移动终端 |
CN107346285A (zh) * | 2017-05-26 | 2017-11-14 | 郑州云海信息技术有限公司 | 一种内存泄露检测方法及装置 |
CN111858112A (zh) * | 2019-04-26 | 2020-10-30 | 腾讯科技(深圳)有限公司 | 一种检测内存泄露的方法、客户端及服务器 |
CN111143100A (zh) * | 2019-12-09 | 2020-05-12 | 北京小米移动软件有限公司 | 内存泄露检测方法、装置、设备及存储介质 |
CN113448735A (zh) * | 2021-07-16 | 2021-09-28 | 维沃移动通信有限公司 | 内存泄露处理方法、装置和电子设备 |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115242462A (zh) * | 2022-06-30 | 2022-10-25 | 北京华顺信安科技有限公司 | 一种数据泄露检测方法 |
CN115794045A (zh) * | 2023-02-07 | 2023-03-14 | 山东信息职业技术学院 | 基于大数据的软件开发应用数据处理方法 |
CN117112193A (zh) * | 2023-04-10 | 2023-11-24 | 荣耀终端有限公司 | 内存资源管理方法及电子设备 |
CN117112192A (zh) * | 2023-04-10 | 2023-11-24 | 荣耀终端有限公司 | 内存资源管理方法及电子设备 |
CN117112192B (zh) * | 2023-04-10 | 2024-04-12 | 荣耀终端有限公司 | 内存资源管理方法及电子设备 |
CN117112193B (zh) * | 2023-04-10 | 2024-07-05 | 荣耀终端有限公司 | 内存资源管理方法及电子设备 |
CN117687820A (zh) * | 2023-06-20 | 2024-03-12 | 荣耀终端有限公司 | 内存泄露检测方法及电子设备 |
CN116578424A (zh) * | 2023-07-11 | 2023-08-11 | 麒麟软件有限公司 | 基于hmat的内存回收方法 |
CN116578424B (zh) * | 2023-07-11 | 2023-09-26 | 麒麟软件有限公司 | 基于hmat的内存回收方法 |
Also Published As
Publication number | Publication date |
---|---|
CN113448735A (zh) | 2021-09-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2023284793A1 (zh) | 内存泄露处理方法、装置和电子设备 | |
WO2018059027A1 (zh) | 一种内存回收方法及终端 | |
US20130031490A1 (en) | On-demand tab rehydration | |
CN108132735B (zh) | 终端与应用控制方法 | |
CN109902255B (zh) | 页面混合浏览记录生成方法、装置、设备和存储介质 | |
CN111984130B (zh) | 快捷操作方法、装置及电子设备 | |
CN103218307B (zh) | 内存管理系统和内存管理方法 | |
US9928083B2 (en) | Tab trimming | |
US11455075B2 (en) | Display method when application is exited and terminal | |
KR20120108891A (ko) | 사용자 인터페이스 커스터마이징 방법 및 그 전자 장치 | |
CN112702261B (zh) | 信息显示方法、装置和电子设备 | |
CN103870955B (zh) | 网页中数据的处理方法及装置 | |
CN107526637A (zh) | 应用程序处理方法、装置、移动终端及存储介质 | |
CN112214376A (zh) | 存储空间提示方法及装置 | |
CN115576645A (zh) | 一种虚拟处理器调度方法、装置、存储介质及电子设备 | |
US20240152439A1 (en) | Detection Method and Electronic Device | |
CN113312263B (zh) | 异常监测方法和装置 | |
EP3008631A1 (en) | Application control of embedded web content execution | |
CN106648916A (zh) | 计步器消息的上报方法及装置 | |
CN114816031B (zh) | 终端设备的省电方法、终端设备及介质 | |
WO2022161265A1 (zh) | 内容显示方法、装置、电子设备和存储介质 | |
CN106547672A (zh) | 一种电量显示的方法及终端 | |
CN111917917A (zh) | 文件备份方法、装置及电子设备 | |
CN112416202B (zh) | 消息通知方法、装置及电子设备 | |
CN115033307B (zh) | 应用启动方法、装置、存储介质及电子设备 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22841426 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 22841426 Country of ref document: EP Kind code of ref document: A1 |