Method for managing file pages and related device

By introducing a combined management mechanism of active, inactive, and temporary linked lists into electronic devices, and prioritizing the reclamation of file pages at the tail of the temporary linked list, the problem of critical file pages of foreground applications being released when memory is insufficient is solved, thus improving the smoothness of electronic devices and the user experience.

CN122173014APending Publication Date: 2026-06-09HONOR DEVICE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HONOR DEVICE CO LTD
Filing Date
2024-12-06
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

When memory is insufficient, critical file pages of the foreground application are released, causing the electronic device to need to read from the disk after being woken up, resulting in IO blocking and affecting the user experience.

Method used

When an electronic device switches from a screen-off state back to a screen-on state, a combined management mechanism of active linked lists, inactive linked lists, and temporary linked lists is adopted. File pages are reclaimed from the tail of the temporary linked list first, reducing the release of file pages of foreground applications and ensuring that critical file pages are hit in memory.

Benefits of technology

It improved the smoothness of the foreground application, reduced IO blocking, and enhanced the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122173014A_ABST
    Figure CN122173014A_ABST
Patent Text Reader

Abstract

The application provides a file page management method and related equipment. The method is used for managing newly accessed file pages when an electronic device is in a screen-off state by setting a temporary linked list, so as to reduce the recycling of file pages associated with a foreground application of the electronic device in an active linked list and an inactive linked list, thereby reducing IO blocking and improving the fluency of the foreground application after the electronic device is re-lit. Specifically, in the method, when the electronic device is in a screen-on state, a newly accessed first file page is added to the head of the inactive linked list; and when the electronic device is in a screen-off state, the first file page is added to the head of the temporary linked list.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of document page management, and more particularly to a document page management method and related equipment. Background Technology

[0002] In a file page caching mechanism, electronic devices can use memory to cache file pages, so that when the file page is needed again, it can be read directly from memory, thereby improving the efficiency of file page reading.

[0003] However, since memory is finite and file pages cannot be cached indefinitely, some file pages need to be released for memory reclamation when memory is insufficient. If critical file pages of the foreground application are released, they will need to be read from disk storage the next time they are needed, which may cause input / output (IO) blocking, resulting in foreground application lag and affecting user experience. Summary of the Invention

[0004] This application provides a method and related equipment for managing file pages, which can improve the smoothness of foreground applications when an electronic device switches from a screen-off state back to a screen-on state.

[0005] In a first aspect, a method and related device for managing file pages are provided. The method is applied to an electronic device, which maintains an active linked list, an inactive linked list, and a temporary linked list in memory. The method includes: determining the current on / off state of the electronic device; when the electronic device is in the on state, adding the first newly accessed file page to the head of the inactive linked list; or, when the electronic device is in the off state, adding the first file page to the head of the temporary linked list.

[0006] In the above solution, when the electronic device is in a screen-off state, a temporary linked list is used to manage the file pages of background running services. Since background services are mostly non-user-sensitive, even if they cause I / O blocking, it is unlikely to be noticed by the user and will not affect the user experience. In contrast, the foreground application's corresponding services are user-sensitive. This solution can maximize the protection of foreground application-related file pages in the screen-off state, reducing the likelihood of foreground application file pages (especially critical file pages) being reclaimed. This way, when the electronic device is reawakened, most of the foreground application's associated file pages can be directly retrieved from memory, reducing I / O blocking and application lag, thus improving the user experience.

[0007] The first file page may include one or more file pages.

[0008] In conjunction with the first aspect, in one implementation of the first aspect, the method further includes: when memory reclamation is triggered, file pages are preferentially reclaimed from the tail of the temporary linked list.

[0009] This implementation reduces the likelihood of the first file page associated with the foreground application being released. Specifically, file pages added in the screen-off state are added to a temporary linked list. Most of these newly added file pages in the screen-off state correspond to background processes, and are therefore generally non-critical. Even if these file pages are recycled, it won't significantly impact the user experience. In contrast, the first file page is associated with the foreground application. Especially if this first file page is critical, its recycling could cause foreground application lag after the screen is turned back on, significantly impacting the user experience. Therefore, by prioritizing the recycling of file pages in the temporary linked list, the recycling of the first file page associated with the foreground application can be reduced, thereby decreasing the probability of foreground application lag after the screen is turned on again and improving the user experience.

[0010] When performing memory reclamation, file pages in the temporary linked list are prioritized for reclamation. For example, multiple file pages (e.g., 32 file pages) are scanned from the tail of the temporary linked list for reclamation. In other words, when the screen is on, no new file pages are added to the temporary linked list, and file pages in the temporary linked list are prioritized for reclamation. This is because the file pages in the temporary linked list are added when the screen is off, and these file pages are mostly related to background business logic. Reclaiming them will not affect the performance of the current foreground application, thus improving the user experience.

[0011] In conjunction with the first aspect, in one implementation of the first aspect, file pages are preferentially reclaimed from the tail of the temporary linked list, including: when the temporary linked list is empty, file pages are reclaimed from the tail of the inactive linked list.

[0012] In the above scheme, during memory reclamation, if the temporary linked list is empty, file pages are reclaimed first from the tail of the inactive linked list. This means that if the temporary linked list is empty when memory reclamation is triggered, file pages are reclaimed directly from the tail of the inactive linked list; if the temporary linked list is not empty when memory reclamation is triggered, file pages are reclaimed first from the tail of the temporary linked list, and only after all file pages in the temporary linked list have been reclaimed are file pages reclaimed from the tail of the inactive linked list. This implementation reduces the number of file pages corresponding to the foreground application, especially critical file pages, that are reclaimed.

[0013] In conjunction with the first aspect, in one implementation of the first aspect, file pages are preferentially reclaimed from the tail of the temporary linked list, including: reclaiming file pages from the temporary linked list and the inactive linked list according to a preset ratio, wherein the proportion of file pages reclaimed from the temporary linked list is greater than the proportion of file pages reclaimed from the inactive linked list.

[0014] For example, if the system requires the reclamation of 10 file pages, 7 file pages can be reclaimed from the temporary linked list and 3 file pages from the inactive linked list in a fixed ratio, such as 7:3. Alternatively, during memory reclamation, file pages in the temporary linked list are reclaimed first. However, if the number of file pages reclaimed in the temporary linked list exceeds threshold #1, reclamation of file pages in the temporary linked list stops, and file pages in the inactive linked list are then reclaimed. Similarly, if the number of file pages reclaimed in the inactive linked list exceeds threshold #2, reclamation of file pages in the inactive linked list stops, and file pages in the temporary linked list are then reclaimed. If the number of file pages reclaimed in the temporary linked list exceeds threshold #3, then file pages in the inactive linked list are reclaimed. If the number of file pages reclaimed in the inactive linked list exceeds threshold #4, reclamation of file pages in the inactive linked list stops, and file pages in the temporary linked list are then reclaimed, and so on. Here, threshold #1 is greater than threshold #2, threshold #3 is greater than threshold #4, and threshold #1 is greater than threshold #3, and threshold #2 is greater than threshold #4. This implementation avoids excessive recycling of file pages in the temporary linked list, which would lead to excessive swapping pressure on file pages within the temporary linked list and thus affect system performance.

