CN110727605B - Memory recovery method and device and electronic equipment - Google Patents

Memory recovery method and device and electronic equipment Download PDF

Info

Publication number
CN110727605B
CN110727605B CN201910925509.XA CN201910925509A CN110727605B CN 110727605 B CN110727605 B CN 110727605B CN 201910925509 A CN201910925509 A CN 201910925509A CN 110727605 B CN110727605 B CN 110727605B
Authority
CN
China
Prior art keywords
memory
recovery
proportion
time
memory recovery
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
CN201910925509.XA
Other languages
Chinese (zh)
Other versions
CN110727605A (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 CN201910925509.XA priority Critical patent/CN110727605B/en
Publication of CN110727605A publication Critical patent/CN110727605A/en
Application granted granted Critical
Publication of CN110727605B publication Critical patent/CN110727605B/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/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)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the application discloses a memory recovery method and device and electronic equipment. The method comprises the following steps: acquiring the memory allocation time consumption in a set window period; acquiring a memory recovery proportion corresponding to the memory allocation consumed time, wherein the memory recovery proportion represents the proportion among multiple memory recovery objects, the recovery costs of different types of memory recovery objects are different, and the memory recovery proportions corresponding to different memory allocation consumed times are different; and performing memory recovery based on the memory recovery proportion. Therefore, under the condition that the memory recovery ratios corresponding to different memory allocation consumed time are different, the current memory allocation consumed time can be obtained firstly when memory recovery starts, and then the process memory recovery ratio is determined according to the current memory allocation consumed time, so that the memory recovery efficiency is improved, and the system performance is improved.

Description

Memory recovery method and device and electronic equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a memory recovery method and apparatus, and an electronic device.
Background
The memory is also called main memory, which is a storage space that the CPU can directly address, and is made of semiconductor devices. The space of the memory in the electronic device is limited, and in order to ensure that the system has enough memory to be used, the system of the electronic device usually performs memory recovery under certain conditions. However, the related memory recovery method also lacks flexibility.
Disclosure of Invention
In view of the foregoing problems, the present application provides a memory recycling method, device and electronic device to improve the foregoing problems.
In a first aspect, the present application provides a memory recycling method, where the method includes: acquiring the memory allocation time consumption in a set window period; acquiring a memory recovery proportion corresponding to the memory allocation consumed time, wherein the memory recovery proportion represents the proportion among multiple memory recovery objects, the recovery costs of different types of memory recovery objects are different, and the memory recovery proportions corresponding to different memory allocation consumed times are different; and performing memory recovery based on the memory recovery proportion.
In a second aspect, the present application provides a memory recycling device, the device comprising: the time acquisition unit is used for acquiring the memory allocation time consumption in the current set window period; a recovery parameter obtaining unit, configured to obtain a memory recovery ratio corresponding to the memory allocation consumed time, where the memory recovery ratio represents a ratio between multiple memory recovery objects, recovery costs of different types of memory recovery objects are different, and memory recovery ratios corresponding to different memory recovery scenes are different; and the recovery unit is used for recovering the memory based on the memory recovery proportion.
In a third aspect, the present application provides an electronic device comprising one or more processors and a memory; one or more programs are stored in the memory and configured to be executed by the one or more processors to implement the methods described above.
In a fourth aspect, the present application provides a computer readable storage medium having program code stored therein, wherein the method described above is performed when the program code is executed by a processor.
According to the memory recovery method, the memory recovery device and the electronic equipment, the memory allocation consumed time in the current set window period is obtained, then the memory recovery proportion corresponding to the memory allocation consumed time is obtained, and memory recovery is carried out based on the memory recovery proportion. Therefore, under the condition that the memory recovery ratios corresponding to different memory allocation consumed time are different, the current memory allocation consumed time can be obtained firstly when memory recovery starts, and then the process memory recovery ratio is determined according to the current memory allocation consumed time, so that the memory recovery efficiency is improved, and the system performance is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 shows a flowchart of a memory reclamation method according to an embodiment of the present application;
fig. 2 is a flowchart illustrating a memory reclamation method according to another embodiment of the present application;
fig. 3 is a flowchart illustrating a memory reclamation method according to another embodiment of the present application;
fig. 4 shows a block diagram of a memory recovery apparatus according to an embodiment of the present application;
fig. 5 is a block diagram illustrating a memory recycling apparatus according to still another embodiment of the present disclosure;
fig. 6 is a block diagram illustrating a memory recycling apparatus according to another embodiment of the present disclosure;
fig. 7 is a block diagram illustrating a memory reclamation unit according to another embodiment of the present application;
fig. 8 is a block diagram illustrating a structure of an electronic device for executing a memory reclamation method according to an embodiment of the present application in real time;
fig. 9 illustrates a storage unit for storing or carrying program codes for implementing the memory reclamation method according to the embodiment of the present application in real time.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
For operating systems, memory reclamation is a relatively common mechanism because the size of the memory itself is limited. The main reasons for performing memory recovery are two reasons: the system needs to provide enough memory for the memory application which comes suddenly at any time, so that the use of the cache and the use of other related memories do not cause the rest of the memory of the system to be in a little state for a long time. In addition, when an application larger than the free memory comes, the memory recovery is also triggered. At present, the Linux kernel memory recovery technology is as follows: the memory reclamation is performed only when the memory space is detected to be insufficient. However, in the case of a large memory usage scenario (for example, a large file needs to be cached, a large application needs to be started, and the like), if the memory space is insufficient, the memory recovery process is performed, which may cause the problems of slow system response and stutter, and may seriously affect the performance of the device and the user experience.
The inventor researches related memory recycling processes to find that the related memory recycling mode lacks certain flexibility. For example, an Android operating system is taken as an example. In an Android operating system, two memory recovery mechanisms mainly exist. One is a kswapd process based reclamation mechanism in which kswapd processes run in the background periodically. The other is a recovery mechanism based on a direct relax process, in which the direct relax process starts to perform memory recovery when receiving a memory allocation demand. Therefore, it can be found that the memory recovery parameters of the related memory recovery methods are relatively fixed.
Therefore, the inventor proposes that under the condition that the memory recovery ratios corresponding to different memory allocation consumed times are different in the present application, the current memory allocation consumed time can be obtained before the memory recovery starts, and then the process memory recovery ratio is determined according to the current memory allocation consumed time, so that the memory recovery efficiency is improved, and the system performance is improved.
Embodiments of the present application will be described in detail below with reference to the accompanying drawings.
Referring to fig. 1, a method for memory recycling according to an embodiment of the present application includes:
step S110: and acquiring the time consumed by memory allocation in the set window period.
It can be understood that when the electronic device performs memory allocation, for example, when a large memory is allocated, the current available memory of the system may not meet the current memory allocation requirement, so that the memory needs to be recycled to meet the memory allocation requirement, and a certain time is consumed in the recycling process, so that the electronic device may consume a certain time in the memory allocation process.
As a manner, in the embodiment of the present application, the pre-calculated memory allocation time consumption in the current set window period may be obtained when starting memory recovery, where as a manner, it may be determined that memory recovery is currently started when it is detected that there is a process in charge of memory recovery to start running. For example, if the environment in which the embodiment operates is in an Android operating system, it may be determined that memory recovery is currently started when it is detected that a kswapd process or a direct callback process is operating.
It should be noted that it is time to acquire memory allocation in a set window period, where the set window period refers to a plurality of periodic time periods for modifying a memory recovery ratio, where the time period is given by the electronic device according to a time required by the application program to perform memory recovery, and one time period may be used as one set window period.
Wherein, the length of the setting window period can be adjusted according to various conditions. Optionally, as a mode, the usage frequency of the application program in the electronic device may be counted, the time of the whole day is divided into a plurality of time periods based on the usage frequency, and then the length of one set window period is configured for each time period. Optionally, as another mode, the length of the set window period may be dynamically extended or shortened according to the number of the applications in the running state in the mobile terminal.
Furthermore, it should be noted that, in the running process of some application programs, there is a certain requirement for memory consumption, and then determining different memory allocation time consumptions for different application programs can better bring favorable conditions for smooth running of the application programs. For example, memory may be frequently required for some applications during operation. For example, for short video-like applications, memory allocation may be applied incrementally to cache the requested short video. For example, for an instant messaging application, it may be applied to allocate memory to buffer video image data when a video call is detected in operation. For another example, some applications themselves will apply for more memory when they are started.
Step S120: and acquiring a memory recovery proportion corresponding to the memory allocation consumed time, wherein the memory recovery proportion represents the proportion among multiple memory recovery objects, the recovery costs of different types of memory recovery objects are different, and the memory recovery proportions corresponding to different memory allocation consumed times are different.
As a mode, the step of obtaining the memory recycling ratio corresponding to the memory allocation consumed time includes: acquiring the current initial memory recovery proportion; determining a memory recovery ratio updating strategy according to memory allocation time consumption; and obtaining the memory recycling proportion corresponding to the memory allocation consumed time based on the memory recycling proportion updating strategy. The initial memory recovery ratio represents a system default recovery ratio of the current application program before memory recovery.
As shown in the foregoing, in the embodiment of the present application, there may be multiple ways to determine the current memory allocation consumed time, and the memory recycling ratios corresponding to different determined memory allocation consumed times are different, so as to adapt to the respective memory recycling requirements of different processes consumed time.
For example, in an embodiment, the memory reclamation object may include an Anonymous page (Anonymous page) and a File page (File page). Anonymous pages are understood to be pages without file background, such as heap, stack, data segment, etc., which are not in the form of a file. A file page is understood to be a page having a file background, and a cache generated in a memory after a program reads the file, for example, for the data stored in the file page, the corresponding data can be found in a disk.
Where the cost is different for reclaiming anonymous pages and for reclaiming file pages. In the process of recovering the anonymous page, the anonymous page is compressed and stored in the RAM, and because the process needs to use the CPU to compress the anonymous page and needs to decompress the compressed anonymous page when in use, the process of recovering the anonymous page needs to consume certain CPU time and is relatively slow. The recovery of the file page is divided into two conditions, if the file content corresponding to the file page is not modified, the file page content is directly discarded, so that the recovery of the file page which is not modified is completed; and if the file content corresponding to the file page is modified, writing the file content back to the disk and discarding the file page so as to complete the recovery of the file page which is not modified. When the file content of the collected file page is reused, the file content is read from the disk again when necessary. In general, many file pages are not modified, so the reclamation process is relatively fast. As a mode, the system may tend to recover anonymous pages and retain file pages to reduce the cost caused by re-reading the disk data IO again, but when the experience is affected by the deadlock possibly caused by slow memory recovery, the proportion of recovering file pages may be increased, and the memory recovery speed is increased.
It can be understood that, when the electronic device detects that a plurality of applications are in an operating state, the consumed memory is large, and in this case, the memory needs to be recycled faster, so that, when the number of applications in the operating state is large, the proportion of memory recycling objects with higher recycling efficiency in the plurality of memory recycling objects is high.
Illustratively, anonymous pages and document pages are taken as examples. It will be appreciated that the recycle rate of file pages is higher than the recycle efficiency of anonymous pages. Wherein the higher the file page specific gravity, the faster the memory recovery efficiency is required for the characterization. Then the recycle ratio of the file pages may be higher than the recycle ratio of the anonymous pages if a larger number of applications are detected to be in a running state. For example, if the number of applications currently in a running state is 5, the ratio of anonymous pages to file pages is 50:150, and if the number of applications currently in a running state is 8, the ratio of anonymous pages to file pages is 10: 190. And if the number of the application programs currently in the running state is 1, the ratio of the anonymous page to the file page is 80: 120.
Step S130: and performing memory recovery based on the memory recovery proportion.
Specifically, the memory recovery based on the memory recovery ratio may include two aspects: firstly, the application program configures the memory recovery proportion corresponding to the current application only by acquiring the process memory allocation time consumption in the current window period, and does not recover the memory; on the other hand, when the application program detects that the memory recovery is needed, the current memory recovery proportion is obtained by obtaining the process memory allocation time consumption in the current window period, and the memory recovery operation is immediately carried out.
According to the memory recovery method, the memory allocation consumed time in the current set window period is firstly obtained, then the memory recovery proportion corresponding to the memory allocation consumed time is obtained, and memory recovery is carried out based on the memory recovery proportion. Therefore, under the condition that the memory recovery ratios corresponding to different memory allocation consumed time are different, the current memory allocation consumed time can be obtained firstly when memory recovery starts, and then the process memory recovery ratio is determined according to the current memory allocation consumed time, so that the memory recovery efficiency is improved, and the system performance is improved.
Referring to fig. 2, a memory recycling method provided in the embodiment of the present application includes:
step S210: and acquiring the time consumed by memory allocation in the set window period.
It is understood that the amount of memory consumed may vary depending on the number of applications currently running. For example, if 10 applications are currently running, there is a greater probability that more memory needs to be allocated than if 3 applications are running. In order to better adapt the running state of the application program of the current electronic device, as one way, the number of the application programs currently in the running state may be obtained first; and then increasing or shortening the window length according to the number of the application programs in the current running state, wherein the window length and the number of the application programs are in an inversely proportional linear relation. That is, the larger the number of applications in the running state, the shorter the length of the setting window.
Therefore, by the mode, when the number of the running application programs is large, the length of the setting window is shortened, and when the number of the running application programs is small, the length of the setting window is prolonged, so that the real-time running state can be better adapted.
Step S220: and acquiring the current initial memory recovery proportion.
It is to be understood that the initial memory recycle ratio represents a default recycle ratio of the system before memory recycle of the current application program. Firstly, the mobile terminal judges whether the application program needs to carry out memory recovery, and if so, the application program takes the recovery ratio defaulted by the system as the initial memory recovery ratio.
Optionally, in this embodiment, the detection of the currently running application may be mainly performed, and when it is detected that the memory allocation time is too long in a process, it may be determined that the current system memory status is not good, and then the recovery parameter policy needs to be adjusted to accelerate the recovery. The time consumption of the kernel memory allocation process can be monitored, and since all the application processes allocate the memory to the kernel via the unified memory management mechanism path, the memory allocation process only needs to be monitored at the kernel, which can be simply understood as "the time consumption of one process entering and exiting the kernel memory allocation function".
Illustratively, the length of the current preset window period is 1s, there may be 2 applications that have memory allocation requirements in the preset window period, the memory allocation time of the application 1 is 150ms, and the memory allocation time of the application 2 is 50ms, the memory allocation time of the application is compared with the first preset threshold, and the memory allocation time of the application 1 exceeds the first preset threshold (100ms), at this time, the application adjusts the recycling parameter, that is, adjusts the recycling proportion of the application.
Step S230: and determining a memory recycling proportion updating strategy according to the memory allocation time consumption.
In specific implementation, when the user operates the application program to trigger the application program to perform memory recovery according to actual needs, for example, a memory recovery time interval may be determined according to information that the application installed in the terminal is used by the user operation and memory occupation information, and memory recovery is triggered according to a preset memory recovery time interval, so that planned recovery of the memory is realized, and available idle memory in the terminal is kept at a better level.
Here, in order to achieve the planned recycling of the application memory, the application memory may be recycled by setting a preset memory recycling time interval, where the preset memory recycling time interval may be one or multiple. Under the condition that the frequency, time or/and times of using the application program are/is single, a preset memory recovery time can be set to recover the application program memory; under the condition that the frequency, time or/and times of using the application program are/is unstable, a preset memory recovery time interval can be set for the application program which is frequently used, and the memory recovery speed of the application program under the current condition is accelerated. For example, if the frequency of using the application program and the memory occupation amount of the user all day are stable, only one memory recovery time interval may be set. For example, in one mode, some applications of the electronic device are started periodically, such as an alarm clock program, and the applications are only used for a certain time period set by a user, and the use frequency and the memory occupation amount of the alarm clock program are stable relative to the communication type applications. We only need to set a memory reclamation interval for the application at this time, for example, memory reclamation immediately after using the alarm clock program.
Or, if the user only uses the application in a time slot in a concentrated manner all day, and the frequency of using the application program is relatively stable, the memory recovery time interval in the time slot may be set, and the memory recovery is not performed in other time slots. For example, in one approach, certain applications of the electronic device may be inertially activated for a certain period of time each day due to the user's usage habits. Such as take-away applications, may be routinely launched each day when approaching a meal point, or video applications may be routinely launched by a user each day when the user is seated in a subway. At this time, the frequency of using the application and the memory footprint of the application are maintained within a comparable interval, and the application is in a more stable state.
If the frequency of the applications used by the user in different time periods of the day is greatly different, different memory reclamation time intervals can be used in different time periods of the day. For example, in one approach, the frequency of use by certain applications of the electronic device may change based on the user himself. For example, in a chat application, a user may use the application according to different situations, so that the use frequency of the application is variable, and at this time, a plurality of memory recovery time intervals may be set, and different memory recovery time intervals are used for memory recovery in different time periods, which is beneficial to improving the smoothness of use of the electronic device.
For another example, it may also be considered that the working days and the non-working days in the one week time are different from each other in the usage of the application program, and different memory recovery time intervals are set for the working days and the non-working days, respectively. For example, if the frequency of using the video application program by the user on saturday and day is significantly more frequent than the frequency of using the application program on weekdays, the memory recovery frequency can be increased on saturday and day, and a shorter memory recovery time interval is set.
In addition, it may also be configured to trigger memory recovery when the free memory in the system is less than a certain threshold (that is, trigger memory recovery according to memory occupation information of an application installed in the terminal), trigger memory recovery according to the memory occupation information of the application and the size of the free memory in the system when it is monitored that the application is started or switched to the foreground interface (that is, trigger memory recovery according to information that the application is used by a user operation and the memory occupation information), trigger memory recovery when it is monitored that the time length that the application stays in the background exceeds a set time length (that is, trigger memory recovery according to information that the application is used by the user operation), and the like.
It is understood that when an application is run, the electronic device executes the corresponding application program and allocates the required memory space, i.e. each running application program has a memory allocation area. The electronic equipment detects the time consumed by the memory allocation of the process in real time or at regular time, records the time consumed by the memory allocation of the current application program, compares the time consumed by the memory allocation of the current application program with a preset threshold value to see whether the time consumed by the memory allocation of the current application program exceeds the preset threshold value, and updates the memory recovery proportion of the application program according to different values exceeding the threshold value.
In this embodiment, there may be a plurality of ways to update the initial memory recycling ratio.
As one mode, acquiring memory allocation consumed time of a currently running program, and if the memory allocation consumed time is less than or equal to a first preset threshold, taking the memory recovery ratio of the current process as a default memory recovery ratio; if the memory allocation time consumption is larger than the first preset threshold and smaller than or equal to a second preset threshold, updating the memory recovery ratio to be a first memory recovery ratio in the current process; wherein the first preset threshold is smaller than the second preset threshold; if the memory allocation consumed time is greater than the second preset threshold and less than or equal to a third preset threshold, updating the memory recovery ratio to be a second memory recovery ratio in the current process; wherein the second preset threshold is smaller than the third preset threshold; and if the memory allocation consumed time is greater than the third preset threshold, updating the memory recovery ratio to be a third memory recovery ratio by the current process.
For example, the first preset threshold is 100ms, the second preset threshold is 200ms, and the third preset threshold is 300ms when memory allocation consumes in the current window period. When detecting that the memory allocation of the application process currently in the running state takes more than 100ms but does not take more than 200ms, the memory recycling ratio can be set to 160:40, namely the ratio of the recovered anonymous page to the file page is 160: 40; or detecting that the memory allocation time of the application process currently in the running state exceeds 200ms but does not exceed 300ms, at this time, the memory recovery ratio may be set to 100:100, namely the ratio of the recovered anonymous page to the file page is 100: 100; or detecting that the memory allocation time of the application process currently in the running state exceeds 300ms, at this time, the memory recovery ratio may be set to 40:160, i.e., the ratio of recycled anonymous pages to file pages is 40: 160. However, this recycle proportion is not always constant, and the recycle proportion is adjusted according to the speed of memory allocation of the application process. For example, if the mobile terminal detects that the latest memory allocation of the application program consumes a long time, the parameter adjustment is accelerated, and if the memory allocation consumes a short time after a period of time, the parameter may be adjusted back to a preset default parameter, for example, the memory recovery ratio of the application program is adjusted to 160: after 40, if the preset threshold is not exceeded after a period of time, the default parameters are adjusted back, such as 180: 60.
step S240: and obtaining the memory recycling proportion corresponding to the memory allocation consumed time based on the memory recycling proportion updating strategy.
As a mode, a memory reclamation ratio may be configured for each memory reclamation, so that the required memory may be reclaimed in the memory reclamation process. The electronic equipment detects the memory allocation time consumption of the application program in real time or at regular time, records the current memory allocation time consumption of the application program, compares the current memory allocation time consumption of the application program with a preset threshold value to see whether the current memory allocation time consumption of the application program exceeds the preset threshold value, and updates the initial memory recovery proportion of the application program to the memory recovery proportion of the application program corresponding to the memory allocation time consumption according to the difference of the current memory allocation time consumption of the application program exceeding the preset threshold value.
Step S250: and performing memory recovery based on the memory recovery proportion.
The memory recycling method includes the steps of firstly obtaining memory allocation consumed time in a current set window period, then obtaining a current initial memory recycling proportion, then determining a memory recycling proportion updating strategy according to the memory allocation consumed time, obtaining a memory recycling proportion corresponding to the memory allocation consumed time based on the memory recycling proportion updating strategy, and finally performing memory recycling based on the updated memory recycling proportion. Therefore, under the condition that the memory recovery ratios corresponding to different memory allocation consumed time are different, the current memory allocation consumed time can be obtained firstly when memory recovery starts, and then the process memory recovery ratio is determined according to the current memory allocation consumed time, so that the memory recovery efficiency is improved, and the system performance is improved.
Referring to fig. 3, a memory recycling method provided in the embodiment of the present application includes:
step S310: and acquiring the time consumed by memory allocation in the set window period.
Step S320: and acquiring a memory recovery proportion corresponding to the memory allocation consumed time, wherein the memory recovery proportion represents the proportion among multiple memory recovery objects, the recovery costs of different types of memory recovery objects are different, and the memory recovery proportions corresponding to different memory allocation consumed times are different.
Step S330: and acquiring the available memory of the current system.
As a way, for an application program that needs to perform memory allocation, the size of the memory required by the application program to operate may be obtained according to the historical operation information of the application program, then the available memory of the current system is obtained, and the sizes of the two are compared to perform memory recovery operation.
Step S340: and calculating the difference between the current system available memory and the first memory to obtain a second memory.
It is understood that the number of applications currently running may be different, and the memory consumed may also be different, and may also result in different available memory for the current system.
As a trigger mechanism, the electronic device may determine the acquired currently available memory, and then start memory recycling when it is determined that the currently available memory is smaller than a specified threshold. As another way, in order to enable the electronic device to start memory reclamation in advance before the currently available memory is smaller than the specified threshold, the first memory may be introduced to help memory reclamation in advance.
It should be noted that the first memory represents a smaller memory capacity. For example, the value of the first memory is set to 10MB, the specified threshold value of the available memory for triggering the electronic device to perform memory recycling is 40MB, and in this way, the current electronic device performs memory recycling when the available memory is 40 MB. In contrast, in the case of introducing the first memory, the electronic device may perform memory reclamation when the system available memory is less than 50 MB.
Therefore, by the method, when the memory required by the application program is large, the memory recovery operation can be performed on other application programs in advance, so that the memory allocation requirement of the application program can be better met.
Step S350: and comparing the size of the memory capacity required by the second memory and the current application program.
It is understood that the second memory is smaller than the actually remaining available memory of the electronic device.
In the embodiments of the present application, there are various ways to determine the size of the first memory value.
As a way of doing this, it is possible that the memory consumed during each run is different for the same application. For example, for an application program in the video playing class, when performing online video playing, the application program occupies a memory to perform video image data caching, and because the size of the video played each time is different, the occupied memory is also different. If the memory allocation is performed according to the maximum memory historically occupied by the application program every time, the memory resource may be wasted. In order to determine a more reasonable memory allocation situation in real time, historical memory consumption of the corresponding application program may be counted and used as a basis for memory allocation.
Then in this manner, the size of the first memory may be set according to the historical memory consumption of the application, the method comprising: acquiring the historical memory consumption of the current application program; if the historical memory consumption is larger than a target threshold value, configuring the value of the first memory as a first memory value; if the historical memory consumption is not larger than the target threshold, configuring the value of the first memory as a second memory value; wherein the first memory value is greater than the second memory value.
Alternatively, the size of the first memory may be determined according to the size of the free memory of the current system, and the method includes: acquiring a free memory of a current system, and configuring the value of the first memory as a first memory value if the free memory of the current system is larger than a memory required by an application program; if the system free memory is not larger than the memory required by the application program, configuring the value of the first memory as a second memory value; wherein the first memory value is greater than the second memory value.
Step S360: and when the required memory capacity is smaller than the second memory, executing the memory recovery based on the memory recovery proportion.
According to the memory recovery method, the memory allocation consumed time in the current set window period is firstly obtained, then the current initial memory recovery proportion is obtained, and then the memory recovery is carried out on the application program of which the required memory is smaller than the system available memory based on the memory recovery proportion according to the size of the memory required by the application program and the size of the idle available memory of the system. Therefore, in different idle available memories of the system, the memory recovery can be carried out on application programs with different requirements according to different memory recovery proportions, the memory recovery efficiency is improved, and the influence on the smoothness brought by the memory recovery process to the current application is reduced.
Referring to fig. 4, a memory recycling apparatus 400 provided in the present application, the apparatus 400 includes:
the time obtaining unit 410 is configured to obtain a memory allocation time consumption within a set window period.
As a mode, the time obtaining unit 410 is specifically configured to obtain the memory recovery time of the application process currently performing memory recovery, and in addition, is also configured to obtain the number of the application programs currently in the running state, and increase or shorten the length of the preset window according to the number of the application programs.
A recycling parameter obtaining unit 420, configured to obtain a memory recycling ratio corresponding to the memory allocation consumed time, where the memory recycling ratio represents a ratio between multiple memory recycling objects, and the recycling costs of different types of memory recycling objects are different, and the memory recycling ratios corresponding to different memory allocation consumed times are different.
As one mode, the recovery parameter obtaining unit 420 is specifically configured to obtain an initial memory recovery ratio corresponding to the memory allocation consumed time; detecting an application program in a running state; and updating the initial memory recovery proportion to obtain a memory recovery proportion corresponding to the memory allocation consumed time based on the application program in the running state.
A recycling unit 430, configured to recycle the memory based on the memory recycling ratio.
As one mode, as shown in fig. 5, the apparatus 400 further includes:
the available memory obtaining unit 440 is specifically configured to obtain a current system available memory. In this way, the difference between the current system available memory and the first memory is calculated to obtain a second memory; comparing the size of the memory capacity required by the second memory and the current application program; and when the required memory capacity is smaller than the second memory, executing the memory recovery based on the memory recovery proportion.
As one mode, as shown in fig. 6, the apparatus 400 further includes:
the memory consumption calculating unit 450 is specifically configured to obtain a historical memory consumption of the current application program. In this way, if the historical memory consumption is greater than a target threshold, configuring the value of the first memory as a first memory value; if the historical memory consumption is not larger than the target threshold, configuring the value of the first memory as a second memory value; wherein the first memory value is greater than the second memory value.
As one mode, as shown in fig. 7, the recycling parameter obtaining unit 420 further includes the following sub-units:
a proportion obtaining module 422, configured to obtain a current initial memory recycling proportion.
A policy updating module 424, configured to determine a memory recycling ratio updating policy according to memory allocation consumed time, where if the memory allocation consumed time is less than or equal to a first preset threshold, the current process memory recycling ratio is a default memory recycling ratio; if the memory allocation time consumption is larger than the first preset threshold and smaller than or equal to a second preset threshold, updating the memory recovery ratio to be a first memory recovery ratio in the current process; wherein the first preset threshold is smaller than the second preset threshold; if the memory allocation consumed time is larger than the second preset threshold and smaller than or equal to a third preset threshold, updating the memory recovery ratio to be a second memory recovery ratio by the current process; wherein the second preset threshold is smaller than the third preset threshold; and if the memory allocation consumed time is greater than the third preset threshold, updating the memory recovery ratio to be a third memory recovery ratio in the current process.
A recycling parameter determining module 426, configured to obtain a memory recycling ratio corresponding to the memory allocation consumed time based on the memory recycling ratio updating policy.
It should be noted that the device embodiment and the method embodiment in the present application correspond to each other, and specific principles in the device embodiment may refer to the contents in the method embodiment, which is not described herein again.
An electronic device provided by the present application will be described with reference to fig. 8.
Referring to fig. 8, based on the memory recycling method and the memory recycling apparatus, another electronic device 100 capable of executing the memory recycling method is further provided in the embodiment of the present application. The electronic device 100 includes one or more processors 102 (only one shown), a memory 104, and a network module 106 coupled to each other. The memory 104 stores programs that can execute the content of the foregoing embodiments, and the processor 102 can execute the programs stored in the memory 104.
Processor 102 may include one or more processing cores, among other things. The processor 102 interfaces with various components throughout the electronic device 100 using various interfaces and circuitry to perform various functions of the electronic device 100 and process data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 104 and invoking data stored in the memory 104. Alternatively, the processor 102 may be implemented in hardware using at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 102 may integrate one or a combination of a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a modem, and the like. Wherein, the CPU mainly processes an operating system, a user interface, an application program and the like; the GPU is used for rendering and drawing display content; the modem is used to handle wireless communications. It is understood that the modem may not be integrated into the processor 102, but may be implemented by a communication chip.
The Memory 104 may include a Random Access Memory (RAM) or a Read-Only Memory (Read-Only Memory). The memory 104 may be used to store instructions, programs, code sets, or instruction sets. The memory 104 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing various method embodiments described below, and the like. The storage data area may also store data created by the terminal 100 in use, such as a phonebook, audio-video data, chat log data, and the like.
The network module 106 is configured to receive and transmit electromagnetic waves, and implement interconversion between the electromagnetic waves and electrical signals, so as to communicate with a communication network or other devices, for example, an audio playing device. The network module 106 may include various existing circuit elements for performing these functions, such as an antenna, a radio frequency transceiver, a digital signal processor, an encryption/decryption chip, a Subscriber Identity Module (SIM) card, memory, and so forth. The network module 106 may communicate with various networks, such as the internet, an intranet, a wireless network, or with other devices via a wireless network. The wireless network may include a cellular telephone network, a wireless local area network, or a metropolitan area network. For example, the network module 106 may interact with a base station.
Referring to fig. 9, a block diagram of a computer-readable storage medium according to an embodiment of the present application is shown. The computer-readable medium 800 has stored therein a program code that can be called by a processor to execute the method described in the above method embodiments.
The computer-readable storage medium 800 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read only memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer-readable storage medium 800 includes a non-volatile computer-readable storage medium. The computer readable storage medium 800 has storage space for program code 810 to perform any of the method steps of the method described above. The program code can be read from or written to one or more computer program products. The program code 810 may be compressed, for example, in a suitable form.
According to the memory recovery method, the memory recovery device and the electronic equipment, the memory allocation consumed time in the set window period is firstly obtained, then the proportion memory recovery proportion between multiple memory recovery objects corresponding to the memory allocation consumed time is obtained, and under the condition that the recovery costs of different types of memory recovery objects are different, memory recovery is carried out based on the memory recovery proportion. Therefore, under the condition that the memory recovery ratios corresponding to different memory allocation consumed time are different, the current memory allocation consumed time can be obtained firstly when memory recovery starts, and then the process memory recovery ratio is determined according to the current memory allocation consumed time, so that the memory recovery efficiency is improved, and the system performance is improved.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (5)

