WO2021036993A1 - Memory reclaiming method and apparatus - Google Patents

Memory reclaiming method and apparatus Download PDF

Info

Publication number
WO2021036993A1
WO2021036993A1 PCT/CN2020/110827 CN2020110827W WO2021036993A1 WO 2021036993 A1 WO2021036993 A1 WO 2021036993A1 CN 2020110827 W CN2020110827 W CN 2020110827W WO 2021036993 A1 WO2021036993 A1 WO 2021036993A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
application
group
waterline
group information
Prior art date
Application number
PCT/CN2020/110827
Other languages
French (fr)
Chinese (zh)
Inventor
易见
李昌龙
李家欣
周未来
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021036993A1 publication Critical patent/WO2021036993A1/en

Links

Images

Classifications

    • 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
    • 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]
    • 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/5022Mechanisms to release resources

Definitions

  • This application relates to the field of information technology, and in particular to a method and device for recovering memory.
  • the memory recovery strategy is mainly based on the memory waterline design.
  • the system memory occupancy information is monitored through the kernel process.
  • the memory recovery mechanism is triggered. For example, according to the priority level, the file page and anonymous page of the APP with the lowest priority are recovered from the memory, and written back to the storage device or data compression is performed.
  • the existing memory reclamation strategy sometimes fails to meet actual needs.
  • the present application provides a memory recovery method and device, which improves the flexibility of memory recovery, and can avoid the problems of excessive memory recovery and insufficient recovery.
  • this application provides a memory recovery method, including:
  • the application whose memory is to be recycled is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space , For the kernel to perform memory recycling according to the memory waterline of the application.
  • the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, according to the memory waterline and system memory of the application
  • the occupancy information determines that the memory reclaim condition is met
  • the application that will be reclaimed is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space for the kernel to execute according to the memory waterline of the application Memory reclamation. Therefore, for applications with different memory requirements, memory recycling can be performed according to different memory pipelines, so that the problems of over-recycling and under-recycling of memory can be avoided, and the keep-alive rate of the application can also be improved.
  • the obtaining the memory waterline of the application from multiple sets of pre-stored memory waterlines includes:
  • the first group information includes the mapping relationship between the application in the group and the memory waterline
  • the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
  • the first group information and the second group information are pre-stored.
  • the determining the target group to which the application belongs based on the memory requirement of the application and pre-stored second group information includes:
  • the group is determined as the target group.
  • the method further includes:
  • the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
  • the memory requirement of the APP is considered to be the sum of the memory required at startup and the increased memory during the expected use phase during memory recycling, which can further improve the accuracy of memory recycling.
  • the obtaining the first group information according to the predicted memory requirements of each application includes:
  • All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
  • the obtaining the second group information according to the predicted memory requirements of each application includes:
  • all applications are divided into groups to obtain multiple groups.
  • One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
  • the method further includes:
  • the first group information is updated according to the update of the application in the group indicated by the configuration file.
  • the transferring the memory waterline of the application into the kernel space includes:
  • this application provides a memory recovery device, including:
  • the acquiring module is used to monitor the application's memory waterline from multiple sets of pre-stored memory waterlines when it is monitored that an application is started or switched to the foreground interface;
  • the processing module is used to determine the application whose memory will be recovered from the applications currently running on the terminal device when it is determined that the memory recovery condition is satisfied according to the memory waterline of the application and the system memory occupancy information, and to compare the memory level of the application
  • the line is passed into the kernel space for the kernel to perform memory recycling according to the memory waterline of the application.
  • the acquisition module is used to:
  • the first group information includes the mapping relationship between the application in the group and the memory waterline
  • the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
  • the first group information and the second group information are pre-stored.
  • the acquisition module is used to:
  • the group is determined as the target group.
  • the acquisition module is also used to:
  • the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
  • the acquisition module is used to:
  • All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
  • the acquisition module is used to:
  • all applications are divided into groups to obtain multiple groups.
  • One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
  • the processing module is also used to:
  • the first group information is updated according to the update of the application in the group indicated by the configuration file.
  • the processing module is used to:
  • the memory waterline of the application is transferred to the kernel space through the reserved function interface.
  • this application provides a terminal device, including: a memory and a processor;
  • a memory for storing executable instructions of the processor
  • the processor is configured to execute the first aspect and the memory recovery method in any one of the possible designs of the first aspect by executing the executable instruction.
  • the present application provides a readable storage medium in which an execution instruction is stored.
  • the terminal device executes any one of the first aspect and the first aspect.
  • the present application provides a program product.
  • the program product includes an execution instruction, and the execution instruction is stored in a readable storage medium.
  • At least one processor of the terminal device can read the execution instruction from the readable storage medium, and the execution of the execution instruction by the at least one processor causes the terminal device to implement the memory recovery method in the first aspect and any one of the possible designs of the first aspect.
  • the present application provides a chip which is connected to a memory, or a memory is integrated on the chip, and when the software program stored in the memory is executed, any one of the first aspect and the first aspect is implemented.
  • Figure 1 is a schematic diagram of a memory recovery process provided by this application.
  • FIG. 2 is a flowchart of an embodiment of a memory recovery method provided by this application.
  • FIG. 3 is a flowchart of an embodiment of a memory recovery method provided by this application.
  • FIG. 4 is a flowchart of an embodiment of a memory recovery method provided by this application.
  • FIG. 5 is a flowchart of an embodiment of a memory recovery method provided by this application.
  • FIG. 6 is a flowchart of an embodiment of a memory recovery method provided by this application.
  • FIG. 7 is a schematic structural diagram of an embodiment of a memory recovery device provided by this application.
  • FIG. 8 is a schematic structural diagram of a terminal device provided by this application.
  • words such as “exemplary” or “for example” are used to represent examples, illustrations or illustrations, and any embodiment or solution described as “exemplary” or “for example” in the embodiments of this application It should not be construed as being more preferable or advantageous than other embodiments or solutions. To be precise, words such as “exemplary” or “for example” are used to present related concepts in a specific manner.
  • first and second are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance. "At least one” means one or more, and “plurality” means two or more.
  • the memory recovery method of the present application can be used in the memory recovery of terminal equipment.
  • the terminal equipment in the embodiment of the present application can be a wireless terminal or a wired terminal, and the wireless terminal can provide voice and/or other service data connectivity to users.
  • a wireless terminal can communicate with one or more core networks via a radio access network (RAN).
  • the wireless terminal can be a mobile terminal, such as a mobile phone (or called a "cellular" phone) and a computer with a mobile terminal, for example, They are portable, pocket-sized, handheld, computer built-in or vehicle-mounted mobile devices that exchange language and/or data with the wireless access network.
  • Wireless terminal can also be called system, subscriber unit (Subscriber Unit), subscriber station (Subscriber Station), mobile station (Mobile Station), mobile station (Mobile), remote station (Remote Station), remote terminal (Remote Terminal), connection The access terminal (Access Terminal), user terminal (User Terminal), user agent (User Agent), and user equipment (User Device or User Equipment) are not limited here.
  • FIG. 1 is a schematic diagram of a memory recovery process provided by this application. As shown in FIG. 1, this application runs a memory recovery strategy in user mode to determine that the memory is satisfied.
  • the memory waterline corresponding to the currently started application or the application currently switched to the foreground interface is transferred to the kernel space, and the kernel performs memory reclaim according to the memory waterline of the application.
  • the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, and the memory waterline of the application and the system memory occupation information are determined
  • the memory recycling condition is met, the application whose memory will be recycled is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space, and the kernel performs memory recycling according to the memory waterline of the application.
  • memory recycling can be performed according to different memory pipelines, so that the problems of over-recycling and under-recycling of memory can be avoided.
  • memory demand of APP tends to increase with the time of use
  • memory recovery can be further improved
  • the accuracy of the memory recovery method avoids excessive memory recovery and insufficient memory recovery.
  • FIG. 2 is a flowchart of an embodiment of a memory recycling method provided by this application. As shown in FIG. 2, the method in this embodiment may include:
  • the running status of each application in the terminal device system can be monitored in the user mode in real time.
  • the memory waterline of the application can be obtained from multiple sets of pre-stored memory waterlines.
  • the corresponding memory waterline may also be different. It should be noted that the memory waterline in the embodiment of the present application is divided into three water levels: high (High), low (Low), and minimum (Min).
  • the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, which may be:
  • the first group information includes the mapping relationship between the applications in the group and the memory waterline, and the memory waterline of the target group is determined as the memory waterline of the application
  • the first group information may also include a group identifier.
  • the currently activated application is APP1
  • the target group to which APP1 belongs is found from the first group information shown in Table 1
  • the memory waterline 1 of group 1 is used as the memory waterline of APP1.
  • Table 1 is only an example, and the group identifier may not be included, and only the mapping relationship between applications and memory waterlines in the group.
  • the first group information can be obtained offline, that is, pre-stored, or obtained online. If the first group information is pre-stored, the first group information can be Obtained by:
  • the first group information is obtained according to the historical memory usage data of each application.
  • the historical memory usage data is the memory required when the application starts, or the historical memory usage data is the memory required when the application starts and the memory required for the preset time period. with.
  • the historical memory usage data is the memory required when the app is started
  • the memory required at the start of each application is counted, that is, the memory occupied when the application is started. It can be run on different terminal devices and count The memory data occupied after each application is run on different terminal devices, and then the first group information is obtained according to all the historical memory usage data.
  • the preset time period can be, for example, half a day, one day, or one week. Because some APP memory requirements tend to increase with the use time Take Honor of Kings as an example. Every game played, the anonymous page size will increase significantly. Therefore, when memory recovery, consider the memory requirement of APP as the sum of the memory required at startup and the memory that is expected to increase during the use phase, which can further improve memory recovery Accuracy.
  • it can be to run each application on different terminal devices, and count the memory required to run each application on different terminal devices when it is started and the memory required to use the preset time period, and the memory required and used when an application is started
  • the sum of the memory required for the preset time period is used as the historical memory usage data to obtain the historical memory usage data of each application, and then the first group information is obtained according to all the historical memory usage data.
  • the first group information may be obtained in the following manner:
  • S101a Predict the memory requirements of each application according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
  • the predicted memory demand of each application is the memory required at startup. If the historical memory usage data is the sum of the memory required at startup and the memory required to use the preset time period, correspondingly, the predicted memory demand of each application is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
  • S101b Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application, the mapping relationship between the application in the group and the memory waterline is obtained, which is the first group information.
  • applications with memory requirements within a range may be divided into a group, for example, applications with memory requirements of 0MB-50MB Divide into a group, divide applications with a memory requirement of 50MB to 100MB into a group, divide applications with a memory requirement of 1GB to 2GB into a group, and so on.
  • a group identifier can be set for each group respectively, and the mapping relationship between the group identifier, the application in the group, and the memory waterline is obtained, which is the first group information.
  • the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the application in the group or the update of the application in the group. That is to say, the applications in the group can be changed. For example, after a certain application version is upgraded, the memory requirement changes and the corresponding group also changes. At this time, the application in the group needs to be updated.
  • the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, which can be:
  • the target group to which the application belongs is determined according to the memory requirements of the application and the pre-stored second group information.
  • the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline, and the memory waterline of the target group Determine the memory waterline of the application.
  • the target group to which the application belongs is determined according to the memory requirement of the application and the pre-stored second group information, which may specifically be: if the memory requirement of the application is within the memory requirement range of a group, then the group Determined as the target group.
  • the second group information may also include a group identifier.
  • the second group information is shown in Table 2 below:
  • Group ID Memory requirement range Memory waterline 1 0MB ⁇ 100MB Memory waterline one 2 100MB ⁇ 200MB Memory waterline two 3 1GB ⁇ 1.5GB Memory waterline three ... ... ...
  • the memory requirement of APP3 is 150MB
  • 150MB is within the memory requirement range of group 2 from 100MB to 200MB
  • group 2 is determined as the target group, and the memory waterline of group 2 The second is the memory waterline of APP1.
  • the second group information can be obtained offline, that is, pre-stored, or obtained online. If the second group information is pre-stored, the second group information can be Obtained in the following manner: in the second implementable manner, further, the above method may further include:
  • the second group information is obtained according to the historical memory usage data of each application.
  • the historical memory usage data is the memory required at startup, or the historical memory usage data is the sum of the memory required at startup and the memory required for the preset time period.
  • the historical memory usage data is the memory required when the app is started
  • the memory required at the start of each application is counted, that is, the memory occupied when the application is started. It can be run on different terminal devices and count The memory data occupied after each application is run on different terminal devices, and then the second group information is obtained according to all the historical memory usage data.
  • the preset time period can be, for example, half a day, one day, or one week. Because some APP memory requirements tend to increase with the use time Take Honor of Kings as an example. Every game played, the anonymous page size will increase significantly. Therefore, when memory recovery, consider the memory requirement of APP as the sum of the memory required at startup and the memory that is expected to increase during the use phase, which can further improve memory recovery Accuracy.
  • it can be to run each application on different terminal devices, and count the memory required to run each application on different terminal devices when it is started and the memory required to use the preset time period, and the memory required and used when an application is started
  • the sum of the memory required for the preset time period is used as the historical memory usage data to obtain the historical memory usage data of each application, and then the second group information is obtained according to all the historical memory usage data.
  • the second group information can be obtained according to the following way:
  • S101a' respectively predict the memory requirements of each application according to the historical memory usage data of each application, the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to increase during the use phase.
  • the predicted memory demand of each application is the memory required at startup. If the historical memory usage data is the sum of the memory required at startup and the memory required to use the preset time period, correspondingly, the predicted memory demand of each application is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
  • S101b' divides all applications into groups based on the predicted memory requirements of each application and multiple sets of memory waterlines to obtain multiple groups, one set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the mapping relationship between the memory demand range and the memory waterline, that is, the second group information divides all applications into groups according to the predicted memory demand of each application, and obtains multiple groups, one memory demand range Apps belong to the same group.
  • applications with memory requirements within a range can be divided into a group, for example, applications with memory requirements of 0MB-50MB can be divided As a group, divide the applications with memory requirements of 50MB-100MB into a group, divide the applications with memory requirements of 1GB-2GB into a group, and so on, to obtain the range of memory requirements corresponding to each group,
  • the memory ranges corresponding to the three groups are 0MB ⁇ 50MB, 50MB ⁇ 100MB and 1GB ⁇ 2GB respectively.
  • the memory requirement range corresponding to each group can be obtained, and a set of memory waterline and a group identifier are set for each group to obtain the group identifier, memory requirement range, and memory level.
  • the mapping relationship of the lines is the second group information.
  • the method of this embodiment may further include:
  • the historical memory usage data is the memory occupied when the application is started, or the historical memory usage data is the sum of the memory occupied when the application is started and the memory occupied by the preset time period.
  • the preset time can be set by the user.
  • S104 Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
  • predicting the memory demand it may be predicted according to a preset rule, for example, taking the average value of the used memory after each application is run, or taking the maximum value.
  • obtaining the first group information according to the predicted memory requirements of each application may be:
  • the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the application in the group or the update of the application in the group. That is to say, the applications in the group can be changed. For example, after a certain application version is upgraded, the memory requirement changes and the corresponding group also changes. At this time, the application in the group needs to be updated.
  • all applications are divided into groups, and multiple groups are obtained.
  • One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same group , Get the second group information.
  • the memory recovery condition is satisfied.
  • the application that will be reclaimed After determining that the memory recycling condition is met, determine the application that will be reclaimed from the currently running applications of the terminal device. For example, it can be determined from the currently running applications according to the pre-saved priority order of the applications whose memory is reclaimed. The application whose memory is to be reclaimed may also be based on other existing methods, which are not limited in the embodiment of the present application.
  • the system call can be made by passing the memory waterline of the application to the kernel space through the reserved function interface, and the kernel determines the condition of the reclaim termination according to the memory waterline of the application. And perform memory reclamation.
  • the memory recycling method obtaineds the memory waterline of the application from multiple sets of pre-stored memory waterlines by monitoring when an application is started or switched to the foreground interface, and according to the memory waterline and system memory of the application
  • the occupancy information determines that the memory reclaim condition is met
  • the application that will be reclaimed is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space for the kernel to execute according to the memory waterline of the application Memory reclamation. Therefore, for applications with different memory requirements, memory recycling can be performed according to different memory pipelines, so that the problems of over-recycling and under-recycling of memory can be avoided, and the keep-alive rate of the application can also be improved.
  • FIG. 3 is a flowchart of an embodiment of a memory recycling method provided by this application. As shown in FIG. 3, the method in this embodiment may include:
  • the first group information includes the group identifier, the application in the group, and the memory level.
  • the mapping relationship of the lines determines the memory waterline of the target group as the memory waterline of the application.
  • the currently activated application is APP4, the target group to which APP4 belongs is found from the first group information shown in Table 1, and the memory waterline 2 of group 2 is used as the memory waterline of APP2.
  • the first group information may be obtained according to the process of S101a to S101b in the embodiment shown in FIG. 2 and the first group information is stored.
  • the process of S101a to S101b in the embodiment shown in FIG. 2 please refer to the detailed description of S101a to S101b in the embodiment shown in FIG. 2 , I won’t repeat it here.
  • the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the update of the application in the group.
  • the applications in the group can be changed.
  • S202 Determine whether the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, if yes, execute S203, if not, return to execute S201.
  • S203 Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
  • FIG. 4 is a flowchart of an embodiment of a memory recycling method provided by this application. As shown in FIG. 4, the method in this embodiment may include:
  • the target group to which the application belongs is determined according to the memory requirement of the application and the pre-stored second group information, the second group information includes the group identifier and the memory requirement
  • the mapping relationship between the range and the memory waterline determines the memory waterline of the target group as the memory waterline of the application.
  • the target group to which the application belongs is determined according to the memory requirement of the application and the pre-stored second group information, which may specifically be: if the memory requirement of the application is within the memory requirement range of a group, then the group Determined as the target group.
  • the currently activated application is APP6. If the memory requirement of APP6 is 1.2GB, and 1.2GB is within the memory requirement range of group 3 from 1GB to 1.5GB, group 3 Determine as the target group, and use the memory waterline 3 of group 3 as the memory waterline of APP6.
  • the second group information may be obtained according to the process of S101a' to S101b' in the embodiment shown in FIG. 2, and the second group information is stored.
  • the process of S101a' to S101b' in the embodiment shown in FIG. 2 please refer to S101a' to S101b in the embodiment shown in FIG. The detailed description will not be repeated here.
  • S302 Determine whether the memory recovery condition is satisfied according to the memory waterline of the application and the system memory occupancy information, if yes, execute S303, if not, return to execute S301.
  • S303 Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
  • FIG. 5 is a flowchart of an embodiment of a memory recycling method provided by this application. The difference from FIG. 3 and FIG. 4 is that the first group information in this embodiment is obtained online. As shown in FIG. 5, this embodiment Examples of methods can include:
  • the historical memory usage data is the memory occupied when the application is started, or the historical memory usage data is the sum of the memory occupied when the application is started and the memory occupied by the preset time period.
  • the preset time can be set by the user.
  • S402 Predict the memory requirements of each application separately according to the historical memory usage data of each application.
  • the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
  • predicting the memory demand it may be predicted according to a preset rule, for example, taking the average value of the used memory after each application is run, or taking the maximum value.
  • S403 Acquire first group information according to the predicted memory requirements of each application, where the first group information includes a group identifier, a mapping relationship between applications in the group, and a memory waterline.
  • the first group information is obtained according to the predicted memory requirements of each application, specifically:
  • the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the application in the group or the update of the application in the group. That is to say, the applications in the group can be changed. For example, after a certain application version is upgraded, the memory requirement changes and the corresponding group also changes. At this time, the application in the group needs to be updated.
  • S404 When it is monitored that an application is started or switched to the foreground interface, search for the target group to which the application belongs from the first group information, and determine the memory waterline of the target group as the memory waterline of the application.
  • S405 Determine whether the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, if yes, execute S403, if not, return to execute S404.
  • S406. Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
  • FIG. 6 is a flowchart of an embodiment of a memory recycling method provided by this application. The difference from FIG. 3 and FIG. 4 is that the second group information in this embodiment is obtained online. As shown in FIG. 6, this embodiment Examples of methods can include:
  • the historical memory usage data is the memory occupied when the application is started, or the historical memory usage data is the sum of the memory occupied when the application is started and the memory occupied by the preset time period.
  • the preset time can be set by the user.
  • S502 Predict the memory requirements of each application separately according to the historical memory usage data of each application.
  • the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
  • predicting the memory demand it may be predicted according to a preset rule, for example, taking the average value of the used memory after each application is run, or taking the maximum value.
  • S503 Obtain second group information according to the predicted memory requirements of each application, where the second group information includes a group identifier, a memory requirement range, and a mapping relationship between a memory waterline.
  • the second group information is acquired according to the predicted memory requirements of each application, specifically:
  • all applications are divided into groups, and multiple groups are obtained.
  • One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same group , Get the second group information.
  • S505 Determine whether the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, if yes, execute S503, if not, return to execute S504.
  • S506. Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
  • FIG. 7 is a schematic structural diagram of an embodiment of a memory recovery device provided by this application.
  • the device of this embodiment may include: an acquisition module 11 and a processing module 12, where the acquisition module 11 is used to monitor When the application is started or switched to the foreground interface, obtain the memory waterline of the application from multiple sets of pre-stored memory waterlines;
  • the processing module 12 is configured to determine the application whose memory is to be recovered from the applications currently running on the terminal device when it is determined that the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, and to compare the memory level of the application The line is passed into the kernel space for the kernel to perform memory recycling according to the memory waterline of the application.
  • the acquisition module 11 is used for:
  • the first group information includes the mapping relationship between the application in the group and the memory waterline
  • the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
  • the first group information and the second group information are pre-stored.
  • the acquisition module 11 is used for:
  • the group is determined as the target group.
  • the acquisition module 11 is also used for:
  • the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
  • the acquisition module 11 is used for:
  • All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
  • the acquisition module 11 is used for:
  • all applications are divided into groups to obtain multiple groups.
  • One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
  • processing module 12 is also used for:
  • the first group information is updated according to the update of the application in the group indicated by the configuration file.
  • processing module 12 is used for:
  • the memory waterline of the application is transferred to the kernel space through the reserved function interface.
  • the device of this embodiment can be used to implement the technical solution of the method embodiment shown in FIG. 2, and its implementation principles are similar, and will not be repeated here.
  • the present application may divide the memory recovery device into functional modules according to the foregoing method examples.
  • each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or software function modules. It should be noted that the division of modules in the embodiments of the present application is illustrative, and is only a logical function division, and there may be other division methods in actual implementation.
  • FIG. 8 is a schematic structural diagram of a terminal device provided by this application, and the terminal device 200 includes:
  • the memory 201 is used to store computer programs
  • the processor 202 is configured to execute a computer program stored in the memory to implement the memory recycling method in the foregoing embodiment. For details, refer to the relevant description in the foregoing method embodiment.
  • the memory 201 may be independent or integrated with the processor 202.
  • the terminal device 200 may further include:
  • the bus 203 is used to connect the memory 201 and the processor 202.
  • this embodiment further includes: a communication interface 204, and the communication interface 204 may be connected to the processor 202 through the bus 203.
  • the processor 202 may control the communication interface 203 to implement the aforementioned receiving and sending functions of the terminal device 200.
  • the terminal device may be used to execute various steps and/or procedures corresponding to the terminal device in the foregoing method embodiments.
  • the present application also provides a readable storage medium in which an execution instruction is stored.
  • the terminal device executes the memory recovery method in the foregoing method embodiment.
  • the application also provides a program product, which includes an execution instruction, and the execution instruction is stored in a readable storage medium.
  • At least one processor of the terminal device can read the execution instruction from the readable storage medium, and the execution of the execution instruction by the at least one processor causes the terminal device to implement the memory recovery method in the foregoing method embodiment.
  • the present application also provides a chip, which is connected to a memory, or a memory is integrated on the chip, and when the software program stored in the memory is executed, the memory recovery method in the above method embodiment is implemented.
  • a person of ordinary skill in the art can understand that: in the foregoing embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof.
  • software it can be implemented in the form of a computer program product in whole or in part.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium.
  • the computer instructions may be transmitted from a website, computer, server, or data center. Transmission to another website site, computer, server or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.).
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center integrated with one or more available media.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System (AREA)
  • Stored Programmes (AREA)

