CN114090465A - Memory recovery method and device - Google Patents

Memory recovery method and device Download PDF

Info

Publication number
CN114090465A
CN114090465A CN202111395891.1A CN202111395891A CN114090465A CN 114090465 A CN114090465 A CN 114090465A CN 202111395891 A CN202111395891 A CN 202111395891A CN 114090465 A CN114090465 A CN 114090465A
Authority
CN
China
Prior art keywords
memory
idle
electronic equipment
preset
preset threshold
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111395891.1A
Other languages
Chinese (zh)
Inventor
韩玉明
马晓松
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Ziguang Zhanrui Communication Technology Co Ltd
Original Assignee
Beijing Ziguang Zhanrui Communication Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Ziguang Zhanrui Communication Technology Co Ltd filed Critical Beijing Ziguang Zhanrui Communication Technology Co Ltd
Priority to CN202111395891.1A priority Critical patent/CN114090465A/en
Publication of CN114090465A publication Critical patent/CN114090465A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation 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/5016Allocation 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The embodiment of the application provides a memory recovery method and device, wherein the method comprises the following steps: when it is monitored that the electronic equipment needs to kill at least two target processes with oom _ adj values being 0, determining a current idle memory and an idle cache of the electronic equipment; if any one of the idle memory and the idle cache is greater than or equal to a first preset threshold value and both the idle memory and the idle cache are smaller than a second preset threshold value, selecting to kill only the earliest started target process; the first preset threshold is smaller than a second preset threshold, and the second preset threshold is a minimum idle memory corresponding to the electronic device when the target process with oom _ adj value of 0 needs to be killed; therefore, the method can prevent the foreground process which is started from being killed by mistake and avoid the flash back of the foreground process; and when the idle memory and the idle cache are both smaller than a first preset threshold value, killing all target processes, thereby fully releasing the memory and avoiding the system restart.

Description

