Cache page management optimization method based on mobile operating system
By recording the application usage and optimizing the cache page replacement algorithm, the problem of insufficient cache space in mobile devices is solved, the response speed of the foreground application is improved, the user experience is improved, and differentiated optimization of cache management is achieved.
Patent Information
- Application Number
- CN202411255042.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-09
- Publication Date
- 2024-12-27
AI Technical Summary
Insufficient cache space on mobile devices leads to delayed application responses and affects user experience. The existing technology solves the problem by increasing the size of flash memory but cannot effectively balance the cost and user experience.
By recording and counting application usage, save the foreground application pages in the cache and prioritize the pages of the backend application to free up cache space. An optimized cache page replacement algorithm is adopted to improve the response speed of the foreground application. .
It significantly improves the response speed of foreground applications, improves user experience, realizes differentiated distinction between applications in mobile devices, and optimizes cache management strategies.
Smart Images

Figure CN119202427A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of cache page management, and in particular to a cache page management optimization method based on a mobile operating system. Background Art
[0002] With the advancement and development of science and technology, mobile devices have become an indispensable part of people's daily lives. Today's mobile devices are more than simple communication tools. There are a large number of mobile applications with a wide variety of types, providing users with a variety of services and functions. There are more than 2.9 million applications in the application market. A large number of applications occupy the storage space of mobile devices, resulting in insufficient storage space, affecting the normal operation of the device, and then affecting the user experience, which brings challenges to the maintenance of mobile devices.
[0003] Mobile devices differ from traditional computing devices in several ways. First, due to their interactive nature, the response time of foreground applications is a key indicator of user experience. Second, compared with traditional computing devices, the hardware resources in mobile devices are also relatively limited, especially for cache resources integrated into storage devices, and the foreground and background applications in mobile devices will compete for the limited cache resources integrated into storage devices. Third, mobile operating systems will save as much data as possible in the cache. Even if some processes have long been running in the background and are no longer used in the foreground, their data is still stored in the cache so that these background applications can be started more quickly when they are switched to the foreground, but this consumes a lot of cache space. As a result, cache management has become an important issue in the development of mobile devices. In order to improve the user experience, major manufacturers initially solved the problem by increasing the size of flash memory. However, as the size of flash memory continues to increase, simply expanding hardware resources such as cache cannot achieve a good balance between cost and improving user experience.
[0004] For mobile operating systems, the root cause of the impact on user experience is page faults, that is, the page requested by the application is not in the page cache. If the requested page is in the page cache, the page cache immediately returns the corresponding page to the application, and the access delay in this case is about 100 nanoseconds. If the requested page is not in the page cache, the system will generate a page fault. In this case, a page allocation operation will be triggered to allocate a free page. If the cache is full at this time and the remaining cache space is insufficient to support this operation, the cache recycling scheme will be triggered, and the pages in the cache will be removed to release space. This process requires a delay of several microseconds to complete.
[0005] In summary, the delay in application response to users is caused by the cache page management strategy. Whether the page requested by the application is in the cache determines the impact on the user experience. Obviously, the page requested by the application can obtain better data results in the cache. Through previous work and experiments, it was found that mobile device users often run more than 10 applications at the same time, but the applications that are frequently opened and used for a long time are concentrated on a few applications. If the pages requested by these frequently used applications are saved in the cache, the user experience will be greatly improved. Summary of the invention
[0006] In order to overcome the problems existing in the prior art, the purpose of the present invention is to provide a cache page management optimization method based on a mobile operating system. The present invention records and counts the usage of each application, divides the application into a foreground application and a background application, and saves the pages required by the foreground application in the cache, while preferentially removing the pages of the background application from the cache, so as to release the required cache space for the foreground application, thereby greatly improving the response speed to the foreground application, thereby improving the user experience.
[0007] The specific technical solution for achieving the purpose of the present invention is:
[0008] A cache page management optimization method based on a mobile operating system, comprising: dividing foreground and background applications, determining pages mapped by foreground and background applications, and optimizing a cache page replacement algorithm;
[0009] The foreground and background application division refers to dividing the application into foreground and background by analyzing the different degrees of use of each application by users, wherein the foreground application refers to the application that is launched more frequently and used for a longer time by users; the background application refers to the application that is launched less frequently and used for a shorter time by users;
[0010] Determining the page mapped by the foreground and background applications refers to saving the result table of the division of the foreground and background applications in the cache system, using the application and its process number monitored by the activity monitor in the mobile operating system, first using the process number of the I / O request to retrieve the corresponding application, and then querying the result table of the division of the foreground and background applications, so as to determine whether the I / O request comes from the foreground application or the background application. The page requested by the I / O generated by the background application is the page mapped by the background application; otherwise, it is the page mapped by the foreground application;
[0011] The optimized cache page replacement algorithm means that when the cache space is insufficient and page recovery is needed to release space, different priorities are adopted for pages mapped by foreground and background applications, and sufficient space is made for pages mapped by foreground applications by adding a flag to the page, dividing the inactive LRU linked list into foreground and background areas, and replacing the pages mapped by the background application first.
[0012] Furthermore, the foreground and background application division is specifically as follows: first, the use of mobile devices by dozens of volunteers for at least 2 consecutive weeks is tracked through an activity monitor to obtain user usage records, including: number of startups, usage duration, average number of startups, and average usage duration; second, the usage records are processed into a two-dimensional table with the application UID as the primary key, and a decision tree CART classification algorithm model is used for training and testing; finally, the applications in the mobile device are divided into two categories: foreground applications and background applications.
[0013] Furthermore, the page mapped by the foreground and background applications is determined as follows: first, a result table of the division of the foreground and background applications is saved in a cache system, which includes the UID of the application and the category of the foreground or background to which the application belongs; secondly, the activity monitor provided by the mobile device monitors the activity stack of the operating system in real time to obtain the application and the corresponding process, and maintains an index table with the process number PID as the primary key, and the index table writes the process PID and the UID of the corresponding application into the cache system through I / O operations; finally, the I / O request uses the provided PID as a keyword to quickly retrieve the table of the activity monitor to obtain the corresponding UID, and then uses the UID as a keyword to query the result table of the division of the foreground and background applications to obtain whether the I / O request is a foreground I / O request or a background I / O request; if the page is requested by the foreground I / O, it is a page mapped by the foreground application; if the page is requested by the background I / O, it is a page mapped by the background application; if the page is requested by the foreground I / O and the background I / O at the same time, it is a page mapped by the foreground application.
[0014] Furthermore, the optimized cache page replacement algorithm is specifically as follows: when the cache space in the UFS controller is insufficient, the page replacement algorithm is triggered to perform page recycling to release sufficient cache space, and when scanning the inactive LRU linked list to select the page to be recycled, the scanning is performed from back to front. If the page mapped by the background application is scanned, that is, the page with a flag of 0, it is directly recycled, wherein the clean page is directly deleted, and the dirty page is deleted after the background write-back is completed; if the page mapped by the foreground application is scanned, that is, the page with a flag of 1, it is skipped, and the flag is set to 0, and then the forward scanning is continued; when scanning, When scanning the active LRU list to select a page to move to the inactive LRU list, the scan is performed from back to front. If a page mapped by a foreground application is scanned, the page is moved to the head of the foreground area of the inactive LRU list; if a page mapped by a background application is scanned, the page is moved to the head of the background area of the inactive LRU list; when there is enough cache space in the UFS controller, if the page requested by the I / O is in the cache, the page is directly moved to the head of the active LRU list; if the page requested by the I / O is not in the cache, the corresponding page needs to be read from the UFS storage medium to the head of the active LRU list.
[0015] Compared with the prior art, the benefit of the present invention is to achieve differentiated use of applications in mobile devices and to store pages mapped by foreground applications in cache as much as possible, thereby improving the response speed of the foreground application to users. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 Schematic diagram of dividing the process for front-end and back-end applications;
[0017] Figure 2 A flowchart for determining whether an I / O request is a foreground / background I / O request;
[0018] Figure 3 This is a schematic diagram of the page replacement algorithm when there are both foreground and background applications in the cache;
[0019] Figure 4 Schematic diagram of page replacement algorithm when there is only one foreground or background application in the cache;
[0020] Figure 5 This is a diagram of the architecture for implementing the method of the present invention. DETAILED DESCRIPTION
[0021] The present invention is described in detail below with reference to the accompanying drawings and embodiments.
[0022] The basic process of the cache page management optimization method proposed by the present invention is as follows: first, when the user uses the mobile device, the application usage record is collected, and the application is divided into the foreground and background through the decision tree CART classification algorithm; second, the application and its process number monitored by the activity monitor in the mobile operating system are indirectly determined to determine whether the page is mapped by the foreground process or the background process; finally, when the cache is recycled, different replacement priorities are given according to the classification of the page. It is mainly divided into three aspects.
[0023] In a first aspect, an application partitioning mechanism is provided, including:
[0024] The application tracker is used to record the time users use each application, the frequency of launching, the average time of use, the average frequency of launching, etc. The tracked data is processed into feature data suitable for the decision tree CART classification algorithm. After model training and testing, the applications in the mobile device are finally divided into two categories (such as Figure 1 As shown). The simple partitioning method works well for three reasons: First, when an application is installed in a mobile device, a permanent UID is assigned to the application and saved in the configuration file; when an application is updated, the UID of the application is updated in the configuration file. So the list of all background applications can be obtained by subtracting the UID of the foreground application from the application list in the configuration file; second, due to the characteristics of mobile devices, every time a user inputs a command to the mobile phone by touching the screen or an icon, the Android platform creates a new activity and puts it into the activity stack of the Android activity manager. Since the activities on the upper layer of the stack point to the application that the user is currently interacting with, the application tracker can identify this foreground application among all available applications; third, the average usage frequency and average usage time are calculated based on the data of the last seven days, so a large storage space is not required to store this data, and the amount of data calculated is not large, which will not cause a large burden on the system.
[0025] In a second aspect, a method for determining a foreground and background application mapping page is provided, comprising:
[0026] First, in order not to occupy the resources of the user when using the mobile device, the process of distinguishing between the foreground and background applications is performed after the screen of the mobile device is turned off. In addition, in order to be able to quickly identify whether the page is mapped by the foreground process or the background process when the cache is recycled, the present invention stores an index table with the process number PID as the primary key in the cache. The I / O request uses the PID as the keyword to retrieve the corresponding UID, and then uses the UID as the keyword to query the result table of the foreground and background application division to obtain whether the I / O request is a foreground I / O request or a background I / O request (such as Figure 2 As shown); if the page is requested by the foreground I / O, it is the page mapped by the foreground application; if the page is requested by the background I / O, it is the page mapped by the background application; if the page is requested by both the foreground I / O and the background I / O, it is the page mapped by the foreground application.
[0027] Thirdly, a page replacement mechanism is provided with different priorities when replacing cache pages of front-end and back-end application programs. This includes:
[0028] Unlike the traditional cache page replacement mechanism, all application process pages are replaced only according to the LRU strategy based on time locality. In the present invention, considering that users use different applications to different extents and that the mobile operating system will not waste available cache during operation, it will always try to use all available caches as an internal cache mechanism, thereby optimizing the cache page replacement algorithm. The first case is that there are pages mapped by both foreground applications and background applications in the cache. In this case, the priority of the foreground application pages is maintained during page replacement, while the priority of the background application pages is lowered during page replacement (such as Figure 3 As shown in ), the pages mapped by the background process or the pages without process mapping are moved first, and the pages mapped by the foreground process are given a second chance to remain in the LRU list, delaying the pages mapped by the foreground application from being swapped out of the cache. (2) The second case is that there are only pages mapped by the foreground application or only pages mapped by the background application in the cache, then they are replaced according to the original LRU replacement algorithm (such as Figure 4 As shown in the figure), a certain number of pages will be moved from the tail of the active LRU list to the head of the inactive LRU list, regardless of whether these pages are pages mapped by the foreground process or the background process.
[0029] Example
[0030] like Figure 5 As shown in the figure, in order to optimize the cache page management of the mobile operating system, the foreground and background application lists are added, the method of mapping pages between foreground and background applications is determined, and the cache page replacement strategy is optimized. It is mainly implemented in the following steps:
[0031] 1. After the user unlocks the phone screen, the application tracker tracks the user's usage, such as the number of times each application is launched per day, the length of time it is used in the foreground, the average number of launches, and the length of time it is used. The collected data is cleaned, filtered, and integrated to form the feature data required by the model. After model training and testing, the applications in the mobile device are divided into two categories.
[0032] 2. Store the index table with the process ID PID as the primary key in the cache. The I / O request uses its own PID to retrieve the corresponding UID, and then uses the UID as the keyword to query the result table divided by the foreground and backend applications to determine whether the I / O request is a foreground I / O request or a background I / O request, and then determine whether it is a page mapped by the foreground application or the background application.
[0033] 3. When the cache space is insufficient and cache pages need to be reclaimed, start scanning from the tail of the inactive LRU list. If the scanned page is a clean page and the page flag is 0, delete it directly; if the scanned page is a dirty page and the page flag is 0, wait for the write-back to complete before removing it from the cache; if the scanned page flag is 1, skip the page and continue scanning forward. At the same time, move the pages in the active LRU list to the inactive LRU list, where the clean pages are moved to the tail of the LRU list corresponding to the category process, and the dirty pages are moved to the head of the LRU list corresponding to the category process. When there are only pages of the same category process in the active LRU list, scan forward directly from the tail of the active LRU list, move the clean pages to the tail of the inactive LRU list, and move the dirty pages to the head of the inactive LRU list.
[0034] The above-mentioned cache page replacement process determines whether to swap out based on the difference in the use of the application. The implementation of this method requires two types of overhead: storage and calculation. For storage costs, since the classification list of applications stores the UID of the application and its corresponding process number, both of which are 4 bytes in size, the storage overhead cost is very small. For computational costs, the application classification algorithm is set to execute in the background during the period when the mobile device is not interacting with the user. In addition, the data set calculated when the classification algorithm is running is not large, and will not incur too much computational cost. For the calculation of the page flag and the identification of the application to which the page belongs, these simple process overheads can be ignored. Therefore, the cost can be ignored.
Claims
1. A cache page management optimization method based on a mobile operating system, characterized in that: include: Divide the front-end and back-end applications, determine the pages mapped by the front-end and back-end applications, and optimize the cache page replacement algorithm; The foreground and background application division refers to dividing the application into foreground and background by analyzing the different degrees of use of each application by users, wherein the foreground application refers to the application that is launched more frequently and used for a longer time by users; the background application refers to the application that is launched less frequently and used for a shorter time by users; Determining the page mapped by the foreground and background applications refers to saving the result table of the division of the foreground and background applications in the cache system, using the application and its process number monitored by the activity monitor in the mobile operating system, first using the process number of the I / O request to retrieve the corresponding application, and then querying the result table of the division of the foreground and background applications, so as to determine whether the I / O request comes from the foreground application or the background application. The page requested by the I / O generated by the background application is the page mapped by the background application; otherwise, it is the page mapped by the foreground application; The optimized cache page replacement algorithm means that when the cache space is insufficient and page recovery is needed to release space, different priorities are adopted for pages mapped by foreground and background applications, and sufficient space is made for pages mapped by foreground applications by adding a flag to the page, dividing the inactive LRU linked list into foreground and background areas, and replacing the pages mapped by the background application first.
2. The method according to claim 1, characterized in that The foreground and background application division is specifically as follows: first, the use of mobile devices by dozens of volunteers for at least 2 consecutive weeks is tracked through an activity monitor to obtain user usage records, including: number of startups, usage time, average number of startups, and average usage time; second, the usage records are processed into a two-dimensional table with the application UID as the primary key, and a decision tree CART classification algorithm model is used for training and testing; finally, the applications in the mobile device are divided into two categories: foreground applications and background applications.
3. The method according to claim 1, characterized in that The page for determining the mapping of the foreground and background applications is specifically as follows: first, a result table of the division of the foreground and background applications is saved in a cache system, which includes the UID of the application and the category of the foreground or background to which the application belongs; Secondly, the activity monitor that comes with the mobile device will monitor the activity stack of the operating system in real time to obtain applications and corresponding processes, and maintain an index table with the process ID PID as the primary key. The index table writes the process PID and the corresponding application's UID into the cache system through I / O operations; finally, the I / O request uses the built-in PID as the keyword to quickly retrieve the table of the activity monitor to obtain the corresponding UID, and then uses the UID as the keyword to query the result table divided by the foreground and background applications to obtain whether the I / O request is a foreground I / O request or a background I / O request; If the page is requested by foreground I / O, it is the page mapped by the foreground application; If the page is requested by the background I / O, it is the page mapped by the background application; if the page is requested by both the foreground I / O and the background I / O, it is the page mapped by the foreground application.
4. The method according to claim 1, characterized in that: The optimized cache page replacement algorithm is specifically as follows: when the cache space in the UFS controller is insufficient, the page replacement algorithm is triggered to perform page recycling to release sufficient cache space. When scanning the inactive LRU linked list to select the page to be recycled, the scanning is performed from back to front. If the page mapped by the background application is scanned, that is, the page with a flag of 0, the recycling is performed directly, wherein the clean page is directly deleted, and the dirty page is deleted after the background write-back is completed; if the page mapped by the foreground application is scanned, that is, the page with a flag of 1, it is skipped, and the flag is set to 0, and then the forward scanning is continued; when scanning the active LRU linked list to select a page to move to the inactive LRU linked list, the scanning is performed from back to front. If the page mapped by the foreground application is scanned, the page is moved to the head of the foreground area of the inactive LRU linked list; if the page mapped by the background application is scanned, the page is moved to the head of the background area of the inactive LRU linked list; when the cache space in the UFS controller is sufficient, if the page requested by the I / O is in the cache, the page is directly moved to the head of the active LRU linked list; If the page requested by the I / O is not in the cache, the corresponding page needs to be read from the UFS storage medium to the head of the active LRU list.