[0015] In conjunction with the first aspect, in one implementation of the first aspect, file page reclamation is preferentially performed from the tail of the temporary linked list, including: first performing file page reclamation from the tail of the temporary linked list; and if the swapping pressure of the temporary linked list exceeds a first preset threshold, continuing to perform file page reclamation from the tail of the inactive linked list.

[0016] This implementation still adheres to the principle of prioritizing the reclamation of file pages in the temporary linked list. For example, after triggering memory reclamation, it checks whether the swap-in / swap-out pressure of the temporary linked list exceeds threshold #5. If so, file pages are directly reclaimed from the tail of the temporary linked list; otherwise, file pages are reclaimed from the temporary linked list first, until the swap-in / swap-out pressure of the temporary linked list exceeds threshold #5, at which point file pages are reclaimed from the inactive linked list. Optionally, when the swap-in / swap-out pressure of the temporary linked list drops below threshold #6, memory reclamation can be performed again from the temporary linked list. This implementation allows for the reclamation of file pages from the inactive linked list when the swap-in / swap-out pressure of the temporary linked list is high, reducing performance issues caused by excessive reclamation of file pages in the temporary linked list.

[0017] It should also be understood that the swap-in and swap-out pressure of the temporary linked list can be calibrated using various metrics, and this application does not limit this. For example, it can be calibrated using the frequency of swapping in and out of all file pages in the temporary linked list; or, for example, it can be calibrated using the frequency of adding new file pages to the temporary linked list; or, for example, it can be calibrated using the frequency of file pages being reclaimed in the temporary linked list.

[0018] In conjunction with the first aspect, in one implementation of the first aspect, when the electronic device is in a screen-off state, the method further includes: moving the second file page that has been accessed twice in the temporary linked list to the head of the temporary linked list.

[0019] This implementation reduces the likelihood of the first file page associated with the foreground application being released. Specifically, file pages added in the screen-off state are added to a temporary linked list, and most of these newly added file pages correspond to background processes. If the second file page is added to the head of the inactive or active linked list, and given the large number of background processes running on the electronic device or the extended screen-off time, many second file pages may be added to the inactive or active linked lists. This could cause the first file page, originally in the active or inactive linked list, to be moved to the tail of the inactive linked list and released during subsequent memory reclamation. Therefore, by adding the second file page, which is accessed a second time, to the head of the temporary linked list instead of the head of the active or inactive linked list, the release of the first file page can be reduced. This decreases the probability of foreground application lag after the screen is turned on, improving the user experience.

[0020] In conjunction with the first aspect, in one implementation of the first aspect, when the electronic device is in a screen-off state, the method further includes: if the number of times the third file page in the temporary linked list is accessed exceeds a second preset threshold, moving the third file page to the head of the inactive linked list.

[0021] For example, if the number of times the third file page in the temporary linked list is accessed exceeds the second preset threshold, the third file page is moved to the head of the inactive linked list. Since the third file page has been accessed multiple times, it indicates that it is a relatively active file page, meaning that the currently running business needs to frequently access file page #4. Adding it to the inactive linked list reduces the probability of the third file page being recycled, thereby improving the overall performance of the system.

[0022] In conjunction with the first aspect, in one implementation of the first aspect, when the electronic device is in a screen-on state, the method further includes: moving the fourth file page that has been accessed twice in the temporary linked list to the head of the inactive linked list.

[0023] In other words, when the screen is on, no new file pages are added to the temporary list. At the same time, the existing file pages in the temporary list are gradually transferred to the inactive list and the active list, thus freeing up the temporary list for use the next time the screen is off.

[0024] In conjunction with the first aspect, in one implementation of the first aspect, the method further includes: closing the entry point of the temporary linked list when the electronic device is in a screen-on state; or, opening the entry point of the temporary linked list when the electronic device is in a screen-off state.

[0025] In a second aspect, an electronic device is provided, including a memory and a processor, the memory storing a computer program executable on the processor, wherein when the processor executes the computer program, the electronic device performs the steps of the method as described in any of the first aspects above.

[0026] Thirdly, a computer-readable storage medium is provided that stores a computer program, which, when executed by a processor, implements the steps of the method as described in any of the first aspects above.

[0027] Fourthly, a computer program product is provided that, when run on an electronic device, causes the electronic device to perform the method described in any one of the first aspects.

[0028] Fifthly, a chip system is provided, the chip system including a processor coupled to a memory, the processor executing a computer program stored in the memory to implement the method described in any one of the first aspects above.

[0029] The chip system can be a single chip or a chip module composed of multiple chips.

[0030] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0031] Figure 1 This illustration shows a schematic diagram of a file page management system provided in an embodiment of this application;

[0032] Figure 2 This illustration shows another file page management method provided by an embodiment of this application;

[0033] Figures 3A-3C This illustrates one possible method for managing file pages in different states of an electronic device;

[0034] Figures 4A to 4C This demonstrates another possible method for managing file pages in different states of an electronic device;

[0035] Figure 5 A software architecture diagram of the electronic device provided in an embodiment of this application is shown;

[0036] Figure 6 The interaction flow of each module in the software architecture diagram is shown;

[0037] Figure 7 A hardware architecture diagram of an electronic device provided in an embodiment of this application is shown. Detailed Implementation

[0038] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0039] With the increasing intelligence of electronic devices, users can install various applications to meet their daily life and work needs, such as video applications, game applications, and instant messaging applications. During the operation of these applications, a series of operations need to be performed on the executable program code segment and resource files. For example, reading data from storage devices into memory (a read operation) and writing data that needs to be persisted back to storage devices (a write operation). These operations are implemented internally by different I / O requests. Specifically, the Linux system manages memory in units of pages, and different operations (such as the read or write operations mentioned above) can be implemented by different threads initiating different I / O requests.

[0040] If there are a large number of I / O requests to the memory in a short period of time, the memory may not be able to respond in time, resulting in I / O blocking. Once I / O blocking occurs, foreground applications may experience slow startup, slow response, frame drops, and other issues that negatively impact the user experience.

[0041] To reduce I / O blocking, electronic devices can employ a file page caching mechanism. A file page is a memory page (or simply a page) that has a source backup page in external storage (such as a disk). File pages are mapped to their source backup pages in external storage and are primarily used to store file-related data, such as code segments and accessed file data. As one possible implementation, applications can read files from the disk using basic operations like read / mmap. The system can allocate pages to store the content read from the disk; these pages used to store disk file content can be considered file pages. File pages can be released directly when reclaimed, and then read from the disk again when needed.

[0042] Based on the file page caching mechanism, the system can use memory to cache file pages. This way, when the file page needs to be read again, it can be read directly from memory instead of storage, thereby improving the efficiency of file reading, reducing the number of disk accesses, and reducing the frequency of I / O blocking.