Memory recovery method and device
Technical Field
The embodiment of the application relates to the technical field of computers, in particular to a memory recovery method and device.
Background
When the system has insufficient idle Memory, the electronic device kills a part of running processes to recover the Memory according to a Low Memory termination (LMK) mechanism, so as to ensure the normal running of the electronic device.
The LMK mechanism classifies all processes, each class of process has its corresponding oom _ adj value, the larger the oom _ adj value is, the less important the process is, and the system starts with the process with the highest oom _ adj value when executing the operation of killing the process. Currently, the android system uses Pressure blockage Information (PSI) to report a Memory Pressure event, and a Low Memory terminator Daemon (LMKD) process is used to implement the LMK mechanism.
After PSI triggers LMKD process, if the LMKD process needs to kill the process with oom _ adj value as 0, then since oom _ adj value of foreground process is 0, oom _ adj value is 0 in the restart process after Application program (APP) is killed, therefore, when the memory pressure is large, even if idle cache (cache) is too much, all foreground processes can still be killed, thereby easily causing mistaken killing, causing the foreground process to flash backward, and further influencing user experience.
Disclosure of Invention
The embodiment of the application provides a memory recovery method and device, which can solve the technical problem that foreground processes are easily mistakenly killed in the prior art.
In a first aspect, an embodiment of the present application provides a memory recycling method, where the method includes:
monitoring whether the electronic equipment needs to kill a target process, wherein the target process is oom _ adj is 0 in the electronic equipment;
when it is monitored that the electronic equipment needs to kill at least two target processes, determining a current idle memory and an idle cache of the electronic equipment;
if any one of the idle memory and the idle cache is greater than or equal to a first preset threshold value, and the idle memory and the idle cache are both less than a second preset threshold value, killing the earliest started target process in the at least two target processes; the first preset threshold is smaller than the second preset threshold, and the second preset threshold is a minimum idle memory corresponding to the electronic device when the target process needs to be killed;
and if the idle memory and the idle cache are both smaller than the first preset threshold value, killing the at least two target processes.
In a possible implementation manner, after determining the current free memory and free cache of the electronic device, the method further includes:
if any one of the idle memory and the idle cache is greater than or equal to the second preset threshold value and both the idle memory and the idle cache are smaller than a third preset threshold value, determining whether a first process with oom _ adj value greater than a first preset value is currently operated by the electronic device; the first preset value is not less than 0, and the third preset threshold is a minimum free memory corresponding to the electronic device when the electronic device needs to kill the first process;
killing the first process when the first process is currently operated by the electronic equipment;
and when the first process is not operated in the electronic equipment currently, determining whether to kill the earliest started target process in the at least two target processes according to a preset judgment condition.
In a possible implementation manner, the determining whether to kill an earliest started target process of the at least two target processes according to a preset judgment condition includes:
determining whether critical events exist in the PSI generated by the electronic equipment and the usage amount of a SWAP partition in the electronic equipment;
and when a critical event exists in the PSI generated by the electronic equipment and the usage of the SWAP partition is greater than a preset usage threshold, killing the target process which is started earliest in the at least two target processes.
In a possible implementation manner, after determining the current free memory and free cache of the electronic device, the method further includes:
if any one of the idle memory and the idle cache is greater than or equal to the third preset threshold, killing a second process of which the oom _ adj value of the electronic equipment currently running is greater than a second preset value; wherein the second preset value is greater than the first preset value.
In one possible embodiment, the monitoring whether the electronic device needs to kill the target process includes:
determining that the electronic device needs to kill a target process when at least one of the following detection items is monitored to be met:
the usage amount of the SWAP partition in the electronic equipment is larger than a preset usage amount threshold;
the current page jolting degree of the electronic equipment is larger than a preset page jolting degree threshold value;
a critical event exists in the PSI generated by the electronic equipment;
and the current idle memory in the electronic equipment is smaller than a preset memory water line value.
In a second aspect, an embodiment of the present application provides a memory recycling device, where the device includes:
the monitoring module is used for monitoring whether the electronic equipment needs to kill a target process, wherein the target process is oom _ adj in the electronic equipment and is 0;
the processing module is used for determining the current idle memory and idle cache of the electronic equipment when monitoring that the electronic equipment needs to kill at least two target processes;
the processing module is further configured to kill the earliest started target process of the at least two target processes if any one of the idle memory and the idle cache is greater than or equal to a first preset threshold and both the idle memory and the idle cache are smaller than a second preset threshold; the first preset threshold is smaller than the second preset threshold, and the second preset threshold is a minimum idle memory corresponding to the electronic device when the target process needs to be killed;
the processing module is further configured to kill the at least two target processes if the idle memory and the idle cache are both smaller than the first preset threshold.
In one possible implementation, the processing module is further configured to:
if any one of the idle memory and the idle cache is greater than or equal to the second preset threshold value and both the idle memory and the idle cache are smaller than a third preset threshold value, determining whether a first process with oom _ adj value greater than a first preset value is currently operated by the electronic device; the first preset value is not less than 0, and the third preset threshold is a minimum free memory corresponding to the electronic device when the electronic device needs to kill the first process;
killing the first process when the first process is currently operated by the electronic equipment;
and when the first process is not operated in the electronic equipment currently, determining whether to kill the earliest started target process in the at least two target processes according to a preset judgment condition.
In a possible implementation, the processing module is specifically configured to:
determining whether critical events exist in the PSI generated by the electronic equipment and the usage amount of a SWAP partition in the electronic equipment;
and when a critical event exists in the PSI generated by the electronic equipment and the usage of the SWAP partition is greater than a preset usage threshold, killing the earliest started target process in the at least two target processes.
In a possible implementation, the processing module is further configured to:
if any one of the idle memory and the idle cache is greater than or equal to the third preset threshold, killing a second process of which the oom _ adj value currently running by the electronic equipment is greater than a second preset value; wherein the second preset value is greater than the first preset value.
In one possible embodiment, the monitoring module is configured to:
determining that the electronic device needs to kill a target process when at least one of the following detection items is monitored to be met:
the usage amount of the SWAP partition in the electronic equipment is larger than a preset usage amount threshold;
the current page jolting degree of the electronic equipment is larger than a preset page jolting degree threshold value;
a critical event exists in the PSI generated by the electronic equipment;
and the current idle memory in the electronic equipment is smaller than a preset memory waterline value.
In a third aspect, an embodiment of the present application provides an electronic device, including: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executes computer-executable instructions stored by the memory such that the at least one processor performs the memory reclamation method as provided in the first aspect.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer executing instruction is stored in the computer-readable storage medium, and when a processor executes the computer executing instruction, the memory recycling method according to the first aspect is implemented.
In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the memory recycling method as provided in the first aspect is implemented.
According to the memory recovery method and the memory recovery device provided by the embodiment of the application, when it is monitored that the electronic device needs to kill at least two target processes with oom _ adj values of 0, if any one of a current idle memory and an idle cache of the electronic device is greater than or equal to the first preset threshold and both the idle memory and the idle cache are smaller than the second preset threshold, only the earliest started target process is selected to be killed, so that a foreground process can be prevented from being killed mistakenly, and the foreground process is prevented from being flashed back; when the idle memory and the idle cache are both smaller than a first preset threshold value, all target processes are killed, so that the memory can be fully released, the system is prevented from restarting, and the user experience is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments of the present application or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without inventive exercise.
Fig. 1 is a first flowchart illustrating a memory recycling method according to an embodiment of the present disclosure;
fig. 2 is a second flowchart illustrating a memory recovery method according to an embodiment of the present disclosure;
fig. 3 is a third schematic flowchart of a memory recovery method according to an embodiment of the present disclosure;
fig. 4 is a schematic diagram of program modules of a memory recovery apparatus according to an embodiment of the present disclosure;
fig. 5 is a schematic hardware structure diagram of an electronic device provided in an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application. In addition, while the disclosure herein has been presented in terms of one or more exemplary examples, it should be appreciated that aspects of the disclosure may be implemented solely as a complete embodiment.
It should be noted that the brief descriptions of the terms in the present application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of the present application. These terms should be understood in their ordinary and customary meaning unless otherwise indicated.
The terms "first," "second," and the like in the description and claims of this application and in the foregoing drawings are used for distinguishing between similar or analogous objects or entities and are not necessarily intended to limit the order or sequence unless otherwise indicated. It is to be understood that the terms so used are interchangeable under appropriate circumstances such that the embodiments described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein.
Furthermore, the terms "comprises" and "comprising," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a product or device that comprises a list of elements is not necessarily limited to those elements explicitly listed, but may include other elements not expressly listed or inherent to such product or device.
The term "module," as used herein, refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and/or software code that is capable of performing the functionality associated with that element.
The embodiment of the application can be applied to various types of electronic devices, such as a smart phone, a tablet computer (pad), a smart watch, a smart television, a set-top box, and the like, and the embodiment of the application is not limited thereto.
At present, when the system is insufficient in idle memory, electronic equipment based on an Android (Android) system can kill a (kill) part of running processes to recover the memory according to an LMK mechanism, and then normal running of the electronic equipment is guaranteed.
In the LMK mechanism, all processes are classified, and for each class of process there is its corresponding oom _ adj value, the greater the oom _ adj value the less important the process is.
The system, when performing operations to kill processes, will start with the process with the highest oom _ adj value. Currently, the android system uses PSI to report memory pressure events, and the LMK mechanism is implemented by the LMKD process.
For better understanding of the embodiment of the present application, referring to fig. 1, fig. 1 is a first schematic flow chart of a memory recovery method provided in the embodiment of the present application; in some embodiments, after the PSI event triggers the LMKD process, the LMKD process collects current operation data of the electronic device, and determines whether memory recovery is required according to the collected operation data; if yes, killing the selected process according to an LMK mechanism; if not, continuing to collect the current operation data of the electronic equipment.
In some embodiments, if the LMKD process needs to kill a process with oom _ adj value of 0, since the oom _ adj value of the foreground process is 0, and the oom _ adj value of the Application program (APP) is also 0 in the process of restarting after being killed, when the memory pressure is high, all foreground processes can be killed even if the idle cache (cache) is large, so that false killing is easily caused, the foreground processes are caused to flash back, and the user experience is further influenced.
In view of the above technical problems, an embodiment of the present application provides a memory recycling method, where a first threshold and a second threshold are set, where the second threshold is a minimum idle memory corresponding to a process whose oom _ adj value is 0 that needs to be killed by an electronic device, and the first preset threshold is smaller than the second preset threshold; when it is monitored that the electronic device needs to kill at least two target processes with oom _ adj value being 0, if any one of the current idle memory and the idle cache of the electronic device is greater than or equal to the first threshold and both the idle memory and the idle cache are smaller than the second threshold, selecting to kill only the target process which is started earliest, so that the foreground process which is being started can be prevented from being killed mistakenly, and the foreground process is prevented from being flashed backwards; when the idle memory and the idle cache are both smaller than the first threshold value, all target processes are killed, so that the memory can be fully released, the system is prevented from restarting, and the user experience is improved. The following examples are given for illustrative purposes.
Referring to fig. 2, fig. 2 is a second flowchart illustrating a memory reclamation method according to an embodiment of the present disclosure, in a feasible implementation manner, the memory reclamation method includes:
s201, monitoring whether the electronic equipment needs to kill oom _ adj 0 target processes.
In one possible embodiment, at least one of the following tests in the electronic device may be monitored to determine whether the electronic device needs to kill the target process: the usage amount of the SWAP partition in the electronic device, the current page thrashing degree of the electronic device, the PSI generated by the electronic device, and the current free memory in the electronic device.
When at least one of the detection items or the combination of the two detection items is monitored to meet the following conditions, it can be determined that the electronic device needs to kill oom processes with the adj value being 0: the usage amount of the SWAP partition in the electronic equipment is larger than a preset usage amount threshold, the current page jolt degree of the electronic equipment is larger than a preset page jolt degree threshold, a critical event exists in PSI generated by the electronic equipment, and the current free memory in the electronic equipment is smaller than a preset memory waterline value.
S202, when it is monitored that the electronic equipment needs to kill at least two target processes, determining the current idle memory and idle cache of the electronic equipment.
In a possible implementation manner, when it is determined that the electronic device needs to kill oom _ adj of 0, the number of oom _ adj of 0 processes in the electronic device is determined, and when the electronic device has only one process oom _ adj of 0, the process is killed directly; when the electronic device has two or more processes with oom _ adj being 0, it is necessary to determine the current free memory and free buffer of the electronic device.
S203, determining whether the free memory and the free cache are both smaller than a first preset threshold value. If yes, executing S204; if not, go to S205.
In the embodiment of the application, the minimum free memory corresponding to the electronic device that needs to kill the process with oom _ adj value being 0 may be set as a second preset threshold minfree [2] in advance; in addition, a first preset threshold value minfree [1] is set, minfree [1] < minfree [2 ].
In one possible embodiment, minfree [1] ═ minfree [2 ]. 80%.
And S204, killing all target processes. Execution returns to S201.
And S205, determining whether the idle memory and the idle cache are both smaller than a second preset threshold, if so, executing S206, and if not, returning to execute S201.
S206, killing the target process started earliest. Execution returns to S201.
In the embodiment of the application, when the idle memory and the idle cache are lower than minfree [1], a target process started earliest is killed, so that the flash back of a foreground process can be avoided.
It can be understood that, when the system idle memory and idle cache are both lower than minfree [1], but all the detection items do not satisfy the condition, the system will be restarted because there is no memory. To avoid this problem, when both the system idle memory and idle cache are below minfree [1], all target processes are killed, thereby releasing the memory sufficiently, thereby avoiding system restart.
According to the memory recovery method provided by the embodiment of the application, when it is monitored that the electronic device needs to kill at least two target processes with oom _ adj values of 0, if any one of a current idle memory and an idle cache of the electronic device is greater than or equal to the first preset threshold and both the idle memory and the idle cache are smaller than the second preset threshold, only the target process which is started earliest is selected to be killed, so that a foreground process which is being started can be prevented from being killed by mistake, and the foreground process is prevented from being flashed back; when the idle memory and the idle cache are both smaller than a first preset threshold value, all target processes are killed, so that the memory can be fully released, the system is prevented from restarting, and the user experience is improved.
Based on the content described in the foregoing embodiment, referring to fig. 3, fig. 3 is a third schematic flow chart of a memory reclamation method provided in the embodiment of the present application, and in a feasible implementation, the memory reclamation method includes:
s301, whether the electronic equipment needs to kill oom _ adj 0 target processes is monitored.
S302, when it is monitored that the electronic equipment needs to kill at least two target processes, determining a current idle memory and an idle cache of the electronic equipment.
In a possible implementation manner, when it is determined that the electronic device needs to kill oom _ adj of 0, the number of oom _ adj of 0 processes in the electronic device is determined, and when the electronic device has only one process oom _ adj of 0, the process is killed directly; when the electronic device has two or more processes with oom _ adj being 0, it is necessary to determine the current free memory and free buffer of the electronic device.
S303, determining whether the idle memory and the idle cache are both smaller than a first preset threshold value. If yes, go to S304; if not, S305 is executed.
In the embodiment of the application, the minimum free memory corresponding to the electronic device that needs to kill the process with oom _ adj value being 0 may be set as a second preset threshold minfree [2] in advance; in addition, a first preset threshold value minfree [1] is set, minfree [1] < minfree [2 ].
In one possible embodiment, minfree [1] ═ minfree [2 ]. 80%.
S304, all target processes are killed. Execution returns to S301.
S305, determining whether both the idle memory and the idle cache are smaller than a second preset threshold, if yes, executing S306, and if no, executing S307.
S306, killing the target process started earliest. Execution returns to S301.
S307, determine whether both the free memory and the free cache are smaller than a third preset threshold? If yes, go to S308, otherwise go to S3012.
S308, whether the electronic equipment runs a first process with oom _ adj value being larger than a first preset value is determined. If so, S309 is executed, and if not, S3010 is executed.
In the embodiment of the present application, a third preset threshold minfree [3] may be preset.
Wherein, the first preset value is not less than 0, the third preset threshold minfree [3] is the minimum free memory corresponding to the electronic device when the first process needs to be killed.
Illustratively, when the first preset value is 100, the third preset threshold minfree [3] is a minimum free memory corresponding to the time when the electronic device needs to kill a process with a value of oom _ adj being 100.
S309, killing the first process.
And S3010, determining whether the electronic equipment meets a preset condition. If so, S3011 is executed, otherwise, S301 is returned to.
S3011, the target process started earliest is killed. Execution returns to S301.
In the embodiment of the application, whether the target process started earliest in the at least two target processes is killed or not can be determined according to the preset judgment condition.
Optionally, determining whether a critical criticality event exists in the PSI generated by the electronic device, and the usage amount of SWAP partitions in the electronic device; when there is critical event in PSI generated by electronic device and the usage of SWAP partition is larger than the preset usage threshold, killing oom _ adj one target process with value 0 which is started earliest in the target processes.
S3012, killing a second process of which the currently running oom _ adj value of the electronic equipment is larger than a second preset value.
Wherein, the second preset value is larger than the first preset value.
For example, when the first preset value is 100, the second preset value may be 200.
According to the memory recovery method and the memory recovery equipment, when the idle memory and the idle cache of the system are lower than minfree [3], the first process with the oom _ adj value larger than the first preset value is killed, so that the foreground process can be prevented from being killed when the idle memory and the idle cache are more; if the electronic device does not run the first process currently, when the swap usage reaches a threshold and the PSI reports a critical event, the process which is started earliest oom _ adj is 0 is selected again to be killed, so that the memory is released to avoid system restart.
Based on the content described in the foregoing embodiments, an embodiment of the present application further provides a memory recycling device, which is applied to an electronic device. Referring to fig. 4, fig. 4 is a schematic diagram of program modules of a memory recovery apparatus provided in an embodiment of the present application, where the memory recovery apparatus includes:
the monitoring module 401 is configured to monitor whether the electronic device needs to kill a target process, where the target process is oom _ adj is 0 in the electronic device.
The processing module 402 is configured to determine a current idle memory and an idle cache of the electronic device when it is monitored that the electronic device needs to kill at least two target processes.
The processing module 402 is further configured to kill the earliest started target process of the at least two target processes if any one of the idle memory and the idle cache is greater than or equal to a first preset threshold and both the idle memory and the idle cache are smaller than a second preset threshold; the first preset threshold is smaller than a second preset threshold, and the second preset threshold is a minimum idle memory corresponding to the electronic device when the target process needs to be killed.
The processing module 402 is further configured to kill the at least two target processes if both the idle memory and the idle cache are smaller than a first preset threshold.
In the memory recovery device provided in the embodiment of the present application, when it is monitored that the electronic device needs to kill at least two target processes with oom _ adj values being 0, if any one of a current idle memory and an idle cache of the electronic device is greater than or equal to the first preset threshold and both the idle memory and the idle cache are smaller than the second preset threshold, only the target process which is started earliest is selected to be killed, so that a foreground process which is being started can be prevented from being killed by mistake, and a foreground process is prevented from being flashed back; when the idle memory and the idle cache are both smaller than a first preset threshold value, all target processes are killed, so that the memory can be fully released, the system is prevented from restarting, and the user experience is improved.
In one possible implementation, the processing module 402 is further configured to:
if any one of the idle memory and the idle cache is greater than or equal to a second preset threshold value and both the idle memory and the idle cache are smaller than a third preset threshold value, determining whether the electronic equipment currently runs a first process with oom _ adj value greater than a first preset value; the first preset value is not less than 0, and the third preset threshold value is a minimum idle memory corresponding to the electronic device when the first process needs to be killed.
When the first process is operated in the electronic equipment currently, killing the first process; when the electronic equipment does not run with the first process at present, whether the target process started earliest in the at least two target processes is killed or not is determined according to a preset judgment condition.
In a possible implementation, the processing module 402 is specifically configured to:
determining whether critical events exist in the PSI generated by the electronic equipment and the usage amount of the SWAP partition in the electronic equipment.
And when the critical event exists in the PSI generated by the electronic equipment and the usage of the SWAP partition is greater than a preset usage threshold, killing the earliest started target process in at least two target processes.
In one possible implementation, the processing module 402 is further configured to:
if any one of the idle memory and the idle cache is greater than or equal to a third preset threshold value, killing a second process of which the oom _ adj value of the current operation of the electronic equipment is greater than a second preset value; wherein the second preset value is greater than the first preset value.
In one possible embodiment, the monitoring module 401 is configured to:
determining that the electronic device needs to kill the target process when at least one of the following detection items is monitored to be met:
the usage amount of the SWAP partition in the electronic equipment is larger than a preset usage amount threshold;
the current page jolting degree of the electronic equipment is larger than a preset page jolting degree threshold value;
a critical event exists in the PSI generated by the electronic equipment;
the current free memory in the electronic equipment is smaller than a preset memory water line value.
It should be noted that, in the embodiment of the present application, details of the specific execution of the monitoring module 401 and the processing module 402 may refer to each step of the memory recovery method described in the embodiment shown in fig. 1 to fig. 3, which are not described herein again.
Further, based on the content described in the foregoing embodiments, an electronic device is also provided in the embodiments of the present application, where the electronic device includes at least one processor and a memory; wherein the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory to implement the steps of the memory recovery method described in the above embodiments, which is not described herein again.
For better understanding of the embodiment of the present application, referring to fig. 5, fig. 5 is a schematic diagram of a hardware structure of an electronic device according to the embodiment of the present application.
As shown in fig. 5, the electronic apparatus 50 of the present embodiment includes: a processor 501 and a memory 502; wherein:
a memory 502 for storing computer-executable instructions;
the processor 501 is configured to execute the computer-executed instructions stored in the memory to implement the steps of the memory reclamation method described in the foregoing embodiments, which may be specifically referred to in the related description of the foregoing method embodiments.
Alternatively, the memory 502 may be separate or integrated with the processor 501.
When the memory 502 is provided separately, the device further comprises a bus 503 for connecting said memory 502 and the processor 501.
Further, based on the content described in the foregoing embodiments, an embodiment of the present application further provides a computer-readable storage medium, where a computer-executable instruction is stored in the computer-readable storage medium, and when a processor executes the computer-executable instruction, each step of the memory recovery method described in the foregoing embodiments may be implemented, which may specifically refer to the relevant description in the foregoing method embodiments.
Further, based on the content described in the foregoing embodiments, an embodiment of the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, each step of the memory reclamation method described in the foregoing embodiments may be implemented, specifically, refer to the relevant description in the foregoing method embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described device embodiments are merely illustrative, and for example, the division of the modules is only one logical division, and other divisions may be realized in practice, for example, a plurality of modules may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or modules, and may be in an electrical, mechanical or other form.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present application may be integrated into one processing unit, or each module may exist alone physically, or two or more modules are integrated into one unit. The module integrated unit can be realized in a hardware form, and can also be realized in a form of hardware and a software functional unit.
The integrated module implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute some steps of the methods according to the embodiments of the present application.
It should be understood that the Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of a method disclosed in the incorporated application may be directly implemented by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
The memory may comprise a high-speed RAM memory, and may further comprise a non-volatile storage NVM, such as at least one disk memory, and may also be a usb disk, a removable hard disk, a read-only memory, a magnetic or optical disk, etc.
The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended ISA (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, the buses in the figures of the present application are not limited to only one bus or one type of bus.
The storage medium may be implemented by any type or combination of volatile or non-volatile memory devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks. A storage media may be any available media that can be accessed by a general purpose or special purpose computer.
An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. Of course, the storage medium may also be integral to the processor. The processor and the storage medium may reside in an Application Specific Integrated Circuits (ASIC). Of course, the processor and the storage medium may reside as discrete components in an electronic device or host device.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.

Claims (13)

1. A method for memory reclamation, the method comprising:
monitoring whether the electronic equipment needs to kill a target process, wherein the target process is a process with an insufficient memory adjustment parameter oom _ adj being 0 in the electronic equipment;
when it is monitored that the electronic equipment needs to kill at least two target processes, determining a current idle memory and an idle cache of the electronic equipment;
if any one of the idle memory and the idle cache is greater than or equal to a first preset threshold value, and the idle memory and the idle cache are both less than a second preset threshold value, killing the earliest started target process in the at least two target processes; the first preset threshold is smaller than the second preset threshold, and the second preset threshold is a minimum idle memory corresponding to the electronic device when the target process needs to be killed;
and if the idle memory and the idle cache are both smaller than the first preset threshold, killing the at least two target processes.
2. The method of claim 1, wherein after determining the current free memory and free cache of the electronic device, further comprising:
if any one of the idle memory and the idle cache is greater than or equal to the second preset threshold value and both the idle memory and the idle cache are smaller than a third preset threshold value, determining whether a first process with oom _ adj value greater than a first preset value is currently operated by the electronic device; the first preset value is not less than 0, and the third preset threshold is a minimum free memory corresponding to the electronic device when the electronic device needs to kill the first process;
killing the first process when the first process is operated in the electronic equipment currently;
and when the first process is not operated in the electronic equipment currently, determining whether to kill the earliest started target process in the at least two target processes according to a preset judgment condition.
3. The method according to claim 2, wherein the determining whether to kill an earliest started target process of the at least two target processes according to a preset judgment condition comprises:
determining whether a critical criticality event exists in pressure blockage information (PSI) generated by the electronic equipment and the usage amount of a SWAP SWAP partition in the electronic equipment;
and when a critical event exists in the PSI generated by the electronic equipment and the usage of the SWAP partition is greater than a preset usage threshold, killing the earliest started target process in the at least two target processes.
4. The method of claim 2, wherein after determining the current free memory and free cache of the electronic device, further comprising:
if any one of the idle memory and the idle cache is greater than or equal to the third preset threshold, killing a second process of which the oom _ adj value of the electronic equipment currently running is greater than a second preset value; wherein the second preset value is greater than the first preset value.
5. The method of any one of claims 1 to 4, wherein the monitoring whether the electronic device needs to kill the target process comprises:
determining that the electronic device needs to kill a target process when at least one of the following detection items is monitored to be met:
the usage amount of the SWAP partition in the electronic equipment is larger than a preset usage amount threshold;
the current page jolting degree of the electronic equipment is larger than a preset page jolting degree threshold value;
a critical event exists in the PSI generated by the electronic equipment;
and the current idle memory in the electronic equipment is smaller than a preset memory water line value.
6. A memory reclamation apparatus, the apparatus comprising:
the system comprises a monitoring module, a processing module and a processing module, wherein the monitoring module is used for monitoring whether the electronic equipment needs to kill a target process, and the target process is a process with an insufficient memory adjustment parameter oom _ adj of the electronic equipment being 0;
the processing module is used for determining the current idle memory and idle cache of the electronic equipment when monitoring that the electronic equipment needs to kill at least two target processes;
the processing module is further configured to kill the earliest started target process of the at least two target processes if any one of the idle memory and the idle cache is greater than or equal to a first preset threshold and both the idle memory and the idle cache are smaller than a second preset threshold; the first preset threshold is smaller than the second preset threshold, and the second preset threshold is a minimum idle memory corresponding to the electronic device when the target process needs to be killed;
the processing module is further configured to kill the at least two target processes if the idle memory and the idle cache are both smaller than the first preset threshold.
7. The apparatus of claim 6, wherein the processing module is further configured to:
if any one of the idle memory and the idle cache is greater than or equal to the second preset threshold value and both the idle memory and the idle cache are smaller than a third preset threshold value, determining whether a first process with oom _ adj value greater than a first preset value is currently operated by the electronic device; the first preset value is not less than 0, and the third preset threshold is a minimum free memory corresponding to the electronic device when the electronic device needs to kill the first process;
killing the first process when the first process is currently operated by the electronic equipment;
and when the first process is not operated in the electronic equipment currently, determining whether to kill the earliest started target process in the at least two target processes according to a preset judgment condition.
8. The apparatus according to claim 7, wherein the processing module is specifically configured to:
determining whether a critical criticality event exists in pressure blockage information (PSI) generated by the electronic equipment and the usage amount of a SWAP SWAP partition in the electronic equipment;
and when a critical event exists in the PSI generated by the electronic equipment and the usage of the SWAP partition is greater than a preset usage threshold, killing the earliest started target process in the at least two target processes.
9. The apparatus of claim 7, wherein the processing module is further configured to:
if any one of the idle memory and the idle cache is greater than or equal to the third preset threshold, killing a second process of which the oom _ adj value of the electronic equipment currently running is greater than a second preset value; wherein the second preset value is greater than the first preset value.
10. The apparatus of any one of claims 6 to 9, wherein the monitoring module is configured to:
determining that the electronic device needs to kill a target process when at least one of the following detection items is monitored to be met:
the usage amount of the SWAP partition in the electronic equipment is larger than a preset usage amount threshold value;
the current page jolting degree of the electronic equipment is larger than a preset page jolting degree threshold value;
a critical event exists in the PSI generated by the electronic equipment;
and the current idle memory in the electronic equipment is smaller than a preset memory water line value.
11. An electronic device, comprising: at least one processor and memory;
the memory stores computer-executable instructions;
the at least one processor executing the computer-executable instructions stored by the memory causes the at least one processor to perform the memory reclamation method as recited in any one of claims 1 to 5.
12. A computer-readable storage medium having computer-executable instructions stored thereon, which when executed by a processor, implement the memory reclamation method as recited in any one of claims 1 to 5.
13. A computer program product comprising a computer program, wherein the computer program, when executed by a processor, implements the memory reclamation method of any of claims 1 to 5.
CN202111395891.1A 2021-11-23 2021-11-23 Memory recovery method and device Pending CN114090465A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111395891.1A CN114090465A (en) 2021-11-23 2021-11-23 Memory recovery method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111395891.1A CN114090465A (en) 2021-11-23 2021-11-23 Memory recovery method and device

Publications (1)

Publication Number Publication Date
CN114090465A true CN114090465A (en) 2022-02-25

Family

ID=80303269

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111395891.1A Pending CN114090465A (en) 2021-11-23 2021-11-23 Memory recovery method and device

Country Status (1)

Country Link
CN (1) CN114090465A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737356A (en) * 2022-09-26 2023-09-12 荣耀终端有限公司 Memory management method and electronic equipment
CN117971712A (en) * 2024-03-29 2024-05-03 阿里云计算有限公司 Memory recycling method, memory recycling device, electronic equipment, storage medium and program product

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116737356A (en) * 2022-09-26 2023-09-12 荣耀终端有限公司 Memory management method and electronic equipment
CN117971712A (en) * 2024-03-29 2024-05-03 阿里云计算有限公司 Memory recycling method, memory recycling device, electronic equipment, storage medium and program product

Similar Documents

Publication Publication Date Title
CN114090465A (en) Memory recovery method and device
CN108874624B (en) Server, method for monitoring Java process and storage medium
CN111258921B (en) Garbage memory recycling method and device, electronic equipment and storage medium
CN111338796B (en) Application memory optimization method and device, terminal equipment and readable storage medium
CN110008016B (en) Anonymous page management method and device, terminal device and readable storage medium
CN110955598B (en) Breakpoint processing method and device for kernel mode program
CN109582332B (en) System upgrading method and device for Internet camera
CN104216771A (en) Restarting method and device for software program
CN116340053A (en) Log processing method, device, computer equipment and medium for system crash
CN106258006A (en) Use status information recovery system
CN113617031A (en) Method and device for replacing role equipment in game and electronic equipment
CN110083493A (en) A kind of embedded system failure self-recovery method, terminal device and storage medium
CN112395121A (en) Drive loading processing method and device, storage medium and computer equipment
CN115421960A (en) UE memory fault recovery method, device, electronic equipment and medium
CN115168921A (en) Lossless deletion management device suitable for multi-solid-state hard disk system
CN115098342A (en) System log collection method, system, terminal and storage medium
CN116009969A (en) Application program control method, device, electronic equipment, chip and storage medium
CN111694713B (en) Application operation optimization method and device and computer readable storage medium
CN116243957B (en) Function extension control method, device and system of SSD
CN113157513B (en) Heap memory damage detection method and device, electronic equipment and storage medium
CN117171062A (en) Memory optimization method, electronic equipment and storage medium
CN117271134A (en) Memory management method and device and electronic equipment
CN114003461A (en) Server failure prediction method, system, terminal and storage medium
CN112817769A (en) Game resource dynamic caching method and device, storage medium and electronic equipment
CN115509801A (en) Method, device, processor and storage medium for detecting equipment state

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination