A storage method, device, equipment and storage medium for swapping anonymous pages of a swap device

By allocating continuous storage blocks for anonymous pages of the same process on the swap device, the problems of low reading efficiency and device fragmentation caused by random storage of anonymous pages are solved, and the reading efficiency and device life are improved, especially in embedded systems.

CN114579037BActive Publication Date: 2025-07-25ZTE CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011385327.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-01
Publication Date
2025-07-25
Estimated Expiration
2040-12-01

AI Technical Summary

Technical Problem

In the prior art, random exchange of anonymous pages on swap devices to different addresses leads to low reading efficiency, especially in embedded systems such as mobile phones, flash fragmentation is severely affected, affecting the life and efficiency of the device.

Method used

By allocating continuous storage blocks for anonymous pages of the same process, ensuring that anonymous pages are continuously stored on the swap device, reducing expensive file IO operations, improving read efficiency and extending device life.

Benefits of technology

It realizes efficient reading of anonymous pages of the same process and extends the service life of swap devices, improving the performance and user experience of embedded systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114579037B_ABST
    Figure CN114579037B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention discloses a storage method, device, equipment and storage medium for swapping anonymous pages of a swap device. The method includes: when a target anonymous page needs to be swapped out of the system to the swap device, determining the application process to which the target anonymous page belongs; when the application process to which the target anonymous page belongs is swapped out of the system to the swap device for the first time, allocating a first block for storing anonymous pages for the application process, and storing the target anonymous page of the application process in the free address of the first block.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of swap device data storage, and in particular, to a method, apparatus, device, and storage medium for storing anonymous pages of a swap device. Background Art

[0002] In the existing technology, when the memory is in short supply, the system will select some anonymous pages of processes to swap to the swap device. At this time, when the anonymous pages of the same process are swapped out to the swap device, they will be randomly swapped to different addresses on the swap device, and the processing method is as Figure 1 shown. There are several problems with this random swapping to the swap device. First, the reading efficiency is low. The anonymous pages of the same process are at multiple addresses on the swap device and need to be read multiple times. Second, especially in an embedded system, such as a mobile phone product, the swap device is flash, and random read and write will cause flash fragmentation and affect the flash lifespan. Third, when the swap device is a hard disk, the magnetic head needs to be moved multiple times to read multiple data of the same process, and the efficiency will be even lower. Summary of the Invention

[0003] The main purpose of the embodiments of the present invention is to propose a method, apparatus, device, and storage medium for storing anonymous pages of a swap device. By continuously swapping out the anonymous pages of the same process to the swap device, the expensive file IO operations are avoided to the greatest extent, which can improve the reading efficiency of the swap device and improve a factor affecting performance. Especially for mobile phones with less memory and more installed applications, the performance improvement effect will be more obvious.

[0004] To achieve the above object, an embodiment of the present invention provides a method for storing anonymous pages of a swap device, including the following steps:

[0005] When a target anonymous page needs to be swapped out from the system to the swap device, determine the application process to which the target anonymous page belongs;

[0006] When the application process to which the target anonymous page belongs is swapped out from the system to the swap device for the first time, allocate a first block for storing anonymous pages for the application process, and store the target anonymous page of the application process in the free address of the first block.

[0007] To achieve the above object, an embodiment of the present invention provides a device for storing anonymous pages of a swap device, including:

[0008] A determination module, configured to determine the application process to which the target anonymous page belongs when the target anonymous page needs to be swapped out from the system to the swap device;

[0009] A storage module, when the application process to which the target anonymous page belongs is swapped out of the system to the swap device for the first time, allocates a first block for storing anonymous pages for the application process, and stores the target anonymous page of the application process in the free address of the first block.

[0010] To achieve the above object, an embodiment of the present invention further provides a storage device for anonymous pages of a swap device. The device includes a memory, a processor, a program stored on the memory and executable on the processor, and a data bus for realizing connection communication between the processor and the memory. When the program is executed by the processor, the steps of the foregoing method are implemented.