[0043] However, electronic devices have limited memory resources and cannot cache file pages indefinitely. Therefore, when memory space is insufficient, Linux kernel-based systems need to perform memory management to ensure a continuous supply of memory. The objects of memory management typically refer to memory regions other than those occupied by kernel code and reserved memory areas. Memory management refers to the rational management of these memory regions, allocating space for drivers and user programs, and reclaiming unused memory. The granularity of allocation and reclamation is usually 4KB pages. Pages that can be released at any time are called reclaimable pages; these include file pages. The process of releasing reclaimable physical memory pages is called memory reclamation or space reclamation. When the system load increases to a certain level, the kswapd daemon scans file pages, causing reclaimable pages to be released.

[0044] In one example, electronic devices can use the Least Recently Used (LRU) algorithm to reclaim file pages. LRU is a commonly used page replacement algorithm used to determine which pages should be discarded when memory is insufficient. Its working principle is largely based on the principle of temporal locality, which states that if data has been recently accessed, it is more likely to be accessed again in the future, and vice versa. In its implementation, LRU continuously updates and evicts file pages according to the principle of least recently used pages; that is, during memory reclamation, it prioritizes evicting the least recently used pages while retaining the most recently used ones. See also... Figure 1 Assume the system currently maintains 10 file pages, named file page 1, file page 2, ..., file page 10. When a file page is accessed a second time, such as... Figure 1 If file page 5 is accessed, then file page 5 will be added to the head of the file page list; when a new file page is accessed, such as... Figure 1 If file page 11 is found in the list, then file page 11 is added to the tail of the file page linked list; when memory reclamation is needed, reclamation starts from the tail of the file page linked list, such as... Figure 1 Page 10 in the file is recycled. In this way, file pages that have not been accessed recently are prioritized for eviction.

[0045] In a more detailed implementation, the LRU mechanism can be implemented using a pair of doubly linked lists: an active list and an inactive list. The system adds the first accessed page to the active list from the head. Then, based on the page's activity level, it moves pages between the two lists, adjusting their positions so that recently used pages are placed in the active list, less recently used pages are placed in the inactive list, and least recently used pages are moved to the tail of the inactive list. When memory reclamation is needed, pages are reclaimed first from the tail of the inactive list. This partitioned management method improves efficiency and reduces the number of page moves. During cache reclamation, the Linux kernel starts reclamation from the tail of the inactive list. The following section combines... Figure 2 An example is provided to illustrate one possible implementation of the LRU mechanism.

[0046] Figure 2 It consists of two linked lists and a data buffer. The two linked lists are the active linked list and the inactive linked list. File pages in the active linked list are called active file pages, and file pages in the inactive linked list are called inactive file pages. Both the active and inactive linked lists generally follow a first-in, first-out (FIFO) order, meaning that new file pages are added from the head of the list and gradually move towards the tail.

[0047] The following section introduces the transformation rules in the LRU mechanism from three aspects: "adding", "deleting", and "modifying".

[0048] 1. Added: See below Figure 2 In step S101, when a new file page is generated by the system calling functions such as read / write / mmap, it is retrieved from the Lru_add partition of the data buffer and then added to the head of the inactive linked list by default.

[0049] 2. Deletion: Please refer to [link / reference] Figure 2 In step S104, during memory reclamation, the file pages in the inactive linked list are traversed, and only a few file pages at the tail of the inactive linked list (e.g., 32 file pages) are reclaimed. This is understandable. Figure 2 Some special document pages shown may not be reclaimable; this application does not specify in detail whatsoever. Please refer to [link / reference needed]. Figure 2In step S105, during memory reclamation, if the length of the inactive list is insufficient, or the length of the file pages already reclaimed in the inactive list exceeds a certain threshold, multiple file pages (e.g., 32 file pages) are scanned from the tail of the active list and added to the head of the inactive list.

[0050] 3. Revision: Please refer to Figure 2 In steps S102 and S103, when a file page in the inactive list is accessed a second or multiple times, that file page is moved to the head of the active list using the active page in the data buffer; please refer to [link to relevant documentation]. Figure 2 In step S107, when a file page in the active list is accessed again or multiple times, that file page is moved to the head of the active list; please refer to [link to relevant documentation]. Figure 2 In step S106, the dirty pages written back in the inactive list are moved to the tail of the inactive list; please refer to [link to relevant documentation]. Figure 2 In steps S105 and S108, pages marked as "keep" are moved to the head of the "inactive" list, and pages marked as "active" are moved to the head of the "active" list; please refer to [link to relevant documentation]. Figure 2 In step S109, the mapped executable file page is moved to the head of the active list.

[0051] In one example, to assess the activity level of a file page, an activity flag (page_active) and a reference flag (page_referenced) are introduced. These flags implement a two-chance algorithm to prevent file pages from moving too frequently between the active and inactive lists. The page_active flag indicates the current activity level of the file page, and the page_referenced flag indicates whether the file page has been recently visited. For example, a page_active flag of 1 indicates that the file page is currently in the active list, and a page_active flag of 0 indicates that the file page is currently in the inactive list; similarly, a page_referenced flag of 1 indicates that the file page has been recently visited, and a page_referenced flag of 0 indicates that the file page has not been recently visited.

[0052] In the specific implementation, when a file page is accessed, its `page_referenced` flag is set to 1, indicating that the page has been recently accessed. When file page reclamation is performed due to insufficient memory, if the `page_referenced` flag of a file page is 1 and the page has not been accessed for a certain period of time, the `page_referenced` flag is cleared, i.e., the `page_referenced` flag is set to 0. When memory is tight and reclamation is required, file pages are scanned starting from the tail of the inactive list. If it is determined that a file page has not been recently accessed, i.e., the `page_referenced` flag of the file page is 0, then the file page is removed from the inactive list, and the physical memory corresponding to the file page is reclaimed. If a page in the inactive list with a `page_referenced` flag of 1 is accessed, then the page is moved from the inactive list to the head of the active list. When file page reclamation is performed, pages at the tail of the active list with a `page_referenced` flag of 0 are moved to the inactive list according to a certain proportion.

[0053] The above provides a brief introduction to the working principle of the LRU mechanism. The following section will combine... Figures 3A-3C This section provides an illustrative example of a practical application scenario for the LRU mechanism. In this example, a mobile phone is used as the electronic device.

[0054] like Figure 3A In the scenario shown in (a), the social app is the current foreground application of mobile phone 200. In this embodiment, a foreground application refers to an application currently running in the foreground of the electronic device. For example, when a user clicks the social app icon on the system desktop of mobile phone 200, mobile phone 200 will load and display the application interface of the social app on the screen, such as... Figure 3A As shown in (a) above. Before the user closes the social app or switches it to the background, the social app is the foreground application of the mobile phone 200. It is understood that the foreground application in this application embodiment refers to the application that runs in the foreground and can be perceived by the user, and generally does not include applications that cannot be perceived by the user, such as system applications such as artificial intelligence assistants and Bluetooth running in the system background, or third-party applications that have been switched to the background.

[0055] During the operation of a social app, basic operations such as read / mmap can be used to read corresponding files from the disk, and the system can request file pages to store the content read from the disk.

[0056] like Figure 3AAs shown in (b), mobile phone 200 manages file pages using the LRU mechanism. Therefore, mobile phone 200 maintains both an active list and an inactive list in memory. Assume that the active list includes file page #1, where file page #1 stores data associated with the social app.