1. A method for memory reclamation, the method comprising:
acquiring the memory allocation time consumption in a set window period;
acquiring the current initial memory recovery proportion;
determining a memory recovery ratio updating strategy according to memory allocation time consumption;
obtaining a memory recovery proportion corresponding to the memory allocation consumed time based on the memory recovery proportion updating strategy, wherein the memory recovery proportion represents the proportion among multiple memory recovery objects, the recovery costs of different types of memory recovery objects are different, and the memory recovery proportions corresponding to different memory allocation consumed times are different;
if the memory recovery requirement is detected, acquiring the available memory of the current system; calculating the difference between the available memory of the current system and the first memory to obtain a second memory; comparing the size of the memory capacity required by the second memory and the current application program; when the required memory capacity is smaller than the second memory, performing memory recovery based on the memory recovery ratio; the method further comprises the following steps: acquiring the historical memory consumption of the current application program; if the historical memory consumption is larger than a target threshold value, configuring the value of the first memory as a first memory value; if the historical memory consumption is not larger than the target threshold, configuring the value of the first memory as a second memory value; wherein the first memory value is greater than the second memory value;
the method further comprises the following steps:
acquiring the number of application programs in a running state at present;
and increasing or shortening the window length of the set window period according to the number of the application programs in the current running state, wherein the window length and the number of the application programs are in an inversely proportional linear relation.
2. The method according to claim 1, wherein the step of determining the memory reclamation proportion update policy according to the memory allocation time consumption comprises:
if the memory allocation consumed time is less than or equal to a first preset threshold, the memory recovery proportion of the current process is a default memory recovery proportion;
if the memory allocation time consumption is larger than the first preset threshold and smaller than or equal to a second preset threshold, updating the memory recovery ratio to be a first memory recovery ratio in the current process; wherein the first preset threshold is smaller than the second preset threshold;
if the memory allocation consumed time is greater than the second preset threshold and less than or equal to a third preset threshold, updating the memory recovery ratio to be a second memory recovery ratio in the current process; wherein the second preset threshold is smaller than the third preset threshold;
and if the memory allocation consumed time is greater than the third preset threshold, updating the memory recovery ratio to be a third memory recovery ratio in the current process.
3. A memory reclamation apparatus, the apparatus comprising:
the time acquisition unit is used for acquiring the memory allocation time consumption in a set window period;
the recovery parameter acquisition unit is used for acquiring the current initial memory recovery proportion; determining a memory recovery ratio updating strategy according to memory allocation time consumption; obtaining a memory recovery proportion corresponding to the memory allocation consumed time based on the memory recovery proportion updating strategy, wherein the memory recovery proportion represents the proportion among multiple memory recovery objects, the recovery costs of different types of memory recovery objects are different, and the memory recovery proportions corresponding to different memory allocation consumed times are different;
the recovery unit is used for acquiring the available memory of the current system if the memory recovery requirement is detected; calculating the difference between the available memory of the current system and the first memory to obtain a second memory; comparing the size of the memory capacity required by the second memory and the current application program; when the required memory capacity is smaller than the second memory, performing memory recovery based on the memory recovery ratio; acquiring the historical memory consumption of the current application program; if the historical memory consumption is larger than a target threshold value, configuring the value of the first memory as a first memory value; if the historical memory consumption is not larger than the target threshold, configuring the value of the first memory as a second memory value; wherein the first memory value is greater than the second memory value;
the time acquisition unit is also used for acquiring the number of the application programs currently in the running state;
and increasing or shortening the window length of the set window period according to the number of the application programs in the current running state, wherein the window length and the number of the application programs are in an inversely proportional linear relation.
4. An electronic device comprising one or more processors and memory; one or more programs stored in the memory and configured to be executed by the one or more processors to perform the method of any of claims 1-2.
5. A computer-readable storage medium, having a program code stored therein, wherein the program code when executed by a processor performs the method of any of claims 1-2.
CN201910925509.XA 2019-09-27 2019-09-27 Memory recovery method and device and electronic equipment Active CN110727605B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910925509.XA CN110727605B (en) 2019-09-27 2019-09-27 Memory recovery method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910925509.XA CN110727605B (en) 2019-09-27 2019-09-27 Memory recovery method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN110727605A CN110727605A (en) 2020-01-24
CN110727605B true CN110727605B (en) 2022-06-21

