A Mobile Device Memory Optimization Method Based on Hot File Page Swapping and Compression Prediction
By supporting the migration of file pages between DRAM and compressed memory space, and utilizing hot file page identification and sliding window dynamic prediction, the problem of memory waste and performance loss in compressed memory space in Android mobile devices is solved, achieving more efficient memory utilization and improved system performance.
Patent Information
- Application Number
- CN202411340572.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2044-09-25
AI Technical Summary
Existing Android mobile devices only support anonymous pages for compressed memory space and do not support file page storage, resulting in wasted memory and performance loss. Furthermore, existing compression prediction interfaces have performance overhead issues.
By supporting the migration of file pages between DRAM and compressed memory space, and utilizing hot file page identification and sliding window dynamic prediction, the compressibility judgment of pages is improved. Anonymous pages and frequently used file pages are prioritized to be sent to compressed memory space, and the compressibility of pages is dynamically predicted by sliding window to reduce unnecessary compression overhead.
It improves the utilization of compressed memory space, increases memory data density, reduces I/O scheduling, and enhances system performance and application warm-start speed.
Smart Images

Figure CN119415243B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of memory optimization, and in particular to a mobile device memory optimization method based on hotspot file page swapping and compression prediction. Background Technology
[0002] Sufficient memory is one of the important prerequisites for ensuring smooth system operation. When the system does not have enough available memory for allocation, it usually relies on the kswapd (periodic memory reclamation mechanism) thread to perform memory cleanup to release system resources. In this process, memory space is often compressed as a swap partition to improve memory utilization efficiency.
[0003] Compressed memory space typically includes ZRAM and ZSWAP, and its workflow is as follows: First, the compression module performs compression operations on the incoming pages. Generally, the page compression value μ = compressed page size / original page size is used to define the page compressibility. If the compressed μ value exceeds a preset threshold μ... T If the page is uncompressible, it is determined that the page is not compressible, and therefore the page is directly copied to the compressed memory storage module. Conversely, if the compressed μ value is less than the set threshold μ, the page is not compressed. T Pages that cannot be fully compressed are considered compressible, and their compressed versions are moved to the compressed memory storage module. The main function of the compressed memory storage module is to store compressed pages or directly save pages that cannot be fully compressed.
[0004] This method of compressing memory space aims to minimize memory usage and improve memory utilization. It dynamically determines whether a page is compressible and decides whether to compress it based on a threshold.
[0005] However, this method only benefits performance when the data is compressible. If the swapped-out pages are incompressible, it will not only fail to save memory but will also incur unnecessary overhead and performance loss due to the compression of these incompressible pages.
[0006] Currently, memory space compression technology is widely used in many Android mobile devices to effectively expand memory capacity, but it has the following problems:
[0007] 1. Due to kernel design, most Android mobile devices currently only support the storage of anonymous pages in their compressed memory space, not file pages. This design was intended to accommodate anonymous pages, which are relatively easy to compress and have a lower compression ratio, making them more suitable for storage in compressed memory. However, reading file pages from Flash is slower, potentially impacting user experience. Furthermore, if a significant amount of space remains after storing anonymous pages in compressed memory, it leads to substantial space waste and performance degradation.
[0008] 2. Compressing memory space cannot determine the compressibility of pages; it performs indiscriminate compression on all incoming pages. If most of the pages entering the compressed memory space are incompressible, it will not only fail to save memory but will also incur unnecessary overhead from compressing these incompressible pages.
[0009] 3. After extensive use of the phone, it was found that under some Android phone configurations (when the ratio of DRAM to ZRAM size exceeds 50%), the compressed memory space was not fully utilized, resulting in a significant waste of space.
[0010] To address problem 1, some research has proposed FLASH swap space technology, which swaps out infrequently used pages to the FLASH swap space and swaps them back in when they are needed. However, this technology suffers from problems such as slow I / O speed, FLASH write wear, and I / O bandwidth contention.
[0011] Regarding question 2, some research has proposed a two-level compression prediction interface. This interface uses the average byte value of a page and page sampling to predict the compressibility of a page. However, when this interface was deployed to an Android test device, significant performance overhead was found, indicating that this interface may have some problems in practical applications and requires further research and improvement to enhance its performance. Summary of the Invention
[0012] In view of the above problems, this invention proposes a memory optimization method for Android mobile devices. This method simultaneously supports sending anonymous pages and frequently used file pages into compressed memory space, aiming to improve the utilization of compressed memory space, increase memory data density, and enhance system performance.
[0013] To achieve the above objectives, the mobile device memory optimization method based on hotspot file page swapping and compression prediction in this invention includes the following steps:
[0014] Step 1: Enable the page reclamation process to support the migration of file pages between DRAM and compressed memory space;
[0015] Step 2: Determine whether the page to be swapped out of FLASH and sent to the compressed memory space is an anonymous page or a hot file page. If so, transfer it to the compressed memory space; otherwise, the page will be discarded or written back to FLASH.
[0016] Step 3: For file pages, dynamically predict the compressibility of the pages passed to the compressed memory space using a sliding window;
[0017] For anonymous pages, the compressibility of the page is initially screened by the average page size and the variance of the page byte value, and then the compressibility of the entire page is evaluated by the compression results of the sampling prediction.
[0018] Step 4: Compress and save the pages whose prediction results are compressible and are passed to the compressed memory space.
[0019] Furthermore, in step 1, the modification to the file page swapping process includes: when memory is insufficient, file pages are preferentially swapped out to compressed memory space;
[0020] The modifications to the file page swapping process include: when a page fault occurs, the missing file page is first searched for in the compressed memory space.
[0021] Furthermore, the process of determining whether a file page is a hot file page in step 2 specifically includes:
[0022] For file pages to be sent to the compressed memory space, if the page is a dirty file page, it is written back to FLASH; if it is a clean file page, its access frequency is determined, including:
[0023] Step 2.1 First, determine whether the page access frequency is greater than or equal to the first threshold. If the condition is met, proceed to the next step; otherwise, discard the page.
[0024] Step 2.2: Determine whether the page access frequency is greater than or equal to the second threshold. If the condition is met, it is determined to be a hot page. If not, proceed to step 2.3.
[0025] Step 2.3: Determine if this page is entering the compressed memory space for the first time. If the condition is met, it is determined to be a hot page, and a flag indicating that the page is not being swapped out for the first time is set; if the condition is not met, the page is discarded.
[0026] Furthermore, in step 3, the compressibility prediction of file pages includes:
[0027] Step 3.1 Set the initial value of the sliding window m, and retain information on whether the first n historical pages are compressible;
[0028] For pages to be sent to the compressed memory space, if the following conditions are met:
[0029] ①The first n history pages are not compressible.
[0030] ②This page is consecutive to the last history page.
[0031] ③ The value of m in the sliding window is greater than 0.
[0032] If the page is determined to be incompressible, the value of m is decreased by 1, the information of the historical page is updated, and the program exits.
[0033] Otherwise, proceed to step 3.2;
[0034] Step 3.2: Compress the page. If the page remains continuous, reset the sliding window value to m and update the historical page information; otherwise, proceed to step 3.3.
[0035] Step 3.3: If the page is not compressible, update the history page information and exit; if the page is compressible, exit directly.
[0036] Furthermore, in step 3, the compressibility prediction for anonymous pages includes:
[0037] Level 1: Judgment based on the average byte value of some pages: If the average byte value is less than a certain low average byte value or greater than a certain high average byte value, it is directly determined to be a compressible page. Pages not in these two areas enter the second level of prediction. If the page is predicted to be compressible, it exits directly.
[0038] Level 2: Compression prediction based on page byte value variance: If the byte value variance is less than a certain low byte value variance or greater than a certain high byte value variance, it is directly determined to be a compressible page. Pages not in these two areas enter the third level of prediction. If the page is predicted to be compressible, it exits directly.
[0039] Level 3: Sample-based prediction: Take the first part of the page as a sample and perform compression prediction on this sample to reflect the compressibility of the complete page.
[0040] This invention modifies the page reclamation process and introduces hot file page identification to filter out hot pages, which are more likely to be accessed again. It then introduces two page compressibility prediction modules: one based on temporal locality and the other based on spatial locality. By supporting the swapping of frequently accessed clean file pages to the compressed memory swap space, the utilization of compressed memory space is improved and I / O scheduling is reduced. Since hot pages are more likely to be accessed again, retaining them in the compressed memory space yields greater benefits. Through compression line prediction, the compressibility of pages can be quickly and accurately determined, reducing the unnecessary compression overhead incurred by the compressed memory space for some incompressible pages. Attached Figure Description
[0041] Figure 1 This is a flowchart of a mobile device memory optimization method for hotspot file page swapping and compression prediction in a specific embodiment of the present invention;
[0042] Figure 2 This is a flowchart of the hotspot file page identification module in a specific embodiment of the present invention;
[0043] Figure 3This is a flowchart of the page compressibility prediction module based on temporal locality in a specific embodiment of the present invention;
[0044] Figure 4 This is a flowchart of the page compressibility prediction module based on spatial locality in a specific embodiment of the present invention;
[0045] Figure 5 The diagram shows the accuracy and performance improvement of the time-based page compressibility prediction module in a specific embodiment of the present invention.
[0046] Figure 6 This is a comparison chart of the accuracy of the space-based page compressibility prediction module in a specific embodiment of the present invention with the secondary compression prediction module of other works;
[0047] Figure 7 This is a comparison chart of the interface call times between the space-based page compressibility prediction module in a specific embodiment of the present invention and the secondary compression prediction module in other works;
[0048] Figure 8 This is a diagram illustrating the effect of improving hot start speed in a specific embodiment of the present invention. Detailed Implementation
[0049] The specific embodiments and working principles of the present invention will be further described in detail below with reference to the accompanying drawings.
[0050] For the compression prediction algorithm of this invention, there are four possible combinations of prediction and actual compression. If we assume y is compressible and n is incompressible, then the possible combinations are yy, yn, ny, and nn. For example, yn means that a page is predicted to be compressible, but it is actually incompressible.
[0051] Prediction overhead is added to all four cases, but its impact differs for each. First, the yy and yn cases simply have additional prediction overhead because the actual compression runs after prediction. While these two cases don't gain any benefit from prediction, it's not significant as long as prediction is faster than compression. Second, this case not only increases prediction overhead but also memory footprint. This is the worst-case scenario that should be avoided whenever possible. Finally, the nn case improves performance by removing unnecessary compression resources, which is the ideal situation.
[0052] Let the total number of pages be defined as:
[0053] N all =N yy +N yn +N ny +N nn
[0054] The accuracy rate of the prediction is:
[0055]
[0056] Where N yy N yn N ny and N nn This indicates the page number for each case.
[0057] In addition, the total savings in compression time and memory loss can be summarized as follows:
[0058]
[0059]
[0060] Where Comp(X) and Pred(X) are the computational costs of actual compression and prediction of page X, respectively, and OrigSZ(X) and CompSZ(X) are the original size and compressed size of page X, respectively.
[0061] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a mobile device memory optimization method based on hotspot file page swapping and compression prediction. The specific process includes:
[0062] Step 1: Modify the kernel code to change the priority of swapping out file pages, from prioritizing swapping out file pages to FLASH to prioritizing swapping out file pages to compressed memory space;
[0063] Step 2: Activate the hotspot file page identification module;
[0064] Step 3: Start the page compressibility prediction module based on temporal locality;
[0065] Step 4: Activate the page compressibility prediction module based on spatial locality;
[0066] Specifically, when a page is swapped out, its attributes are first assessed. If the page is an anonymous page, it is sent to compressed memory space B for compression prediction. If the page is a dirty file page, it is written back to FLASH. If the page is a clean file page, it is sent to compressed memory space A, where its hotness / coldness is determined. The goal of this invention is to improve the utilization rate of compressed memory space, increase memory data density, reduce I / O scheduling, and ultimately improve system performance by supporting the sending of anonymous pages and some qualified file pages to compressed memory space and minimizing system latency caused by page compression through the compression prediction module.
[0067] Figure 2This diagram shows the workflow of the hot file page identification module, and its steps are as follows:
[0068] Step 1: For file pages about to enter the compressed memory space, this module first determines whether the page access frequency is greater than or equal to the first threshold. If the condition is met, proceed to the next step; otherwise, discard the page and exit the module.
[0069] Step 2: Determine if the page access frequency is greater than or equal to the second threshold. If the condition is met, it is determined to be a hot page and the module is exited; otherwise, proceed to Step 3.
[0070] Step 3: Determine if this page is entering the compressed memory space for the first time. If the condition is met, it is determined to be a hot page, and a flag indicating that the page is not being swapped out for the first time is set, and the module is exited; if the condition is not met, the page is discarded and the module is exited.
[0071] In steps 3 and 4, the page passes through the page compressibility prediction module. If the page is predicted to be incompressible, the page compression module is skipped and the page is directly copied to the page storage module; if the page is predicted to be compressible, the page compression module is entered to compress the page.
[0072] Figure 3 This diagram illustrates the workflow of the page compression prediction module based on temporal locality. The steps are as follows:
[0073] Step 1: Upon entering the page compressibility prediction module, first access the storage of n historical page information and the current sliding window value m. If all of the following conditions are met simultaneously: ① the previous n historical pages are all incompressible, ② this page is consecutive to the last historical page, and ③ the sliding window value m is greater than 0, then the page is determined to be incompressible, the m value is decreased by 1, the historical page information is updated, and the module exits; otherwise, proceed to Step 2.
[0074] Step 2: Compress the page. If the page remains continuous, reset the sliding window value to m and update the historical page information; otherwise, proceed to Step 3.
[0075] Step 3: If the page is not compressible, update the historical page information and exit the module; if the page is compressible, exit the module.
[0076] Figure 4 This diagram illustrates the workflow of the page compression prediction module based on spatial locality. The steps are as follows:
[0077] Step 1: For the page compressibility prediction module, the compression prediction of the average byte value of the page is performed first. This prediction method is mainly based on the average byte value of some pages. If the average byte value is less than a certain low average byte value or greater than a certain high average byte value, the page within this range is directly determined to be a compressible page. Pages not in these two areas proceed to the next step. If the page is predicted to be compressible, the module is exited directly.
[0078] Step 2: Compression prediction based on page byte value variance: This prediction method mainly judges based on the byte value variance of some pages. If the byte value variance is less than a certain low byte value variance or greater than a certain high byte value variance, the page within this range is directly determined to be a compressible page. Pages not in these two areas proceed to the next step. If the page is predicted to be compressible, the module exits directly.
[0079] Step 3: Sample-based prediction: Partial sampling of a page can reflect the compressibility of the entire page to a certain extent. That is, take the first part of the page as a sample and perform compression prediction on this sample to reflect the compressibility of the complete page.
[0080] The page compressibility prediction module is designed to quickly and accurately determine the compressibility of a page, effectively reducing the unnecessary compression overhead of the compression module for some incompressible pages, and reducing the system latency caused by supporting the loading of file pages into the compressed swap memory.
[0081] Figure 5 The diagram shows the accuracy and performance improvement of the time-based page compressibility prediction module. Due to the principle of temporal locality, consecutive recycled file pages have similar compressibility. By simulating user behavior, the time-based page compressibility prediction module was deployed on 940,000 recycled file pages, with n=2, m=3, and a page compression threshold μ. T Setting it to 0.75, the module effect is as follows: Figure 5 As shown, the accuracy of predicting incompressible pages is as high as 85.8%, and the reduction in invalid compression (number of correctly predicted incompressible pages / total number of incompressible pages) reaches 47.8%.
[0082] Figure 6 The chart shows a comparison of the accuracy of using a spatially based page compressibility prediction module (level 3 prediction) with a level 2 compression prediction module (level 2 prediction) from other works.
[0083] Figure 7The diagram shows a comparison of interface call times between the spatially based page compression prediction module and other two-level compression prediction modules. It reveals that using the proposed three-level prediction method can save 79.6% of the interface call time. The conclusion is that the spatially based page compression prediction module proposed in this study can significantly reduce interface call time without sacrificing prediction accuracy.
[0084] Figure 8 This chart shows the improvement in warm-up speed for seven apps on mobile devices before and after using the aforementioned optimization methods. The testing method involved launching 11 frequently used apps in the background, with four apps running as background processes to consume memory. The remaining seven apps were manually switched, and the warm-up duration was recorded. This process was repeated 10 times, and the median was used for comparison. Observations revealed that some apps (such as the library and calculator) saw an improvement of approximately 15% in warm-up speed. The average app warm-up speed improved by 11.7%.
[0085] The above descriptions are merely embodiments of the present invention, and common knowledge such as specific technical solutions and / or characteristics are not described in detail here. It should be noted that those skilled in the art can make various modifications and improvements without departing from the technical solutions of the present invention, and these should also be considered within the scope of protection of the present invention. These modifications and improvements will not affect the effectiveness of the implementation of the present invention or the practicality of the patent. The scope of protection claimed by the present invention should be determined by the content of its claims, and the specific embodiments described in the specification can be used to interpret the content of the claims.
Claims
1. A mobile device memory optimization method based on hotspot file page swapping and compression prediction, characterized in that, Includes the following steps: Step 1: Enable the page reclamation process to support the migration of file pages between DRAM and compressed memory space; Step 2: Determine whether the page to be swapped out of FLASH and sent to the compressed memory space is an anonymous page or a hot file page. If so, transfer it to the compressed memory space; otherwise, the page will be discarded or written back to FLASH. Step 3: For file pages, dynamically predict the compressibility of the pages passed to the compressed memory space using a sliding window; The compressibility prediction of file pages includes: Step 3.1 Set the initial value of the sliding window m, and retain information on whether the first n historical pages are compressible; For pages to be sent to the compressed memory space, if the following conditions are met: ①The first n history pages are not compressible. ②This page is consecutive to the last history page. ③ The value of m in the sliding window is greater than 0. If the page is determined to be incompressible, the value of m is decreased by 1, the information of the historical page is updated, and the program exits. Otherwise, proceed to step 3.2; Step 3.2: Compress the page. If the page remains continuous, reset the sliding window value to m and update the historical page information; otherwise, proceed to step 3.
3. Step 3.3: If the page is not compressible, update the history page information and exit; if the page is compressible, exit directly. For anonymous pages, the compressibility of the page is initially screened by the average page size and the variance of the page byte value, and then the compressibility of the entire page is evaluated by the compression results of the sampling prediction. The compressibility prediction for anonymous pages includes: Level 1: Judgment based on the average byte value of some pages: If the average byte value is less than a certain low average byte value or greater than a certain high average byte value, it is directly determined to be a compressible page. Pages not in these two areas enter the second level of prediction. If the page is predicted to be compressible, it exits directly. Level 2: Compression prediction based on page byte value variance: If the byte value variance is less than a certain low byte value variance or greater than a certain high byte value variance, it is directly determined to be a compressible page. Pages not in these two areas enter the third level of prediction. If the page is predicted to be compressible, it exits directly. Level 3: Sample-based prediction: Take the first part of the page as a sample and perform compression prediction on this sample to reflect the compressibility of the complete page. Step 4: Compress and save the pages whose prediction results are compressible and are passed to the compressed memory space.
2. The method according to claim 1, characterized in that, In step 1, the modifications to the file page swapping process include: when memory is insufficient, file pages are preferentially swapped out to compressed memory space; The modifications to the file page swapping process include: when a page fault occurs, the missing file page is first searched for in the compressed memory space.
3. The method according to claim 2, characterized in that, Step 2, which determines whether a file page is a hot file page, specifically includes: For file pages to be sent to the compressed memory space, if the page is a dirty file page, it is written back to FLASH; if it is a clean file page, its access frequency is determined, including: Step 2.1 First, determine whether the page access frequency is greater than or equal to the first threshold. If the condition is met, proceed to the next step; otherwise, discard the page. Step 2.2: Determine whether the page access frequency is greater than or equal to the second threshold. If the condition is met, it is determined to be a hot page. If not, proceed to step 2.
3. Step 2.3: Determine if this page is entering the compressed memory space for the first time. If the condition is met, it is determined to be a hot page, and a flag indicating that the page is not being swapped out for the first time is set; if the condition is not met, the page is discarded.
Citation Information
Patent Citations
Memory recovery method and device, electronic equipment and storage medium
CN113138940A
Exchange memory optimization method based on asynchronous deduplication and recompression
CN118245396A