[0057] While the social app is running in the foreground, in response to the first operation, the phone 200 switches from screen-on to screen-off state.

[0058] In this context, "screen on" refers to the state in which the display screen of an electronic device is lit up; it can also be called "wake-up state" or "screen-on state." At this time, the display screen may show the lock screen, the system desktop or the negative one screen, or the application interface of an application installed on the electronic device, etc.

[0059] Screen off state refers to the state in which the display screen of an electronic device is not lit, that is, the display screen is in a turned-off state. Screen off state can also be called hibernation state, screen-off state, black screen state, etc.

[0060] It is understandable that a screen being off does not necessarily mean that the screen is completely devoid of content. For example, even when the screen is off, it can still display information such as time, date, battery level, application notifications, and wallpaper in certain areas of the screen (i.e., the always-on display function of electronic devices).

[0061] It is also understandable that electronic devices can include multiple displays. For example, a foldable electronic device may include at least two screens: a first screen and a second screen, where the first screen is foldable. When the electronic device is folded, the first and second screens face opposite directions; when the electronic device is unfolded, the first and second screens face the same direction. In one scenario, when the electronic device switches from unfolded to folded, the first screen switches from on to off, while the second screen switches from off to on. However, for the entire electronic device, it remains on. In other words, for an electronic device with multiple displays, as long as at least one display is on, the device is considered to be in an on-screen state; only when all displays are off is the device considered to be in an off-screen state.

[0062] The aforementioned first operation is used to instruct the mobile phone 200 to switch from a screen-on state to a screen-off state. As an example, this first operation could be pressing the power button on the mobile phone 200, such as... Figure 3AThe gesture is shown in (a). The first operation can also be clicking the icon of the always-on display application in the status bar of the phone 200, or a voice command entered by the user to instruct the phone to turn off the screen, which is not limited in this application.

[0063] Figure 3B (a) shows a schematic diagram of a mobile phone 200 in a screen-off state. Even when the mobile phone 200 is in a screen-off state, many services still run in the background. These services require memory allocations and involve swapping in and out of file pages. The following section combines... Figure 3B Section (b) provides an example of one possible scenario.

[0064] Please refer to step S201: When a file page in the inactive list is accessed multiple times, or a file page in the active list is accessed multiple times, these file pages are moved to the head of the active list. Correspondingly, other file pages in the active list can be considered to move towards the tail of the active list. As time goes on, more and more file pages are added to the head of the active list, and some file pages that were originally in the active list, such as file page #1, may move to the tail of the active list.

[0065] Please refer to step S202: When performing memory reclamation, if the length of the inactive list is insufficient, or the length of the file pages that have been reclaimed in the inactive list exceeds a certain threshold, then multiple file pages (e.g., 32 file pages) are scanned from the tail of the active list and added to the head of the inactive list, which may include file page #1.

[0066] Please refer to step S203: When a new file page is accessed, or a file page in the inactive list is accessed a second time, these file pages will be added to or moved to the tail of the inactive list. Correspondingly, other file pages in the inactive list can be considered to be moving towards the tail of the inactive list. As time goes on, more and more file pages are added to the head of the inactive list, and some existing file pages in the inactive list, such as file page #1, may be moved to the tail of the inactive list.

[0067] Please refer to step S204: During memory reclamation, multiple file pages (e.g., 32 file pages) are scanned from the tail of the inactive list for reclaim, which may include file page #1.

[0068] according to Figure 3BAs can be seen from the description in (b) above, when the phone 200 is in a screen-off state, as background services continue to run, the file page #1 corresponding to the original foreground application (social app) may be reclaimed.

[0069] Furthermore, while the phone 200 is in a screen-off state, in response to the second operation, the phone 200 switches from a screen-off state to a screen-on state.

[0070] The second operation is used to instruct the phone 200 to switch from a screen-off state to a screen-on state. As an example, this second operation could be pressing the power button on the phone 200, such as... Figure 3B The gesture is shown in (a). The second operation can also be a user triggering fingerprint unlocking or face unlocking, which is not limited in this application.

[0071] After the phone 200 returns to screen-on mode (and is successfully unlocked), it displays as follows: Figure 3C The application interface is shown in (a) above. It can be understood that before the phone 200 enters screen-off mode, the social app is the foreground application of the phone 200, displaying an interface as shown below. Figure 3A The application interface is shown in (a) above. When the phone 200 switches back from the screen-off state to the screen-on state, the phone 200 will automatically re-display the interface that was in the screen-off state before, such as... Figure 3C As shown in (a) above. It's understandable that even when the phone screen is off, social apps may continue to run in the background; therefore, the phone will redisplay the application interface (as shown in (a) above). Figure 3C The application interface shown in (a) is different from the application interface displayed before entering the screen-off state. Figure 3A The application interface shown in (a) may be the same or different, and this application does not limit it.

[0072] After the screen returns to on state, the user may directly use a social media app. In providing services to the user, the social media app involves data reading and writing operations. In one exemplary scenario, the social media app needs to read file page #1 during operation. According to the cached file management mechanism, the system will first request to read file page #1 from memory. Figure 3B As described in (b), when the phone 200 is in a screen-off state, file page #1 in memory may have been reclaimed. In this case, the system's attempt to read file page #1 from memory fails, so it re-initiates a read operation from the disk storage.

[0073] As shown above, memory read speed is very fast, but due to memory size priority, file pages cannot be cached indefinitely. Therefore, an LRU (Least Recently Accessed) mechanism can be used for file page management. When memory space is insufficient, memory can be reclaimed based on the principle of prioritizing the removal of the least recently accessed file pages. This process continues even when the electronic device is in a screen-off state, which may result in some file pages of the foreground application being reclaimed. When the electronic device returns to a screen-on state, the foreground application resumes providing services to the user. At this time, if the file pages associated with the foreground application are to be read, it may be found that some file pages cannot be read from memory, and a read operation must be initiated from the disk storage again, thus affecting system performance and causing I / O blocking.

[0074] In view of this, embodiments of this application provide a file page management method. In this method, the system simultaneously maintains an active linked list, an inactive linked list, and a temporary linked list. The temporary linked list is mainly used to manage newly added file pages when the electronic device is in a screen-off state, reducing the occurrence of file pages of foreground applications being swapped out of memory, thereby improving system performance and reducing I / O blocking. The following is in conjunction with... Figures 4A to 4C The methods provided in the embodiments of this application are illustrated by way of example. It is understood that, in Figures 4A to 4C In this example, we will still use the mobile phone 200 as an example.

[0075] like Figure 4A As shown in (a), the social app is the current foreground application on the phone 200. During the operation of the social app, basic operations such as read / mmap can be used to read corresponding files from the disk, and the system can allocate file pages to store the content read from the disk.

