CN110532197B - Memory recovery method and device, electronic equipment and storage medium - Google Patents

Memory recovery method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN110532197B
CN110532197B CN201910815705.1A CN201910815705A CN110532197B CN 110532197 B CN110532197 B CN 110532197B CN 201910815705 A CN201910815705 A CN 201910815705A CN 110532197 B CN110532197 B CN 110532197B
Authority
CN
China
Prior art keywords
memory
preset
target
page
target process
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.)
Active
Application number
CN201910815705.1A
Other languages
Chinese (zh)
Other versions
CN110532197A (en
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.)
Oppo Chongqing Intelligent Technology Co Ltd
Original Assignee
Oppo Chongqing Intelligent 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 Oppo Chongqing Intelligent Technology Co Ltd filed Critical Oppo Chongqing Intelligent Technology Co Ltd
Priority to CN201910815705.1A priority Critical patent/CN110532197B/en
Publication of CN110532197A publication Critical patent/CN110532197A/en
Application granted granted Critical
Publication of CN110532197B publication Critical patent/CN110532197B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44594Unloading
    • 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)
  • Retry When Errors Occur (AREA)

Abstract

The disclosed embodiment relates to a memory recovery method and device, an electronic device and a storage medium, and relates to the technical field of computers, wherein the method comprises the following steps: if the memory allocation operation on the preset process is detected to fail, triggering a low memory management service to perform cleaning operation on the target process; and if the cleaning operation is detected to be finished, performing recovery operation on the memory page of the target process, and continuing performing memory allocation operation on the preset process through the recovery operation. The technical scheme disclosed by the invention can timely recover the memory, relieve the situation of memory shortage and improve the system performance.

Description