[0011] To achieve the above object, an embodiment of the present invention further provides a storage medium for computer-readable storage. The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the foregoing method.

[0012] For a storage method, device, equipment and storage medium of anonymous pages of a swap device provided by the present invention, multiple anonymous pages of the same process are placed at consecutive addresses, and can be read at one time when swapped in, improving the reading efficiency and service life of the swap device and enhancing the user experience. Description of the Drawings

[0013] Figure 1 is a schematic diagram of anonymous pages of the same process provided by the prior art being randomly swapped to different addresses of the swap device.

[0014] Figure 2 is a flowchart of a storage method of anonymous pages of a swap device provided in Embodiment 1 of the present invention.

[0015] Figure 3 is a schematic diagram of a storage device for anonymous pages of a swap device provided in Embodiment 2 of the present invention.

[0016] Figure 4 is a schematic diagram of anonymous pages of the same process being swapped to the swap device provided in Embodiment 3 of the present invention.

[0017] Figure 5 is a schematic diagram of a storage system for anonymous pages of a swap device provided in Embodiment 4 of the present invention.

[0018] Figure 6 is a flowchart of a storage method of anonymous pages of a swap device provided in Embodiment 4 of the present invention. Detailed Embodiments

[0019] It should be understood that the specific embodiments described herein are merely used to explain the present invention and are not intended to limit the present invention.

[0020] In the following description, suffixes such as "module", "component", or "unit" used to represent elements are only for the convenience of describing the present invention, and they have no specific meaning in themselves. Therefore, "module", "component", or "unit" can be used interchangeably.

[0021] Figure 2 It is a flowchart of a method for storing anonymous pages of a swap device provided in the first embodiment of the present invention. As Figure 2 shown, it includes:

[0022] Step S101: When a target anonymous page needs to be swapped out of the system to the swap device, determine the application process to which the target anonymous page belongs;

[0023] Step S102: When the application process to which the target anonymous page belongs is swapped out of the system to the swap device for the first time, allocate a first block for storing anonymous pages for the application process, and store the target anonymous page of the application process in the free address of the first block.

[0024] The embodiment of the present invention further includes: when the application process to which the target anonymous page belongs is not swapped out of the system to the swap device for the first time, find the second block that has been allocated for storing anonymous pages for the application process; when the second block that has been allocated for the application process is not full of anonymous pages, store the target anonymous page of the application process in the free address of the second block; when the second block that has been allocated for the application process is full of anonymous pages, allocate a third block for storing anonymous pages for the application process, and store the target anonymous page of the application process in the free address of the third block.

[0025] The embodiment of the present invention further includes: when the target anonymous page of the application process needs to be swapped into the system from the swap device, find the block in which the target anonymous page of the application process is stored; pre-read the target anonymous page from the block in which the target anonymous page of the application process is stored, and cache it in the system.

[0026] The embodiment of the present invention further includes: after pre-reading the target anonymous page of the application process from the block into the system cache, determine whether all addresses of the block are idle; when all addresses of the block are idle, recycle the block; when all addresses of the block are not idle, erase the target anonymous page of the application process swapped in the block.

[0027] Figure 3is a schematic diagram of a storage device for anonymous pages of a swap device provided in the second embodiment of the present invention, such as Figure 3 As shown, it includes: a determination module and a storage module. The determination module is used to determine the application process to which the target anonymous page belongs when the target anonymous page needs to be swapped out from the system to the swap device; the storage module is used to allocate a first block for storing anonymous pages to the application process when the application process to which the target anonymous page belongs is swapped out from the system to the swap device for the first time, and store the target anonymous page of the application process in the free address of the first block.

[0028] Among them, the storage module is also specifically used to search for the second block allocated to the application process for storing anonymous pages when the application process to which the target anonymous page belongs is not swapped out from the system to the swap device for the first time; when the second block allocated to the application process is not full of anonymous pages, store the target anonymous page of the application process in the free address of the second block; when the second block allocated to the application process is full of anonymous pages, allocate a third block for storing anonymous pages to the application process, and store the target anonymous page of the application process in the free address of the third block.