[0076] like Figure 4A As shown in (b), the mobile phone 200 manages file pages through a novel mechanism. Specifically, in the file page management mechanism provided in this application embodiment, the system maintains three linked lists simultaneously: an active linked list, an inactive linked list, and a temporary linked list. When the mobile phone 200 is in the on-screen state, the mobile phone 200 closes the entry point of the temporary linked list. After the entry point of the temporary linked list is closed, no new file pages are added to the temporary linked list. It should be understood that the exit point of the temporary linked list is not closed at this time. If there are file pages in the temporary linked list, operations such as removing file pages or recycling file pages may be involved. For details, please refer to the following sections. Figure 4C The description corresponding to (b) in the text will not be repeated here.

[0077] When the phone screen is on, file pages are managed using active and inactive lists, specifically in the same way as... Figure 2 The proposed solutions are similar and will not be repeated here.

[0078] In the current scenario, assume that the active or inactive linked list includes file page #1 (the diagram shows file page #1 located in the active linked list as an example), where file page #1 stores data associated with the social app. It can be understood that file page #1 comprises one or more file pages.

[0079] Optionally, in one possible example, file page #1 is a key file page associated with the social app, meaning that file page #1 stores data of the key threads corresponding to the social app. Here, the key thread can be a thread on the critical path corresponding to the current scenario. For example, if the social app is a foreground application, the UI thread of the foreground application is responsible for responding to input events, launching the app, and drawing the screen. After drawing, it is submitted to the render thread for rendering, then submitted for compositing, and finally submitted for LCD display. Therefore, the UI thread, rendering thread, and compositing thread are connected to form a critical path; that is, the critical path is composed of threads, and these threads are the key threads affecting the user experience. The critical path is the program execution path that directly affects the user experience during system operation. It should also be emphasized that the critical path will vary depending on the application scenario, and this application does not limit this. Alternatively, the key thread can also be understood as a thread that has a significant impact on the computation time of the entire process. Correspondingly, non-critical threads can be understood as threads that have a smaller impact on the computation time of the entire process. Whether a thread is a key thread can be determined according to the computational logic of the business itself; the specific implementation method is not limited in this application. For example, when evaluating whether a thread is a critical thread, a preset threshold for computational load (i.e., computational amount) can be set. A thread is considered critical if its computational load is greater than or equal to this preset threshold, or if it is the thread with the highest load and is determined not to be an abnormal thread. This computational load can be the amount of computation or the normalized computation time, i.e., the computation time required to process this thread using a standard processor. The preset threshold can also be a threshold representing the proportion of computational load in the total computational load of the entire process. As an example, critical threads may include window management threads (userinterface thread), image rendering threads (render thread), system service threads (Android pools), push service threads, etc. The window management thread can be used to manage windows; for example, it can be used to obtain the screen size, determine if there is a status bar, lock the screen, and capture the screen. The image rendering thread can be used for image rendering. The system service thread can be used to call system services. Push service threads can be used to manage communication information. It should be noted that these threads are only examples of threads in the target application and should not constitute specific limitations on the names, functions, etc. of the threads in the target application.

[0080] While the social app is running in the foreground, in response to the first operation, phone 200 switches from screen-on to screen-off mode. This first operation is used to instruct phone 200 to switch from screen-on to screen-off mode. As an example, this first operation could be pressing the power button on phone 200, such as... Figure 4AThe gesture is shown in (a). The first operation can also be clicking the icon of the always-on display application in the status bar of the phone 200, or a voice command entered by the user to instruct the phone to turn off the screen, which is not limited in this application.

[0081] Figure 4B Figure (a) shows a schematic diagram of a mobile phone 200 in a screen-off state. Even when the mobile phone 200 is in a screen-off state, many services still run in the background. These services require memory allocation and involve swapping in and out of file pages. In this embodiment, after the mobile phone 200 enters the screen-off state, newly added file pages are managed through a temporary linked list, while existing file pages are maintained in the active and inactive linked lists. Specifically, when the mobile phone 200 is in a screen-off state, the entry point of the temporary linked list is opened. After the entry point is opened, newly added file pages can be added to the head of the temporary linked list. During memory reclamation, memory is preferentially reclaimed from the tail of the temporary linked list, thereby reducing the likelihood of file page #1 being reclaimed when the mobile phone 200 is in a screen-off state.

[0082] In one possible implementation, the mobile phone 200 can maintain a flag. When the mobile phone 200 is in a screen-on state, the flag is set to 0; when the mobile phone 200 is in a screen-off state, the flag is set to 1. The mobile phone 200 can determine whether to open the entry point of the temporary linked list based on this flag. For example, when the flag is 0, the mobile phone 200 closes the entry point of the temporary linked list; when the flag is 1, the mobile phone 200 opens the entry point of the temporary linked list.

[0083] It should be noted that the entry point for opening or closing the temporary linked list on mobile phone 200 specifically refers to the different modes that mobile phone 200 uses for file page management. For example, when the flag is 0, mobile phone 200 manages file pages in the first mode; when the flag is 1, mobile phone 200 manages file pages in the second mode. In the first mode, mobile phone 200 does not add new file pages to the temporary linked list and prioritizes memory reclamation from the tail of the temporary linked list. For details on the specific operation of the first mode, please refer to [link to relevant documentation]. Figure 4C The description corresponds to (b) in the second mode; in this mode, the phone 200 adds the new file page to the head of the temporary linked list and prioritizes memory reclamation from the tail of the temporary linked list. For details on how the second mode works, please refer to [link to relevant documentation]. Figure 4B The description corresponding to (b) in the text.

[0084] The following is a combination of... Figure 4B Section (b) provides an example of one working mode in the screen-off state.

[0085] Please refer to step S301: When a new file page is accessed, such as file page #2 in the figure, add file page #2 to the head of the temporary linked list.

[0086] This implementation reduces the likelihood of file page #1, associated with the foreground application (i.e., the social app), being released. Specifically, when the phone 200 is in a screen-off state, adding a new file page to the head of the inactive or active list may cause file page #1, originally in the active or inactive list, to be moved to the tail of the inactive list and released during memory reclamation. When the phone 200 then switches back to a screen-on state, if the foreground application (such as the social app) needs to read file page #1, it can only read it from the disk, potentially leading to I / O blocking.

[0087] Please refer to step S302: When a file page already in the temporary linked list, such as file page #3 in the figure, is accessed a second time, the file page #3 is moved to the head of the temporary linked list.

[0088] This implementation reduces the likelihood of file page #1, associated with the foreground application (i.e., the social app), being released. Specifically, as explained in step S301, newly added file pages (such as file page #2) in the screen-off state are added to a temporary linked list. Most of these newly added file pages in the screen-off state correspond to background processes. If file page #3 is added to the head of the inactive or active linked list, and given that the phone 200 has many background processes running or the screen is off for a long time, a significant number of file pages #3 might be added to the inactive or active linked lists. This could cause file page #1, originally in the active or inactive linked list, to be moved to the tail of the inactive linked list and released during subsequent memory reclamation. Therefore, by adding the file page accessed a second time from the temporary linked list to the head of the temporary linked list, instead of the head of the active or inactive linked list, the likelihood of file page #1 being released can be reduced. This reduces the probability of foreground application lag after the screen is turned on, improving the user experience.

