CN113392037A - Memory recovery method and device, computer equipment and storage medium - Google Patents
Memory recovery method and device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN113392037A CN113392037A CN202010170565.XA CN202010170565A CN113392037A CN 113392037 A CN113392037 A CN 113392037A CN 202010170565 A CN202010170565 A CN 202010170565A CN 113392037 A CN113392037 A CN 113392037A
- Authority
- CN
- China
- Prior art keywords
- memory
- memory page
- recovered
- linked list
- application
- 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.)
- Granted
Links
- 230000015654 memory Effects 0.000 title claims abstract description 482
- 238000000034 method Methods 0.000 title claims abstract description 113
- 238000011084 recovery Methods 0.000 title claims abstract description 92
- 238000004590 computer program Methods 0.000 claims description 25
- 238000004891 communication Methods 0.000 claims description 6
- 238000012544 monitoring process Methods 0.000 claims description 4
- 238000010586 diagram Methods 0.000 description 5
- 238000005192 partition Methods 0.000 description 3
- 230000002159 abnormal effect Effects 0.000 description 2
- JHIVVAPYMSGYDF-UHFFFAOYSA-N cyclohexanone Chemical compound O=C1CCCCC1 JHIVVAPYMSGYDF-UHFFFAOYSA-N 0.000 description 2
- 238000004064 recycling Methods 0.000 description 2
- 230000001360 synchronised effect Effects 0.000 description 2
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/0223—User address space allocation, e.g. contiguous or non contiguous base addressing
- G06F12/023—Free address space management
- G06F12/0253—Garbage collection, i.e. reclamation of unreferenced memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/08—Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
- G06F12/0802—Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
- G06F12/0877—Cache access modes
- G06F12/0882—Page mode
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5021—Priority
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Memory System Of A Hierarchy Structure (AREA)
- Memory System (AREA)
Abstract
The application provides a memory recovery method, a memory recovery device, computer equipment and a storage medium. The method comprises the following steps: receiving a memory recovery instruction; the memory recovery instruction carries a linked list identifier; acquiring a target linked list corresponding to memory recovery according to the linked list identifier; scanning identification bit information of a plurality of memory pages in the target linked list; determining a memory page to be recovered, which is recovered by the memory, according to the identification bit information; the memory pages to be recovered comprise the memory pages of the application programs in the background application state; and recovering the memory page to be recovered. The method can be used for accurately recovering the memory.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for memory recovery, a computer device, and a storage medium.
Background
In the running process of the terminal, in order to accelerate the speed of reading or writing the disk, the kernel of the operating system caches a large amount of data in the memory when the kernel of the operating system reads or writes the disk. However, the memory space of the terminal is limited, a large amount of data is cached in the memory and cannot be released in time, which causes the abnormal operation of the operating system due to insufficient memory allocation, and therefore, the operating system is required to recycle the memory.
At present, the conventional memory recovery mechanism recovers memory pages in an anonymous linked list or a file linked list according to a policy of preferentially recovering the least recently used memory pages. At this time, the retrieved memory page may be the memory of the foreground application or the memory of the background application, and if the retrieved memory page is the memory of the foreground application, the risk of the foreground application being stuck is increased.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a memory recovery method, device, computer device, and storage medium capable of improving the accuracy of memory recovery.
A method of memory reclamation, the method comprising:
receiving a memory recovery instruction; the memory recovery instruction carries a linked list identifier;
acquiring a target linked list corresponding to memory recovery according to the linked list identifier;
scanning identification bit information of a plurality of memory pages in the target linked list;
determining a memory page to be recovered, which is recovered by the memory, according to the identification bit information; the memory pages to be recovered comprise the memory pages of the application programs in the background application state;
and recovering the memory page to be recovered.
In one embodiment, the identification bit information includes application state information; the method further comprises the following steps:
calling a process management service to monitor the application state of the application program;
when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state;
and determining whether to recycle the memory page according to the updated application state information.
In an embodiment, the updating the application state information of the memory page corresponding to the application program according to the application state includes:
transmitting process identifications of processes respectively corresponding to the front and the rear of the switching state to a kernel space;
scanning a memory page corresponding to each process identifier through the kernel space;
and updating the application state information of the memory page according to the application state corresponding to the process identifier.
In one embodiment, the memory reclamation instruction further carries a number of memories to be reclaimed; the scanning the memory pages of the target linked list, and determining the memory pages to be recovered of the target linked list according to the identification bit information of the memory pages includes:
taking the memory page located at the last sequence bit of the target linked list as the current memory page;
when the identification bit information of the current memory page is the same as the corresponding state threshold value, determining the current memory page as a memory page to be recovered;
and acquiring a next sequential memory page according to a reverse order, taking the next sequential memory page as a current memory page, and returning a step of determining the current memory page as a memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold value, until the number of the memories to be recovered is reached, and acquiring all the memory pages to be recovered, which are recovered by the memories.
In one embodiment, the identification bit information includes application state information, accessed information, and linked list state information; determining the current memory page as a memory page to be recycled when the identification bit information of the current memory page is the same as the corresponding state threshold comprises:
and when the application state information, the accessed information and the linked list state information of the current memory page are respectively the same as the corresponding state threshold values, determining the current memory page as a memory page to be recovered.
In one embodiment, the method further comprises:
setting corresponding resource priority for the application program;
when detecting that a background application program and a foreground application program have at least one of a communication mechanism and a synchronization mechanism, taking the background application program as a depended application program;
and updating the application state information of the memory page corresponding to the depended application program.
A memory reclamation apparatus, the apparatus comprising:
the instruction receiving module is used for receiving the memory recovery instruction; the memory recovery instruction carries a linked list identifier;
a linked list obtaining module, configured to obtain a target linked list corresponding to memory recovery according to the linked list identifier;
a memory page scanning module, configured to scan identification bit information of multiple memory pages in the target linked list;
the memory recovery module is used for determining a memory page to be recovered, which is recovered by the memory, according to the identification bit information; and recovering the memory page to be recovered.
In one embodiment, the apparatus further includes an application state monitoring module, configured to invoke a process management service to monitor an application state of the application program; when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state; and determining whether to recycle the memory page according to the updated application state information.
A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the memory recovery method when executing the computer program.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned memory reclamation method.
According to the memory recovery method, the memory recovery device, the computer equipment and the storage medium, when a memory recovery instruction is received, the target linked list is determined according to the linked list identification carried by the memory recovery instruction, and then the memory page in the target linked list is scanned to obtain the identification bit information, so that the memory page to be recovered is determined through the identification bit information, and whether the corresponding memory page is the memory page of a foreground application program or the memory page of a background application program can be better judged through the identification bit information, namely whether the memory page belongs to the background process or the foreground process is avoided, the memory page belonging to the foreground process is prevented from being recovered by mistake in the memory recovery process, and the accuracy of memory recovery is improved.
Drawings
Fig. 1 is an application scenario diagram of a memory reclamation method in an embodiment;
FIG. 2 is a flow chart illustrating a memory reclamation method according to an embodiment;
FIG. 3 is a block diagram illustrating an exemplary memory reclamation apparatus;
FIG. 4 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The memory recovery method provided by the application can be applied to the application environment shown in fig. 1. The terminal 102 receives the memory recovery instruction, acquires a corresponding target linked list according to a linked list identifier carried by the memory recovery instruction, further scans application state information of a plurality of memory pages arranged in sequence in the target linked list, determines a memory page to be recovered for memory recovery according to the application state information obtained by scanning, and recovers according to the determined memory page to be recovered. The terminal 102 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices.
In an embodiment, as shown in fig. 2, a memory reclamation method is provided, which is described by taking the application of the method to the terminal in fig. 1 as an example, and includes the following steps:
step S202, receiving a memory recovery instruction; the memory recycle instruction carries a linked list identification.
The memory recovery instruction comprises a linked list identifier and a memory number to be recovered. The linked list identifier is used for distinguishing each linked list, and the linked list identifier can be a linked list address or one or more combinations of numbers, characters and symbols. The number of memory pages to be recovered includes the number or space of memory pages recovered by the terminal, or the number or space of memory pages that the terminal needs to recover at least, or the number or space of memory pages that the terminal needs to recover at most.
Due to the limited memory space of the terminal, a large amount of data is cached in the memory and cannot be released in time, so that the abnormal operation of the operating system caused by insufficient memory allocation can be caused. When at least one of the following conditions is met, the terminal receives a memory recovery instruction: the current available memory value is lower than the memory value required by the running of the application program in the foreground application state; the sum of the memory values of the application programs in the background application state reaches a condition threshold; the terminal is in a standby state.
(1) The current available memory value is lower than the memory value required by the running of the application program in the foreground application state. The terminal can obtain a memory resource value required by the operation of the foreground application program, when the current available memory resource value of the terminal is lower than the memory resource value required by the operation of the foreground application program, the terminal transmits a memory recovery instruction to the user space through the kernel space, and the user space recovers the memory resource according to the received memory recovery instruction.
(2) The sum of the memory values of the application programs in the background application state reaches the condition threshold. The terminal can obtain the sum of the memory resource values occupied by each background application program. And when the sum of the acquired memory resource values of the background application program is greater than or equal to the condition threshold value, the terminal transmits a memory recovery instruction to the user space through the kernel space, and the user space recovers the memory resources according to the received memory recovery instruction. The condition threshold may be a number preset by the terminal, or may be a number set by the user, for example, the condition threshold may be 70% of the total memory resource value of the terminal.
(3) The terminal is in a standby state. When the terminal is in a standby state, the terminal transmits a memory recovery instruction to a user space of the terminal through the kernel space, and the user space recovers memory resources according to the received memory recovery instruction. Wherein the standby state may be a state when the screen of the terminal is off.
Step S204, a target linked list corresponding to the memory recovery is obtained according to the linked list identification.
The linked list is a non-sequential and non-sequential storage structure in the memory, and the target linked list may be an LRU (Least Recently Used) linked list. The LRU linked list includes: an INACTIVE anonymous page linked list (INACTIVE _ ANON) for holding all INACTIVE anonymous pages in use; an ACTIVE anonymous page linked list (ACTIVE _ ANON) for holding all ACTIVE anonymous pages in use; INACTIVE FILE page linked list (INACTIVE _ FILE) for saving all INACTIVE FILE pages in use; ACTIVE FILE page link list (ACTIVE _ FILE) for holding all ACTIVE FILE pages in use.
Specifically, the terminal links to the corresponding target linked list according to the linked list identifier carried by the memory recovery instruction, and performs memory recovery on the target linked list according to the number of memories to be recovered. When the terminal recovers the memory, the memory recovery is generally performed from the inactive anonymous linked list, and then from the inactive file page linked list. Active linked lists are generally not reclaimed unless a memory reclamation instruction specifies that the active linked list is reclaimed. In the LRU linked list, the chain is the memory page of the application that has been used least recently and the chain head is the most recently used memory page.
Step S206 scans the flag information of the memory pages in the target linked list.
The memory page refers to a physical page of the memory and is a minimum management unit of the memory. The identification bit information of the memory page comprises application state information, accessed information and linked list state information.
The application state information is information recorded according to the application state when the application state of the application program is switched, and the application state comprises a foreground application state and a background application state. The application state information is used to distinguish whether a process of the application program is in a foreground application state or a background application state. The application state information may adopt a preset numerical value, for example, "1" indicates that the application program is in the foreground application state, and "0" indicates that the application program is in the background application state.
The accessed information is whether the memory page is accessed at the current time. For example, if the accessed information is accessed, the accessed information is "1", otherwise, the accessed information is "0", and when the accessed information of the memory page scanned by the terminal is "1" in memory recovery, the memory page is moved to the head position of the linked list.
The linked list state information refers to whether the linked list corresponding to the memory is an active linked list or an inactive linked list. The identification bit information may adopt one or more combinations of numbers, characters and symbols, and the application state information, the accessed information and the linked list state information may be the same or different.
The terminal scans the target linked list, starts scanning from the chain tail of the target linked list, namely the memory page of the last sequence bit, and scans a plurality of memory pages of the target linked list according to the sequence from the chain tail to the chain head. During scanning, the terminal acquires application state information, accessed information and linked list state information of a currently scanned memory page, and then judges whether the memory page needs to be recycled according to the scanned information.
In one embodiment, the method further includes: setting corresponding resource priority for the application program; when detecting that the background application program and the foreground application program have at least one of a communication mechanism and a synchronization mechanism, taking the background application program as a depended application program; and updating the application state information of the memory page corresponding to the depended application program.
Specifically, the terminal sets a resource priority level for each application, where the terminal may set the resource priority level corresponding to the application according to the type of the application, the frequency of use of the application, and the like. The resource priority is a limit level of a resource usable by the application program, and the limit level of the resource usable by the application program is different according to the resource priority. The higher the resource priority level of an application, the less the available resource limit of the corresponding application. The usable resources include CPU resources, memory resources, I/O resources, and network resources. When the terminal detects that the background application program and the foreground application program have at least one of a communication mechanism and a synchronization mechanism, it indicates that the foreground application program needs to call data of the background application program to be smoothly executed at the moment, so that the background application program is used as a depended application program, and at the moment, the memory page of the background application program cannot be recycled. And the terminal updates the application state information of the memory page corresponding to the depended application program from the first threshold value to a fourth threshold value, and determines that the memory page of the depended application program does not need to be recycled according to the fourth threshold value. In this embodiment, when it is detected that the background application is the application that the foreground application depends on, the application state information of the memory page of the depended-on application is updated, so that memory recovery of the depended-on application is avoided, and the foreground application of the terminal is sequentially executed.
Step S208, determining the memory page to be recovered of the memory recovery according to the application state information; the memory pages to be recycled comprise the memory pages of the application program in the background application state.
The memory page to be recovered refers to a memory page corresponding to the background application program. Specifically, the terminal determines whether the memory page needs to be recovered according to the application state information, the accessed information, and the linked list state information of the memory page obtained by scanning. When the application state information indicates that the application state corresponding to the memory page is a background process, the accessed information indicates that the memory page is not accessed at the current time, and the linked list state is an inactive state, the terminal may determine the memory page as a memory page to be recovered.
Step S210, a memory page to be recovered is recovered.
Specifically, the terminal recovers the memory pages to be recovered obtained by scanning to obtain the idle memory pages. And the terminal writes the memory to be recovered back to the exchange partition so as to access the exchange partition for re-reading when the data in the memory page to be recovered is needed. And after the terminal writes the data in the memory page to be recovered back to the exchange partition, deleting the memory page to be recovered in the target linked list to obtain an idle memory page. The free memory page refers to a physical page that is not occupied by the application program.
In the above embodiment, when the memory recovery instruction is received, the target linked list is determined according to the linked list identifier carried by the memory recovery instruction, and then the memory pages in the target linked list are scanned to obtain the identifier information, so that the memory pages to be recovered are determined through the identifier information, and whether the corresponding memory pages belong to the background process or the foreground process can be better determined through the identifier information, thereby avoiding the memory pages belonging to the foreground process from being recovered by mistake in the memory recovery process, and improving the accuracy of memory recovery.
In one embodiment, the identification bit information includes application state information; the method further comprises the following steps: calling a process management service to monitor the application state of the application program; when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state; and determining whether to recycle the memory page according to the updated application state information.
Among them, the Activity Manager Service (AMS) is a Service for managing process objects.
Specifically, the terminal invokes the process management service to monitor the application state of each application program and determine whether the application state is in a foreground application state or a background application state, wherein the application state includes the foreground application state and the background application state. When the process management service monitors that the application program is switched from the foreground application state to the background application state or monitors that the application program is switched from the background application state to the foreground application state, the terminal updates the application state information of the memory page corresponding to the application program according to the application state at the moment, and then determines whether the memory page needs to be recycled according to the updated application state information.
In one embodiment, updating the application state information of the memory page corresponding to the application program according to the application state includes: transmitting process identifications of processes respectively corresponding to the front and the rear of the switching state to a kernel space; scanning a memory page corresponding to each process identifier through a kernel space; and updating the application state information of the memory page according to the application state corresponding to the process identifier.
Specifically, once the process management service monitors that the application state of the application program is switched, the terminal switches the process identifiers of all processes corresponding to the application program before the state is switched through the process management service; and after the state is switched, the process identifications of all processes corresponding to the application program and the corresponding application states are jointly transmitted to the kernel space of the terminal. The kernel space stores the received process identifiers and the corresponding application states, and further, the memory pages corresponding to each stored process identifier are scanned through the kernel space, and the application state information of the corresponding memory pages is updated according to the application states corresponding to the process identifiers.
For example, the application state of the current application program is foreground application, and the corresponding processes are all foreground processes; and then, the application program is switched from foreground application to background application, the corresponding foreground process is changed into a background process, at the moment, the process management service transmits the foreground process identification, the background process identification and the corresponding application state of the application program to a kernel space together, the kernel space scans each process identification, and the application state information of the memory page is updated according to the application state corresponding to each process identification.
In one embodiment, when the process management service monitors that the application state of the application program is switched for the first time, the method further includes: the kernel space stores the received process identification and the corresponding application state, the memory page corresponding to each stored process identification is scanned through the kernel space, the application state information is added into the identification bit information of the corresponding memory page, and the application state information of the corresponding memory page is recorded according to the application state.
In this embodiment, the application state of the application program is monitored by the process management service, and when the application state is switched, the application state information is added to the identification bit information of the memory page corresponding to the application program, and the corresponding application state information is recorded or updated according to the switching state, so that when a memory recovery instruction is executed, the problem that the application program is suddenly switched from background application to foreground application, and the terminal is likely to cause the application program to be stuck because the application program is still used as background application to perform memory page recovery is effectively avoided. Therefore, the accuracy of memory recovery is improved.
In one embodiment, the memory reclamation instruction also carries the number of memories to be reclaimed; scanning the memory pages of the target linked list, and determining the memory pages to be recycled of the target linked list according to the identification bit information of the memory pages comprises: taking the memory page located at the last sequence bit of the target linked list as the current memory page; when the identification bit information of the current memory page is the same as the corresponding state threshold value, determining the current memory page as a memory page to be recovered; and obtaining the next sequential memory page in a reverse order, taking the next sequential memory page as the current memory page, returning to the step of determining the current memory page as the memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold value, and obtaining all memory pages to be recovered, which are recovered by the memory, until the number of the memories to be recovered is reached.
The state threshold is used for representing whether the identification bit information conforms to the parameter of the memory page to be recovered.
Specifically, the terminal uses the memory page located at the last sequential bit of the target linked list, that is, at the tail of the target linked list, as the current memory page, scans the current memory page, and determines that the current memory page is the memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold. And obtaining a next sequential memory page according to the sequence from the chain tail to the chain head, taking the obtained next sequential memory as a current memory page, scanning the current memory page by the terminal, determining the current memory page as a memory page to be recycled when the identification bit information of the current memory page is the same as the corresponding state threshold value, and obtaining all memory pages to be recycled of the current memory recycling until the number of the memories to be recycled is reached.
In one embodiment, the identification bit information includes application state information, accessed information, and linked list state information; when the identification bit information of the current memory page is the same as the corresponding state threshold, determining the current memory page as the memory page to be recycled includes: and when the application state information, the accessed information and the linked list state information of the current memory page are respectively the same as the corresponding state threshold values, determining the current memory page as the memory page to be recovered.
Specifically, the state threshold includes a first threshold, a second threshold, and a third threshold. And when the application state information of the current memory page is the same as the first threshold, the accessed information is the same as the second threshold and the linked list state information is the same as the third threshold, determining the current memory page as the memory page to be recycled. The state threshold includes a first threshold, a second threshold, and a third threshold, which may be the same or different. Each threshold may be represented by one or more combinations of numbers, characters, and symbols. The first threshold, the second threshold and the third threshold are used for representing parameters of the corresponding memory page conforming to the memory page to be recovered.
In this embodiment, the identification bit information of the memory page is obtained by scanning the memory page of the target linked list, the memory page to be recovered is determined according to the identification bit information and the state threshold, and the next sequential memory page is obtained according to the reverse order, so that the memory recovery is realized, and the efficiency and accuracy of the memory recovery are improved.
It should be understood that, although the steps in the flowchart of fig. 2 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 2 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in fig. 3, there is provided a memory reclamation apparatus 300, including: an instruction receiving module 302, a linked list obtaining module 304, a memory page scanning module 306, and a memory recycling module 308, where:
an instruction receiving module 302, configured to receive a memory recovery instruction; the memory recycle instruction carries a linked list identification.
A linked list obtaining module 304, configured to obtain a target linked list corresponding to the memory recovery according to the linked list identifier.
The memory page scanning module 306 is configured to scan identification bit information of multiple memory pages in the target linked list.
The memory recovery module 308 is configured to determine, according to the identification bit information, a memory page to be recovered, where the memory is recovered; the memory pages to be recovered comprise the memory pages of the application programs in the background application state; and recovering the memory pages to be recovered.
In an embodiment, the apparatus further includes an instruction generating module, configured to receive the memory reclamation instruction when at least one of the following conditions is satisfied: the current available memory value is lower than the memory value required by the foreground application program to run; the sum of the used memory values of the background application program reaches a condition threshold value; the terminal is in a standby state.
In one embodiment, the apparatus further includes an application state monitoring module, configured to invoke a process management service to monitor an application state of the application program; when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state; and determining whether to recycle the memory page according to the updated application state information.
In one embodiment, the application state monitoring module is further configured to transmit process identifiers of processes respectively corresponding to before and after the switching state to a kernel space; scanning a memory page corresponding to each process identifier through a kernel space; and updating the application state information of the memory page according to the application state corresponding to the process identifier.
In one embodiment, the memory recovery module is further configured to use a memory page located in a last sequential bit of the target linked list as a current memory page; when the identification bit information of the current memory page is the same as the corresponding state threshold value, determining the current memory page as a memory page to be recovered; and obtaining the next sequential memory page in a reverse order, taking the next sequential memory page as the current memory page, returning to the step of determining the current memory page as the memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold value, and obtaining all memory pages to be recovered, which are recovered by the memory, until the number of the memories to be recovered is reached.
In an embodiment, the memory recovery module is further configured to determine the current memory page as the memory page to be recovered when the application state information, the accessed information, and the linked list state information of the current memory page are respectively the same as the respective corresponding state thresholds.
In this embodiment, when a memory recovery instruction is received, a target linked list is determined according to a linked list identifier carried by the memory recovery instruction, and then memory pages in the target linked list are scanned to obtain identifier information, so that the memory pages to be recovered are determined through the identifier information, and whether the corresponding memory pages belong to a background process or a foreground process can be better determined through the identifier information, thereby avoiding mistaken recovery of the memory pages belonging to the foreground process in a memory recovery process, and improving the accuracy of memory recovery.
For specific limitations of the memory recovery device, reference may be made to the above limitations of the memory recovery method, which is not described herein again. All or part of the modules in the memory recovery device can be realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 4. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a memory reclamation method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the architecture shown in fig. 4 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, there is provided a computer device comprising a memory storing a computer program and a processor implementing the following steps when the processor executes the computer program: receiving a memory recovery instruction; the memory recovery instruction carries a linked list identifier; acquiring a target linked list corresponding to memory recovery according to the linked list identifier; scanning identification bit information of a plurality of memory pages in a target linked list; determining a memory page to be recovered for memory recovery according to the identification bit information; the memory pages to be recovered comprise the memory pages of the application programs in the background application state; and recovering the memory pages to be recovered.
In one embodiment, the processor, when executing the computer program, further performs the steps of: the current available memory value is lower than the memory value required by the foreground application program to run; the sum of the used memory values of the background application program reaches a condition threshold value; the terminal is in a standby state.
In one embodiment, the processor, when executing the computer program, further performs the steps of: calling a process management service to monitor the application state of the application program; when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state; and determining whether to recycle the memory page according to the updated application state information.
In one embodiment, the processor, when executing the computer program, further performs the steps of: transmitting process identifications of processes respectively corresponding to the front and the rear of the switching state to a kernel space; scanning a memory page corresponding to each process identifier through a kernel space; and updating the application state information of the memory page according to the application state corresponding to the process identifier.
In one embodiment, the processor, when executing the computer program, further performs the steps of: taking the memory page located at the last sequence bit of the target linked list as the current memory page; when the identification bit information of the current memory page is the same as the corresponding state threshold value, determining the current memory page as a memory page to be recovered; and obtaining the next sequential memory page in a reverse order, taking the next sequential memory page as the current memory page, returning to the step of determining the current memory page as the memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold value, and obtaining all memory pages to be recovered, which are recovered by the memory, until the number of the memories to be recovered is reached.
In one embodiment, the processor, when executing the computer program, further performs the steps of: and when the application state information, the accessed information and the linked list state information of the current memory page are respectively the same as the corresponding state threshold values, determining the current memory page as the memory page to be recovered.
In one embodiment, the processor, when executing the computer program, further performs the steps of: setting corresponding resource priority for the application program; when detecting that the background application program and the foreground application program have at least one of a communication mechanism and a synchronization mechanism, taking the background application program as a depended application program; and updating the application state information of the memory page corresponding to the depended application program.
In this embodiment, when a memory recovery instruction is received, a target linked list is determined according to a linked list identifier carried by the memory recovery instruction, and then memory pages in the target linked list are scanned to obtain identifier information, so that the memory pages to be recovered are determined through the identifier information, and whether the corresponding memory pages belong to a background process or a foreground process can be better determined through the identifier information, thereby avoiding mistaken recovery of the memory pages belonging to the foreground process in a memory recovery process, and improving the accuracy of memory recovery.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of: receiving a memory recovery instruction; the memory recovery instruction carries a linked list identifier; acquiring a target linked list corresponding to memory recovery according to the linked list identifier; scanning identification bit information of a plurality of memory pages in a target linked list; determining a memory page to be recovered for memory recovery according to the identification bit information; the memory pages to be recovered comprise the memory pages of the application programs in the background application state; and recovering the memory pages to be recovered.
In one embodiment, the computer program when executed by the processor implements the steps of: the current available memory value is lower than the memory value required by the foreground application program to run; the sum of the used memory values of the background application program reaches a condition threshold value; the terminal is in a standby state.
In one embodiment, the computer program when executed by the processor implements the steps of: calling a process management service to monitor the application state of the application program; when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state; and determining whether to recycle the memory page according to the updated application state information.
In one embodiment, the computer program when executed by the processor implements the steps of: transmitting process identifications of processes respectively corresponding to the front and the rear of the switching state to a kernel space; scanning a memory page corresponding to each process identifier through a kernel space; and updating the application state information of the memory page according to the application state corresponding to the process identifier.
In one embodiment, the computer program when executed by the processor implements the steps of: taking the memory page located at the last sequence bit of the target linked list as the current memory page; when the identification bit information of the current memory page is the same as the corresponding state threshold value, determining the current memory page as a memory page to be recovered; and obtaining the next sequential memory page in a reverse order, taking the next sequential memory page as the current memory page, returning to the step of determining the current memory page as the memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold value, and obtaining all memory pages to be recovered, which are recovered by the memory, until the number of the memories to be recovered is reached.
In one embodiment, the computer program when executed by the processor implements the steps of: and when the application state information, the accessed information and the linked list state information of the current memory page are respectively the same as the corresponding state threshold values, determining the current memory page as the memory page to be recovered.
In one embodiment, the computer program when executed by the processor implements the steps of: setting corresponding resource priority for the application program; when detecting that the background application program and the foreground application program have at least one of a communication mechanism and a synchronization mechanism, taking the background application program as a depended application program; and updating the application state information of the memory page corresponding to the depended application program.
In this embodiment, when a memory recovery instruction is received, a target linked list is determined according to a linked list identifier carried by the memory recovery instruction, and then memory pages in the target linked list are scanned to obtain identifier information, so that the memory pages to be recovered are determined through the identifier information, and whether the corresponding memory pages belong to a background process or a foreground process can be better determined through the identifier information, thereby avoiding mistaken recovery of the memory pages belonging to the foreground process in a memory recovery process, and improving the accuracy of memory recovery.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above examples only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.
Claims (10)
1. A method of memory reclamation, the method comprising:
receiving a memory recovery instruction; the memory recovery instruction carries a linked list identifier;
acquiring a target linked list corresponding to memory recovery according to the linked list identifier;
scanning identification bit information of a plurality of memory pages in the target linked list;
determining a memory page to be recovered, which is recovered by the memory, according to the identification bit information; the memory pages to be recovered comprise the memory pages of the application programs in the background application state;
and recovering the memory page to be recovered.
2. The method of claim 1, wherein the identification bit information comprises application state information; the method further comprises the following steps:
calling a process management service to monitor the application state of the application program;
when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state;
and determining whether to recycle the memory page according to the updated application state information.
3. The method according to claim 2, wherein the updating the application state information of the memory page corresponding to the application program according to the application state includes:
transmitting process identifications of processes respectively corresponding to the front and the rear of the switching state to a kernel space;
scanning a memory page corresponding to each process identifier through the kernel space;
and updating the application state information of the memory page according to the application state corresponding to the process identifier.
4. The method of claim 1, wherein the memory reclamation instruction further carries a number of memories to be reclaimed; the scanning the memory pages of the target linked list, and determining the memory pages to be recovered of the target linked list according to the identification bit information of the memory pages includes:
taking the memory page located at the last sequence bit of the target linked list as the current memory page;
when the identification bit information of the current memory page is the same as the corresponding state threshold value, determining the current memory page as a memory page to be recovered;
and acquiring a next sequential memory page according to a reverse order, taking the next sequential memory page as a current memory page, and returning a step of determining the current memory page as a memory page to be recovered when the identification bit information of the current memory page is the same as the corresponding state threshold value, until the number of the memories to be recovered is reached, and acquiring all the memory pages to be recovered, which are recovered by the memories.
5. The method of claim 4, wherein the identification bit information comprises application state information, accessed information, and linked list state information; determining the current memory page as a memory page to be recycled when the identification bit information of the current memory page is the same as the corresponding state threshold comprises:
and when the application state information, the accessed information and the linked list state information of the current memory page are respectively the same as the corresponding state threshold values, determining the current memory page as a memory page to be recovered.
6. The method of claim 1, further comprising:
setting corresponding resource priority for the application program;
when detecting that a foreground application program and a background application program have at least one of a communication mechanism and a synchronization mechanism, taking the background application program as a depended application program;
and updating the application state information of the memory page corresponding to the depended application program.
7. A memory reclamation apparatus, the apparatus comprising:
the instruction receiving module is used for receiving the memory recovery instruction; the memory recovery instruction carries a linked list identifier;
a linked list obtaining module, configured to obtain a target linked list corresponding to memory recovery according to the linked list identifier;
a memory page scanning module, configured to scan identification bit information of multiple memory pages in the target linked list;
the memory recovery module is used for determining a memory page to be recovered, which is recovered by the memory, according to the identification bit information; the memory pages to be recovered comprise the memory pages of the application programs in the background application state; and recovering the memory page to be recovered.
8. The apparatus of claim 7, further comprising an application state monitoring module configured to invoke a process management service to monitor an application state of the application; when the application state of the application program is switched, updating the application state information of the memory page corresponding to the application program according to the application state; and determining whether to recycle the memory page according to the updated application state information.
9. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010170565.XA CN113392037B (en) | 2020-03-12 | 2020-03-12 | Memory recycling method, memory recycling device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010170565.XA CN113392037B (en) | 2020-03-12 | 2020-03-12 | Memory recycling method, memory recycling device, computer equipment and storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113392037A true CN113392037A (en) | 2021-09-14 |
CN113392037B CN113392037B (en) | 2024-06-18 |
Family
ID=77615746
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010170565.XA Active CN113392037B (en) | 2020-03-12 | 2020-03-12 | Memory recycling method, memory recycling device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113392037B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115982060A (en) * | 2021-10-14 | 2023-04-18 | 华为技术有限公司 | Memory recovery method and related device |
CN116185890A (en) * | 2023-04-23 | 2023-05-30 | 荣耀终端有限公司 | Memory recycling method and electronic equipment |
CN116775506A (en) * | 2023-08-22 | 2023-09-19 | 腾讯科技(深圳)有限公司 | Memory recycling method, device, equipment and medium |
Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104008061A (en) * | 2013-02-22 | 2014-08-27 | 华为技术有限公司 | Internal memory recovery method and device |
CN104375828A (en) * | 2014-10-27 | 2015-02-25 | 小米科技有限责任公司 | Method and device for optimizing memory |
CN106843756A (en) * | 2017-01-13 | 2017-06-13 | 中国科学院信息工程研究所 | Memory pages recovery method and system based on page classifications |
CN107220076A (en) * | 2016-09-27 | 2017-09-29 | 华为技术有限公司 | A kind of method for recovering internal storage and device |
CN108228339A (en) * | 2017-07-28 | 2018-06-29 | 珠海市魅族科技有限公司 | A kind of method for recovering internal storage and device, terminal device and computer readable storage medium |
CN108228340A (en) * | 2017-08-07 | 2018-06-29 | 珠海市魅族科技有限公司 | terminal control method and device, terminal device and computer readable storage medium |
CN109857544A (en) * | 2018-12-27 | 2019-06-07 | 努比亚技术有限公司 | Resource reclaim control method, terminal and computer readable storage medium |
CN110018900A (en) * | 2018-01-10 | 2019-07-16 | 广东欧珀移动通信有限公司 | Internal memory processing method and device, electronic equipment, computer readable storage medium |
CN110018901A (en) * | 2018-01-10 | 2019-07-16 | 广东欧珀移动通信有限公司 | Method for recovering internal storage, device, computer equipment and computer readable storage medium |
WO2019137252A1 (en) * | 2018-01-10 | 2019-07-18 | Oppo广东移动通信有限公司 | Memory processing method, electronic device, and computer-readable storage medium |
US20190220418A1 (en) * | 2016-09-28 | 2019-07-18 | Huawei Technologies Co., Ltd. | Memory Management Method and Apparatus |
CN110162396A (en) * | 2018-02-14 | 2019-08-23 | 阿里巴巴集团控股有限公司 | Method for recovering internal storage, device, system and storage medium |
-
2020
- 2020-03-12 CN CN202010170565.XA patent/CN113392037B/en active Active
Patent Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104008061A (en) * | 2013-02-22 | 2014-08-27 | 华为技术有限公司 | Internal memory recovery method and device |
CN104375828A (en) * | 2014-10-27 | 2015-02-25 | 小米科技有限责任公司 | Method and device for optimizing memory |
CN107220076A (en) * | 2016-09-27 | 2017-09-29 | 华为技术有限公司 | A kind of method for recovering internal storage and device |
US20190220418A1 (en) * | 2016-09-28 | 2019-07-18 | Huawei Technologies Co., Ltd. | Memory Management Method and Apparatus |
CN106843756A (en) * | 2017-01-13 | 2017-06-13 | 中国科学院信息工程研究所 | Memory pages recovery method and system based on page classifications |
CN108228339A (en) * | 2017-07-28 | 2018-06-29 | 珠海市魅族科技有限公司 | A kind of method for recovering internal storage and device, terminal device and computer readable storage medium |
CN108228340A (en) * | 2017-08-07 | 2018-06-29 | 珠海市魅族科技有限公司 | terminal control method and device, terminal device and computer readable storage medium |
CN110018900A (en) * | 2018-01-10 | 2019-07-16 | 广东欧珀移动通信有限公司 | Internal memory processing method and device, electronic equipment, computer readable storage medium |
CN110018901A (en) * | 2018-01-10 | 2019-07-16 | 广东欧珀移动通信有限公司 | Method for recovering internal storage, device, computer equipment and computer readable storage medium |
WO2019137252A1 (en) * | 2018-01-10 | 2019-07-18 | Oppo广东移动通信有限公司 | Memory processing method, electronic device, and computer-readable storage medium |
CN110162396A (en) * | 2018-02-14 | 2019-08-23 | 阿里巴巴集团控股有限公司 | Method for recovering internal storage, device, system and storage medium |
CN109857544A (en) * | 2018-12-27 | 2019-06-07 | 努比亚技术有限公司 | Resource reclaim control method, terminal and computer readable storage medium |
Non-Patent Citations (2)
Title |
---|
ANDERS GIDENSTAM 等: "Efficient and Reliable Lock-Free Memory Reclamation Based on Reference Counting", IEEE TRANSACTIONS ON PARALLEL AND DISTRIBUTED SYSTEMS, vol. 20, no. 8, pages 1173 - 1187 * |
魏绍蓉;: "基于对象的反向映射机制的研究", 实验室研究与探索, vol. 32, no. 01, pages 67 - 69 * |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115982060A (en) * | 2021-10-14 | 2023-04-18 | 华为技术有限公司 | Memory recovery method and related device |
CN116185890A (en) * | 2023-04-23 | 2023-05-30 | 荣耀终端有限公司 | Memory recycling method and electronic equipment |
CN116185890B (en) * | 2023-04-23 | 2023-09-19 | 荣耀终端有限公司 | Memory recycling method and electronic equipment |
CN116775506A (en) * | 2023-08-22 | 2023-09-19 | 腾讯科技(深圳)有限公司 | Memory recycling method, device, equipment and medium |
CN116775506B (en) * | 2023-08-22 | 2023-12-05 | 腾讯科技(深圳)有限公司 | Memory recycling method, device, equipment and medium |
Also Published As
Publication number | Publication date |
---|---|
CN113392037B (en) | 2024-06-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN113392037B (en) | Memory recycling method, memory recycling device, computer equipment and storage medium | |
CN110764906B (en) | Memory recovery processing method and device, electronic equipment and storage medium | |
CN108205473B (en) | Memory processing method and device, computer device and computer readable storage medium | |
CN108228341B (en) | Memory recovery method and device, terminal equipment and computer readable storage medium | |
CN109992523B (en) | Memory processing method and device, electronic equipment and computer readable storage medium | |
CN108228449B (en) | Terminal device control method and device, terminal device and computer readable storage medium | |
CN108205498B (en) | Memory recovery method and device, computer device and computer readable storage medium | |
CN111274039B (en) | Memory recycling method and device, storage medium and electronic equipment | |
US20220035655A1 (en) | Method and Device for Anonymous Page Management, Terminal Device, and Readable Storage Medium | |
CN108205471B (en) | Memory recovery method and device, computer device and computer readable storage medium | |
CN112115167B (en) | Cache system hot spot data access method, device, equipment and storage medium | |
CN108205501B (en) | Memory recovery method and device, computer device and computer readable storage medium | |
CN114185494B (en) | Memory anonymous page processing method, electronic device and readable storage medium | |
CN111679914B (en) | Memory management method, system, computer equipment and storage medium | |
CN108287760B (en) | Terminal device control method and device, terminal device and computer readable storage medium | |
CN111984413A (en) | Memory recovery method and device, electronic equipment and storage medium | |
CN108228339B (en) | Memory recovery method and device, terminal equipment and computer readable storage medium | |
CN115421909A (en) | Memory management method and device, electronic equipment and storage medium | |
CN115421907A (en) | Memory recovery method and device, electronic equipment and storage medium | |
CN108228340B (en) | Terminal control method and device, terminal equipment and computer readable storage medium | |
CN108287761B (en) | Memory recovery method and device, terminal equipment and computer readable storage medium | |
CN108228342B (en) | Terminal device control method and device, terminal device and computer readable storage medium | |
CN116107925B (en) | Data storage unit processing method | |
CN111966701A (en) | Metadata updating method, device, equipment and storage medium | |
CN108228472B (en) | Terminal device control method and device, terminal device and computer readable storage medium |
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 |