[0029] An embodiment of the present invention also proposes a storage device for anonymous pages of a swap device, the device comprising a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, wherein the program implements the steps of the aforementioned method when executed by the processor.

[0030] An embodiment of the present invention further provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the aforementioned method.

[0031] The present invention is applied to all terminal products based on Linux operating system. As more and more applications are running on mobile phones, the memory occupied is getting larger and larger. Moreover, many applications want to be resident in the memory, which leads to tight memory. At this time, the system will swap the anonymous pages occupied by the process to the swap device. Therefore, the present invention aims to improve the data storage method of the swap device to improve the system performance. By placing multiple anonymous page applications of the same process on continuous addresses, they can be read at one time when swapped in, thereby improving the reading efficiency and service life of the swap device and improving the user experience.

[0032] The present invention allocates a large block of space to each process swapped out to the swap device. For example, the large block of space can store 64 anonymous pages. Figure 4As shown in the figure, when the anonymous pages of a process are to be swapped out, first check whether the large block is full. If it is not full, store the anonymous page at the free address; if the large block is full, allocate a new large block of space. This can ensure that any process has at least 64 anonymous pages stored together. In this way, it is ensured that the anonymous pages of the same process are not randomly stored on the swap device. When swapping in, multiple pages can be prefetched into the cache at one time.

[0033] Flash memory is non-volatile memory, and memory cell blocks called blocks can be erased, written, and reprogrammed. The write operation of any flash device can only be performed on empty or erased cells. Therefore, in most cases, erasure must be performed before the write operation. Flash reads and writes data in pages, while erases data in blocks. These two units are different. When the swap device is flash, the size of the large block is set to the size of flash erasure. This can avoid fragmentation. When a process exits, the swap space occupied by the process's anonymous pages can be directly erased, which will improve the service life and efficiency of flash. The size of the large block can be set through the proc or sys interface.

[0034] The present invention uses the external proc or sys file system node of the operating system to output block size setting information; uses the operating system interface to inject block setting information into the operating system for block size setting; and can prefetch multiple anonymous pages into the cache at one time when swapping in.

[0035] Figure 5 is a schematic diagram of the storage system for anonymous pages of the swap device provided in Embodiment 4 of the present invention. As Figure 5 shown, it includes a swap device module, a process management module, a process anonymous page management module, a cache module, a prefetch module, and a block management module.

[0036] Among them, the swap device management module is responsible for the storage and reading of process anonymous pages; the block management module is responsible for the functions of allocating, searching, recycling, and erasing the addresses of process anonymous pages. When swapping out, it is necessary to allocate storage space for anonymous pages, and when swapping in, it is necessary to erase the space occupied by the anonymous pages of the relevant process. The blocks allocated by the block management module can store multiple anonymous pages, so that some anonymous pages of each process can be stored continuously. When the system needs to swap in data from the swap device, the prefetch module needs to read the anonymous page data into the cache module.

[0037] Figure 6 is a flowchart of the storage method for anonymous pages of the swap device provided in Embodiment 4 of the present invention. As Figure 6 shown, it includes:

[0038] Step S601: When memory becomes tense, the system will select some anonymous pages of processes for swapping out;

[0039] Step S602: Determine whether the process to which the anonymous page belongs is swapped out for the first time. If so, go to Step S604; otherwise, go to Step S603;

[0040] Step S603: Search for the blocks allocated to the process;

[0041] Step S604: Set information according to the block size and allocate a new block for the process. The allocated block can store multiple anonymous pages, ensuring that some anonymous pages of each process can be stored continuously;

[0042] Step S605: Check whether all the found blocks are already storing anonymous pages. If the block is not full, execute Step S607; otherwise, execute Step S606;

[0043] Step S606: The same process applies for a new block again;