Abstract

A memory reclaiming method and apparatus. The method comprises: when it is detected that there is an application which is started or switched to a foreground interface, acquiring a memory watermark of the application from multiple sets of pre-stored memory watermarks (S101); and when it is determined, according to the memory watermark of the application and system memory usage information, that a memory reclaiming condition is satisfied, determining, from the currently operating applications of a terminal device, the application for which the memory is to be reclaimed, and transmitting the memory watermark of the application into a kernel space such that a kernel executes memory reclaiming according to the memory watermark of the application (S102). Therefore, the problems of a memory being over-reclaimed and under-reclaimed can be prevented, and the keep-alive ratio of an application is improved.

Description

内存回收方法及装置Memory recovery method and device
本申请要求于2019年08月30日提交中国专利局、申请号为201910812574.1、申请名称为“内存回收方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on August 30, 2019 with application number 201910812574. 1, application titled "Memory Recovery Method and Device", the entire content of which is incorporated into this application by reference.
技术领域Technical field
本申请涉及信息技术领域,尤其涉及一种内存回收方法及装置。This application relates to the field of information technology, and in particular to a method and device for recovering memory.
背景技术Background technique
近年来,移动应用(application,APP)对内存的需求量日益增多,呈现逐年增长的趋势,而终端设备的内存容量有限,无法容纳大量应用常驻内存。因此,当内存不足时,***将进行内存回收。In recent years, the demand for memory of mobile applications (applications, APPs) has been increasing, showing a trend of increasing year by year, while the memory capacity of terminal devices is limited and cannot accommodate a large number of application resident memories. Therefore, when the memory is insufficient, the system will reclaim the memory.
现有技术中,内存回收策略主要是基于内存水线设计,通过内核进程对***内存占用信息进行监控,当监控到内存剩余空间低于内存水线中的低(low)水位则触发内存回收机制,例如根据优先级的高低将优先级最低的APP的文件页、匿名页从内存回收,并写回存储器件或进行数据压缩。然而,现有的内存回收策略有时满足不了实际需求。In the prior art, the memory recovery strategy is mainly based on the memory waterline design. The system memory occupancy information is monitored through the kernel process. When the remaining memory space is monitored to be lower than the low water level in the memory waterline, the memory recovery mechanism is triggered. For example, according to the priority level, the file page and anonymous page of the APP with the lowest priority are recovered from the memory, and written back to the storage device or data compression is performed. However, the existing memory reclamation strategy sometimes fails to meet actual needs.
发明内容Summary of the invention
本申请提供一种内存回收方法及装置,提高内存回收的灵活性,可避免内存过度回收和回收不足的问题。The present application provides a memory recovery method and device, which improves the flexibility of memory recovery, and can avoid the problems of excessive memory recovery and insufficient recovery.
第一方面,本申请提供一种内存回收方法,包括:In the first aspect, this application provides a memory recovery method, including:
监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取所述应用的内存水线;When it is monitored that an application is started or switched to the foreground interface, obtain the memory waterline of the application from multiple sets of pre-stored memory waterlines;
根据所述应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将所述应用的内存水线传入内核空间,用于内核根据所述应用的内存水线执行内存回收。When it is determined that the memory recycling condition is satisfied according to the memory waterline of the application and the system memory occupancy information, the application whose memory is to be recycled is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space , For the kernel to perform memory recycling according to the memory waterline of the application.
通过第一方面提供的内存回收方法,监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取该应用的内存水线,根据该应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。从而,针对不同内存需求的应用,可根据不同的内存水线进行内存回收,因此可避免内存过度回收和回收不足的问题,还可提高应用的保活率。Through the memory recycling method provided in the first aspect, when it is monitored that an application is started or switched to the foreground interface, the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, according to the memory waterline and system memory of the application When the occupancy information determines that the memory reclaim condition is met, the application that will be reclaimed is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space for the kernel to execute according to the memory waterline of the application Memory reclamation. Therefore, for applications with different memory requirements, memory recycling can be performed according to different memory pipelines, so that the problems of over-recycling and under-recycling of memory can be avoided, and the keep-alive rate of the application can also be improved.
在一种可能的设计中,所述从预存的多套内存水线中获取所述应用的内存水线,包括:In a possible design, the obtaining the memory waterline of the application from multiple sets of pre-stored memory waterlines includes:
从第一群组信息中查找所述应用所属的目标群组,所述第一群组信息包括群组内应用和内存水线的映射关系;Searching for the target group to which the application belongs from the first group information, where the first group information includes the mapping relationship between the application in the group and the memory waterline;
将所述目标群组的内存水线确定为所述应用的内存水线;或者,Determine the memory waterline of the target group as the memory waterline of the application; or,
根据所述应用的内存需求和第二群组信息确定所述应用所属的目标群组,所述第 二群组信息包括群组内存需求范围和内存水线的映射关系;Determining the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
将所述目标群组的内存水线确定为所述应用的内存水线。Determine the memory waterline of the target group as the memory waterline of the application.
在一种可能的设计中,所述第一群组信息和所述第二群组信息是预先存储的。In a possible design, the first group information and the second group information are pre-stored.
在一种可能的设计中,所述根据所述应用的内存需求和预存的第二群组信息确定所述应用所属的目标群组,包括:In a possible design, the determining the target group to which the application belongs based on the memory requirement of the application and pre-stored second group information includes:
若所述应用的内存需求在一群组的内存需求范围内,则将所述群组确定为所述目标群组。If the memory requirement of the application is within the memory requirement range of a group, the group is determined as the target group.
在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:
获取预设时间内各个应用运行后的历史使用内存数据,所述历史使用内存数据为应用启动时所占内存,或者,所述历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和;Obtain historical memory usage data after each application is running within a preset time, where the historical memory usage data is the memory occupied when the application is started, or the historical memory occupied data is the memory occupied when the application is started and the preset time period of use The sum of memory occupied;
根据各个应用的历史使用内存数据分别预测各个应用的内存需求,所述内存需求为启动时所需内存;或者,所述内存需求为启动时所需内存和预期使用阶段增长内存之和;Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
根据预测的各个应用的内存需求获取所述第一群组信息或所述第二群组信息。Obtain the first group information or the second group information according to the predicted memory requirements of each application.
通过该实施方式提供的内存回收方法,在内存回收时考虑APP内存需求为启动时所需内存和预期使用阶段增长内存之和,可进一步提高内存回收的准确性。With the memory recycling method provided by this implementation manner, the memory requirement of the APP is considered to be the sum of the memory required at startup and the increased memory during the expected use phase during memory recycling, which can further improve the accuracy of memory recycling.
在一种可能的设计中,所述根据预测的各个应用的内存需求获取所述第一群组信息,包括:In a possible design, the obtaining the first group information according to the predicted memory requirements of each application includes:
根据预测的各个应用的内存需求和所述多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到所述第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and the multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
在一种可能的设计中,所述根据预测的各个应用的内存需求获取所述第二群组信息,包括:In a possible design, the obtaining the second group information according to the predicted memory requirements of each application includes:
根据预测的各个应用的内存需求和所述多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到所述第二群组信息。According to the predicted memory requirements of each application and the multiple sets of memory waterlines, all applications are divided into groups to obtain multiple groups. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:
根据配置文件指示的群组内应用的更新,更新所述第一群组信息。The first group information is updated according to the update of the application in the group indicated by the configuration file.
在一种可能的设计中,所述将所述应用的内存水线传入内核空间,包括:In a possible design, the transferring the memory waterline of the application into the kernel space includes:
第二方面,本申请提供一种内存回收装置,包括:In a second aspect, this application provides a memory recovery device, including:
获取模块,用于监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取所述应用的内存水线;The acquiring module is used to monitor the application's memory waterline from multiple sets of pre-stored memory waterlines when it is monitored that an application is started or switched to the foreground interface;
处理模块,用于根据所述应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将所述应用的内存水线传入内核空间,用于内核根据所述应用的内存水线执行内存回收。The processing module is used to determine the application whose memory will be recovered from the applications currently running on the terminal device when it is determined that the memory recovery condition is satisfied according to the memory waterline of the application and the system memory occupancy information, and to compare the memory level of the application The line is passed into the kernel space for the kernel to perform memory recycling according to the memory waterline of the application.
在一种可能的设计中,所述获取模块用于:In a possible design, the acquisition module is used to:
从第一群组信息中查找所述应用所属的目标群组,所述第一群组信息包括群组内应用和内存水线的映射关系;Searching for the target group to which the application belongs from the first group information, where the first group information includes the mapping relationship between the application in the group and the memory waterline;
将所述目标群组的内存水线确定为所述应用的内存水线;或者,Determine the memory waterline of the target group as the memory waterline of the application; or,
根据所述应用的内存需求和第二群组信息确定所述应用所属的目标群组,所述第二群组信息包括群组内存需求范围和内存水线的映射关系;Determining the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
将所述目标群组的内存水线确定为所述应用的内存水线。Determine the memory waterline of the target group as the memory waterline of the application.
在一种可能的设计中,所述第一群组信息和所述第二群组信息是预先存储的。In a possible design, the first group information and the second group information are pre-stored.
在一种可能的设计中,所述获取模块用于:In a possible design, the acquisition module is used to:
若所述应用的内存需求在一群组的内存需求范围内,则将所述群组确定为所述目标群组。If the memory requirement of the application is within the memory requirement range of a group, the group is determined as the target group.
在一种可能的设计中,所述获取模块还用于:In a possible design, the acquisition module is also used to:
获取预设时间内各个应用运行后的历史使用内存数据,所述历史使用内存数据为应用启动时所占内存,或者,所述历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和;Obtain historical memory usage data after each application is running within a preset time, where the historical memory usage data is the memory occupied when the application is started, or the historical memory occupied data is the memory occupied when the application is started and the preset time period of use The sum of memory occupied;
根据各个应用的历史使用内存数据分别预测各个应用的内存需求,所述内存需求为启动时所需内存;或者,所述内存需求为启动时所需内存和预期使用阶段增长内存之和;Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
根据预测的各个应用的内存需求获取所述第一群组信息或所述第二群组信息。Acquire the first group information or the second group information according to the predicted memory requirements of each application.
在一种可能的设计中,所述获取模块用于:In a possible design, the acquisition module is used to:
根据预测的各个应用的内存需求和所述多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到所述第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and the multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
在一种可能的设计中,所述获取模块用于:In a possible design, the acquisition module is used to:
根据预测的各个应用的内存需求和所述多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到所述第二群组信息。According to the predicted memory requirements of each application and the multiple sets of memory waterlines, all applications are divided into groups to obtain multiple groups. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
在一种可能的设计中,所述处理模块还用于:In a possible design, the processing module is also used to:
根据配置文件指示的群组内应用的更新,更新所述第一群组信息。The first group information is updated according to the update of the application in the group indicated by the configuration file.
在一种可能的设计中,所述处理模块用于:In a possible design, the processing module is used to:
通过预留的函数接口将所述应用的内存水线传入内核空间。The memory waterline of the application is transferred to the kernel space through the reserved function interface.
上述第二方面以及上述第二方面的各可能的设计中所提供的内存回收装置,其有益效果可以参见上述第一方面和第一方面的各可能的实施方式所带来的有益效果,在此不再赘述。For the beneficial effects of the memory recovery device provided in the foregoing second aspect and each possible design of the foregoing second aspect, refer to the beneficial effects brought about by the foregoing first aspect and each possible implementation of the first aspect, here No longer.
第三方面,本申请提供一种终端设备,包括:存储器和处理器;In a third aspect, this application provides a terminal device, including: a memory and a processor;
处理器;以及Processor; and
存储器,用于存储所述处理器的可执行指令;A memory for storing executable instructions of the processor;
其中,所述处理器配置为经由执行所述可执行指令来执行第一方面及第一方面任一种可能的设计中的内存回收方法。Wherein, the processor is configured to execute the first aspect and the memory recovery method in any one of the possible designs of the first aspect by executing the executable instruction.
第四方面,本申请提供一种可读存储介质,可读存储介质中存储有执行指令,当终端设备的至少一个处理器执行该执行指令时,终端设备执行第一方面及第一方面任一种可能的设计中的内存回收方法。In a fourth aspect, the present application provides a readable storage medium in which an execution instruction is stored. When at least one processor of a terminal device executes the execution instruction, the terminal device executes any one of the first aspect and the first aspect. A possible design method of memory reclamation.
第五方面,本申请提供一种程序产品,该程序产品包括执行指令,该执行指令存储在可读存储介质中。终端设备的至少一个处理器可以从可读存储介质读取该执行指令,至少 一个处理器执行该执行指令使得终端设备实施第一方面及第一方面任一种可能的设计中的内存回收方法。In a fifth aspect, the present application provides a program product. The program product includes an execution instruction, and the execution instruction is stored in a readable storage medium. At least one processor of the terminal device can read the execution instruction from the readable storage medium, and the execution of the execution instruction by the at least one processor causes the terminal device to implement the memory recovery method in the first aspect and any one of the possible designs of the first aspect.
第六方面,本申请提供一种芯片,所述芯片与存储器相连,或者所述芯片上集成有存储器,当所述存储器中存储的软件程序被执行时,实现第一方面及第一方面任一种可能的设计中的内存回收方法。In a sixth aspect, the present application provides a chip which is connected to a memory, or a memory is integrated on the chip, and when the software program stored in the memory is executed, any one of the first aspect and the first aspect is implemented. A possible design method of memory reclamation.
附图说明Description of the drawings
图1为本申请提供的一种内存回收过程示意图;Figure 1 is a schematic diagram of a memory recovery process provided by this application;
图2为本申请提供的一种内存回收方法实施例的流程图;FIG. 2 is a flowchart of an embodiment of a memory recovery method provided by this application;
图3为本申请提供的一种内存回收方法实施例的流程图;FIG. 3 is a flowchart of an embodiment of a memory recovery method provided by this application;
图4为本申请提供的一种内存回收方法实施例的流程图;FIG. 4 is a flowchart of an embodiment of a memory recovery method provided by this application;
图5为本申请提供的一种内存回收方法实施例的流程图;FIG. 5 is a flowchart of an embodiment of a memory recovery method provided by this application;
图6为本申请提供的一种内存回收方法实施例的流程图;FIG. 6 is a flowchart of an embodiment of a memory recovery method provided by this application;
图7为本申请提供的一种内存回收装置实施例的结构示意图;FIG. 7 is a schematic structural diagram of an embodiment of a memory recovery device provided by this application;
图8为本申请提供的一种终端设备结构示意图。FIG. 8 is a schematic structural diagram of a terminal device provided by this application.
具体实施方式detailed description
本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明,本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或方案不应被解释为比其它实施例或方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。In the embodiments of this application, words such as "exemplary" or "for example" are used to represent examples, illustrations or illustrations, and any embodiment or solution described as "exemplary" or "for example" in the embodiments of this application It should not be construed as being more preferable or advantageous than other embodiments or solutions. To be precise, words such as "exemplary" or "for example" are used to present related concepts in a specific manner.
本申请实施例中,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性。“至少一个”是指一个或者多个,“多个”是指两个或两个以上。In the embodiments of the present application, the terms "first" and "second" are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance. "At least one" means one or more, and "plurality" means two or more.
本申请的内存回收方法可用于对终端设备的内存回收中,其中,本申请实施例的终端设备:可以是无线终端或有线终端,无线终端可以是指向用户提供语音和/或其他业务数据连通性的设备,具有无线连接功能的手持式设备、或连接到无线调制解调器的其他处理设备。无线终端可以经无线接入网(RAN)与一个或多个核心网进行通信,无线终端可以是移动终端,如移动电话(或称为“蜂窝”电话)和具有移动终端的计算机,例如,可以是便携式、袖珍式、手持式、计算机内置的或者车载的移动装置,它们与无线接入网交换语言和/或数据。例如,个人通信业务(Personal Communication Service,PCS)电话、无绳电话、会话发起协议(Session Initiation Protocol,SIP)话机、无线本地环路(Wireless Local Loop,WLL)站、个人数字助理(Personal Digital Assistant,PDA)等设备。无线终端也可以称为***、订户单元(Subscriber Unit)、订户站(Subscriber Station),移动站(Mobile Station)、移动台(Mobile)、远程站(Remote Station)、远程终端(Remote Terminal)、接入终端(Access Terminal)、用户终端(User Terminal)、用户代理(User Agent)、用户设备(User Device or User Equipment),在此不作限定。The memory recovery method of the present application can be used in the memory recovery of terminal equipment. Among them, the terminal equipment in the embodiment of the present application: can be a wireless terminal or a wired terminal, and the wireless terminal can provide voice and/or other service data connectivity to users. , A handheld device with wireless connectivity, or other processing equipment connected to a wireless modem. A wireless terminal can communicate with one or more core networks via a radio access network (RAN). The wireless terminal can be a mobile terminal, such as a mobile phone (or called a "cellular" phone) and a computer with a mobile terminal, for example, They are portable, pocket-sized, handheld, computer built-in or vehicle-mounted mobile devices that exchange language and/or data with the wireless access network. For example, personal communication service (PCS) phones, cordless phones, Session Initiation Protocol (SIP) phones, wireless local loop (Wireless Local Loop, WLL) stations, and personal digital assistants (Personal Digital Assistant, PDA) and other equipment. Wireless terminal can also be called system, subscriber unit (Subscriber Unit), subscriber station (Subscriber Station), mobile station (Mobile Station), mobile station (Mobile), remote station (Remote Station), remote terminal (Remote Terminal), connection The access terminal (Access Terminal), user terminal (User Terminal), user agent (User Agent), and user equipment (User Device or User Equipment) are not limited here.
相关技术中,通过设置一套内存水线,当监控到内存剩余空间低于内存水线中的低(low)水位则触发内存回收,但是在实际使用过程中,有时会出现一些特殊的应用,例如大型的游戏应用,若还是按照相关技术中的内存回收策略进行内存回收,会出现内存回 收不足或者内存回收过度的情况,不能很好地满足实际需求。为解决这一问题,本申请提供一种内存回收方法,图1为本申请提供的一种内存回收过程示意图,如图1所示,本申请通过在用户态运行内存回收策略,在判定满足内存回收条件时,将当前被启动的应用或当前切换到前台界面的应用对应的内存水线传入内核空间,由内核根据该应用的内存水线执行内存回收。具体地,通过在用户态监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取该应用的内存水线,根据该应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将该应用的内存水线传入内核空间,由内核根据该应用的内存水线执行内存回收。从而,针对不同内存需求的应用,可根据不同的内存水线进行内存回收,因此可避免内存过度回收和回收不足的问题。进一步地,由于APP的内存需求随使用时间往往呈递增趋势,本申请实施例中在内存回收时考虑到APP内存需求为启动时所需内存和预期使用阶段增长内存之和,可进一步提高内存回收的准确性,避免内存过度回收和回收不足,下面结合附图详细说明本申请提供的内存回收方法的具体过程。In related technologies, by setting a set of memory waterline, when the remaining space of the memory is monitored to be lower than the low water level in the memory waterline, memory recovery is triggered. However, in actual use, some special applications sometimes appear. For example, for large-scale game applications, if memory recovery is performed according to the memory recovery strategy in related technologies, there will be insufficient memory recovery or excessive memory recovery, which cannot meet actual needs well. To solve this problem, this application provides a memory recovery method. FIG. 1 is a schematic diagram of a memory recovery process provided by this application. As shown in FIG. 1, this application runs a memory recovery strategy in user mode to determine that the memory is satisfied. When the condition is reclaimed, the memory waterline corresponding to the currently started application or the application currently switched to the foreground interface is transferred to the kernel space, and the kernel performs memory reclaim according to the memory waterline of the application. Specifically, when the user mode monitors that an application is started or switched to the foreground interface, the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, and the memory waterline of the application and the system memory occupation information are determined When the memory recycling condition is met, the application whose memory will be recycled is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space, and the kernel performs memory recycling according to the memory waterline of the application. Therefore, for applications with different memory requirements, memory recycling can be performed according to different memory pipelines, so that the problems of over-recycling and under-recycling of memory can be avoided. Further, since the memory demand of APP tends to increase with the time of use, in the embodiment of the present application, considering that the memory demand of APP is the sum of the memory required at startup and the memory that is expected to increase during the use phase, memory recovery can be further improved The accuracy of the memory recovery method avoids excessive memory recovery and insufficient memory recovery. The specific process of the memory recovery method provided by this application will be described in detail below with reference to the accompanying drawings.
图2为本申请提供的一种内存回收方法实施例的流程图,如图2所示,本实施例的方法可以包括:FIG. 2 is a flowchart of an embodiment of a memory recycling method provided by this application. As shown in FIG. 2, the method in this embodiment may include:
S101、监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取所述应用的内存水线。S101. When it is monitored that an application is started or switched to the foreground interface, obtain the memory waterline of the application from multiple sets of pre-stored memory waterlines.
具体地,可以在用户态实时监控终端设备***内各个应用的运行状态,在监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取该应用的内存水线,不同的应用,由于内存需求的不同,对应的内存水线也可能不同。需要说明的是,本申请实施例中的内存水线分为高(High)、低(Low)、最小(Min)三个水位。Specifically, the running status of each application in the terminal device system can be monitored in the user mode in real time. When it is monitored that an application is started or switched to the foreground interface, the memory waterline of the application can be obtained from multiple sets of pre-stored memory waterlines. For different applications, due to different memory requirements, the corresponding memory waterline may also be different. It should be noted that the memory waterline in the embodiment of the present application is divided into three water levels: high (High), low (Low), and minimum (Min).
作为第一种可实施的方式,从预存的多套内存水线中获取所述应用的内存水线,可以为:As a first implementable manner, the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, which may be:
从第一群组信息中查找该应用所属的目标群组,第一群组信息包括群组内应用和内存水线的映射关系,将目标群组的内存水线确定为该应用的内存水线,可选的,第一群组信息还可以包括群组标识。Find the target group to which the application belongs from the first group information. The first group information includes the mapping relationship between the applications in the group and the memory waterline, and the memory waterline of the target group is determined as the memory waterline of the application Optionally, the first group information may also include a group identifier.
示例性地,第一群组信息如下表一所示:Exemplarily, the first group information is shown in Table 1 below:
表一Table I
群组标识Group ID 群组内应用In-group applications 内存水线Memory waterline
11 APP1、APP2、APP3APP1, APP2, APP3 内存水线一Memory waterline one
22 APP4、APP5APP4, APP5 内存水线二Memory waterline two
33 APP6、APP7、APP8、APP9APP6, APP7, APP8, APP9 内存水线三Memory waterline three
……... ……... ……...
例如,当前被启动应用为APP1,从表一所示的第一群组信息中查找到APP1所属的目标群组为群组1,将群组1的内存水线一作为APP1的内存水线。表一仅是示例,也可以不包括群组标识,只有群组内应用和内存水线的映射关系。For example, the currently activated application is APP1, the target group to which APP1 belongs is found from the first group information shown in Table 1, and the memory waterline 1 of group 1 is used as the memory waterline of APP1. Table 1 is only an example, and the group identifier may not be included, and only the mapping relationship between applications and memory waterlines in the group.
在第一种可实施的方式下,其中的第一群组信息可以是离线获取,即预先存储,也可以是在线获取的,若第一群组信息为预先存储的,第一群组信息可通过如下方式获取:In the first practicable way, the first group information can be obtained offline, that is, pre-stored, or obtained online. If the first group information is pre-stored, the first group information can be Obtained by:
根据各个应用的历史使用内存数据获取第一群组信息,历史使用内存数据为应用启动时所需内存,或者,历史使用内存数据为应用启动时所需内存和使用预设时间段所需内存之和。The first group information is obtained according to the historical memory usage data of each application. The historical memory usage data is the memory required when the application starts, or the historical memory usage data is the memory required when the application starts and the memory required for the preset time period. with.
具体来说,历史使用内存数据为APP启动时所需内存时,统计各个应用启动时所需的内存,即启动运行时所占的内存,可以是在不同的终端设备上运行各个应用,并统计在不同终端设备上运行各个应用后所占的内存数据,然后根据所有的历史使用内存数据获取第一群组信息。Specifically, when the historical memory usage data is the memory required when the app is started, the memory required at the start of each application is counted, that is, the memory occupied when the application is started. It can be run on different terminal devices and count The memory data occupied after each application is run on different terminal devices, and then the first group information is obtained according to all the historical memory usage data.
历史使用内存数据为启动时所需内存和使用预设时间段所需内存之和时,预设时间段例如可以是半天,一天,一个周,由于有的APP内存需求随使用时间往往呈递增趋势,以王者荣耀为例,每打一局游戏,匿名页规模都会明显增加,因此,在内存回收时考虑APP内存需求为启动时所需内存和预期使用阶段增长内存之和,可进一步提高内存回收的准确性。具体地,可以是在不同的终端设备上运行各个应用,并统计在不同终端设备上运行各个应用启动时所需内存和使用预设时间段所需内存,将一个应用启动时所需内存和使用预设时间段所需内存之和作为历史使用内存数据,得到各个应用的历史使用内存数据,然后根据所有的历史使用内存数据获取第一群组信息。When the historical memory usage data is the sum of the memory required at startup and the memory required to use the preset time period, the preset time period can be, for example, half a day, one day, or one week. Because some APP memory requirements tend to increase with the use time Take Honor of Kings as an example. Every game played, the anonymous page size will increase significantly. Therefore, when memory recovery, consider the memory requirement of APP as the sum of the memory required at startup and the memory that is expected to increase during the use phase, which can further improve memory recovery Accuracy. Specifically, it can be to run each application on different terminal devices, and count the memory required to run each application on different terminal devices when it is started and the memory required to use the preset time period, and the memory required and used when an application is started The sum of the memory required for the preset time period is used as the historical memory usage data to obtain the historical memory usage data of each application, and then the first group information is obtained according to all the historical memory usage data.
作为一种可实施的方式,可以是根据如下方式获取第一群组信息:As an implementable manner, the first group information may be obtained in the following manner:
S101a、根据各个应用的历史使用内存数据分别预测各个应用的内存需求,内存需求为启动时所需内存;或者,内存需求为启动时所需内存和预期使用阶段增长内存之和。S101a: Predict the memory requirements of each application according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
若历史使用内存数据为启动时所需内存,则相应的,预测的各个应用的内存需求为启动时所需内存。若历史使用内存数据为启动时所需内存和使用预设时间段所需内存之和,则相应地,预测的各个应用的内存需求为启动时所需内存和预期使用阶段增长内存之和。If the historical memory usage data is the memory required at startup, correspondingly, the predicted memory demand of each application is the memory required at startup. If the historical memory usage data is the sum of the memory required at startup and the memory required to use the preset time period, correspondingly, the predicted memory demand of each application is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
S101b、根据预测的各个应用的内存需求和多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到群组内应用和内存水线的映射关系,即为第一群组信息。S101b. Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application, the mapping relationship between the application in the group and the memory waterline is obtained, which is the first group information.
示例性地,可以是根据多套内存水线对所有应用在进行群组划分时,例如可将内存需求在一个范围内的应用划分为一个群组,例如可将内存需求为0MB~50MB的应用划分为一个群组,将内存需求为50MB~100MB的应用划分为一个群组,将内存需求为1GB~2GB的应用划分为一个群组,等等。Exemplarily, it may be when all applications are grouped according to multiple sets of memory pipelines, for example, applications with memory requirements within a range may be divided into a group, for example, applications with memory requirements of 0MB-50MB Divide into a group, divide applications with a memory requirement of 50MB to 100MB into a group, divide applications with a memory requirement of 1GB to 2GB into a group, and so on.
可选的,群组划分完成后,可以为每个群组分别设置一个群组标识,得到群组标识、群组内应用和内存水线的映射关系,即为第一群组信息。Optionally, after the group division is completed, a group identifier can be set for each group respectively, and the mapping relationship between the group identifier, the application in the group, and the memory waterline is obtained, which is the first group information.
在将获得的第一群组信息存储后,进一步地,后续还可以根据配置文件指示的群组标识和群组内应用或者群组内应用的更新,更新第一群组信息。也就是说群组内的应用是可以变化的,例如某一应用版本升级后内存需求发生变化,对应所属的群组也发生变化,此时需要更新群组内应用。After the obtained first group information is stored, further, the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the application in the group or the update of the application in the group. That is to say, the applications in the group can be changed. For example, after a certain application version is upgraded, the memory requirement changes and the corresponding group also changes. At this time, the application in the group needs to be updated.
作为第二种可实施的方式,从预存的多套内存水线中获取该应用的内存水线,可以为:As a second practicable way, the memory waterline of the application is obtained from multiple sets of pre-stored memory waterlines, which can be:
根据该应用的内存需求和预存的第二群组信息确定该应用所属的目标群组,第二群组信息包括群组内存需求范围和内存水线的映射关系,将目标群组的内存水线确定为该应用的内存水线。The target group to which the application belongs is determined according to the memory requirements of the application and the pre-stored second group information. The second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline, and the memory waterline of the target group Determine the memory waterline of the application.
其中,根据该应用的内存需求和预存的第二群组信息确定该应用所属的目标群组,具体可以是:若该应用的内存需求在一群组的内存需求范围内,则将该群组确定为目标群组。Wherein, the target group to which the application belongs is determined according to the memory requirement of the application and the pre-stored second group information, which may specifically be: if the memory requirement of the application is within the memory requirement range of a group, then the group Determined as the target group.
可选的,第二群组信息还可以包括群组标识,示例性地,第二群组信息如下表二所示:Optionally, the second group information may also include a group identifier. Illustratively, the second group information is shown in Table 2 below:
表二Table II
群组标识Group ID 内存需求范围Memory requirement range 内存水线Memory waterline
11 0MB~100MB0MB~100MB 内存水线一Memory waterline one
22 100MB~200MB100MB~200MB 内存水线二Memory waterline two
33 1GB~1.5GB1GB~1.5GB 内存水线三Memory waterline three
……... ……... ……...
例如,当前被启动应用为APP3,若APP3的内存需求为150MB,150MB在群组2的内存需求范围100MB~200MB内,将群组2确定为目标群组,并将群组2的内存水线二作为APP1的内存水线。For example, if the currently activated application is APP3, if the memory requirement of APP3 is 150MB, and 150MB is within the memory requirement range of group 2 from 100MB to 200MB, group 2 is determined as the target group, and the memory waterline of group 2 The second is the memory waterline of APP1.
在第二种可实施的方式下,其中的第二群组信息可以是离线获取,即预先存储,也可以是在线获取的,若第二群组信息为预先存储的,第二群组信息可通过如下方式获取:在第二种可实施的方式下,进一步地,上述方法还可以包括:In the second practicable way, the second group information can be obtained offline, that is, pre-stored, or obtained online. If the second group information is pre-stored, the second group information can be Obtained in the following manner: in the second implementable manner, further, the above method may further include:
根据各个应用的历史使用内存数据获取第二群组信息,历史使用内存数据为启动时所需内存,或者,历史使用内存数据为启动时所需内存和使用预设时间段所需内存之和。The second group information is obtained according to the historical memory usage data of each application. The historical memory usage data is the memory required at startup, or the historical memory usage data is the sum of the memory required at startup and the memory required for the preset time period.
具体来说,历史使用内存数据为APP启动时所需内存时,统计各个应用启动时所需的内存,即启动运行时所占的内存,可以是在不同的终端设备上运行各个应用,并统计在不同终端设备上运行各个应用后所占的内存数据,然后根据所有的历史使用内存数据获取第二群组信息。Specifically, when the historical memory usage data is the memory required when the app is started, the memory required at the start of each application is counted, that is, the memory occupied when the application is started. It can be run on different terminal devices and count The memory data occupied after each application is run on different terminal devices, and then the second group information is obtained according to all the historical memory usage data.
历史使用内存数据为启动时所需内存和使用预设时间段所需内存之和时,预设时间段例如可以是半天,一天,一个周,由于有的APP内存需求随使用时间往往呈递增趋势,以王者荣耀为例,每打一局游戏,匿名页规模都会明显增加,因此,在内存回收时考虑APP内存需求为启动时所需内存和预期使用阶段增长内存之和,可进一步提高内存回收的准确性。具体地,可以是在不同的终端设备上运行各个应用,并统计在不同终端设备上运行各个应用启动时所需内存和使用预设时间段所需内存,将一个应用启动时所需内存和使用预设时间段所需内存之和作为历史使用内存数据,得到各个应用的历史使用内存数据,然后根据所有的历史使用内存数据获取第二群组信息。When the historical memory usage data is the sum of the memory required at startup and the memory required to use the preset time period, the preset time period can be, for example, half a day, one day, or one week. Because some APP memory requirements tend to increase with the use time Take Honor of Kings as an example. Every game played, the anonymous page size will increase significantly. Therefore, when memory recovery, consider the memory requirement of APP as the sum of the memory required at startup and the memory that is expected to increase during the use phase, which can further improve memory recovery Accuracy. Specifically, it can be to run each application on different terminal devices, and count the memory required to run each application on different terminal devices when it is started and the memory required to use the preset time period, and the memory required and used when an application is started The sum of the memory required for the preset time period is used as the historical memory usage data to obtain the historical memory usage data of each application, and then the second group information is obtained according to all the historical memory usage data.
作为一种可实施的方式,可以是根据如下方式获取第二群组信息:As an implementable way, the second group information can be obtained according to the following way:
S101a’、根据各个应用的历史使用内存数据分别预测各个应用的内存需求,内存需求为启动时所需内存;或者,内存需求为启动时所需内存和预期使用阶段增长内存之和。S101a', respectively predict the memory requirements of each application according to the historical memory usage data of each application, the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to increase during the use phase.
若历史使用内存数据为启动时所需内存,则相应的,预测的各个应用的内存需求为启动时所需内存。若历史使用内存数据为启动时所需内存和使用预设时间段所需内存之和,则相应地,预测的各个应用的内存需求为启动时所需内存和预期使用阶段增长内存之和。If the historical memory usage data is the memory required at startup, correspondingly, the predicted memory demand of each application is the memory required at startup. If the historical memory usage data is the sum of the memory required at startup and the memory required to use the preset time period, correspondingly, the predicted memory demand of each application is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
S101b’根据预测的各个应用的内存需求和多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到内存需求范围和内存水线的映射关系,即为第二群组信息根据预测的各个应用的内存需求将所有应用进行群组划分,得到多个群组,一个内存需求范围内的应用属于同一个群组。S101b' divides all applications into groups based on the predicted memory requirements of each application and multiple sets of memory waterlines to obtain multiple groups, one set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the mapping relationship between the memory demand range and the memory waterline, that is, the second group information divides all applications into groups according to the predicted memory demand of each application, and obtains multiple groups, one memory demand range Apps belong to the same group.
示例性地,可以是根据多套内存水线对所有应用在进行群组划分时,可将内存需求在一个范围内的应用划分为一个群组,例如可将内存需求为0MB~50MB的应用划分为一个群组,将内存需求为50MB~100MB的应用划分为一个群组,将内存需求为1GB~2GB的应用划分为一个群组,等等,可获得每个群组对应的内存需求范围,如三个群组对应的内存范围分别是0MB~50MB、50MB~100MB和1GB~2GB。Exemplarily, when all applications are grouped according to multiple sets of memory pipelines, applications with memory requirements within a range can be divided into a group, for example, applications with memory requirements of 0MB-50MB can be divided As a group, divide the applications with memory requirements of 50MB-100MB into a group, divide the applications with memory requirements of 1GB-2GB into a group, and so on, to obtain the range of memory requirements corresponding to each group, For example, the memory ranges corresponding to the three groups are 0MB~50MB, 50MB~100MB and 1GB~2GB respectively.
具体地,群组划分完成后,可以得到每个群组对应的内存需求范围,为每个群组分别设置一套内存水线和一个群组标识,得到群组标识、内存需求范围和内存水线的映射关系,即为第二群组信息。Specifically, after the group division is completed, the memory requirement range corresponding to each group can be obtained, and a set of memory waterline and a group identifier are set for each group to obtain the group identifier, memory requirement range, and memory level. The mapping relationship of the lines is the second group information.
在第一种可实施的方式和第二种可实施的方式下,若第一群组信息为在线获取的,在S101之前,本实施例的方法还可以包括:In the first implementable manner and the second implementable manner, if the first group information is obtained online, before S101, the method of this embodiment may further include:
S103、获取预设时间内各个应用运行后的历史使用内存数据。S103. Obtain historical memory usage data after each application runs within a preset time.
其中,历史使用内存数据为应用启动时所占内存,或者,历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和。Among them, the historical memory usage data is the memory occupied when the application is started, or the historical memory usage data is the sum of the memory occupied when the application is started and the memory occupied by the preset time period.
具体地,可以是用户拿到终端设备之后,运行终端设备上的各个应用,由***获取各个应用运行后的历史使用内存数据,预设时间可以根据用户自己设定。Specifically, after the user obtains the terminal device, he runs each application on the terminal device, and the system obtains the historical memory usage data of each application after running. The preset time can be set by the user.
S104、根据各个应用的历史使用内存数据分别预测各个应用的内存需求,内存需求为启动时所需内存;或者,内存需求为启动时所需内存和预期使用阶段增长内存之和。S104. Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
具体地,在预测内存需求时,可以是根据预设的规则预测,例如取每次应用运行后的使用内存的平均值,或者取最大值等。Specifically, when predicting the memory demand, it may be predicted according to a preset rule, for example, taking the average value of the used memory after each application is run, or taking the maximum value.
S105、根据预测的各个应用的内存需求获取第一群组信息或第二群组信息。S105. Obtain the first group information or the second group information according to the predicted memory requirements of each application.
具体地,根据预测的各个应用的内存需求获取第一群组信息,可以为:Specifically, obtaining the first group information according to the predicted memory requirements of each application may be:
根据预测的各个应用的内存需求和多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one application. Get the first group information.
在将获得的第一群组信息存储后,进一步地,后续还可以根据配置文件指示的群组标识和群组内应用或者群组内应用的更新,更新第一群组信息。也就是说群组内的应用是可以变化的,例如某一应用版本升级后内存需求发生变化,对应所属的群组也发生变化,此时需要更新群组内应用。After the obtained first group information is stored, further, the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the application in the group or the update of the application in the group. That is to say, the applications in the group can be changed. For example, after a certain application version is upgraded, the memory requirement changes and the corresponding group also changes. At this time, the application in the group needs to be updated.
根据预测的各个应用的内存需求获取第二群组信息,可以为:Obtain the second group information according to the predicted memory requirements of each application, which can be:
根据预测的各个应用的内存需求和多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到第二群组信息。According to the predicted memory requirements of each application and multiple sets of memory waterlines, all applications are divided into groups, and multiple groups are obtained. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same group , Get the second group information.
通过上述在线获取的方式获取第一群组信息或第二群组信息时,由于是根据用户的使用习惯来获取和更新群组内应用与内存水线的映射关系的,因此准确性更高。When acquiring the first group information or the second group information through the above-mentioned online acquisition method, since the mapping relationship between the applications in the group and the memory waterline is acquired and updated according to the user's usage habits, the accuracy is higher.
S102、根据该应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。S102. When it is determined that the memory recycling condition is satisfied according to the memory waterline of the application and the system memory occupancy information, determine the application whose memory will be recycled from the applications currently running on the terminal device, and transfer the memory waterline of the application to the kernel space , Used by the kernel to perform memory recycling based on the memory waterline of the application.
具体地,例如,若***内存剩余空间低于目标群组的内存水线中的低水位,则判定满足内存回收条件。Specifically, for example, if the remaining space of the system memory is lower than the low water level in the memory waterline of the target group, it is determined that the memory recovery condition is satisfied.
判定满足内存回收条件后,从终端设备当前正在运行的应用中确定将被回收内存的应用,例如可以是根据预先保存的被回收内存的应用的优先级顺序,来从当前正在运行的应用中确定将被回收内存的应用,还可以是根据现有的其它方式,本申请实施例对此不作限制。确定了将被回收内存的应用后,进行***调用,可以是通过预留的函数接口将该应用的内存水线传入内核空间,由内核根据该应用的内存水线来确定回收终止的条件,并执行内存回收。After determining that the memory recycling condition is met, determine the application that will be reclaimed from the currently running applications of the terminal device. For example, it can be determined from the currently running applications according to the pre-saved priority order of the applications whose memory is reclaimed. The application whose memory is to be reclaimed may also be based on other existing methods, which are not limited in the embodiment of the present application. After determining the application whose memory will be reclaimed, the system call can be made by passing the memory waterline of the application to the kernel space through the reserved function interface, and the kernel determines the condition of the reclaim termination according to the memory waterline of the application. And perform memory reclamation.
本实施例提供的内存回收方法,通过监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取该应用的内存水线,根据该应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。从而,针对不同内存需求的应用,可根据不同的内存水线进行内存回收,因此可避免内存过度回收和回收不足的问题,还可提高应用的保活率。The memory recycling method provided in this embodiment obtains the memory waterline of the application from multiple sets of pre-stored memory waterlines by monitoring when an application is started or switched to the foreground interface, and according to the memory waterline and system memory of the application When the occupancy information determines that the memory reclaim condition is met, the application that will be reclaimed is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space for the kernel to execute according to the memory waterline of the application Memory reclamation. Therefore, for applications with different memory requirements, memory recycling can be performed according to different memory pipelines, so that the problems of over-recycling and under-recycling of memory can be avoided, and the keep-alive rate of the application can also be improved.
下面采用三个具体的实施例,对图2所示方法实施例的技术方案进行详细说明。The following three specific embodiments are used to describe the technical solution of the method embodiment shown in FIG. 2 in detail.
图3为本申请提供的一种内存回收方法实施例的流程图,如图3所示,本实施例的方法可以包括:FIG. 3 is a flowchart of an embodiment of a memory recycling method provided by this application. As shown in FIG. 3, the method in this embodiment may include:
S201、监控到有应用被启动或切换到前台界面时,从预存的第一群组信息中查找该应用所属的目标群组,第一群组信息包括群组标识、群组内应用和内存水线的映射关系,将目标群组的内存水线确定为该应用的内存水线。S201. When it is monitored that an application is started or switched to the foreground interface, search for the target group to which the application belongs from the pre-stored first group information. The first group information includes the group identifier, the application in the group, and the memory level. The mapping relationship of the lines determines the memory waterline of the target group as the memory waterline of the application.
例如,当前被启动应用为APP4,从表一所示的第一群组信息中查找到APP4所属的目标群组为群组2,将群组2的内存水线二作为APP2的内存水线。For example, the currently activated application is APP4, the target group to which APP4 belongs is found from the first group information shown in Table 1, and the memory waterline 2 of group 2 is used as the memory waterline of APP2.
具体地,可以是根据图2所示实施例中S101a~S101b的过程获取第一群组信息,并存储第一群组信息,详细过程可参见图2所示实施例中S101a~S101b的详细描述,此处不再赘述。Specifically, the first group information may be obtained according to the process of S101a to S101b in the embodiment shown in FIG. 2 and the first group information is stored. For the detailed process, please refer to the detailed description of S101a to S101b in the embodiment shown in FIG. 2 , I won’t repeat it here.
在将获得的第一群组信息存储后,进一步地,后续还可以根据配置文件指示的群组标识和群组内应用的更新,更新第一群组信息。也就是说群组内的应用是可以变化的。After the obtained first group information is stored, further, the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the update of the application in the group. In other words, the applications in the group can be changed.
S202、根据该应用的内存水线和***内存占用信息判定是否满足内存回收条件,若是则执行S203,若否返回执行S201。S202: Determine whether the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, if yes, execute S203, if not, return to execute S201.
S203、从终端设备当前正在运行的应用中确定将被回收内存的应用,并通过预留的函数接口将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。S203. Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
图4为本申请提供的一种内存回收方法实施例的流程图,如图4所示,本实施例的方法可以包括:FIG. 4 is a flowchart of an embodiment of a memory recycling method provided by this application. As shown in FIG. 4, the method in this embodiment may include:
S301、监控到有应用被启动或切换到前台界面时,根据该应用的内存需求和预存的第 二群组信息确定该应用所属的目标群组,第二群组信息包括群组标识、内存需求范围和内存水线的映射关系,将目标群组的内存水线确定为该应用的内存水线。S301. When it is monitored that an application is started or switched to the foreground interface, the target group to which the application belongs is determined according to the memory requirement of the application and the pre-stored second group information, the second group information includes the group identifier and the memory requirement The mapping relationship between the range and the memory waterline determines the memory waterline of the target group as the memory waterline of the application.
其中,根据该应用的内存需求和预存的第二群组信息确定该应用所属的目标群组,具体可以是:若该应用的内存需求在一群组的内存需求范围内,则将该群组确定为目标群组。Wherein, the target group to which the application belongs is determined according to the memory requirement of the application and the pre-stored second group information, which may specifically be: if the memory requirement of the application is within the memory requirement range of a group, then the group Determined as the target group.
例如,如表二所示的第二群组信息,当前被启动应用为APP6,若APP6的内存需求为1.2GB,1.2GB在群组3的内存需求范围1GB~1.5GB内,将群组3确定为目标群组,并将群组3的内存水线三作为APP6的内存水线。For example, in the second group information shown in Table 2, the currently activated application is APP6. If the memory requirement of APP6 is 1.2GB, and 1.2GB is within the memory requirement range of group 3 from 1GB to 1.5GB, group 3 Determine as the target group, and use the memory waterline 3 of group 3 as the memory waterline of APP6.
具体地,可以是根据图2所示实施例中S101a’~S101b’的过程获取第二群组信息,并存储第二群组信息,详细过程可参见图2所示实施例中S101a’~S101b’的详细描述,此处不再赘述。Specifically, the second group information may be obtained according to the process of S101a' to S101b' in the embodiment shown in FIG. 2, and the second group information is stored. For the detailed process, please refer to S101a' to S101b in the embodiment shown in FIG. The detailed description will not be repeated here.
S302、根据该应用的内存水线和***内存占用信息判定是否满足内存回收条件,若是则执行S303,若否返回执行S301。S302: Determine whether the memory recovery condition is satisfied according to the memory waterline of the application and the system memory occupancy information, if yes, execute S303, if not, return to execute S301.
S303、从终端设备当前正在运行的应用中确定将被回收内存的应用,并通过预留的函数接口将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。S303. Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
图5为本申请提供的一种内存回收方法实施例的流程图,与图3和图4的区别在于,本实施例中第一群组信息是在线获取的,如图5所示,本实施例的方法可以包括:FIG. 5 is a flowchart of an embodiment of a memory recycling method provided by this application. The difference from FIG. 3 and FIG. 4 is that the first group information in this embodiment is obtained online. As shown in FIG. 5, this embodiment Examples of methods can include:
S401、获取预设时间内各个应用运行后的历史使用内存数据。S401. Acquire historical memory usage data after each application runs within a preset time.
其中,历史使用内存数据为应用启动时所占内存,或者,历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和。Among them, the historical memory usage data is the memory occupied when the application is started, or the historical memory usage data is the sum of the memory occupied when the application is started and the memory occupied by the preset time period.
具体地,可以是用户拿到终端设备之后,运行终端设备上的各个应用,由***获取各个应用运行后的历史使用内存数据,预设时间可以根据用户自己设定。Specifically, after the user obtains the terminal device, he runs each application on the terminal device, and the system obtains the historical memory usage data of each application after running. The preset time can be set by the user.
S402、根据各个应用的历史使用内存数据分别预测各个应用的内存需求。S402: Predict the memory requirements of each application separately according to the historical memory usage data of each application.
其中,内存需求为启动时所需内存;或者,内存需求为启动时所需内存和预期使用阶段增长内存之和。Among them, the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
具体地,在预测内存需求时,可以是根据预设的规则预测,例如取每次应用运行后的使用内存的平均值,或者取最大值等。Specifically, when predicting the memory demand, it may be predicted according to a preset rule, for example, taking the average value of the used memory after each application is run, or taking the maximum value.
S403、根据预测的各个应用的内存需求获取第一群组信息,第一群组信息包括群组标识、群组内应用和内存水线的映射关系。S403: Acquire first group information according to the predicted memory requirements of each application, where the first group information includes a group identifier, a mapping relationship between applications in the group, and a memory waterline.
具体地,根据预测的各个应用的内存需求获取第一群组信息,具体为:Specifically, the first group information is obtained according to the predicted memory requirements of each application, specifically:
根据预测的各个应用的内存需求和多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one application. Get the first group information.
在将获得的第一群组信息存储后,进一步地,后续还可以根据配置文件指示的群组标识和群组内应用或者群组内应用的更新,更新第一群组信息。也就是说群组内的应用是可以变化的,例如某一应用版本升级后内存需求发生变化,对应所属的群组也发生变化,此时需要更新群组内应用。After the obtained first group information is stored, further, the first group information may be updated subsequently according to the group identifier indicated by the configuration file and the application in the group or the update of the application in the group. That is to say, the applications in the group can be changed. For example, after a certain application version is upgraded, the memory requirement changes and the corresponding group also changes. At this time, the application in the group needs to be updated.
S404、监控到有应用被启动或切换到前台界面时,从第一群组信息中查找该应用所 属的目标群组,将目标群组的内存水线确定为该应用的内存水线。S404: When it is monitored that an application is started or switched to the foreground interface, search for the target group to which the application belongs from the first group information, and determine the memory waterline of the target group as the memory waterline of the application.
S405、根据该应用的内存水线和***内存占用信息判定是否满足内存回收条件,若是则执行S403,若否返回执行S404。S405: Determine whether the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, if yes, execute S403, if not, return to execute S404.
S406、从终端设备当前正在运行的应用中确定将被回收内存的应用,并通过预留的函数接口将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。S406. Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
图6为本申请提供的一种内存回收方法实施例的流程图,与图3和图4的区别在于,本实施例中第二群组信息是在线获取的,如图6所示,本实施例的方法可以包括:FIG. 6 is a flowchart of an embodiment of a memory recycling method provided by this application. The difference from FIG. 3 and FIG. 4 is that the second group information in this embodiment is obtained online. As shown in FIG. 6, this embodiment Examples of methods can include:
S501、获取预设时间内各个应用运行后的历史使用内存数据。S501. Obtain historical memory usage data after each application is running within a preset time.
其中,历史使用内存数据为应用启动时所占内存,或者,历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和。Among them, the historical memory usage data is the memory occupied when the application is started, or the historical memory usage data is the sum of the memory occupied when the application is started and the memory occupied by the preset time period.
具体地,可以是用户拿到终端设备之后,运行终端设备上的各个应用,由***获取各个应用运行后的历史使用内存数据,预设时间可以根据用户自己设定。Specifically, after the user obtains the terminal device, he runs each application on the terminal device, and the system obtains the historical memory usage data of each application after running. The preset time can be set by the user.
S502、根据各个应用的历史使用内存数据分别预测各个应用的内存需求。S502: Predict the memory requirements of each application separately according to the historical memory usage data of each application.
其中,内存需求为启动时所需内存;或者,内存需求为启动时所需内存和预期使用阶段增长内存之和。Among them, the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase.
具体地,在预测内存需求时,可以是根据预设的规则预测,例如取每次应用运行后的使用内存的平均值,或者取最大值等。Specifically, when predicting the memory demand, it may be predicted according to a preset rule, for example, taking the average value of the used memory after each application is run, or taking the maximum value.
S503、根据预测的各个应用的内存需求获取第二群组信息,第二群组信息包括群组标识、内存需求范围和内存水线的映射关系。S503: Obtain second group information according to the predicted memory requirements of each application, where the second group information includes a group identifier, a memory requirement range, and a mapping relationship between a memory waterline.
具体地,根据预测的各个应用的内存需求获取第二群组信息,具体为:Specifically, the second group information is acquired according to the predicted memory requirements of each application, specifically:
根据预测的各个应用的内存需求和多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到第二群组信息。According to the predicted memory requirements of each application and multiple sets of memory waterlines, all applications are divided into groups, and multiple groups are obtained. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same group , Get the second group information.
S504、监控到有应用被启动或切换到前台界面时,根据该应用的内存需求和第二群组信息确定该应用所属的目标群组,将目标群组的内存水线确定为该应用的内存水线。S504. When it is monitored that an application is started or switched to the foreground interface, determine the target group to which the application belongs according to the memory requirements of the application and the second group information, and determine the memory waterline of the target group as the memory of the application Waterline.
S505、根据该应用的内存水线和***内存占用信息判定是否满足内存回收条件,若是则执行S503,若否返回执行S504。S505: Determine whether the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, if yes, execute S503, if not, return to execute S504.
S506、从终端设备当前正在运行的应用中确定将被回收内存的应用,并通过预留的函数接口将该应用的内存水线传入内核空间,用于内核根据该应用的内存水线执行内存回收。S506. Determine the application whose memory will be reclaimed from the applications currently running on the terminal device, and pass the memory waterline of the application to the kernel space through the reserved function interface, so that the kernel executes the memory according to the memory waterline of the application. Recycling.
图7为本申请提供的一种内存回收装置实施例的结构示意图,如图7所示,本实施例的装置可以包括:获取模块11和处理模块12,其中,获取模块11用于监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取所述应用的内存水线;FIG. 7 is a schematic structural diagram of an embodiment of a memory recovery device provided by this application. As shown in FIG. 7, the device of this embodiment may include: an acquisition module 11 and a processing module 12, where the acquisition module 11 is used to monitor When the application is started or switched to the foreground interface, obtain the memory waterline of the application from multiple sets of pre-stored memory waterlines;
处理模块12用于根据所述应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将所述应用的内存水线传入内核空间,用于内核根据所述应用的内存水线执行内存回收。The processing module 12 is configured to determine the application whose memory is to be recovered from the applications currently running on the terminal device when it is determined that the memory recovery condition is met according to the memory waterline of the application and the system memory occupancy information, and to compare the memory level of the application The line is passed into the kernel space for the kernel to perform memory recycling according to the memory waterline of the application.
进一步地,所述获取模块11用于:Further, the acquisition module 11 is used for:
从第一群组信息中查找所述应用所属的目标群组,所述第一群组信息包括群组内应用 和内存水线的映射关系;Searching for the target group to which the application belongs from the first group information, where the first group information includes the mapping relationship between the application in the group and the memory waterline;
将所述目标群组的内存水线确定为所述应用的内存水线;或者,Determine the memory waterline of the target group as the memory waterline of the application; or,
根据所述应用的内存需求和第二群组信息确定所述应用所属的目标群组,所述第二群组信息包括群组内存需求范围和内存水线的映射关系;Determining the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
将所述目标群组的内存水线确定为所述应用的内存水线。Determine the memory waterline of the target group as the memory waterline of the application.
可选的,所述第一群组信息和所述第二群组信息是预先存储的。Optionally, the first group information and the second group information are pre-stored.
进一步地,所述获取模块11用于:Further, the acquisition module 11 is used for:
若所述应用的内存需求在一群组的内存需求范围内,则将所述群组确定为所述目标群组。If the memory requirement of the application is within the memory requirement range of a group, the group is determined as the target group.
进一步地,所述获取模块11还用于:Further, the acquisition module 11 is also used for:
获取预设时间内各个应用运行后的历史使用内存数据,所述历史使用内存数据为应用启动时所占内存,或者,所述历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和;Obtain historical memory usage data after each application is running within a preset time, where the historical memory usage data is the memory occupied when the application is started, or the historical memory occupied data is the memory occupied when the application is started and the preset time period of use The sum of memory occupied;
根据各个应用的历史使用内存数据分别预测各个应用的内存需求,所述内存需求为启动时所需内存;或者,所述内存需求为启动时所需内存和预期使用阶段增长内存之和;Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
根据预测的各个应用的内存需求获取所述第一群组信息或所述第二群组信息。Acquire the first group information or the second group information according to the predicted memory requirements of each application.
进一步地,所述获取模块11用于:Further, the acquisition module 11 is used for:
根据预测的各个应用的内存需求和所述多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到所述第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and the multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
进一步地,所述获取模块11用于:Further, the acquisition module 11 is used for:
根据预测的各个应用的内存需求和所述多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到所述第二群组信息。According to the predicted memory requirements of each application and the multiple sets of memory waterlines, all applications are divided into groups to obtain multiple groups. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
进一步地,所述处理模块12还用于:Further, the processing module 12 is also used for:
根据配置文件指示的群组内应用的更新,更新所述第一群组信息。The first group information is updated according to the update of the application in the group indicated by the configuration file.
进一步地,所述处理模块12用于:Further, the processing module 12 is used for:
通过预留的函数接口将所述应用的内存水线传入内核空间。The memory waterline of the application is transferred to the kernel space through the reserved function interface.
本实施例的装置,可以用于执行图2所示方法实施例的技术方案,其实现原理类似,此处不再赘述。The device of this embodiment can be used to implement the technical solution of the method embodiment shown in FIG. 2, and its implementation principles are similar, and will not be repeated here.
本申请可以根据上述方法示例对内存回收装置进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本申请各实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。The present application may divide the memory recovery device into functional modules according to the foregoing method examples. For example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The above-mentioned integrated modules can be implemented in the form of hardware or software function modules. It should be noted that the division of modules in the embodiments of the present application is illustrative, and is only a logical function division, and there may be other division methods in actual implementation.
图8为本申请提供的一种终端设备结构示意图,该终端设备200包括:FIG. 8 is a schematic structural diagram of a terminal device provided by this application, and the terminal device 200 includes:
存储器201和处理器202; Memory 201 and processor 202;
存储器201,用于存储计算机程序;The memory 201 is used to store computer programs;
处理器202,用于执行存储器存储的计算机程序,以实现上述实施例中的内存回收方 法。具体可以参见前述方法实施例中的相关描述。The processor 202 is configured to execute a computer program stored in the memory to implement the memory recycling method in the foregoing embodiment. For details, refer to the relevant description in the foregoing method embodiment.
可选地,存储器201既可以是独立的,也可以跟处理器202集成在一起。Optionally, the memory 201 may be independent or integrated with the processor 202.
当存储器201是独立于处理器202之外的器件时,终端设备200还可以包括:When the memory 201 is a device independent of the processor 202, the terminal device 200 may further include:
总线203,用于连接存储器201和处理器202。The bus 203 is used to connect the memory 201 and the processor 202.
可选地,本实施例还包括:通信接口204,该通信接口204可以通过总线203与处理器202连接。处理器202可以控制通信接口203来实现终端设备200的上述的接收和发送的功能。Optionally, this embodiment further includes: a communication interface 204, and the communication interface 204 may be connected to the processor 202 through the bus 203. The processor 202 may control the communication interface 203 to implement the aforementioned receiving and sending functions of the terminal device 200.
该终端设备可以用于执行上述方法实施例中终端设备对应的各个步骤和/或流程。The terminal device may be used to execute various steps and/or procedures corresponding to the terminal device in the foregoing method embodiments.
本申请还提供一种可读存储介质,可读存储介质中存储有执行指令,当终端设备的至少一个处理器执行该执行指令时,终端设备执行上述方法实施例中的内存回收方法。The present application also provides a readable storage medium in which an execution instruction is stored. When at least one processor of a terminal device executes the execution instruction, the terminal device executes the memory recovery method in the foregoing method embodiment.
本申请还提供一种程序产品,该程序产品包括执行指令,该执行指令存储在可读存储介质中。终端设备的至少一个处理器可以从可读存储介质读取该执行指令,至少一个处理器执行该执行指令使得终端设备实施上述方法实施例中的内存回收方法。The application also provides a program product, which includes an execution instruction, and the execution instruction is stored in a readable storage medium. At least one processor of the terminal device can read the execution instruction from the readable storage medium, and the execution of the execution instruction by the at least one processor causes the terminal device to implement the memory recovery method in the foregoing method embodiment.
本申请还提供一种芯片,所述芯片与存储器相连,或者所述芯片上集成有存储器,当所述存储器中存储的软件程序被执行时,实现上述方法实施例中的内存回收方法。The present application also provides a chip, which is connected to a memory, or a memory is integrated on the chip, and when the software program stored in the memory is executed, the memory recovery method in the above method embodiment is implemented.
本领域普通技术人员可以理解:在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘Solid State Disk(SSD))等。A person of ordinary skill in the art can understand that: in the foregoing embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented by software, it can be implemented in the form of a computer program product in whole or in part. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center. Transmission to another website site, computer, server or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center integrated with one or more available media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, and a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)).