[0089] Please refer to step S303: When performing memory reclamation, prioritize reclaiming file pages in the temporary linked list. For example, scan multiple file pages (e.g., 32 file pages) from the tail of the temporary linked list for reclamation.

[0090] This implementation reduces the likelihood of file page #1, associated with the foreground application (i.e., the social app), being released. Specifically, as explained in step S301, newly added file pages (such as file page #2) in the screen-off state are added to a temporary linked list. Most of these newly added file pages in the screen-off state correspond to background processes, and therefore are generally non-critical. Even if these file pages are recycled, it won't significantly impact the user experience. In contrast, file page #1 is associated with the foreground application (i.e., the social app). Especially if file page #1 is a critical file page, its recycling could cause foreground application lag after the phone is turned back on, significantly impacting the user experience. Therefore, by prioritizing the recycling of file pages in the temporary linked list, the recycling of file page #1 can be reduced, thereby decreasing the probability of foreground application lag after the screen is turned on again and improving the user experience.

[0091] Step S303 may specifically include the following possible implementation methods:

[0092] In one possible implementation, during memory reclamation, if the temporary linked list is empty, file pages are reclaimed preferentially from the tail of the inactive linked list (refer to step S305). The specific implementation logic is the same as... Figure 2 The memory reclamation logic is the same as that received in the previous version. Understandably, if the temporary linked list is empty when memory reclamation is triggered, then file pages are reclaimed directly from the tail of the inactive linked list; if the temporary linked list is not empty when memory reclamation is triggered, then file pages are reclaimed first from the tail of the temporary linked list, and only after all file pages in the temporary linked list have been reclaimed, are file pages reclaimed from the tail of the inactive linked list. This implementation reduces the number of file pages corresponding to the foreground application, especially critical file pages, that are reclaimed.

[0093] In another possible implementation, during memory reclamation, while prioritizing the reclamation of file pages in the temporary linked list, file pages are reclaimed from the temporary linked list and the inactive linked list at a preset ratio, where the proportion of file pages reclaimed from the temporary linked list is greater than the proportion reclaimed from the inactive linked list. For example, if the system requires the reclamation of 10 file pages, 7 file pages can be reclaimed from the temporary linked list and 3 file pages from the inactive linked list in a fixed ratio, such as 7:3. Alternatively, during memory reclamation, file pages in the temporary linked list are reclaimed first. However, if the number of file pages reclaimed from the temporary linked list exceeds a threshold #1, reclamation of file pages from the temporary linked list is stopped, and file pages from the inactive linked list are then reclaimed. Similarly, if the number of file pages reclaimed from the inactive linked list exceeds a threshold #2, reclamation of file pages from the inactive linked list is stopped, and then file pages from the temporary linked list are reclaimed. When the number of file pages reclaimed in the temporary linked list exceeds threshold #3, the process then switches to reclaiming file pages in the inactive linked list. When the number of file pages reclaimed in the inactive linked list exceeds threshold #4, the reclamation of file pages in the inactive linked list stops, and then file pages in the temporary linked list are reclaimed, and so on. Specifically, threshold #1 is greater than threshold #2, threshold #3 is greater than threshold #4, threshold #1 is greater than threshold #3, and threshold #2 is greater than threshold #4. This implementation avoids excessive reclamation of file pages in the temporary linked list, which could lead to excessive swapping pressure within the temporary linked list and negatively impact system performance.

[0094] In another possible implementation, if the swapping pressure of the temporary linked list exceeds the threshold #5 during memory reclamation, file pages are reclaimed from the temporary linked list.

[0095] It should be understood that this implementation still adheres to the principle of prioritizing the reclamation of file pages in the temporary linked list. For example, after triggering memory reclamation, it checks whether the swap-in / swap-out pressure of the temporary linked list exceeds threshold #5. If so, file pages are directly reclaimed from the tail of the temporary linked list; otherwise, file pages are reclaimed from the temporary linked list first, until the swap-in / swap-out pressure of the temporary linked list exceeds threshold #5, at which point file pages are reclaimed from the inactive linked list. Optionally, when the swap-in / swap-out pressure of the temporary linked list drops below threshold #6, memory reclamation can be performed again from the temporary linked list. This implementation allows for the reclamation of file pages from the inactive linked list when the swap-in / swap-out pressure of the temporary linked list is high, reducing performance issues caused by excessive reclamation of file pages in the temporary linked list.

[0096] It should also be understood that the swap-in and swap-out pressure of the temporary linked list can be calibrated using various metrics, and this application does not limit this. For example, it can be calibrated using the frequency of swapping in and out of all file pages in the temporary linked list; or, for example, it can be calibrated using the frequency of adding new file pages to the temporary linked list; or, for example, it can be calibrated using the frequency of file pages being reclaimed in the temporary linked list.

[0097] Please refer to step S304: Optionally, if a file page in the temporary linked list, such as file page #4, is accessed multiple times, file page #4 can be moved to the head of the inactive linked list. For example, if the number of accesses to file page #4 reaches threshold #7, file page #4 can be moved to the head of the inactive linked list because the multiple accesses indicate that file page #4 is a currently highly active file page, meaning that the currently running business needs to frequently access file page #4. Adding it to the inactive linked list at this time can reduce the probability of file page #4 being recycled, thereby improving the overall performance of the system. Further optionally, when the number of accesses to file page #4 exceeds threshold #8 (threshold #8 is greater than threshold #7), file page #4 can be further moved to the head of the active linked list to further reduce the probability of file page #4 being recycled.

[0098] Optionally, when a file page in either the active or inactive list, such as file page #5, is accessed a second time, it can be added to the head of a temporary list. Since the phone is in a screen-off state, most of the accessed file pages are not associated with the original foreground application (social app). Moving these file pages to the temporary list prevents the foreground application-associated file pages (such as file page #1) from shifting to the back of the list, thus reducing the risk of file page #1 being reclaimed in the screen-off state. Of course, in another possible implementation, when file page #5 is accessed a second time, it can also be handled using the LRU mechanism; see the following for details. Figure 2 The corresponding descriptions will not be repeated here.

[0099] Furthermore, when the phone 200 is in a screen-off state, in response to the second operation, the phone 200 switches from a screen-off state to a screen-on state. This second operation is used to instruct the phone 200 to switch from a screen-off state to a screen-on state. As an example, this second operation could be pressing the power button on the phone 200, such as... Figure 4B The gesture is shown in (a). The second operation can also be a user triggering fingerprint unlocking or face unlocking, which is not limited in this application.

[0100] After the phone 200 returns to screen-on mode (and is successfully unlocked), it displays as follows: Figure 4CThe application interface is shown in (a) above. It can be understood that before the phone 200 enters screen-off mode, the social app is the foreground application of the phone 200, displaying an interface as shown below. Figure 4A The application interface is shown in (a) above. When the phone 200 switches back from the screen-off state to the screen-on state, the phone 200 will automatically re-display the interface that was in the screen-off state before, such as... Figure 4C As shown in (a) above. It's understandable that even when the phone screen is off, social apps may continue to run in the background; therefore, the phone will redisplay the application interface (as shown in (a) above). Figure 4C The application interface shown in (a) is different from the application interface displayed before entering the screen-off state. Figure 4A The application interface shown in (a) may be the same or different, and this application does not limit it.