[0044] Step S607: Store the anonymous page onto the block;

[0045] Step S608: When the anonymous page of a process needs to be swapped in, some anonymous pages of the process need to be pre-read into the system cache;

[0046] Step S609: After reading, check whether the block space is free. If it is free, execute Step S610; if it is not free, execute Step S611;

[0047] Step S610: Execute block erasure;

[0048] Step S611: Execute block recycling;

[0049] Step S612: The pre-read anonymous page is successfully swapped in.

[0050] Those of ordinary skill in the art can understand that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, and their appropriate combinations.

[0051] In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be executed by the cooperation of several physical components. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or transitory medium). As is well known to those of ordinary skill in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes but is not limited to RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those of ordinary skill in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.

[0052] The preferred embodiments of the present invention have been illustrated above with reference to the accompanying drawings, and thus do not limit the scope of the rights of the present invention. Any modifications, equivalent replacements, and improvements made by those skilled in the art without departing from the scope and essence of the present invention shall be within the scope of the rights of the present invention.

Claims

1. A storage method for swapping anonymous pages of a swap device, characterized in that It includes the following steps: When a target anonymous page needs to be swapped out from the system to a swap device, determine the application process to which the target anonymous page belongs; When the application process to which the target anonymous page belongs is swapped out from the system to the swap device for the first time, allocate a first block for storing anonymous pages for the application process, and store the target anonymous page of the application process in the free address of the first block; When the application process to which the target anonymous page belongs is not swapped out from the system to the swap device for the first time, find the second block that has been allocated for storing anonymous pages for the application process; When the second block allocated for the application process is not full of anonymous pages, store the target anonymous page of the application process in the free address of the second block; When the second block allocated for the application process is full of anonymous pages, allocate a third block for storing anonymous pages for the application process, and store the target anonymous page of the application process in the free address of the third block, so as to store multiple target anonymous pages of the same application process in consecutive free addresses.

2. The method according to claim 1, wherein It also includes: When the target anonymous page of the application process needs to be swapped into the system from the swap device, find the block where the target anonymous page of the application process is stored; Prefetch the target anonymous page from the block where the target anonymous page of the application process is stored, and cache it in the system.

3. The method according to claim 2, wherein It also includes: After prefetching the target anonymous page of the application process from the block into the system cache, determine whether all addresses of the block are free; When all addresses of the block are free, recycle the block; When all addresses of the block are not free, erase the target anonymous page of the swapped-in application process in the block.

4. A storage device for swapping anonymous pages of a swap device, characterized in that It includes: A determination module, configured to determine the application process to which the target anonymous page belongs when the target anonymous page needs to be swapped out from the system to a swap device; A storage module, configured to allocate a first block for storing anonymous pages for the application process and store the target anonymous page of the application process in the free address of the first block when the application process to which the target anonymous page belongs is swapped out from the system to the swap device for the first time; The storage module is further configured to find the second block that has been allocated for storing anonymous pages for the application process when the application process to which the target anonymous page belongs is not swapped out from the system to the swap device for the first time; store the target anonymous page of the application process in the free address of the second block when the second block allocated for the application process is not full of anonymous pages; and allocate a third block for storing anonymous pages for the application process and store the target anonymous page of the application process in the free address of the third block when the second block allocated for the application process is full of anonymous pages, so as to store multiple target anonymous pages of the same application process in consecutive free addresses.

5. A storage device for swapping anonymous pages of a swap device, characterized in that, The device includes a memory, a processor, a program stored on the memory and executable on the processor, and a data bus for implementing connection communication between the processor and the memory. When the program is executed by the processor, it implements the steps of the storage method of the swap device anonymous page as described in any one of claims 1-3.

6. A storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the storage method of the swap device anonymous page as described in any one of claims 1-3.

Citation Information

Patent Citations

  • Anonymous page management method and device, terminal equipment and readable storage medium

    CN110008016A

  • Shielding method of Linux page replacement mechanism

    CN111782397A