Memory recovery method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a memory recovery method, a memory recovery device, an electronic device, and a computer-readable storage medium.
Background
The memory space of the android mobile phone is limited, and after the mobile phone is used for a period of time, a background can accumulate more processes, so that a certain memory space can be occupied. If the system memory is in shortage and the memory allocation request of the application in use can not be met, memory recovery is carried out, and if the memory recovery can not be met and the available memory is lower than the preset value, the low memory management service is started to select the process which is not used recently to clean.
In the related art, the memory occupation of the low memory management service is released when the process quits destruction after the low memory management service cleans the process. However, in some scenarios, some resources are required before the process is destroyed, and the process may be slow or even impossible. In the above manner, the memory release efficiency is low and the memory release reliability is low, and the situation of memory shortage will not be alleviated, which affects the system stability.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present disclosure, and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
The present disclosure is directed to a memory recycling method and apparatus, an electronic device, and a storage medium, which overcome, at least to some extent, the problem that a memory cannot be recycled due to the limitations and disadvantages of the related art.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to an aspect of the present disclosure, there is provided a memory recycling method, including: if the memory allocation operation on the preset process is detected to fail, triggering a low memory management service to perform cleaning operation on the target process; and if the cleaning operation is detected to be finished, performing recovery operation on the memory page of the target process, and continuing performing memory allocation operation on the preset process through the recovery operation.
According to an aspect of the present disclosure, there is provided a memory recycling apparatus including: the process cleaning module is used for triggering the low memory management service to perform cleaning operation on the target process if the failure of the memory allocation operation on the preset process is detected; and the page recycling module is used for recycling the memory page of the target process if the cleaning operation is detected to be finished, and continuing to perform memory allocation operation on the preset process through the recycling operation.
According to an aspect of the present disclosure, there is provided an electronic device including: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform any of the memory reclamation methods described above via execution of the executable instructions.
According to an aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a memory reclamation method as recited in any one of the above.
In the memory recovery method, the memory recovery device, the electronic device, and the computer-readable storage medium provided in the embodiments of the present disclosure, when a memory allocation operation on a preset process fails, a target process is cleaned, and a memory page of the target process is recovered when the cleaning operation is finished. On one hand, the resource information in the preset process is not required to be automatically released, but the target process is automatically exited by recovering the memory page of the target process, so that the memory is allocated to the preset process, the operations of exiting the target process and allocating the memory to the preset process are completed, the situation that the memory cannot be recovered due to dead circulation caused by mutual waiting and limiting of the preset process and the target process is avoided, the memory recovery and memory allocation efficiency is improved, and the memory recovery effectiveness and the memory release reliability are improved. On the other hand, the memory page of the target process is directly recycled, and the memory allocation is continuously performed on the preset process according to the recycling operation, so that the process to be cleaned can be accurately determined in the memory allocation process, and the accuracy of the memory optimization is improved. On the other hand, the target process can be cleared in time and the memory space can be allocated to the preset process, so that the situation of memory shortage can be quickly relieved, and the system stability is improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty.
Fig. 1 schematically illustrates a schematic diagram of a memory reclamation method in an embodiment of the present disclosure.
Fig. 2 schematically illustrates a flow of performing a recycle operation on a memory page of a target process in the embodiment of the present disclosure.
Fig. 3 is a schematic diagram schematically illustrating a flow of a reclamation operation performed according to an associated process and a candidate process in the embodiment of the present disclosure.
Fig. 4 schematically shows a block diagram of a memory reclamation apparatus in an embodiment of the present disclosure.
Fig. 5 schematically illustrates a block diagram of an electronic device in an embodiment of the disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the disclosure. One skilled in the relevant art will recognize, however, that the subject matter of the present disclosure can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and the like. In other instances, well-known technical solutions have not been shown or described in detail to avoid obscuring aspects of the present disclosure.
Furthermore, the drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
The inventor finds that in some scenarios, the process of process quitting may be slow or even cause the process to fail to quit due to the reason that resources wait before the process quitting destruction. For example, the process 1 executes some operations of the file system and needs to allocate some memories, the memory allocation fails and enters the memory recovery, and finally the low memory management service cleaning process 2 is started, and the process 2 must execute some operations of the file system when completely exiting, and the operations will apply for the lock a. If process 1 happens to hold the lock A, the process 1 waits for each other to form a deadlock, and finally process 2 cannot quit, so that the memory cannot be released, and the memory tension encountered by the memory allocation of process 1 cannot be well relieved.
In order to solve the above technical problem, an embodiment of the present disclosure first provides a memory recovery method, which can be applied to an application scenario in which a memory of a terminal is released and optimized, where the terminal includes any electronic product installed with an android system, such as a mobile phone, a tablet computer, and the like. Referring to fig. 1, the memory recycling method may include step S110 and step S120, where:
in step S110, if it is detected that the memory allocation operation for the preset process fails, triggering a low memory management service to perform a cleaning operation on the target process;
in step S120, if it is detected that the cleaning operation is finished, performing a recycle operation on the memory page of the target process, and continuing to perform a memory allocation operation on the preset process through the recycle operation.
In the memory recovery method provided in the embodiment of the disclosure, on one hand, the target process is automatically exited by recovering the memory page of the target process without waiting for the automatic release of the resource information in the preset process, and then the memory is allocated to the preset process, so that the operations of exiting the target process and allocating the memory to the preset process are completed, the condition of forming a dead cycle due to the mutual waiting and limiting of the preset process and the target process is avoided, and the efficiency of memory recovery and memory allocation is improved. On the other hand, the memory page of the target process is directly recycled, and the memory allocation is continuously performed on the preset process according to the recycling operation, so that the process to be cleaned can be accurately determined in the memory allocation process, and the accuracy and relevance of the memory optimization are improved. On the other hand, the target process can be cleared in time and the memory space can be allocated to the preset process, so that the situation of memory shortage can be quickly relieved, and the system stability is improved.
Next, a memory recovery method in the embodiment of the present disclosure is specifically described with reference to fig. 1 to 3.
In step S110, if it is detected that the memory allocation operation for the preset process fails, the low memory management service is triggered to perform a cleaning operation on the target process.
In the embodiment of the present disclosure, the preset process may be any process or a starting process, and the starting process is taken as an example for description here. The starting process may be a process, and may also be an operation that needs to allocate a memory, such as file storage, and the like, which is described here by taking a process as an example. In the embodiment of the present disclosure, the starting process may specifically be a process that is not yet in a running state but is about to start running, for example, a newly started process. The start-up process may be various types of processes, and may be started in response to an operation by a user. For example, the starting process may be a game program a with a large memory. The memory allocation operation refers to a method for allocating a storage space for a starting process. The memory allocation operation includes two types, static memory allocation and dynamic memory allocation. The memory allocation operation may be executed once or multiple times, and the memory allocated by each memory allocation operation may be the same or different, which is not limited herein. For example, the preset threshold set by the system is 200MB, the available memory of the current system is 210M (no low memory management service is triggered), at this time, a large game program is started, and the allocated memory is 200 MB.
If the current available memory in the system is larger than the memory occupied by the preset process, the memory allocation operation can be successful; if the current available memory in the system is smaller than the memory occupied by the preset process, the memory allocation operation for the preset process may fail.
In the embodiment of the present disclosure, if the current available memory of the system is smaller than the occupied memory required by the preset process, it may be considered that the memory allocation operation for the preset process fails. In addition, memory allocation failures due to other reasons are also within the scope of the embodiments of the present disclosure. If the purpose of allocating the memory for the preset process is to be achieved under the condition that the memory allocation operation fails, the process in the system can be cleaned up. It should be noted that the process herein refers to a process running in the system. The Android system provides the following classes of processes: foreground process, visible process, secondary service, background process, content provider, and null process. The priority of the processes of each category sequentially changes from high to low, and the processes of each category are configured with corresponding memory threshold values in advance. Based on this, the process for low memory management service cleaning can be all processes running in the system or part of the processes. The partial processes may be processes of the same priority or processes of different priorities, and are not limited herein.
When the memory allocation operation of the preset process fails, the target process can be cleaned. The target process may or may not be associated with resource information. The number of the target processes may be one or multiple, and the number of the target processes may be determined according to the occupied memory of the preset process and the available memory of the system. In a case that the target process is associated with the resource information, the target process may be a process associated with the preset process, that is, an associated process, and the target process may be the same as or different from the preset process, which is not limited herein. The target process may also be an associated process and any type of process, and is not limited herein.
The target process is associated with the preset process, namely the preset process is associated with the target process through resource information. The resource information may be a resource which exists only in a preset process (a process to which a memory is to be allocated) and is required by a target process (a process to which a memory is to be reclaimed), and may be, for example, a resource which exists in the preset process but is necessary when the target process exits. The resource information may be, for example, a lock or other type of resource, and is described herein as a lock. Locks are a synchronization mechanism in concurrent processes. The lock can make the critical sections execute mutually exclusive, and can also make the thread releasing the lock send messages to the thread acquiring the same lock, so as to avoid mutual conflict among processes and prevent a plurality of processes from reading and writing a certain memory area simultaneously. Where the target process is not associated with resource information, the target process may be any suitable process. In the embodiment of the present disclosure, the technical problem to be solved is: one process has a lock but can release the lock only if the memory allocation is successful, and the other process exits from the lock and can allocate the memory space for the process, so that the target process can be associated with the preset process through the resource information. Based on this, the target process including the associated process corresponding to the preset process passing resource information is taken as an example for explanation.
In the embodiment of the present disclosure, the low memory management service may be activated when the memory allocation operation fails. After the low memory management memory is activated, the process in the system can be acquired through the low memory management service for cleaning. Generally, for low memory management services, whether to kill a process is determined according to the priority of the process and the size of the occupied memory. That is, the process is selected from the low priority to the high priority, and the process with the largest memory occupation is selected to be killed under the condition of equal priority. According to the method, the target process is cleaned directly, the range of the process to be cleaned can be narrowed, and the accuracy of determining the cleaning process is improved.
On this basis, in the present exemplary embodiment, if the target process is determined, the low memory management service may perform a cleaning operation on the determined target process. Clean-up here refers to stopping or shutting down the target process so that it is no longer running or leaving the target process running in the background. After the cleaning operation is performed on the target process, the memory space occupied by the target process can be released, so that the situation of system memory shortage is quickly relieved, and the memory space is conveniently distributed for the preset process under the situation of cleaning the target process.
In step S120, if it is detected that the cleaning operation is finished, performing a recycle operation on the memory page of the target process, and continuing to perform a memory allocation operation on the preset process through the recycle operation.
In the embodiment of the present disclosure, if it is detected that the cleaning operation on the target process is finished, the memory page of the target process may be directly recycled under the condition that the target process is associated with the preset process through the resource information. The memory page of the target process refers to a page for controlling the target process to rapidly exit. By recycling the memory page of the target process, the target process can be rapidly exited without waiting for the preset process to release the resource information and then exiting, so that the exiting efficiency of the target process is improved, a long-time waiting process between the preset process and the target process is avoided, the memory allocation efficiency and the memory recycling efficiency are improved, and the memory recycling and the memory allocation between different processes which are restricted with each other are completed simultaneously.
Specifically, the memory page may be an anonymous page, or may be a file page, and here, the anonymous page is described as an example. The anonymous page refers to a memory allocated through a dynamic memory allocation function, and the anonymous page can be consistent with an occupied memory of a target process. Anonymous pages belong to an anonymous linear region of a process and are mainly used for page swapping. For example, all pages in the user-mode heap and stack of a process are anonymous pages. Pages with file background, namely called anonymous pages, such as heap, stack, data segment and the like do not exist in memory pages in a file form, so that the pages cannot be exchanged with a disk file, but can be exchanged by dividing an additional exchange partition on a hard disk or using an exchange file. A file page refers to memory allocated when a file is read or written.
When the memory page is an anonymous page, the specific process of performing the recycling operation on the memory page of the target process comprises the following steps: and judging whether the memory information of the preset process meets preset conditions or not, and performing the recovery operation on the anonymous page of the target process according to a judgment result. Fig. 2 schematically shows a flowchart of performing a recycle operation on a memory page of a target process, and referring to fig. 2, the method mainly includes steps S210 to S230, where:
in step S210, it is determined whether the memory information of the preset process satisfies a preset condition. If yes, go to step S220; if not, go to step S230.
In this step, the preset condition is used to indicate whether the size of the memory is sufficient. The memory information of the default process may include an occupied memory of the default process and an available memory of the system. The memory information of the preset process meeting the preset condition can be understood as that the available memory of the system is insufficient and the occupied memory of the preset process is not large, and can be specifically represented by the size between the occupied memory of the preset process and the available memory of the system. For example, if the occupied memory of the preset process is greater than the available memory of the system, and the portion greater than the available memory of the system is smaller than the threshold, the preset condition is considered to be satisfied. If the occupied memory of the preset process is larger than the available memory of the system, and the part larger than the available memory of the system is larger than the threshold value, the preset condition is considered not to be met. Wherein the threshold value may be a small value, such as 20M, etc.
In step S220, if the occupied memory of the preset process and the available memory of the system satisfy the preset condition, determining the associated process corresponding to the preset process as a target process, and performing the recycle operation on the anonymous page of the target process.
In this step, if the occupied memory of the preset process is greater than the available memory of the system, but the part of the preset process that occupies the memory greater than the available memory of the system is less than the threshold value 20M, the preset condition is considered to be satisfied. At this time, the number of the target processes may be one, and the associated process corresponding to the preset process may be determined as the target process. For example, the occupied memory of process 1 is 200M, the available memory of the system is 190M, and although the available memory of the system is smaller than the occupied memory of process 1, the difference between the two is smaller than 20M. The associated process associated with process 1 via the resource information may thus be selected as its corresponding target process. For example, process 2 must use the resource information in process 1 when exiting, so process 2 can be the target process and the anonymous page of process 2 is recycled to cause process 2 to exit.
It should be noted that, under the condition that the memory occupied by the preset process and the available memory of the system satisfy the preset condition, the target process needs to be completely exited, so that the target process is no longer in the running state. The anonymous page of the target process needs to be fully recycled to facilitate the target process to exit.
In step S230, if the occupied memory of the preset process and the available memory of the system do not satisfy the preset condition, performing a recycle operation on the candidate process and the anonymous page of the associated process.
In this step, if the memory occupied by the preset process is greater than the available memory of the system, but the part of the preset process that occupies the memory and is greater than the available memory of the system is greater than 20M, the preset condition is considered to be not satisfied. When the preset condition is not met, the number of the target processes can be one or more. Specifically, the number of target processes may be determined according to a comparison result between a difference between an available memory of the system and an occupied memory of the preset process and a threshold. The higher the degree to which the difference is greater than the threshold, the greater the number of target processes. For example, the part a where the difference is larger than the threshold is the first level (20M < a <50M), the number of target processes may be 1; if the portion a of the difference greater than the threshold is of a second level (50M < a <100M), the number of target processes may be 2; the part a where the difference is greater than the threshold is the third level (100M < a <200M), and the number of target processes may be 3; the portion a where the difference is greater than the threshold is the fourth level (200M < a), and the number of target processes may be 5. When the number of the target processes is one, the associated process corresponding to the preset process may be determined as the target process, and the specific implementation manner is the same as the step in step S220, which is not described herein again. When the number of the target processes is multiple, the target processes may include associated processes corresponding to the preset processes, and may further include candidate processes. The candidate process may be other associated processes corresponding to the preset process, or may be any process, which is not limited herein.
For example, the occupied memory of the process 1 is 260M, the available memory of the system is 190M, although the available memory of the system is smaller than the occupied memory of the process 1, the difference between the two is greater than 20M and of low level, and the number of target processes may be 2. One of the processes may be an associated process associated with process 1 through the resource information, and the other process may be a candidate process. On the basis, the recovery operation can be carried out on the anonymous pages of the associated process and the candidate process contained in the target process so as to quit the target process.
Fig. 3 schematically shows a flowchart of the recycling operation according to the associated process and the candidate process, and referring to fig. 3, the method mainly includes steps S310 to S330, where:
in step S310, if the memory occupied by the preset process and the available memory of the system do not satisfy the preset condition, determining a candidate process from the multiple processes;
in step S320, determining the target process according to the associated process corresponding to the preset process and the candidate process;
in step S330, a recycle operation is performed on the anonymous page of the target process.
In the embodiment of the present disclosure, the candidate process may be a process selected from a plurality of processes other than the associated process for performing the recycling operation according to a preset rule. The preset rule comprises at least one of the lowest priority of the process, the largest memory occupied by the process, the resource information contained in the process and the queue to be cleaned of the process. Wherein, the process containing the resource information means that the process quits and needs the resource information. The process is in the queue to be cleaned means that the process is in a list to be cleaned, and the processes in the list are cleaned in sequence. For example, the process occupying the largest memory may be selected as the candidate process from the processes with the lowest priority. After determining the candidate process, the associated process and the candidate process may be jointly determined as the target process.
The candidate process may be a background running process or a completely exited process. When the candidate process is a process running in the background, the process of performing the recovery operation on the anonymous page of the candidate process in the target process may be: and recycling the part of anonymous pages in the candidate process in a compression mode. Specifically, the anonymous pages that have been used less recently (e.g., one day, one week, etc.) may be compressed and stored, for example, 150M anonymous pages may be compressed and changed to 50M anonymous pages, and then decompressed when there is a demand for use next time. When the candidate process is a process to be cleaned (a process to be killed or a process to be finished), the process of performing a recycle operation on the anonymous page of the candidate process in the target process may be: and carrying out recovery operation on all anonymous pages of the candidate process.
After step S130, the method for recycling memory further includes: and determining a target memory according to the anonymous page of the target process acted by the recovery operation, and allocating the target memory to the preset process. For example, if the entire anonymous page 100M of the process 2 is recycled, and besides, a part of the anonymous page of the process 3 is recycled, for example, 20M, the target memory is the sum of the recycled anonymous page of the process 2 and the recycled anonymous page of the process 3, that is, 120M, and the target memory 120M may be further allocated to the preset process.
In the technical scheme in fig. 3, the anonymous page of the target process is recycled, so that the target process can timely quit and release the memory, the memory space is conveniently allocated to the preset process, and the memory recycling and memory allocation efficiency is improved.
According to the technical scheme in the embodiment of the disclosure, when the memory allocation for the preset process fails (namely, the available memory of the system is smaller than the memory occupied by the preset process), the low memory management service can be activated in time to clear the target process, and the memory page of the target process is recycled when the clearing operation is finished. In addition, the target process can be rapidly quitted by recovering the memory page of the target process, so that the memory space can be rapidly allocated to the preset process, and the memory allocation and memory recovery efficiency is improved. And thirdly, the memory recovery function can be realized by timely cleaning the process through the memory page of the recovery target process, so that the stability of the system is improved.
Fig. 4 shows a memory recovery apparatus in an embodiment of the present disclosure, and referring to fig. 4, the memory recovery apparatus 400 mainly includes a process cleaning module 401 and a page recovery module 402, where:
the process cleaning module 401 is configured to trigger a low memory management service to perform a cleaning operation on a target process if it is detected that a memory allocation operation on a preset process fails;
a page recycling module 402, configured to, if it is detected that the cleaning operation is finished, perform a recycling operation on the memory page of the target process, and continue to perform a memory allocation operation on the preset process through the recycling operation.
In an exemplary embodiment of the present disclosure, the page recycling module includes: and the anonymous page recovery module is used for performing the recovery operation on the anonymous page of the target process so as to facilitate memory recovery on the target process.
In an exemplary embodiment of the present disclosure, the anonymous page reclaim module includes: and the recovery control module is used for judging whether the memory information of the preset process meets a preset condition or not and carrying out the recovery operation on the anonymous page of the target process according to a judgment result.
In an exemplary embodiment of the present disclosure, the recycling control module includes: and the first recovery module is used for determining the associated process corresponding to the preset process as a target process and performing the recovery operation on the anonymous page of the target process if the occupied memory of the preset process and the available memory of the system meet the preset conditions.
In an exemplary embodiment of the present disclosure, the apparatus further includes: the candidate process determining module is used for determining a candidate process from a plurality of processes if the memory occupied by the preset process and the available memory of the system do not meet the preset condition; the target process determining module is used for determining the target process according to the associated process corresponding to the preset process and the candidate process; and the second recovery module is used for performing recovery operation on the anonymous page of the target process.
In an exemplary embodiment of the disclosure, the candidate process determination module is configured to: determining the candidate process according to a preset rule; the preset rule comprises at least one of the lowest priority of the process, the largest memory occupied by the process, the resource information contained in the process and the queue to be cleaned of the process.
In an exemplary embodiment of the present disclosure, the page recycling module includes: and the memory allocation module is used for determining a target memory according to the anonymous page of the target process acted by the recovery operation and allocating the target memory to the preset process.
It should be noted that the specific details of each module in the memory recovery device have been described in detail in the corresponding memory recovery method, and therefore are not described herein again.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Moreover, although the steps of the methods of the present disclosure are depicted in the drawings in a particular order, this does not require or imply that the steps must be performed in this particular order, or that all of the depicted steps must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions, etc.
In the embodiment of the disclosure, an electronic device capable of implementing the method is also provided.
As will be appreciated by one skilled in the art, aspects of the present disclosure may be embodied as a system, method or program product. Accordingly, various aspects of the present disclosure may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
An electronic device 500 according to this embodiment of the disclosure is described below with reference to fig. 5. The electronic device 500 shown in fig. 5 is only an example and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 5, the electronic device 500 is embodied in the form of a general purpose computing device. The components of the electronic device 500 may include, but are not limited to: the at least one processing unit 510, the at least one memory unit 520, and the bus 550 that couples the various system components including the memory unit 520 and the processing unit 510.
Wherein the storage unit stores program code that is executable by the processing unit 510 to cause the processing unit 510 to perform steps according to various exemplary embodiments of the present disclosure as described in the above section "exemplary methods" of this specification. For example, the processing unit 510 may perform the steps as shown in fig. 1: in step S110, if it is detected that the memory allocation operation for the preset process fails, triggering a low memory management service to perform a cleaning operation on the target process; in step S120, if it is detected that the cleaning operation is finished, performing a recycle operation on the memory page of the target process, and continuing to perform a memory allocation operation on the preset process through the recycle operation.
The memory unit 520 may include a readable medium in the form of a volatile memory unit, such as a random access memory unit (RAM)5201 and/or a cache memory unit 5202, and may further include a read only memory unit (ROM) 5203.
Storage unit 520 may also include a program/utility 5204 having a set (at least one) of program modules 5205, such program modules 5205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 530 may be one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, a graphics acceleration interface, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 500 may also communicate with one or more external devices 600 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 500, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 500 to communicate with one or more other computing devices. Such communication may occur via input/output (I/O) interfaces 550. Also, the electronic device 500 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 560. As shown, the network adapter 560 communicates with the other modules of the electronic device 500 over the bus 530. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
In an embodiment of the present disclosure, a computer-readable storage medium is further provided, on which a program product capable of implementing the above-mentioned method of the present specification is stored. In some possible embodiments, various aspects of the disclosure may also be implemented in the form of a program product comprising program code for causing a terminal device to perform the steps according to various exemplary embodiments of the disclosure described in the "exemplary methods" section above of this specification, when the program product is run on the terminal device.
According to the program product for implementing the above method of the embodiments of the present disclosure, it may employ a portable compact disc read only memory (CD-ROM) and include program codes, and may be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes included in methods according to embodiments of the present disclosure, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.

