TECHNICAL FIELD

This application relates to the field of terminals, and in particular, to a method and a terminal for allocating a system resource to an application.

BACKGROUND

In the field of terminals including smartphones, a most important task of an operating system of a terminal is to maintain system resource allocation. There are a plurality of types of system resources, for example, a central processing unit (CPU) resource represented in a form of a time slice, a memory resource represented in a form of a memory page, an input/output (I/O) resource represented in a form of bandwidth, and a broadcast resource. In the prior art, a manner of allocating a system resource by a terminal includes: An operating system of the terminal extracts, according to a resource allocation request sent by an application to the operating system, a system resource from current remaining system resources and allocates the system resource to the application. However, when an application having a relatively great system resource requirement (for example, a camera application having a relatively great memory resource requirement) needs to be started, if current available resources of the system cannot satisfy the requirement of the application, the operating system enters a slow system resource allocation path, to be specific, the operating system first needs to release an occupied system resource and then allocates a resource to the application after sufficient system resources are released. Such a system resource allocation method features relatively low efficiency, and increases an application startup time, thereby affecting user experience.

SUMMARY

This application provides a method and a terminal for allocating a system resource to an application, so as to allocate a system resource to an application in a timelier manner, and reduce an application startup delay.

According to a first aspect, a method for allocating a system resource to an application is provided, including: predicting, by a terminal based on a current status of the terminal, a target application to be used by a user; reserving, by the terminal for the target application based on a prediction result, a system resource required for running the target application; and providing, by the terminal according to a resource allocation request of the target application, the reserved system resource for the target application to use. Optionally, the reserving a system resource includes reserving, for the target application, an idle system resource greater than or equal to a system resource requirement of the target application.

In this embodiment of this application, the to-be-used target application of the terminal is predicted, and sufficient system resources are reserved for the target application before the resource allocation request of the target application is received. In this way, the system resource can be allocated to the target application in a timely manner, an application startup delay is reduced, and user experience is improved.

In a possible implementation, the method further includes: predicting, by the terminal, a use time point of the target application; and the reserving, by the terminal for the target application based on a prediction result, a system resource required for running the target application includes: reserving, by the terminal, the system resource for the target application before the use time point.

In this embodiment of this application, the use time point of the target application is predicted, and the system resource is reserved for the target application before the use time point of the target application. In this way, the resource can be allocated to the target application in a timely manner before the resource allocation request of the target application is received, an application startup delay is reduced, and user experience is improved.

In a possible implementation, the predicting, by the terminal, a use time point of the target application includes: predicting, by the terminal, the use time point of the target application based on a machine learning model, where a model parameter of the machine learning model is determined based on historical data of using the target application by the user.

In a possible implementation, the machine learning model includes an exponential distribution model; and the predicting, by the terminal, a use time point of the target application includes: predicting, by the terminal, the use time point of the target application by using the exponential distribution model, where the exponential distribution model is used to indicate a probability of using the target application in a target time range.

In a possible implementation, the target time range is a time range between a time point when the target application is used last time and a target time point, and the target time point is a time point after a current time point.

In a possible implementation, the target time range is a time range between a first time point and a second time point, the first time point is a current time point or a time point after a current time point, and the second time point is a time point after the first time point.

In a possible implementation, the predicting, by the terminal, the use time point of the target application by using the exponential distribution model includes: collecting, by the terminal, statistics on an average quantity of use times of the target application in a unit time; determining, by the terminal, a model parameter of the exponential distribution model based on the average quantity of use times; and predicting, by the terminal, the use time point of the target application based on the exponential distribution model and the model parameter of the exponential distribution model.

In a possible implementation, the machine learning model includes a hidden Markov model; and the predicting, by the terminal, a use time point of the target application includes: predicting the use time point of the target application by using the hidden Markov model, where the hidden Markov model is used to indicate a probability of using the target application in a target discrete time range.

In a possible implementation, the reserving, by the terminal for the target application based on a prediction result, a system resource required for running the target application includes: when current idle system resources do not satisfy a resource requirement of the target application, releasing, by the terminal, some occupied system resources to obtain updated idle system resources, so as to allocate the system resource to the target application.

In a possible implementation, the predicting, based on a current status of the terminal, a target application to be used by a user includes: predicting, by the terminal based on the current status of the terminal, a plurality of candidate applications to be used by the user, where the plurality of candidate applications include the target application; and the reserving, by the terminal based on a prediction result, a system resource for the target application includes: collecting statistics on a system resource required by each of the plurality of candidate applications; determining a maximum volume of each type of system resource in system resources required by the plurality of candidate applications; and reserving each type of system resource for the target application based on types of the system resources and the maximum volume of each type of system resource.

In a possible implementation, the types of the system resources include at least one of the following resources: a memory resource, a central processing unit CPU resource, and an input/output IO resource.

In a possible implementation, the predicting a target application to be used by a user includes starting, by the terminal, to predict the target application after receiving a foreground-background switching instruction.

According to a second aspect, a terminal is provided. The terminal includes modules configured to perform the method in the first aspect. Based on a same inventive concept, a principle of resolving a problem by the terminal is corresponding to that of the solution in the method design of the first aspect. Therefore, for implementation of the terminal, refer to the implementation of the method, and details are not described herein again.

According to a third aspect, a terminal is provided, including a memory, configured to store a program; and a processor, configured to execute the program in the memory. When executing the program, the processor is configured to perform the method in the first aspect.

According to a fourth aspect, a computer storage medium is provided. The computer storage medium is configured to store a computer program. The computer program includes an instruction used for performing the method in any one of the first aspect and the possible implementations of the first aspect.