Claims (21)

  1. 一种内存回收方法,其特征在于,包括:A method for reclaiming memory, characterized in that it comprises:
    监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取所述应用的内存水线;When it is monitored that an application is started or switched to the foreground interface, obtain the memory waterline of the application from multiple sets of pre-stored memory waterlines;
    根据所述应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将所述应用的内存水线传入内核空间,用于内核根据所述应用的内存水线执行内存回收。When it is determined that the memory recycling condition is satisfied according to the memory waterline of the application and the system memory occupancy information, the application whose memory is to be recycled is determined from the applications currently running on the terminal device, and the memory waterline of the application is transferred to the kernel space , For the kernel to perform memory recycling according to the memory waterline of the application.
  2. 根据权利要求1所述的方法,其特征在于,所述从预存的多套内存水线中获取所述应用的内存水线,包括:The method according to claim 1, wherein the obtaining the memory waterline of the application from a plurality of sets of pre-stored memory waterlines comprises:
    从第一群组信息中查找所述应用所属的目标群组,所述第一群组信息包括群组内应用和内存水线的映射关系;Searching for the target group to which the application belongs from the first group information, where the first group information includes the mapping relationship between the application in the group and the memory waterline;
    将所述目标群组的内存水线确定为所述应用的内存水线;或者,Determine the memory waterline of the target group as the memory waterline of the application; or,
    根据所述应用的内存需求和第二群组信息确定所述应用所属的目标群组,所述第二群组信息包括群组内存需求范围和内存水线的映射关系;Determining the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
    将所述目标群组的内存水线确定为所述应用的内存水线。Determine the memory waterline of the target group as the memory waterline of the application.
  3. 根据权利要求2所述的方法,其特征在于,所述第一群组信息和所述第二群组信息是预先存储的。The method according to claim 2, wherein the first group information and the second group information are pre-stored.
  4. 根据权利要求2所述的方法,其特征在于,所述根据所述应用的内存需求和预存的第二群组信息确定所述应用所属的目标群组,包括:The method according to claim 2, wherein the determining the target group to which the application belongs based on the memory requirement of the application and pre-stored second group information comprises:
    若所述应用的内存需求在一群组的内存需求范围内,则将所述群组确定为所述目标群组。If the memory requirement of the application is within the memory requirement range of a group, the group is determined as the target group.
  5. 根据权利要求2所述的方法,其特征在于,所述方法还包括:The method according to claim 2, wherein the method further comprises:
    获取预设时间内各个应用运行后的历史使用内存数据,所述历史使用内存数据为应用启动时所占内存,或者,所述历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和;Obtain historical memory usage data after each application is running within a preset time, where the historical memory usage data is the memory occupied when the application is started, or the historical memory occupied data is the memory occupied when the application is started and the preset time period of use The sum of memory occupied;
    根据各个应用的历史使用内存数据分别预测各个应用的内存需求,所述内存需求为启动时所需内存;或者,所述内存需求为启动时所需内存和预期使用阶段增长内存之和;Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
    根据预测的各个应用的内存需求获取所述第一群组信息或所述第二群组信息。Acquire the first group information or the second group information according to the predicted memory requirements of each application.
  6. 根据权利要求5所述的方法,其特征在于,所述根据预测的各个应用的内存需求获取所述第一群组信息,包括:The method according to claim 5, wherein the obtaining the first group information according to the predicted memory requirements of each application comprises:
    根据预测的各个应用的内存需求和所述多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到所述第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and the multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
  7. 根据权利要求5所述的方法,其特征在于,所述根据预测的各个应用的内存需求获取所述第二群组信息,包括:The method according to claim 5, wherein the obtaining the second group information according to the predicted memory requirements of each application comprises:
    根据预测的各个应用的内存需求和所述多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到所述第二群组信息。According to the predicted memory requirements of each application and the multiple sets of memory waterlines, all applications are divided into groups to obtain multiple groups. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
  8. 根据权利要求2所述的方法,其特征在于,所述方法还包括:The method according to claim 2, wherein the method further comprises:
    根据配置文件指示的群组内应用的更新,更新所述第一群组信息。The first group information is updated according to the update of the application in the group indicated by the configuration file.
  9. 根据权利要求1所述的方法,其特征在于,所述将所述应用的内存水线传入内核空间,包括:The method according to claim 1, wherein the transferring the memory pipeline of the application to the kernel space comprises:
    通过预留的函数接口将所述应用的内存水线传入内核空间。The memory waterline of the application is transferred to the kernel space through the reserved function interface.
  10. 一种内存回收装置,其特征在于,包括:A memory recovery device, characterized in that it comprises:
    获取模块,用于监控到有应用被启动或切换到前台界面时,从预存的多套内存水线中获取所述应用的内存水线;The acquiring module is used to monitor the application's memory waterline from multiple sets of pre-stored memory waterlines when it is monitored that an application is started or switched to the foreground interface;
    处理模块,用于根据所述应用的内存水线和***内存占用信息判定满足内存回收条件时,从终端设备当前正在运行的应用中确定将被回收内存的应用,并将所述应用的内存水线传入内核空间,用于内核根据所述应用的内存水线执行内存回收。The processing module is used to determine the application whose memory will be recovered from the applications currently running on the terminal device when it is determined that the memory recovery condition is satisfied according to the memory waterline of the application and the system memory occupancy information, and to compare the memory level of the application The line is passed into the kernel space for the kernel to perform memory recycling according to the memory waterline of the application.
  11. 根据权利要求10所述的装置,其特征在于,所述获取模块用于:The device according to claim 10, wherein the acquisition module is used to:
    从第一群组信息中查找所述应用所属的目标群组,所述第一群组信息包括群组内应用和内存水线的映射关系;Searching for the target group to which the application belongs from the first group information, where the first group information includes the mapping relationship between the application in the group and the memory waterline;
    将所述目标群组的内存水线确定为所述应用的内存水线;或者,Determine the memory waterline of the target group as the memory waterline of the application; or,
    根据所述应用的内存需求和第二群组信息确定所述应用所属的目标群组,所述第二群组信息包括群组内存需求范围和内存水线的映射关系;Determining the target group to which the application belongs according to the memory requirement of the application and the second group information, where the second group information includes the mapping relationship between the memory requirement range of the group and the memory waterline;
    将所述目标群组的内存水线确定为所述应用的内存水线。Determine the memory waterline of the target group as the memory waterline of the application.
  12. 根据权利要求11所述的装置,其特征在于,所述第一群组信息和所述第二群组信息是预先存储的。The device according to claim 11, wherein the first group information and the second group information are pre-stored.
  13. 根据权利要求11所述的装置,其特征在于,所述获取模块用于:The device according to claim 11, wherein the acquisition module is used to:
    若所述应用的内存需求在一群组的内存需求范围内,则将所述群组确定为所述目标群组。If the memory requirement of the application is within the memory requirement range of a group, the group is determined as the target group.
  14. 根据权利要求11所述的装置,其特征在于,所述获取模块还用于:The device according to claim 11, wherein the acquiring module is further configured to:
    获取预设时间内各个应用运行后的历史使用内存数据,所述历史使用内存数据为应用启动时所占内存,或者,所述历史占用内存数据为应用启动时所占内存和使用预设时间段所占内存之和;Obtain historical memory usage data after each application is running within a preset time, where the historical memory usage data is the memory occupied when the application is started, or the historical memory occupied data is the memory occupied when the application is started and the preset time period of use The sum of memory occupied;
    根据各个应用的历史使用内存数据分别预测各个应用的内存需求,所述内存需求为启动时所需内存;或者,所述内存需求为启动时所需内存和预期使用阶段增长内存之和;Predict the memory requirements of each application separately according to the historical memory usage data of each application, where the memory requirement is the memory required at startup; or, the memory requirement is the sum of the memory required at startup and the memory that is expected to grow during the use phase;
    根据预测的各个应用的内存需求获取所述第一群组信息或所述第二群组信息。Acquire the first group information or the second group information according to the predicted memory requirements of each application.
  15. 根据权利要求14所述的装置,其特征在于,所述获取模块用于:The device according to claim 14, wherein the acquisition module is used to:
    根据预测的各个应用的内存需求和所述多套内存水线确定各个应用对应的内存水线,与一套内存水线对应的所有应用为一个群组内的元素,一个群组内包括至少一个应用,得到所述第一群组信息。Determine the memory waterline corresponding to each application according to the predicted memory requirements of each application and the multiple sets of memory waterlines. All applications corresponding to a set of memory waterlines are elements in a group, and a group includes at least one Application to obtain the first group information.
  16. 根据权利要求14所述的装置,其特征在于,所述获取模块用于:The device according to claim 14, wherein the acquisition module is used to:
    根据预测的各个应用的内存需求和所述多套内存水线将所有应用进行群组划分,得到多个群组,一套内存水线对应一个群组,一个内存需求范围内的应用属于同一个群组,得到所述第二群组信息。According to the predicted memory requirements of each application and the multiple sets of memory waterlines, all applications are divided into groups to obtain multiple groups. One set of memory waterlines corresponds to one group, and applications within the range of memory requirements belong to the same Group to obtain the second group information.
  17. 根据权利要求11所述的装置,其特征在于,所述处理模块还用于:The device according to claim 11, wherein the processing module is further configured to:
    根据配置文件指示的群组内应用的更新,更新所述第一群组信息。The first group information is updated according to the update of the application in the group indicated by the configuration file.
  18. 根据权利要求10所述的装置,其特征在于,所述处理模块用于:The device according to claim 10, wherein the processing module is configured to:
    通过预留的函数接口将所述应用的内存水线传入内核空间。The memory waterline of the application is transferred to the kernel space through the reserved function interface.
  19. 一种终端设备,其特征在于,包括:A terminal device, characterized in that it comprises:
    处理器;以及Processor; and
    存储器,用于存储所述处理器的可执行指令;A memory for storing executable instructions of the processor;
    其中,所述处理器配置为经由执行所述可执行指令来执行权利要求1-9任一项所述的内存回收方法。Wherein, the processor is configured to execute the memory reclamation method according to any one of claims 1-9 by executing the executable instruction.
  20. 一种可读存储介质,所述可读存储介质中存储有执行指令,其特征在于,当终端设备的至少一个处理器执行所述执行指令时,所述终端设备执行权利要求1-9任一项所述的内存回收方法。A readable storage medium storing an execution instruction, wherein when at least one processor of a terminal device executes the execution instruction, the terminal device executes any one of claims 1-9 The memory reclamation method described in the item.
  21. 一种程序产品,其特征在于,所述程序产品包括计算机程序,所述计算机程序存储在可读存储介质中,通信装置的至少一个处理器可以从所述可读存储介质读取所述计算机程序,所述至少一个处理器执行所述计算机程序使得通信装置实施如权利要求1-9任意一项所述的方法。A program product, characterized in that the program product includes a computer program, the computer program is stored in a readable storage medium, and at least one processor of a communication device can read the computer program from the readable storage medium The execution of the computer program by the at least one processor causes the communication device to implement the method according to any one of claims 1-9.