Claims (9)

1. A memory reclamation method, comprising:
if the memory allocation operation on the preset process is detected to fail, triggering a low memory management service to perform cleaning operation on the target process;
if the cleaning operation is detected to be finished, carrying out recovery operation on the anonymous page of the target process so that the target process cannot continuously execute page exchange to exit, and continuously carrying out memory allocation operation on the preset process through the recovery operation; the target process is associated with the preset process through resource information, at least one process in the target process is an associated process associated with the preset process through the resource information, and the at least one process must use the resource information in the preset process when exiting.
2. The method according to claim 1, wherein performing the recycle operation on the anonymous page of the target process comprises:
and judging whether the memory information of the preset process meets preset conditions or not, and performing the recovery operation on the anonymous page of the target process according to a judgment result.
3. The method according to claim 2, wherein performing the recycle operation on the anonymous page of the target process according to the determination result comprises:
and if the occupied memory of the preset process and the available memory of the system meet the preset conditions, determining the associated process corresponding to the preset process as a target process, and performing the recovery operation on the anonymous page of the target process.
4. The method of claim 3, further comprising:
if the memory occupied by the preset process and the available memory of the system do not meet the preset condition, determining a candidate process from a plurality of processes;
determining the target process according to the associated process corresponding to the preset process and the candidate process;
and carrying out recovery operation on the anonymous page of the target process.
5. The method of claim 4, wherein determining the candidate process from the plurality of processes comprises:
determining the candidate process according to a preset rule;
the preset rule comprises at least one of the lowest priority of the process, the largest memory occupied by the process, the resource information contained in the process and the queue to be cleaned of the process.
6. The method according to claim 1, wherein continuing to perform the memory allocation operation on the predetermined process through the recycle operation comprises:
and determining a target memory according to the anonymous page of the target process acted by the recovery operation, and distributing the target memory to the preset process.
7. A memory recycling device, comprising:
the process cleaning module is used for triggering the low memory management service to perform cleaning operation on the target process if the failure of the memory allocation operation on the preset process is detected;
and the page recovery module is configured to, if it is detected that the cleaning operation is finished, perform a recovery operation on the anonymous page of the target process, so that the target process cannot continue to perform page switching to exit, and continue to perform a memory allocation operation on the preset process through the recovery operation, where the target process is associated with the preset process through resource information, at least one process of the target process is an associated process in which the preset process is associated with the resource information, and the at least one process must use the resource information in the preset process when exiting.
8. An electronic device, comprising:
a processor; and
a memory for storing executable instructions of the processor;
wherein the processor is configured to perform the memory reclamation method of any of claims 1-6 via execution of the executable instructions.
9. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the memory reclamation method as recited in any one of claims 1 to 6.
CN201910815705.1A 2019-08-30 2019-08-30 Memory recovery method and device, electronic equipment and storage medium Active CN110532197B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910815705.1A CN110532197B (en) 2019-08-30 2019-08-30 Memory recovery method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910815705.1A CN110532197B (en) 2019-08-30 2019-08-30 Memory recovery method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110532197A CN110532197A (en) 2019-12-03
CN110532197B true CN110532197B (en) 2022-03-01