[0101] In this embodiment, after the mobile phone 200 re-enters the screen-on state, it maintains the file pages through an active list and an inactive list. Specifically, when the mobile phone 200 is in the screen-on state, it closes the entry point of the temporary list. After the entry point of the temporary list is closed, the default condition for adding a file page is placed at the head of the inactive list. For details, please refer to [reference needed]. Figure 2 The corresponding description. When performing memory reclamation, priority is given to reclaiming memory from the tail of the temporary linked list.

[0102] The following is a combination of... Figure 4C Section (b) provides an example of one working mode in the screen-on state.

[0103] Please refer to step S306: When a new file page is accessed, such as file page #6 in the figure, file page #6 is added to the head of the inactive list.

[0104] In other words, when the screen is on, newly accessed file pages are managed according to the original LRU mechanism. This is because the original LRU mechanism is sufficient to process file pages when the screen is on, and the temporary linked list is specifically used to manage newly accessed file pages when the screen is off. This way, only a small temporary linked list needs to be maintained, and the performance of the foreground application is not affected.

[0105] Please refer to step S307: When a file page already in the temporary linked list, such as file page #7 in the figure, is accessed a second time, the file page #7 is moved to the head of the inactive linked list.

[0106] In other words, when the screen is on, no new file pages are added to the temporary list. At the same time, the existing file pages in the temporary list are gradually transferred to the inactive list and the active list, thus freeing up the temporary list for use the next time the screen is off.

[0107] Please refer to step S308: When performing memory reclamation, prioritize reclaiming file pages in the temporary linked list. For example, scan multiple file pages (e.g., 32 file pages) from the tail of the temporary linked list for reclamation.

[0108] In other words, when the screen is on, no new file pages are added to the temporary list. At the same time, file pages in the temporary list are prioritized for recycling. This is because the file pages in the temporary list are added when the screen is off, and these file pages are mostly related to background business functions. Even if they are recycled, it will not affect the performance of the current foreground application, thereby improving the user experience.

[0109] In the above solution, when the electronic device is in screen-off mode, a temporary linked list is used to manage the file pages of background running services. During memory reclamation, file pages in the temporary linked list are prioritized for reclamation. Since background running services are mostly non-user-sensitive, even if they cause I / O blocking, it is unlikely to be noticed by the user and will not affect the user experience. In contrast, the foreground application's corresponding services are user-sensitive. This solution can maximize the protection of foreground application-related file pages in screen-off mode, reducing the likelihood of foreground application file pages (especially critical file pages) being reclaimed. This allows for direct access to most of the foreground application's associated file pages from memory after the electronic device is reactivated, reducing I / O blocking and application lag, thus improving the user experience.

[0110] Figure 5 This is a software architecture block diagram 400 corresponding to an electronic device provided in this application embodiment. The steps executed by the electronic device in the method provided in this application embodiment can be performed by… Figure 5 The software module implementation is shown.

[0111] It is understood that the electronic device in this application embodiment can be any type of electronic device, and the operating system installed on the electronic device can specifically be an operating system that uses the LRU mechanism for memory page management. For example, it can be an operating system based on the Linux kernel, such as the Android operating system. Electronic devices using this system include, but are not limited to, mobile phones, tablets, PDAs, etc. The following uses the Android system as an example to introduce the layered architecture of electronic devices.

[0112] The software architecture 400 is further divided into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. Figure 5 In the example shown, the software layer of the electronic device includes at least the application layer, the application framework layer, and the kernel layer.

[0113] Understandable. Figure 5This is just an example; that is, the layers in an electronic device are not limited to... Figure 5 The layers shown, for example, the software architecture layer can also include the hardware abstraction layer (HAL), the native service layer, etc.

[0114] Electronic devices can execute the file page management method provided in this application through the software modules in software architecture 400. The functions of each module are illustrated below.

[0115] The application layer can include a series of application packages. For example, these application packages may include social media apps, camera apps, gallery apps, WLAN apps, Bluetooth apps, calling apps, calendar apps, map apps, navigation apps, music apps, video apps, and SMS apps. When the electronic device's screen is on, it can launch an application and display its interface; at this time, the application is the foreground application of the electronic device.

[0116] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. As shown in the figure, the application framework layer includes a screen-on / off state management module, which monitors the current screen-on / off state of the electronic device.

[0117] The kernel layer is the layer between hardware and software. The kernel layer may include drivers such as display drivers, camera drivers, audio drivers, and sensor drivers. In some embodiments of this application, the kernel layer may include an I / O module, a memory management module, and kswapd. The I / O module handles I / O requests triggered by the application. The memory management module manages file pages. kswapd performs file page reclamation.

[0118] The following is combined Figure 6 The method 500 shown provides an example of the interaction flow of each module.

[0119] from Figure 6 As can be seen, method 500 includes at least three processes, denoted as process #1, process #2, and process #3. Process #1 is the procedure executed when the electronic device is in screen-on state; process #2 is the procedure executed when the electronic device switches from screen-on to screen-off state; and process #3 is the procedure executed when the electronic device switches back from screen-off to screen-on state. As an example, process #1 can correspond to... Figure 4A The scenario shown corresponds to process #2. Figure 4B The scenario shown corresponds to process #3. Figure 4CThe scenario shown will be explained in detail below.

[0120] Process #1:

[0121] S501, Application #1 runs in the foreground.

[0122] That is, application #1 is the currently foreground application of the electronic device. For example, application #1 could be like this: Figure 4A The social application shown in (a) is shown in the image.

[0123] Optionally, the S502 and IO modules may cause IO blocking.

[0124] Once application #1 is started, it will be accompanied by a large number of I / O requests, that is, operations such as reading and writing data to disk storage, which may lead to I / O blocking.

[0125] S503, the memory management module adds the file pages related to application #1 to the inactive list and the active list.

[0126] It should be understood that at this point, the memory management module can traverse file pages according to the LRU mechanism; for details, please refer to [link / reference needed]. Figure 2 The corresponding descriptions will not be repeated here.

[0127] Process #2:

[0128] S504 The screen-off status management module detects that the electronic device has entered the screen-off state.

[0129] S505, the entry point for the memory management module to open the temporary linked list.

[0130] For example, after the screen-on / off state management module detects that the electronic device has switched from a screen-on state to a screen-off state, it triggers the memory management module to open the entry point of the temporary linked list. For instance, the screen-on / off state management module sends an instruction to the memory management module to instruct it to open the entry point of the temporary linked list. The specific implementation process is not limited in this application.

[0131] S506, Application #2 runs in the background.

[0132] Application #2 is the current background application of the electronic device, which runs in the background when the electronic device is in a screen-off state.

[0133] Optionally, the S507 and IO modules may cause IO blocking.

[0134] When application #2 runs in the background, it will be accompanied by a large number of I / O requests, that is, operations such as reading and writing data to disk storage, which may lead to I / O blocking.

[0135] S508, the memory management module adds the file pages related to application #2 to a temporary linked list.