Family

ID=69218498

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910925509.XA Active CN110727605B (en) 2019-09-27 2019-09-27 Memory recovery method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN110727605B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110727606A (en) * 2019-09-27 2020-01-24 Oppo(重庆)智能科技有限公司 Memory recovery method and device and electronic equipment
CN112783656B (en) * 2021-01-29 2024-04-30 杭州网易智企科技有限公司 Memory management method, medium, device and computing equipment
CN117707988A (en) * 2023-08-08 2024-03-15 荣耀终端有限公司 Method and device for recycling memory

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20080036332A (en) * 2006-10-23 2008-04-28 삼성전자주식회사 Nonvolatile semi-conductor memory device and data recovery method of the nonvolatile semi-conductor memory device
US7974291B1 (en) * 2001-12-21 2011-07-05 Juniper Networks, Inc. Reorder engine with error recovery
CN108776624A (en) * 2018-05-29 2018-11-09 北京小米移动软件有限公司 Determine the method, apparatus and storage medium of terminal interim card reason
CN109086141A (en) * 2018-09-19 2018-12-25 北京京东尚科信息技术有限公司 EMS memory management process and device and computer readable storage medium
CN109857555A (en) * 2019-01-15 2019-06-07 Oppo广东移动通信有限公司 Method for recovering internal storage and device, storage medium and electronic equipment
CN110083450A (en) * 2019-04-09 2019-08-02 Oppo广东移动通信有限公司 Method for recovering internal storage, device, electronic equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7974291B1 (en) * 2001-12-21 2011-07-05 Juniper Networks, Inc. Reorder engine with error recovery
KR20080036332A (en) * 2006-10-23 2008-04-28 삼성전자주식회사 Nonvolatile semi-conductor memory device and data recovery method of the nonvolatile semi-conductor memory device
CN108776624A (en) * 2018-05-29 2018-11-09 北京小米移动软件有限公司 Determine the method, apparatus and storage medium of terminal interim card reason
CN109086141A (en) * 2018-09-19 2018-12-25 北京京东尚科信息技术有限公司 EMS memory management process and device and computer readable storage medium
CN109857555A (en) * 2019-01-15 2019-06-07 Oppo广东移动通信有限公司 Method for recovering internal storage and device, storage medium and electronic equipment
CN110083450A (en) * 2019-04-09 2019-08-02 Oppo广东移动通信有限公司 Method for recovering internal storage, device, electronic equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
Memory Erasure and Write Field Requirements in HAMR Using L1o -FePt Nanoparticles;Andreas Lyberatos等;《IEEE Transactions on Magnetics》;IEEE;20141202;第50卷(第11期);全文 *
分代算法在KVM 中的实现;李守龙;<<计算机工程>>;20061120;第32卷(第22期);第69-71页 *