Family

ID=68665593

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910815705.1A Active CN110532197B (en) 2019-08-30 2019-08-30 Memory recovery method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110532197B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111580980B (en) * 2020-05-15 2024-01-30 北京小米松果电子有限公司 Memory management method and device
CN111679914B (en) * 2020-06-12 2023-06-27 北京字节跳动网络技术有限公司 Memory management method, system, computer equipment and storage medium
CN111722903A (en) * 2020-06-16 2020-09-29 北京达佳互联信息技术有限公司 Data processing method and device, electronic equipment and storage medium
CN114443277A (en) * 2020-10-31 2022-05-06 华为终端有限公司 Memory management method and device, electronic equipment and computer readable storage medium
CN112363841B (en) * 2020-11-27 2022-11-04 Oppo(重庆)智能科技有限公司 Application process searching and killing method and device, electronic equipment and storage medium
CN116244067B (en) * 2021-06-10 2024-05-03 荣耀终端有限公司 Virtual memory management method and electronic equipment
CN115617529B (en) * 2022-11-17 2023-03-10 中国人民解放军国防科技大学 Process management method and device in mobile application compatible running environment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106354562A (en) * 2016-08-25 2017-01-25 上海传英信息技术有限公司 Memory cleaning system and memory cleaning method
CN108958911A (en) * 2018-05-30 2018-12-07 北京小米移动软件有限公司 The control method and device of process
CN109376002A (en) * 2018-08-14 2019-02-22 广东格兰仕集团有限公司 A kind of internal memory optimization control method based on oven control system
CN109857556A (en) * 2019-01-15 2019-06-07 Oppo广东移动通信有限公司 Method for recovering internal storage and device, storage medium and electronic equipment
CN110008016A (en) * 2019-04-15 2019-07-12 深圳市万普拉斯科技有限公司 Anonymous page management method, device, terminal device and readable storage medium storing program for executing

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080162612A1 (en) * 2006-12-28 2008-07-03 Andrew Tomlin Method for block relinking
CN104239147B (en) * 2014-10-20 2018-03-09 浪潮(北京)电子信息产业有限公司 One kind processing deadlock round-robin method and system
CN109213539B (en) * 2016-09-27 2021-10-26 华为技术有限公司 Memory recovery method and device
CN107704321A (en) * 2017-09-30 2018-02-16 北京元心科技有限公司 Memory allocation method and device and terminal equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106354562A (en) * 2016-08-25 2017-01-25 上海传英信息技术有限公司 Memory cleaning system and memory cleaning method
CN108958911A (en) * 2018-05-30 2018-12-07 北京小米移动软件有限公司 The control method and device of process
CN109376002A (en) * 2018-08-14 2019-02-22 广东格兰仕集团有限公司 A kind of internal memory optimization control method based on oven control system
CN109857556A (en) * 2019-01-15 2019-06-07 Oppo广东移动通信有限公司 Method for recovering internal storage and device, storage medium and electronic equipment
CN110008016A (en) * 2019-04-15 2019-07-12 深圳市万普拉斯科技有限公司 Anonymous page management method, device, terminal device and readable storage medium storing program for executing