[0136] S509, the memory management module controls kswapd to prioritize the reclamation of file pages in the temporary linked list.

[0137] It should be understood that the memory management module can utilize a temporary linked list to manage newly added file pages. When memory reclamation is needed, kswapd can be controlled to prioritize reclaiming file pages in the temporary linked list. For specific implementation details, please refer to [reference needed]. Figure 4B The description corresponding to (b) in the text will not be repeated here.

[0138] Process #3:

[0139] S504, The on / off state management module detects that the electronic device has entered the on state.

[0140] S505, the entry point for the memory management module to open the temporary linked list.

[0141] For example, after the screen-off state management module detects that the electronic device has switched from a screen-off state to a screen-on state, it triggers the memory management module to close the entry point of the temporary linked list. For instance, the screen-off state management module sends an instruction to the memory management module to instruct it to close the entry point of the temporary linked list. The specific implementation process is not limited in this application.

[0142] S512, Application #1 runs in the foreground.

[0143] Since the electronic device was switched to the off state while application #1 was still running in the foreground, after switching back to the on state, the application interface of application #1 will still be displayed by default, meaning that application #1 continues to run in the foreground.

[0144] S513, the memory management module directly accesses the file page related to application #1 from memory.

[0145] S514, the memory management module controls kswapd to preferentially reclaim file pages in the temporary linked list.

[0146] When application #1 runs in the foreground, it generates a large number of I / O requests, specifically requests for relevant file pages. Since a temporary linked list is used to manage newly added file pages in the screen-off state, these foreground application-related file pages are unlikely to be reclaimed, meaning they remain in either the active or inactive linked list. Therefore, for I / O requests triggered by application #1, the memory management module directly retrieves the relevant file pages from memory, preventing I / O blocking and improving the smoothness of application #1's operation.

[0147] Figure 7This is a schematic diagram of the hardware structure of the electronic device 600 provided in an embodiment of this application. For example... Figure 7 As shown, the electronic device 600 may include a processor 610, a memory 620, and 1 to N displays 630, where N is a positive integer greater than or equal to 1.

[0148] It is understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 600. In other embodiments, the electronic device 600 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0149] Processor 610 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.

[0150] The memory 620 can be used to store computer-executable program code, which includes instructions. The processor 610 executes various functional applications and data processing of the electronic device 600 by running the instructions stored in the memory 620, such as executing the file page management method provided in this application embodiment. In this application embodiment, the memory 620 can be used to store file pages, including various application data.

[0151] The display screen 630 is used to display images, videos, etc. For example, the display screen 630 includes a display panel, which may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 600 may include one or N display screens 630, where N is a positive integer greater than 1. In this embodiment, the display screen 630 can display the application interface of the foreground application and can switch between a screen-on state and a screen-off state.

[0152] All methods described in the embodiments can be implemented in the electronic device 600 having the above-described hardware structure.

[0153] That concludes the introduction to the hardware structure of electronic devices. It is understandable that... Figure 7 The components included in the hardware structure shown do not constitute a specific limitation on the electronic device. The electronic device may have more or fewer components than shown in the figure, may combine two or more components, or may have different component configurations. The various components shown in the figure may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.

[0154] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.

[0155] This application provides a computer program product that, when run on a device, enables the device to perform the steps described in the various method embodiments above.

[0156] This application provides a chip for executing instructions. When the chip is running, it executes the technical solutions described in the above embodiments. Its implementation principle and technical effects are similar and will not be repeated here.

[0157] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., high-density digital video discs (DWDs)), or semiconductor media (e.g., solid-state disks (SSDs)).

[0158] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying the computer program code to a photographic device / electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0159] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0160] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0161] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0162] It should be understood that the term "embodiment" used throughout the specification means that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, various embodiments throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0163] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

[0164] Furthermore, it should be noted that the various numerical designations used in this application (such as the terms "first," "second," "third," "fourth," and other terminology used in the specification, claims, and accompanying drawings, if any) are merely for descriptive convenience and are not intended to limit the scope of this application. The order of the process numbers does not imply the sequence of execution; the execution order of each process should be determined by its function and internal logic.

[0165] The terms “comprising” and “having”, and any variations thereof, mean “including, but not limited to”, unless otherwise specifically emphasized, for example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such process, method, product, or device.

[0166] In the embodiments of this application, the words "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of the words "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.

[0167] In the various embodiments of this application, unless otherwise specified or logically conflicting, the terminology and / or descriptions between different embodiments are consistent and can be referenced mutually. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships. The specific operational methods in the method embodiments of this application can also be applied to the device embodiments or system embodiments.

Claims

1. A method for managing file pages, characterized in that, The method is applied to an electronic device that simultaneously maintains active linked lists, inactive linked lists, and temporary linked lists in memory. The method includes: Determine the current on / off state of the electronic device; If the electronic device is in a screen-on state, add the newly accessed first file page to the head of the inactive list; or, When the electronic device is in a screen-off state, the first file page is added to the head of the temporary linked list.

2. The method according to claim 1, characterized in that, The method further includes: When memory reclamation is triggered, file pages are reclaimed preferentially from the tail of the temporary linked list.

3. The method according to claim 2, characterized in that, The step of preferentially reclaiming file pages from the tail of the temporary linked list includes: If the temporary linked list is empty, file pages are reclaimed from the tail of the inactive linked list.

4. The method according to claim 2, characterized in that, The step of preferentially reclaiming file pages from the tail of the temporary linked list includes: File pages are reclaimed from temporary and inactive lists according to a preset ratio, wherein the proportion of file pages reclaimed from temporary lists is greater than the proportion of file pages reclaimed from inactive lists.

5. The method according to claim 2, characterized in that, The step of preferentially reclaiming file pages from the tail of the temporary linked list includes: First, reclaim file pages from the end of the temporary linked list; If the swapping pressure of the temporary linked list exceeds a first preset threshold, file page reclamation continues from the tail of the inactive linked list.

6. The method according to any one of claims 1 to 5, characterized in that, When the electronic device is in a screen-off state, the method further includes: Move the second file page that is accessed twice in the temporary linked list to the head of the temporary linked list.

7. The method according to any one of claims 1 to 6, characterized in that, When the electronic device is in a screen-off state, the method further includes: If the number of times a third file page in the temporary linked list is accessed exceeds a second preset threshold, the third file page is moved to the head of the inactive linked list.

8. The method according to any one of claims 1 to 7, characterized in that, When the electronic device is in a screen-on state, the method further includes: Move the fourth file page that has been accessed twice in the temporary linked list to the head of the inactive linked list.

9. The method according to any one of claims 1 to 8, characterized in that, The method further includes: When the electronic device is in a screen-on state, close the entry point of the temporary linked list; or, When the electronic device is in a screen-off state, the entry point of the temporary linked list is opened.

10. An electronic device, characterized in that, The device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that, when the processor executes the computer program, the electronic device performs the method as described in any one of claims 1-9.

11. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the one or more processors being used to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1 to 9.

12. A computer program product, characterized in that, Includes a computer program, which, when run, causes the method as described in any one of claims 1-9 to be performed.