PCT/CN2020/110827 2019-08-30 2020-08-24 Memory reclaiming method and apparatus WO2021036993A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910812574.1A CN112445606B (en) 2019-08-30 2019-08-30 Memory recycling method and device
CN201910812574.1 2019-08-30

Publications (1)

Publication Number Publication Date
WO2021036993A1 true WO2021036993A1 (en) 2021-03-04

Family

ID=74684164

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/110827 WO2021036993A1 (en) 2019-08-30 2020-08-24 Memory reclaiming method and apparatus

Country Status (2)

Country Link
CN (1) CN112445606B (en)
WO (1) WO2021036993A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113961427B (en) * 2021-12-20 2022-05-24 荣耀终端有限公司 System memory analysis method and electronic equipment
CN116700944A (en) * 2022-11-03 2023-09-05 荣耀终端有限公司 Memory recycling method and device and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110051525A1 (en) * 2007-10-04 2011-03-03 Macronix International Co., Ltd. Power saving method and circuit thereof for a semiconductor memory
CN102968335A (en) * 2012-10-25 2013-03-13 东莞宇龙通信科技有限公司 Terminal and terminal memory management method
CN103902359A (en) * 2014-03-31 2014-07-02 深圳创维-Rgb电子有限公司 Android based system memory optimizing and application scheduling method and system
CN105701025A (en) * 2015-12-31 2016-06-22 华为技术有限公司 Memory recovery method and device
CN107220076A (en) * 2016-09-27 2017-09-29 华为技术有限公司 A kind of method for recovering internal storage and device
CN108205474A (en) * 2017-08-23 2018-06-26 珠海市魅族科技有限公司 EMS memory management process, terminal device, computer installation and readable storage medium storing program for executing

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109669877B (en) * 2018-12-11 2023-04-04 腾讯科技(深圳)有限公司 Memory management method, device, terminal and storage medium
CN109656722B (en) * 2019-01-04 2021-05-11 Oppo广东移动通信有限公司 Memory optimization method and device, mobile terminal and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110051525A1 (en) * 2007-10-04 2011-03-03 Macronix International Co., Ltd. Power saving method and circuit thereof for a semiconductor memory
CN102968335A (en) * 2012-10-25 2013-03-13 东莞宇龙通信科技有限公司 Terminal and terminal memory management method
CN103902359A (en) * 2014-03-31 2014-07-02 深圳创维-Rgb电子有限公司 Android based system memory optimizing and application scheduling method and system
CN105701025A (en) * 2015-12-31 2016-06-22 华为技术有限公司 Memory recovery method and device
CN107220076A (en) * 2016-09-27 2017-09-29 华为技术有限公司 A kind of method for recovering internal storage and device
CN108205474A (en) * 2017-08-23 2018-06-26 珠海市魅族科技有限公司 EMS memory management process, terminal device, computer installation and readable storage medium storing program for executing