Also Published As

Publication number Publication date
CN110532197A (en) 2019-12-03

Similar Documents

Publication Publication Date Title
CN110532197B (en) Memory recovery method and device, electronic equipment and storage medium
US11531625B2 (en) Memory management method and apparatus
CN109857555B (en) Memory recovery method and device, storage medium and electronic equipment
US10114740B2 (en) Memory management techniques
CN109857556B (en) Memory recovery method and device, storage medium and electronic equipment
CN108459898B (en) Resource recovery method and device
CN108228482B (en) Method and system for managing cache devices in a storage system
CN112579251B (en) Method and equipment for managing virtual machine memory
US20230120580A1 (en) Access control method and apparatus for shared memory, electronic device and autonomous vehicle
CN113064748B (en) Process succession method, device, electronic equipment and storage medium
US20200249969A1 (en) Electronic device having multi-operating system and method for managing dynamic memory for same
CN113254223B (en) Resource allocation method and system after system restart and related components
CN111679914B (en) Memory management method, system, computer equipment and storage medium
CN111488316B (en) File cache recovery method and device
CN110532095B (en) Memory optimization method and device, electronic equipment and storage medium
US20130318310A1 (en) Processor processing method and processor system
CN107870877B (en) Method and system for managing data access in a storage system
CN112363828B (en) Memory fragment management method and device, vehicle-mounted system and vehicle
CN114077493A (en) Resource allocation method and related equipment
CN112162864A (en) Cloud resource allocation method and device and storage medium
CN112817769B (en) Game resource dynamic caching method and device, storage medium and electronic equipment
CN117234431B (en) Cache management method and device, electronic equipment and storage medium
US8566829B1 (en) Cooperative multi-level scheduler for virtual engines
CN116431338A (en) Memory optimization method, memory manager, electronic device and storage medium
CN116991584A (en) Resource allocation system, control method, device, medium and hardware acceleration engine

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
GR01 Patent grant
GR01 Patent grant