Also Published As

Publication number Publication date
CN110727605A (en) 2020-01-24

Similar Documents

Publication Publication Date Title
CN110764906B (en) Memory recovery processing method and device, electronic equipment and storage medium
CN110727605B (en) Memory recovery method and device and electronic equipment
CN110727607B (en) Memory recovery method and device and electronic equipment
US20220121495A1 (en) Memory reclamation method, electronic device and storage medium
CN111352861B (en) Memory compression method and device and electronic equipment
CN110018900B (en) Memory processing method and device, electronic equipment and computer readable storage medium
CN109992523B (en) Memory processing method and device, electronic equipment and computer readable storage medium
CN109992402B (en) Memory processing method and device, electronic equipment and computer readable storage medium
CN111158910A (en) Memory management method and device, storage medium and electronic equipment
CN110018902B (en) Memory processing method and device, electronic equipment and computer readable storage medium
CN111984413A (en) Memory recovery method and device, electronic equipment and storage medium
CN110765031B (en) Data storage method and device, mobile terminal and storage medium
CN108205498B (en) Memory recovery method and device, computer device and computer readable storage medium
CN110704189A (en) Memory recovery method and device and electronic equipment
CN108205473B (en) Memory processing method and device, computer device and computer readable storage medium
CN108205474B (en) Memory management method, terminal device, computer apparatus, and readable storage medium
CN108205471B (en) Memory recovery method and device, computer device and computer readable storage medium
CN110737606B (en) Memory recovery processing method and device, electronic equipment and storage medium
CN111245732A (en) Flow control method, device and equipment
CN115421909A (en) Memory management method and device, electronic equipment and storage medium
CN115421907A (en) Memory recovery method and device, electronic equipment and storage medium
CN108287760B (en) Terminal device control method and device, terminal device and computer readable storage medium
CN108205501B (en) Memory recovery method and device, computer device and computer readable storage medium
CN108228342B (en) Terminal device control method and device, terminal device and computer readable storage medium
CN115587049A (en) Memory recovery method and device, electronic equipment and 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