Also Published As

Publication number Publication date
CN112445606A (en) 2021-03-05
CN112445606B (en) 2024-06-18

Similar Documents

Publication Publication Date Title
US11531625B2 (en) Memory management method and apparatus
US10853329B2 (en) Distributed file system
WO2021036993A1 (en) Memory reclaiming method and apparatus
US9678678B2 (en) Storage network data retrieval
US20130246825A1 (en) Method and system for dynamically power scaling a cache memory of a multi-core processing system
US9060009B2 (en) Network-extended data storage for mobile applications
US8738094B2 (en) Automatically enabling wireless communication
TWI697239B (en) Resource block group division method and user terminal
EP3974969A1 (en) System startup method and related device
CN110868339A (en) Node distribution method and device, electronic equipment and readable storage medium
KR20220116425A (en) Data cache mechanism through dual SIP phones
WO2024060682A1 (en) Memory management method and apparatus, memory manager, device and storage medium
KR20180088880A (en) Use network-supported protocols to improve network utilization
EP4246934A1 (en) Data transmission method, electronic device, and computer readable storage medium
WO2014159252A2 (en) Methods and systems for providing resources for cloud storage
CN107670276B (en) Game application control method and equipment
WO2023193599A1 (en) File transmission method and apparatus, and terminal device
TW201914353A (en) Control method and edge computing device for network communication system with base station network management server
US20140025630A1 (en) Data-store management apparatus, data providing system, and data providing method
CN109193653B (en) Power distribution method and device
CN104750614A (en) Memory management method and device
US9210568B1 (en) Hardware-capability update method for a portable device with multiple SIM cards
CN106326326B (en) A kind of image cache optimization method in android system
US20080294851A1 (en) Method, apparatus, computer program product, and system for management of shared memory
CN112286695A (en) Server resource allocation method and edge data center

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20857279

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20857279

Country of ref document: EP

Kind code of ref document: A1