A method and device for establishing a mapping relationship between a backup file and a virtual memory

By establishing a mapping relationship between the backup file and virtual memory in the user program, and reclaiming historical virtual memory blocks, the problem of virtual memory space exhaustion is solved, and the expansion of virtual memory and the stable execution of user programs is achieved.

CN118860912BActive Publication Date: 2025-09-02上海芯联芯智能科技有限公司
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411336568.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-25
Publication Date
2025-09-02
Estimated Expiration
2044-09-25

AI Technical Summary

Technical Problem

When a user program uses a backup file, the virtual memory space is exhausted, causing the program to crash, and the existing technology cannot effectively expand the virtual memory.

Method used

By establishing a named memory mapping relationship between the backup file and virtual memory, recyclable historical virtual memory blocks are recycled, virtual memory space is expanded, and time division multiplexing is used to ensure the smooth execution of user programs.

Benefits of technology

It effectively expands the virtual memory space, reduces the possibility of virtual memory exhaustion, and improves the execution success rate and performance of user programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118860912B_ABST
    Figure CN118860912B_ABST
Patent Text Reader

Abstract

The present application provides a method and device for establishing a mapping relationship between a backup file and virtual memory, including: triggering a backup memory mapping establishment request for a first backup file block; determining the size of the first backup file block from a backup file allocation table according to a second parameter in the backup memory mapping establishment request; judging whether there is a free virtual memory block in the virtual memory that meets the size of the first backup file block; if not, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; judging whether there is a free virtual memory block that meets the size of the first backup file block in the virtual memory after the recovery is completed; using the starting address of the free virtual memory block that meets the size of the first backup file block as the value of the first parameter, storing the first parameter, and establishing a named memory mapping between the first backup file block and the free virtual memory block through the kernel. This solution can realize the expansion of virtual memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and device for establishing a mapping relationship between a backup file and a virtual memory. Background Art

[0002] When a user program uses a backup file, the kernel needs to establish a mapping relationship between the virtual memory block and the backup file block. The user program accesses the backup file through this mapping relationship and performs read and write operations.

[0003] Virtual memory is generally divided into non-overlapping kernel space and user space. User programs can only access user space, which means that the maximum virtual memory space a user program can use depends on the size of the user space. For example, for some instruction set architectures, the total virtual memory is 4GB, of which 2GB is user space and 2GB is kernel space. If the 2GB corresponding to the user space has been used up by the user program, then when the user program requests virtual memory from the kernel again, the kernel will no longer be able to allocate virtual memory to the user program, eventually causing the program to crash.

[0004] So, how to expand virtual memory remains to be solved. Summary of the Invention

[0005] The present application provides a method and device for establishing a mapping relationship between a backup file and a virtual memory, which can realize the expansion of the virtual memory.

[0006] In the first aspect, an embodiment of the present application provides a method for establishing a mapping relationship between a backup file and a virtual memory. The method can be executed by an apparatus for establishing a mapping relationship between a backup file and a virtual memory. The apparatus for establishing a mapping relationship between a backup file and a virtual memory can be a terminal device or a module for a terminal device, or a server or a module for a server. The present application does not limit the execution subject of the method. The method includes: triggering a backup memory mapping establishment request for a first backup file block; wherein the backup file is any file that can be mounted on a file system; the first backup file block is a continuous area in the backup file; the backup memory mapping establishment request is used to establish a named memory mapping between the backup file block and the virtual memory block; according to the second parameter in the backup memory mapping establishment request, the size of the first backup file block is determined from the backup file allocation table; the second parameter is used to indicate the address where the first parameter of the first backup file block is located; the value of the first parameter is used to indicate the starting address on the virtual memory to which the first backup file block is mapped by the named memory mapping; the backup file allocation table includes the address where the first parameter is located, and the first the size of the backup file block; determining whether there is a free virtual memory block that meets the first backup file block size in the virtual memory; if not, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; if the reclaimable historical virtual memory block exists, reclaiming the reclaimable historical virtual memory block and releasing the named memory mapping corresponding to the reclaimable historical virtual memory block; determining whether there is a free virtual memory block that meets the first backup file block size in the virtual memory after the recovery is completed; using the starting address of the free virtual memory block that meets the first backup file block size as the value of the first parameter, storing the first parameter, and establishing a named memory mapping between the first backup file block and the free virtual memory block through the kernel.

[0007] In the above scheme, when there are no free virtual memory blocks in the virtual memory that meet the first backup file block size, reclaimable historical virtual memory blocks are recycled, so that the current free virtual memory blocks meet the needs of the user program. This application uses a time-division multiplexing method to reclaim reclaimable historical virtual memory blocks, expand the size of the virtual memory, and ensure the smooth execution of the user program.

[0008] In one possible implementation method, the backup file allocation table is traversed to determine the address of the first parameter corresponding to the historical backup file block; the value of the first parameter corresponding to the historical backup file block is determined based on the address of the first parameter corresponding to the historical backup file block; if the value of the first parameter corresponding to the historical backup file block is not empty, and the historical virtual memory block indicated by the first parameter corresponding to the historical backup file block is not locked, then the historical virtual memory block is determined to be a reclaimable historical virtual memory block.

[0009] In the above solution, the backup file allocation table and the first parameter record the information of the historical virtual memory blocks. The above method can accurately and effectively determine which historical virtual memory blocks are reclaimable.

[0010] In one possible implementation method, a kernel is requested to establish a named memory mapping from the first backup file block to an arbitrary virtual memory block; if the kernel fails to establish the named memory mapping, it is determined that there is no free virtual memory block in the virtual memory that meets the size of the first backup file block; if the kernel successfully establishes the named memory mapping, the starting address of the virtual memory block corresponding to the named memory mapping is used as the value of the first parameter, and the first parameter is stored.

[0011] The above solution can ensure accurate and effective establishment of named memory mapping.

[0012] In one possible implementation method, a backup memory allocation request for the first backup file block is triggered; the backup memory allocation request includes a memory request size; it is determined whether there is a continuous area in the backup file that meets the memory request size; if so, the continuous area in the backup file that meets the memory request size is determined as the first backup file block, and a first storage space is requested from the virtual memory, and the address of the first storage space is returned to the user program as the address of the first parameter of the first backup file block; the first storage space is used to store the value of the first parameter of the first backup file block; the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0013] The above scheme can accurately and effectively determine the addresses of the first backup file block and the first parameter; and the scheme does not actually establish a naming mapping relationship between the first backup file block and the virtual memory block, that is, the virtual memory block is not occupied at this time. When the user program really needs to access the backup file block just applied for, it will request to establish a naming memory mapping between the virtual memory block and the backup file block. Therefore, it can reduce the possibility of virtual memory exhaustion and improve the success rate of smooth execution of user programs.

[0014] In a possible implementation method, if the first storage space is not applied for from the virtual memory, it is determined whether there is a reclaimable historical virtual memory block based on the backup file allocation table; if the reclaimable historical virtual memory block exists, the reclaimable historical virtual memory block is reclaimed, and the named memory mapping corresponding to the reclaimable historical virtual memory block is released; a second storage space is applied for from the virtual memory after the recovery is completed, and the address of the second storage space is returned to the user program as the address of the first parameter of the first backup file block; the second storage space is used to store the value of the first parameter of the first backup file block; the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0015] In the above solution, if the virtual memory is not provided with a backup memory mapping area and a first parameter storage area, when it is determined that the virtual memory is exhausted, that is, the first storage space is not applied for from the virtual memory, the virtual memory can be expanded by recycling the historical virtual memory blocks so that the user program can be executed smoothly.

[0016] In a possible implementation method, a backup memory mapping release request is triggered; the backup memory mapping release request is used to request the release of the virtual memory block mapped to the second backup file block; according to the second parameter in the backup memory mapping release request, the starting address of the virtual memory block corresponding to the second backup file block is determined; according to the second parameter in the backup memory mapping release request, the size of the second backup file block is determined from the backup file allocation table; the starting address of the virtual memory block corresponding to the second backup file block and the size of the second backup file block are passed to the kernel, and the named memory mapping is canceled by the kernel; after receiving the indication information sent by the kernel that the named memory mapping is successfully canceled, the value of the first parameter corresponding to the second backup file block is updated.

[0017] The above solution can accurately and effectively release the backup memory mapping.

[0018] In a possible implementation method, when it is determined that the memory access requirement of the user program meets a set condition, a backup memory allocation request is triggered.

[0019] The above solution can relieve most of the virtual memory pressure by establishing a backup file mapping, reducing the possibility of virtual memory exhaustion; at the same time, ordinary memory allocation can still be used for performance-sensitive memory allocation, and user programs can still maintain high performance.

[0020] In a possible implementation method, data in the first backup file block is accessed through a named memory mapping between the first backup file block and the free virtual memory block.

[0021] The above solution can achieve accurate and efficient access to data in the first backup file block through named memory mapping between the first backup file block and the free virtual memory block.

[0022] In a possible implementation method, a lock flag is set for the virtual memory block corresponding to the first backup file block according to the first parameter.

[0023] The above solution sets a lock flag on the virtual memory block corresponding to the first backup file block, so the virtual memory block corresponding to the first backup file block will not be reclaimed. This solution can accurately and effectively determine which virtual memory blocks can be reclaimed. If the first backup file block is called multiple times by the user program, locking the virtual memory block corresponding to the first backup file block can reduce the number of times the backup memory mapping needs to be re-established, thus saving resources.

[0024] In a possible implementation method, a first parameter storage area is provided in the virtual memory; the first parameter storage area stores a plurality of first parameter values; and an application is made to the first parameter storage area for allocation of a first storage space.

[0025] The above solution, on the one hand, centrally stores the first parameters in one place, thereby preventing memory fragmentation caused by scattered allocation of the first parameters and minimizing the problem of insufficient continuous free space when needed due to discontinuous free space. On the other hand, centrally storing the first parameters in one place eliminates the need to obtain the memory space required for the first parameters through ordinary memory allocation each time. Furthermore, when recording the addresses of the first parameters in the backup file allocation table, since the first parameters are concentrated in the first parameter storage area, such addresses will have a common prefix. Therefore, it is unnecessary to record this common prefix, thereby saving storage space in the backup file allocation table.

[0026] In a possible implementation method, if the application for allocating the first storage space from the first parameter storage area is unsuccessful, a memory exhaustion indication is returned to the user program.

[0027] The above solution can accurately and effectively determine whether the virtual memory is exhausted.

[0028] In one possible implementation method, a backup memory mapping area is set in the virtual memory; the backup file mapping area is the virtual memory block to which the backup file block recorded in the backup file allocation table is mapped; and the backup file allocation table is used to determine whether there is an idle virtual memory block in the backup file mapping area that meets the size of the first backup file block.

[0029] The above solution, on the one hand, ensures that ordinary memory allocation does not excessively occupy the heap / file mapping area by presetting the backup file mapping area, so that when the user space pressure is high (that is, the user space is about to be filled), there is still enough virtual memory area to safely establish the backup memory mapping; on the other hand, the backup memory mapping windows are centralized and managed in one place, so that when necessary, they can be defragmented to free up the small free spaces (i.e., fragments) sandwiched between the mapping windows to form a new large continuous free space.

[0030] In a possible implementation method, a backup memory mapping area is provided in the virtual memory; if there are no free virtual memory blocks that meet the first backup file block size in the backup memory mapping area after recovery, the fragments in the backup memory mapping area are defragmented; it is determined whether there are free virtual memory blocks that meet the first backup file block size in the backup memory mapping area after recovery and defragmentation; if so, the starting address of the free virtual memory block that meets the first backup file block size in the backup memory mapping area is used as the value of the first parameter, the first parameter is stored, and a named memory mapping between the first backup file block and the free virtual memory block is established through the kernel.

[0031] In the above solution, a backup memory mapping area is set in the virtual memory. In addition to recycling the backup memory mapping area, it can also be defragmented; further expanding the available virtual memory blocks of the virtual memory, and improving the possibility of smooth execution of user programs.

[0032] In a possible implementation method, the value of the first parameter corresponding to each historical backup file block is updated according to the defragmented virtual memory.

[0033] The above solution can improve the accuracy and effectiveness of the backup file allocation table.

[0034] In one possible implementation method, if there is no continuous area in the backup file that meets the memory request size, the fragments in the backup file are defragmented, and it is determined whether the backup file after defragmentation meets the continuous area of ​​the memory request size; if not, a backup file exhaustion indication is returned to the user program.

[0035] The above solution defragments the backup file, thereby improving the success rate of obtaining the first backup file block from the backup file.

[0036] In a second aspect, an embodiment of the present application provides a device for establishing a mapping relationship between a backup file and a virtual memory, comprising: a triggering unit, a determining unit, a judging unit, and a recycling unit:

[0037] The trigger unit is configured to trigger a backup memory mapping establishment request for a first backup file block; wherein the backup file is any file that can be mounted on a file system; the first backup file block is a continuous area in the backup file; and the backup memory mapping establishment request is configured to establish a named memory mapping between the backup file block and the virtual memory block;

[0038] The determining unit is configured to determine the size of the first backup file block from a backup file allocation table according to a second parameter in the backup memory mapping establishment request; the second parameter is configured to indicate the address of the first parameter of the first backup file block; the value of the first parameter is configured to indicate the starting address on the virtual memory to which the first backup file block is mapped by the named memory mapping; the backup file allocation table includes the address of the first parameter and the size of the first backup file block; the starting address of the free virtual memory block that meets the size of the first backup file block is used as the value of the first parameter, the first parameter is stored, and a named memory mapping between the first backup file block and the free virtual memory block is established through the kernel.

[0039] The determining unit is configured to determine whether there is a free virtual memory block in the virtual memory that meets the first backup file block size; if not, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; and determining whether there is a free virtual memory block in the virtual memory after the recovery is completed that meets the first backup file block size;

[0040] The recycling unit is configured to recycle the recyclable historical virtual memory block if the recyclable historical virtual memory block exists, and release the named memory mapping corresponding to the recyclable historical virtual memory block.

[0041] In a possible implementation method, the determination unit is used to traverse the backup file allocation table to determine the address of the first parameter corresponding to the historical backup file block; determine the value of the first parameter corresponding to the historical backup file block according to the address of the first parameter corresponding to the historical backup file block; if the value of the first parameter corresponding to the historical backup file block is not empty, and the historical virtual memory block indicated by the first parameter corresponding to the historical backup file block is not locked, then determine that the historical virtual memory block is a reclaimable historical virtual memory block.

[0042] In one possible implementation method, the determination unit is used to request the kernel to establish a named memory mapping from the first backup file block to any virtual memory block; if the kernel fails to establish the named memory mapping, it is determined that there is no free virtual memory block in the virtual memory that meets the size of the first backup file block; if the kernel successfully establishes the named memory mapping, the starting address of the virtual memory block corresponding to the named memory mapping is used as the value of the first parameter, and the first parameter is stored.

[0043] In one possible implementation method, the trigger unit is used to trigger a backup memory allocation request for the first backup file block; the backup memory allocation request includes a memory request size; the judgment unit is used to judge whether there is a continuous area in the backup file that meets the memory request size; if so, the determination unit is used to determine the continuous area in the backup file that meets the memory request size as the first backup file block, and apply for a first storage space from the virtual memory, and return the address of the first storage space as the address of the first parameter of the first backup file block to the user program; the first storage space is used to store the value of the first parameter of the first backup file block; and the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0044] In one possible implementation method, the judgment unit is used to determine whether there is a reclaimable historical virtual memory block based on the backup file allocation table if the first storage space is not applied for from the virtual memory; the recovery unit is used to reclaim the reclaimable historical virtual memory block if it exists, and release the named memory mapping corresponding to the reclaimable historical virtual memory block; the determination unit is used to apply for a second storage space from the virtual memory after the recovery is completed, and return the address of the second storage space as the address of the first parameter of the first backup file block to the user program; the second storage space is used to store the value of the first parameter of the first backup file block; and the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0045] In a possible implementation method, the trigger unit is used to trigger a backup memory mapping release request; the backup memory mapping release request is used to request the release of the virtual memory block mapped to the second backup file block; the determination unit is used to determine the starting address of the virtual memory block corresponding to the second backup file block according to the second parameter in the backup memory mapping release request; determine the size of the second backup file block from the backup file allocation table according to the second parameter in the backup memory mapping release request; pass the starting address of the virtual memory block corresponding to the second backup file block and the size of the second backup file block to the kernel, and cancel the named memory mapping through the kernel; after receiving the indication information sent by the kernel that the named memory mapping is successfully canceled, update the value of the first parameter corresponding to the second backup file block.

[0046] In a possible implementation method, the determining unit is configured to trigger a backup memory allocation request when determining that a memory access requirement of a user program meets a set condition.

[0047] In a possible implementation method, the above-mentioned device further includes an access unit, and the access unit is used to access data in the first backup file block through a named memory mapping between the first backup file block and the free virtual memory block.

[0048] In a possible implementation method, the determining unit is configured to set a lock flag for the virtual memory block corresponding to the first backup file block according to a first parameter.

[0049] In a possible implementation method, the determining unit is configured to: provide a first parameter storage area in the virtual memory; store multiple values ​​of first parameters in the first parameter storage area; and apply to the first parameter storage area for allocation of first storage space.

[0050] In a possible implementation method, the determining unit is configured to return a memory exhaustion indication to the user program if the application for allocating the first storage space from the first parameter storage area is unsuccessful.

[0051] In one possible implementation method, a backup memory mapping area is provided in the virtual memory; the backup file mapping area contains the virtual memory blocks to which the backup file blocks recorded in the backup file allocation table are mapped; and the judgment unit is used to judge whether there is a free virtual memory block that meets the size of the first backup file block in the backup file mapping area through the backup file allocation table.

[0052] In a possible implementation method, a backup memory mapping area is provided in the virtual memory; the determining unit is used to defragment the fragments in the backup memory mapping area if there are no free virtual memory blocks that meet the first backup file block size in the backup memory mapping area after recovery; the judging unit is used to judge whether there are free virtual memory blocks that meet the first backup file block size in the backup memory mapping area after recovery and defragmentation; if so, the determining unit is used to use the starting address of the free virtual memory block that meets the first backup file block size in the backup memory mapping area as the value of the first parameter, store the first parameter, and establish a named memory mapping between the first backup file block and the free virtual memory block through the kernel.

[0053] In a possible implementation method, the determining unit is configured to update the value of the first parameter corresponding to each historical backup file block according to the defragmented virtual memory.

[0054] In one possible implementation method, the recycling unit is used to defragment the fragments in the backup file if there is no continuous area in the backup file that meets the memory request size; the judgment unit is used to judge whether the backup file after defragmentation meets the continuous area of ​​the memory request size; if not, return a backup file exhaustion indication to the user program.

[0055] In a third aspect, an embodiment of the present application further provides a computing device, including:

[0056] a memory for storing program instructions;

[0057] The processor is configured to call the program instructions stored in the memory and execute any method for implementing the first aspect according to the obtained program instructions.

[0058] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which computer-readable instructions are stored. When a computer reads and executes the computer-readable instructions, any method of the above-mentioned first aspect is implemented.

[0059] In a fifth aspect, an embodiment of the present application provides a computer program product, comprising a computer program executable by a computer device, wherein when the program is run on the computer device, the computer device executes any method for implementing the above-mentioned first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0060] Figure 1 A flowchart of a method for establishing a mapping relationship between a backup file and virtual memory provided in an embodiment of the present application;

[0061] Figure 2 A flowchart of a method for processing a backup memory allocation request provided in an embodiment of the present application;

[0062] Figure 3 A flowchart of a method for processing a backup memory mapping release request provided in an embodiment of the present application;

[0063] Figure 4 A schematic diagram of the structure of a virtual memory provided in an embodiment of the present application;

[0064] Figure 5 A schematic diagram of the structure of a virtual memory provided in an embodiment of the present application;

[0065] Figure 6 A schematic diagram of the structure of a virtual memory provided in an embodiment of the present application;

[0066] Figure 7 A flowchart of a method for processing a backup memory allocation request provided in an embodiment of the present application;

[0067] Figure 8 A flowchart of a method for processing a backup memory mapping establishment request provided in an embodiment of the present application;

[0068] Figure 9 A flowchart of a method for processing a backup memory mapping reclaim request provided in an embodiment of the present application;

[0069] Figure 10 A flowchart of a method for processing a backup memory mapping release request provided in an embodiment of the present application;

[0070] Figure 11 A schematic diagram of the structure of a virtual memory provided in an embodiment of the present application;

[0071] Figure 12 A schematic diagram of the structure of a virtual memory provided in an embodiment of the present application;

[0072] Figure 13A flowchart of a method for processing a backup memory allocation request provided in an embodiment of the present application;

[0073] Figure 14 A flowchart of a method for processing a backup memory mapping establishment request provided in an embodiment of the present application;

[0074] Figure 15 A flowchart of a method for processing a backup memory mapping reclaim request provided in an embodiment of the present application;

[0075] FIG16( a ) and FIG16 ( b ) are flowcharts of a method for allocating backup memory for a non-leaf function according to an embodiment of the present application;

[0076] Figure 17 A flowchart of a method for allocating backup memory for a non-leaf function provided in an embodiment of the present application;

[0077] Figure 18 A flowchart of a method for allocating backup memory for a non-leaf function provided in an embodiment of the present application;

[0078] Figure 19 A flowchart of a method for processing a backup memory mapping lock request provided in an embodiment of the present application;

[0079] Figure 20 A flowchart of a method for processing a backup memory mapping resolution request provided in an embodiment of the present application;

[0080] Figure 21 A schematic diagram of the structure of a device for establishing a mapping relationship between a backup file and a virtual memory provided in an embodiment of the present application;

[0081] Figure 22 A schematic diagram of the structure of a device for establishing a mapping relationship between a backup file and a virtual memory provided in an embodiment of the present application. DETAILED DESCRIPTION

[0082] Figure 1 This is a flow chart of a method for establishing a mapping relationship between a backup file and virtual memory, provided in an embodiment of the present application. This method can be performed by an apparatus for establishing a mapping relationship between a backup file and virtual memory. The apparatus for establishing a mapping relationship between a backup file and virtual memory can be a terminal device or a module for a terminal device, or a server or a module for a server. This application does not limit the execution entity of this method.

[0083] The method comprises the following steps:

[0084] Step 101: triggering a backup memory mapping establishment request for a first backup file block.

[0085] Among them, the backup file is any file that can be mounted on the file system; the first backup file block is a continuous area in the backup file; the backup memory mapping refers to a named memory mapping between the backup file block and the virtual memory block; the backup memory mapping establishment request is used to establish a named memory mapping between the backup file block and the virtual memory block.

[0086] In one possible implementation method, the named memory mapping is a function provided by the operating system kernel, which can map a block in a file to a virtual memory block, so that accessing the virtual memory block is equivalent to indirectly accessing the block in the file.

[0087] Step 102: Determine the size of the first backup file block from a backup file allocation table according to a second parameter in the backup memory mapping establishment request.

[0088] The second parameter is used to indicate the address of the first parameter of the first backup file block; the value of the first parameter is used to indicate the starting address on the virtual memory to which the first backup file block is mapped by the named memory mapping; the backup file allocation table includes the address of the first parameter and the size of the first backup file block.

[0089] In one possible implementation method, the backup file allocation table is stored in a user program; in addition to including the address of the first parameter and the size of the first backup file block, the backup file allocation table may also include the offset address of the first backup file block in the backup file. This application does not limit the content stored in the backup file allocation table.

[0090] In one possible implementation, a check is performed to determine whether the address in the backup file allocation table is the same as the second parameter. If so, the size of the first backup file block corresponding to the second parameter is searched in the backup file allocation table. If not, a memory exception indication is returned to the user program.

[0091] In a possible implementation method, before receiving the backup memory mapping establishment request of the first backup file block, the value of the first parameter of the first backup file block is empty.

[0092] Step 103: Determine whether there is a free virtual memory block in the virtual memory that meets the first backup file block size.

[0093] In a possible implementation method, the free virtual memory block is a free continuous area in the virtual memory.

[0094] Step 104: If not, determine whether there is a reclaimable historical virtual memory block according to the backup file allocation table.

[0095] In one possible implementation method, the backup file allocation table is traversed to determine the address of the first parameter corresponding to the historical backup file block; the value of the first parameter corresponding to the historical backup file block is determined based on the address of the first parameter corresponding to the historical backup file block; if the value of the first parameter corresponding to the historical backup file block is not empty, and the historical virtual memory block indicated by the first parameter corresponding to the historical backup file block is not locked, then the historical virtual memory block is determined to be a reclaimable historical virtual memory block. In this solution, the backup file allocation table and the first parameter record the information of the historical virtual memory block. Using this method, it is possible to accurately and effectively determine which historical virtual memory blocks are reclaimable.

[0096] In a possible implementation method, the first parameter is a non-null value, indicating that the backup memory mapping has been established for the historical backup file block.

[0097] Step 105: If the reclaimable historical virtual memory block exists, reclaim the reclaimable historical virtual memory block and release the named memory mapping corresponding to the reclaimable historical virtual memory block.

[0098] Step 106 , determining whether there is a free virtual memory block that meets the first backup file block size in the virtual memory after the recovery is completed.

[0099] In a possible implementation method, the virtual memory after the recovery is completed includes the free virtual memory blocks that do not meet the first backup file block size in step 103 and the recovered historical virtual memory blocks.

[0100] Step 107: Use the starting address of the free virtual memory block that meets the first backup file block size as the value of the first parameter, store the first parameter, and establish a named memory mapping between the first backup file block and the free virtual memory block through the kernel.

[0101] In a possible implementation method, the value of the first parameter is stored in the address where the first parameter is located.

[0102] In one possible implementation method, if the virtual memory after recovery is larger than the size of the first backup file block, a first virtual memory block is selected from the virtual memory after recovery, the starting address of the first virtual memory block is used as the value of the first parameter, the first parameter is stored, and a named memory mapping between the first backup file block and the first virtual memory block is established through the kernel; the size of the first virtual memory block is equal to the first backup file block size and is less than or equal to the virtual memory after recovery. This solution selects part of the virtual memory from the virtual memory after recovery to establish a named memory mapping with the first backup file area, which not only meets the requirements of the first backup file area, but also allows the remaining virtual memory blocks to be used by subsequent user programs.

[0103] In one possible implementation, after the kernel establishes a named memory mapping between the first backup file block and the free virtual memory block, the method further includes: accessing data in the first backup file block through the named memory mapping between the first backup file block and the free virtual memory block. This solution enables accurate and efficient access to data in the first backup file block.

[0104] In one possible implementation method, before accessing the first backup file block, the method further includes: setting a lock flag on the virtual memory block corresponding to the first backup file block based on a first parameter. The lock flag is used to indicate that the virtual memory block corresponding to the first backup file block is currently unreclaimable.

[0105] In the above scheme, when there are no free virtual memory blocks in the virtual memory that meet the first backup file block size, reclaimable historical virtual memory blocks are recycled, so that the current free virtual memory blocks meet the needs of the user program. This application uses a time-division multiplexing method to reclaim reclaimable historical virtual memory blocks, expand the size of the virtual memory, and ensure the smooth execution of the user program.

[0106] The following describes the contents of the backup file.

[0107] A backup file is any file that can be mounted on a file system, such as a file on a physical disk, a file on a memory disk, or a file on a network file system. The backup memory mappings in this application are all based on named mmap (named file mapping, or named memory mapping); wherein, establishing a file mapping as a named memory mapping through mmap() is to map a certain virtual memory area in the process virtual memory space to a certain area in a file on disk: once the named memory mapping is established, the read (or write) operations on the virtual memory area in the process virtual memory space will be synchronized to the corresponding area of ​​the file on disk. In other words, accessing the virtual memory area in the process virtual memory space is equivalent to accessing the corresponding area of ​​the file on disk.

[0108] Taking the disk as an example, after opening the file to obtain the file descriptor, you can pass it to mmap() along with the appropriate parameters to establish file mapping for them.

[0109] Taking the memory disk as an example, common implementations of the memory disk include the tmpfs and ramfs file systems provided by the Linux kernel. After a general Linux distribution is started, at least one memory disk, such as / dev / shm, will be mounted. The common implementation of the memory disk is to divide a fixed or dynamic size area on the physical or virtual memory, and then treat it as equivalent to a disk for reading and writing. This embodiment is very useful when there is sufficient physical memory but it is limited by the size of the user space and all physical memory cannot be utilized. The operating system has provided a unified file system interface to the upper level, and the user program does not need to understand the underlying details of the memory disk. Therefore, for the user program, reading and writing files on the memory disk is no different from reading and writing files on the file system on the disk. Once the memory disk already exists, the process of establishing file mappings for the files therein is no different from the process of establishing file mappings for files on the disk.

[0110] Take the network file system, for example. A network file system is a way to mount a file system over a network. All files reside on the peer machine on the network. All local operations on the network file system are transmitted back to the peer machine over the network, or data is retrieved from the peer machine. The operating system provides a unified file system interface, and user programs do not need to understand the underlying details of the network file system. Therefore, for user programs, reading and writing files on a network file system is no different from reading and writing files on a disk file system. Once a network file system is mounted, the process of establishing file mappings for the files is no different from establishing file mappings for files on disk.

[0111] The following introduces the backup file allocation table in one of its forms.

[0112] The so-called backup file allocation table is a table that records the information of the backup memory allocation itself and its corresponding specific location on the backup file.

[0113] The backup file allocation table can be stored in the computer in the form of an array, a linked list, a tree, a stack, a heap, a queue, a graph, a hash table, etc., which is not limited here.

[0114] In a possible implementation method, the backup file allocation table is shown in Table 1.

[0115] Table 1

[0116]

[0117] The address of the first parameter. Each backup file block must correspond to a first parameter. Regardless of whether the corresponding backup memory mapping has been established, once a backup file block is allocated, a unique first parameter should be assigned to it. After the first parameter is assigned, the address of the first parameter should also be written into the backup file allocation table. In this way, given the address of the first parameter, it is possible to determine whether the first parameter has been used by a backup file block by searching the backup file allocation table; or, if the first parameter has been used by a backup file block, the size of the backup file block and its offset address in the backup file can be determined.

[0118] The offset address of the backup file block in the backup file is actually the position of the backup file block in the backup file. After the first backup file block is allocated, the address (or offset) of the first backup file block in the backup file should be written into the backup file allocation table.

[0119] The size of the backup file block may be different for each backup file block. Therefore, after the first backup file block is allocated, the size of the first backup file block should be written into the backup file allocation table.

[0120] In one possible implementation, the backup file allocation table may include, in addition to the address of the first parameter, the offset address of the backup file block in the backup file, and the size of the backup file block, one or more of the following: a backup file identifier and the value of the first parameter. This application does not limit the content of the backup file allocation table.

[0121] Backup file identification. Sometimes you may want to use multiple backup files at the same time. At this time, you need to be able to identify which backup file a backup file block is on. Therefore, you can write the backup file identification into the backup file allocation table.

[0122] Optionally, the above problem can be solved by establishing multiple backup file allocation tables, each of which corresponds to a backup file; the above problem can also be solved by using non-overlapping backup file addresses for different backup files, which is not limited in this application.

[0123] The value of the first parameter, ie, the starting address of the virtual memory block in the virtual memory that has a mapping relationship with the first backup file block, can be directly obtained from the backup file allocation table.

[0124] In one possible implementation, a first parameter storage area is set up in virtual memory. The first parameters are then aggregated into a single virtual memory area, so the highest bits of the addresses of the first parameters may be identical. For example, if the first parameter storage area is placed in virtual memory numbered 0x6F000000-0x6FFFFFFF, all first parameter addresses will satisfy the pattern 0x6F****** and thus share a common prefix of 0x6F. This common prefix can then be stored elsewhere, allowing the common prefix to be omitted from the backup file allocation table, saving space. The backup file allocation table is shown in Table 2.

[0125] Table 2

[0126]

[0127] In a possible implementation method, a backup memory mapping area is set in the virtual memory, and the backup file allocation table includes the value of the first parameter. Then, according to the above method, the common prefix of the value of the first parameter can be omitted.

[0128] In one embodiment, before step 101, the method further includes triggering a backup memory allocation request for the first backup file block. Figure 2 As shown, the following steps are included:

[0129] Step 201: triggering a backup memory allocation request for the first backup file block.

[0130] The backup memory allocation request includes a memory request size.

[0131] In one possible implementation, lazy allocation of backup memory mapping is used. When a user program triggers a backup memory allocation request, named memory mappings for the virtual memory blocks and backup file blocks are not actually created. Only when the user program actually needs to access the newly requested backup file block will a request to create a named memory mapping for the virtual memory blocks and backup file blocks be made (i.e., the backup memory mapping creation request for the first backup file block in this application). In this way, even if the user program requests more backup file blocks than it needs, some of these requested backup file blocks may not be actually used until the program exits, and unnecessary named memory mappings will not be created, thus avoiding impacts on performance and robustness.

[0132] In a possible implementation method, when it is determined that the memory access requirements of the user program meet the set conditions, a backup memory allocation request is triggered. The set conditions include one or more of the following: the memory access life cycle is less than the first threshold, the memory request size is greater than the second threshold, the speed requirement for accessing the memory is less than the third threshold, and the single use cycle is less than the fourth threshold. This application does not limit the size of the first threshold, the second threshold, the third threshold and the fourth threshold. In general, the establishment of the backup memory mapping of this application is mainly aimed at target user programs with a short memory access life cycle, a large memory request size, low speed requirement for accessing the memory or a short single use cycle. This solution can share most of the pressure of the virtual memory and reduce the possibility of virtual memory exhaustion by establishing a backup file mapping; at the same time, ordinary memory allocation can still be used for performance-sensitive memory allocation, and the user program can still guarantee higher performance.

[0133] Step 202: Determine whether there is a continuous area in the backup file that meets the memory request size.

[0134] Step 203: If it exists, determine the continuous area in the backup file that meets the memory request size as the first backup file block, apply for a first storage space from the virtual memory, and return the address of the first storage space as the address of the first parameter of the first backup file block to the user program.

[0135] The first storage space is used to store a value of a first parameter of the first backup file block.

[0136] In a possible implementation method, if the first storage space is not applied for from the virtual memory, it is determined whether there is a reclaimable historical virtual memory block based on the backup file allocation table; if the reclaimable historical virtual memory block exists, the reclaimable historical virtual memory block is reclaimed, and the named memory mapping corresponding to the reclaimable historical virtual memory block is released; a second storage space is applied for from the virtual memory after the recovery is completed, and the address of the second storage space is returned to the user program as the address of the first parameter of the first backup file block; the second storage space is used to store the value of the first parameter of the first backup file block; the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0137] In a possible implementation method, the value of the first parameter is set to empty.

[0138] Step 204 : Add the address of the first parameter of the first backup file block and the memory request size to the backup file allocation table.

[0139] In one possible implementation method, an entry is added to the backup file block allocation record, the entry content being the address of the first parameter corresponding to the first backup file block, the offset address of the first backup file block in the backup file, and the memory request size; the address of the first parameter corresponding to the first backup file is, that is, the address of the first storage space.

[0140] The above scheme can accurately and effectively determine the addresses of the first backup file block and the first parameter; and the scheme does not actually establish a naming mapping relationship between the first backup file block and the virtual memory block, that is, the virtual memory block is not occupied at this time. When the user program really needs to access the backup file block just applied for, it will request to establish a naming memory mapping between the virtual memory block and the backup file block. Therefore, it can reduce the possibility of virtual memory exhaustion and improve the success rate of smooth execution of user programs.

[0141] In one possible implementation method, in the above step 203, if there is no continuous area in the backup file that meets the memory request size, the fragments in the backup file are defragmented, and it is determined whether the backup file after defragmentation meets the continuous area of ​​the memory request size; if not, a backup file exhaustion indication is returned to the user program.

[0142] In one possible implementation method, if the defragmented backup file contains a continuous area that satisfies the memory request size, the continuous area in the defragmented backup file that satisfies the memory request size is determined as the first backup file block, a third storage space is requested from the virtual memory, and the address of the third storage space is returned to the user program as the address of the first parameter of the first backup file block. The address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0143] In one possible implementation, when the backup file is subsequently defragmented, the addresses and lengths of the different backup file blocks are analyzed according to the backup file allocation table to determine how to move the backup file blocks. After the backup file blocks are moved, the addresses and lengths of the different backup file blocks in the backup file allocation table are updated.

[0144] In one possible implementation method, after the backup file block is moved, the first parameter corresponding to the backup file block is queried, and based on the value of the first parameter, it is determined whether there is a corresponding backup memory mapping (i.e., the named memory mapping of the backup file block and the virtual memory block) for the backup file block. If so, the backup memory mapping corresponding to the backup file block is re-established, or the backup memory mapping corresponding to the backup file block is recovered.

[0145] In one possible implementation method, after re-establishing the backup memory mapping corresponding to the backup file block or reclaiming the backup memory mapping corresponding to the backup file block, the value of the first parameter of the corresponding backup file block is updated for the re-established or reclaimed backup memory mapping. Exemplarily, if the backup memory mapping is re-established, the value of the first parameter of the corresponding backup file block is updated to the starting address of the new virtual memory block to which it corresponds. Exemplarily, if the backup memory mapping is reclaimed, the value of the first parameter of the corresponding backup file block is updated to a value indicating that there is no corresponding backup memory mapping for the backup file block, such as a null value.

[0146] In one possible implementation method, when establishing a backup memory mapping, the length of the backup file block and its address in the backup file are used as parameters of the mmap() system call to represent the file segment to be mapped to ensure the correct establishment of the backup memory mapping.

[0147] In a possible implementation method, when performing the backup memory mapping recovery, the value of the first parameter and the length of the backup file block are used as parameters of the munmap() system call.

[0148] In a possible implementation method, when performing backup memory map defragmentation, it involves re-establishing the backup memory map window, and using the value of the first parameter and the length of the backup file block as parameters for the mremap() system call.

[0149] In one embodiment, after the above step 107, the method further includes triggering a backup memory mapping release request. Figure 3 As shown, the following steps are included:

[0150] Step 301: triggering a backup memory mapping release request.

[0151] The backup memory mapping release request is used to request the release of the virtual memory block to which the second backup file block is mapped.

[0152] In a possible implementation method, after the execution of the user program ends or after receiving the backup memory mapping release indication information, the backup memory mapping release request is triggered.

[0153] Step 302: Determine the starting address of the virtual memory block corresponding to the second backup file block according to the second parameter in the backup memory mapping release request.

[0154] In one possible implementation method, the backup memory mapping release request includes a second parameter, the address of the first parameter is determined based on the second parameter, a first storage space on the virtual memory is determined based on the address of the first parameter, and a value of the first parameter is determined based on the first storage space, where the value of the first parameter corresponds to the starting address of the virtual memory block corresponding to the second backup file block. The first storage space is used to store the value of the first parameter of the first backup file block.

[0155] Step 303: Determine the size of the second backup file block from the backup file allocation table according to the second parameter in the backup memory mapping release request.

[0156] In a possible implementation method, the backup file allocation table is queried according to the second parameter, and the size of the second backup file block is determined from the backup file allocation table.

[0157] In a possible implementation method, the address of the first parameter is determined according to the second parameter, the backup file allocation table is queried according to the address of the first parameter, and the size of the second backup file block is determined from the backup file allocation table.

[0158] Step 304: The starting address of the virtual memory block corresponding to the second backup file block and the size of the second backup file block are transmitted to the kernel, and the kernel cancels the named memory mapping.

[0159] Step 305: After receiving the indication information sent by the kernel that the named memory mapping is successfully cancelled, update the value of the first parameter corresponding to the second backup file block.

[0160] The above solution can accurately and effectively release the backup memory mapping.

[0161] In one possible implementation method, virtual memory includes user space and kernel space, where user space can be divided into stack area, file mapping area, heap area and other partitions, such as Figure 4 This application sets a first parameter storage area and a backup memory mapping area in the file mapping area and / or the heap area, as shown. Figure 5 As shown. Among them, the pointer storage area is the first parameter storage area, and the conventional use area, that is, the area in the file mapping area and the heap area except the first parameter storage area and the backup memory mapping area, can be used for normal memory allocation. The secondary pointer is the second parameter, and the primary pointer is the first parameter. The backup memory mapping area includes multiple mapping windows, each mapping window corresponds to a virtual memory block, and there is a named memory mapping between the virtual memory block and the backup file block. Exemplarily, the value stored in the secondary pointer is the address of the primary pointer, and the address of the primary pointer can be determined through the secondary pointer. The value stored in the primary pointer is the starting address of the mapping window, and the mapping window can be determined through the primary pointer. All data in the mapping window is equivalent to all data in the backup file block, and the data block in the mapping window is equivalent to the data block in the backup file block.

[0162] In one embodiment, the virtual memory does not include the first parameter storage area and the backup memory mapping area. The virtual memory is divided as follows: Figure 6 As shown, the first-level pointers and mapping windows are randomly allocated in the mixed-use area.

[0163] In one embodiment, the specific implementation method for the backup memory allocation request for the first backup file block is as follows: Figure 7 As shown, the process includes the following steps:

[0164] Step 701: triggering a backup memory allocation request for a first backup file block.

[0165] The backup memory allocation request includes a memory request size.

[0166] In one possible implementation, the user program requests allocation of a backing file memory segment of a specific size.

[0167] Step 702: query the backup file allocation table to determine whether there is a continuous area in the backup file that is larger than the required memory.

[0168] In a possible implementation method, if the backup file has such a continuous area, step 705 is executed; if the backup file has such a continuous area, step 703 is executed.

[0169] Step 703: Determine whether the total remaining space of the backup file meets the memory request size.

[0170] In one possible implementation method, if the total remaining space of the backup file does not meet the memory request size, a backup file exhaustion indication is returned to the user program; if the total remaining space of the backup file meets the memory request size, step 704 is executed.

[0171] Step 704: tidy up the fragments in the backup file.

[0172] In one possible implementation method, if the defragmented backup file meets the memory request size, step 705 is executed; if the defragmented backup file does not meet the memory request size, a backup file exhaustion indication is returned to the user program.

[0173] Step 705: Apply for a first storage space from the virtual memory.

[0174] In one possible implementation method, a block of memory no smaller than the size required to store a pointer is requested from the virtual memory and used as a first-level pointer, that is, the first parameter.

[0175] In one possible implementation method, if the application is successful, execute step 707; if the application is unsuccessful, execute step 706.

[0176] Step 706: Reclaim the backup memory mapping.

[0177] In a possible implementation method, if the backup memory mapping is successfully reclaimed and the reclaimed virtual memory block meets the memory request size, step 705 is re-executed to apply for the first storage space from the virtual memory.

[0178] In a possible implementation method, if the application for the first storage space from the virtual memory fails again, a backup file exhaustion indication is returned to the user program.

[0179] In one possible implementation method, if the backing memory mapping recovery fails, a backing file exhaustion indication is returned to the user program.

[0180] Step 707: Modify the backup file allocation table.

[0181] In one possible implementation, modifying the backup file allocation table is not limited to adding the address of the first parameter of the first backup file block and the memory request size in the backup file allocation table, but also includes deleting information corresponding to recycled backup file blocks or updating information corresponding to defragmented backup file blocks from the backup file allocation table. Both of these have been described above and will not be repeated in this application. Modifying the backup file allocation table enables it to reflect the status after the current allocation.

[0182] Step 708: Return the second parameter to the user program.

[0183] In one possible implementation method, lazy allocation is adopted, that is, when the user program uses the current backup memory mapping, a backup memory mapping establishment request is triggered.

[0184] In another possible implementation method, active allocation is adopted, that is, a backup memory mapping establishment request is triggered immediately.

[0185] In a possible implementation method, a second parameter is returned to the user program, where the second parameter is used to indicate the address where the first parameter is located.

[0186] In one embodiment, the specific implementation method for establishing the backup memory mapping request for the first backup file block is as follows: Figure 8 As shown, the process includes the following steps:

[0187] Step 801: triggering a backup memory mapping establishment request for a first backup file block.

[0188] In one possible implementation method, the backup memory mapping establishment request includes a second parameter, the first parameter is determined based on the second parameter, and it is determined whether the value of the first parameter is empty. If it is not empty, an indication of successful backup memory mapping establishment is returned to the user program; if it is empty, step 802 is executed.

[0189] Step 802: query the backup file allocation table to determine the first backup file block corresponding to the second parameter.

[0190] In a possible implementation method, according to the second parameter, the backup file allocation table is queried to determine the backup file, the offset of the first backup file block, and the size of the first backup file block, that is, the mapping length.

[0191] Step 803: Request the kernel to establish a named memory mapping between the first backup file block and the virtual memory block.

[0192] In one possible implementation method, the first attempt is to request the kernel to establish a named memory mapping between the first backup file block and the virtual memory block; if the first attempt request is successful, it means that there is a free virtual memory block in the virtual memory, and step 805 is executed; if the first attempt request fails, it means that there is no free virtual memory block in the virtual memory, and step 804 is executed.

[0193] In one possible implementation method, the kernel uses a memory mapping mmap() system call processing function to establish a named memory mapping between the first backup file block and the virtual memory block based on the backup file, the offset of the first backup file block, and the size of the first backup file block.

[0194] In one possible implementation, if the kernel cannot establish a named memory mapping between the first backup file block and the virtual memory block, a named memory mapping establishment failure indication message is returned. Upon receiving the indication message, the backup memory mapping establishment request processing function returns the backup memory mapping establishment failure indication message to the user program.

[0195] In one possible implementation method, if the kernel successfully establishes a named memory mapping between the first backup file block and the virtual memory block, step 805 is executed.

[0196] Step 804: reclaim the backup memory mapping.

[0197] In a possible implementation method, if the recycling fails, a backup memory mapping establishment failure indication message is returned to the user program.

[0198] In a possible implementation method, if the recycling is successful, step 803 is executed again to request the kernel to establish a named memory mapping between the first backup file block and the virtual memory block. If the request is successful, step 805 is executed.

[0199] Step 805: Obtain the starting address of the first mapping window selected by the kernel from the return value of the system call.

[0200] Step 806: Modify the value of the first parameter to the starting address of the first mapping window.

[0201] Step 807: Return the starting address of the first mapping window to the user program.

[0202] In one embodiment, in the above step 707 and the above step 804, the method for recycling the backup memory mapping is as follows: Figure 9 As shown, the method includes the following steps:

[0203] Step 901: trigger a backup memory mapping reclaim request.

[0204] Step 902: query the backup file allocation table to obtain a backup memory mapping that has been established but not locked.

[0205] Step 903: Analyze the sizes of these backup memory mappings and plan reclaimable mapping windows based on the memory request size.

[0206] Step 904 : If the reclaimable mapping window is reclaimed, it is determined whether the free virtual memory after the reclaiming satisfies the memory request size.

[0207] In a possible implementation method, if the free virtual memory after being reclaimed meets the memory request size, step 905 is executed; if the free virtual memory after being reclaimed does not meet the memory request size, memory exhaustion indication information is returned to the user program.

[0208] Step 905: reclaim the backup memory mapping corresponding to the reclaimable mapping window.

[0209] In a possible implementation method, the starting address and the size of the recyclable mapping window are sent to the kernel as parameters, and the kernel calls the munmap() system call processing function to cancel the memory mapping and recycle the corresponding mapping window.

[0210] In one possible implementation method, if there are multiple mapping windows that need to be reclaimed, the memory mapping cancellation munmap() system call processing function needs to be called multiple times.

[0211] In a possible implementation method, if the backup memory mapping is reclaimed successfully, step 906 is executed; if the backup memory mapping is reclaimed unsuccessfully, an indication of the backup memory mapping reclaim failure is returned to the user program.

[0212] Step 906: Modify the value of the first parameter corresponding to the recovered mapping window to be empty.

[0213] In one possible implementation method, an indication of successful recycling is returned to the user program.

[0214] In one embodiment, the method for triggering the backup memory mapping release request is as follows: Figure 10 As shown, the method includes the following steps:

[0215] Step 1001: trigger a backup memory mapping release request.

[0216] In a possible implementation method, the backup memory mapping release request includes a second parameter, and the value of the first parameter is determined according to the second parameter.

[0217] Step 1002: Determine whether the value of the first parameter is empty.

[0218] In a possible implementation method, if the value of the first parameter is empty, an indication that the backup memory mapping is released successfully is returned to the user program; if the value of the first parameter is not empty, step 1003 is executed.

[0219] Step 1003: query the backup file allocation table and determine the size of the second backup file block according to the second parameter.

[0220] Step 1004: Send the value of the first parameter and the size of the second backup file block to the kernel.

[0221] Step 1005: The kernel cancels the backup memory mapping corresponding to the second backup file block.

[0222] In a possible implementation method, the kernel receives the value of the first parameter and the size of the second backup file block, and cancels the backup memory mapping corresponding to the second backup file block using a munmap() system call processing function.

[0223] In a possible implementation method, if the kernel successfully cancels the backup memory mapping corresponding to the second backup file block, step 1006 is executed; otherwise, an indication that the backup memory mapping cancellation fails is returned to the user program.

[0224] Step 1006: Update the value of the first parameter corresponding to the second backup file block.

[0225] In a possible implementation method, an indication that the backup memory mapping is successfully cancelled is returned to the user program.

[0226] In one embodiment, the virtual memory includes the first parameter storage area but does not include the backup memory mapping area. The virtual memory is divided as follows: Figure 11 As shown. A first parameter storage area, i.e., a pointer storage area, is provided in the virtual memory; the first parameter storage area stores the values ​​of multiple first parameters, i.e., the values ​​of multiple first-level pointers. The mapping window is stored in the mixed use area. This solution, on the one hand, stores the first parameters in one place, so that memory fragmentation will not be formed due to the scattered allocation of the first parameters, and avoids as much as possible the problem of insufficient continuous free space when needed due to discontinuous free space; on the other hand, the first parameters are stored in one place, and the memory space required for the first parameters does not need to be obtained through ordinary memory allocation every time; on the other hand, when recording the address of the first parameter in the backup file allocation table, since the first parameters are concentrated in the first parameter storage area, such addresses will have a common prefix. Therefore, there is no need to record this common prefix, thereby saving storage space for the backup file allocation table.

[0227] In one possible implementation, where the virtual memory includes the first parameter storage area but does not include the backup memory mapping area, the backup memory mapping establishment request is the same as steps 801 to 808 described above, and the backup memory mapping reclaim request is the same as steps 901 to 906 described above, and will not be further described. The backup memory allocation request and the backup memory mapping release request are the same as those for the case where the virtual memory includes the first parameter storage area and the backup memory mapping area, and will be described together in the following embodiments.

[0228] In one embodiment, the virtual memory does not include the first parameter storage area, but includes a backup memory mapping area. The virtual memory is divided as follows: Figure 12 As shown in the figure. This solution, on the one hand, ensures that ordinary memory allocation does not excessively occupy the heap / file mapping area by presetting the backup file mapping area. Therefore, when the user space is under great pressure (that is, when the user space is about to be full), there is still enough memory area to safely establish the backup memory mapping. On the other hand, the backup memory mapping windows are centralized and managed in one place, so that when necessary, they can be defragmented to free up the small free spaces between the mapping windows to form a new large continuous free space.

[0229] In one possible implementation, if the virtual memory does not include the first parameter storage area but includes a backup memory mapping area, the backup memory mapping release request is the same as steps 1001 to 1006 described above and will not be described in detail here. The backup memory mapping establishment request and the backup memory mapping reclaim request are the same as those for the case where the virtual memory includes both the first parameter storage area and the backup memory mapping area and will be described together in the following embodiments.

[0230] In one possible implementation method, the method for requesting backup memory allocation is similar to steps 701 to 708 above, but does not include step 706, in which the backup memory mapping is recycled. This is because, in this embodiment, a backup memory mapping area is set in the virtual memory, while the allocation of the first parameter, i.e., the first-level pointer, adopts ordinary memory allocation. When step 705 fails to apply to the virtual memory for a memory size not less than that required to store a pointer as the first-level pointer, it indicates that the mixed-use area is exhausted. Even if the backup memory mapping area is recycled, the backup memory mapping area cannot be allocated for use with the first parameter. Therefore, when step 705 fails to apply to the virtual memory for the first storage space, an indication of backup file exhaustion is returned to the user program.

[0231] In one embodiment, the virtual memory includes a first parameter storage area and a backup memory mapping area. The virtual memory is divided as follows: Figure 5 shown.

[0232] This application does not have any strict requirements on the location or order of virtual memory partitions. Figure 5 As can be seen from the partitioning of the user space, space needs to be reserved for the pointer storage area and the backup memory mapping area.

[0233] The pointer storage area stores a first-level pointer, which can be either null or non-null. When non-null, it points to a mapping window in the backup memory mapping area. The pointer storage area can be likened to a drawer. Some drawers are empty, meaning their first-level pointer is null (NULL); while others are non-null and contain an address that records the starting address of the corresponding mapping window. Dereferencing allows access to the corresponding mapping window.

[0234] The backup memory mapping area can contain multiple mapping windows corresponding to different areas of the same backup file, multiple mapping windows corresponding to multiple backup files, or multiple mapping windows corresponding to partial mappings of a single backup file, etc. This application does not impose any restrictions on this. The backup memory mapping is actually a file mapping (named memory mapping) established for the backup file. Once the backup memory mapping is established, the file contents can be accessed just like accessing memory. Data can be read or written using first-level pointers, just like operating on ordinary memory.

[0235] These partitions are virtual, they are not necessarily continuous, and the location relationship is not necessarily as Figure 5 、 6 , 11, and 12, and this application does not limit this.

[0236] In one possible implementation method, the above partitions are reserved as follows:

[0237] 1. When the user program starts, it allocates a memory area through malloc() (or directly uses mmap() to allocate an anonymous mapping) as a pointer storage area, and then holds and uses the area.

[0238] 2. When the user program starts, a memory area is allocated through malloc() (or mmap() is used to allocate an anonymous mapping) as a backup memory mapping area, and then the area is held but not used directly. When a backup memory mapping needs to be established, it is only necessary to bring the target mapping window start address when calling mmap(), and at the same time bring the flag MAP_FIXED to require the kernel to establish the backup memory mapping on the specified address. At this time, the kernel will automatically revoke the overlapping part from the mapping previously established for reserving the backup memory area (note that only the overlapping part will be revoked, and the non-overlapping part will be retained, so the other reserved parts will still be reserved), and then establish the backup memory mapping.

[0239] 3. The regular use area is provided for regular malloc() use and does not require any special processing or reservation.

[0240] In one embodiment, the specific implementation method for the backup memory allocation request for the first backup file block is as follows: Figure 13 As shown, the process includes the following steps:

[0241] Step 1301: trigger a backup memory allocation request for a first backup file block.

[0242] Step 1302: Determine whether there is an idle pointer in the first parameter storage area.

[0243] In one possible implementation, when a user program requests a specific size of back file memory, i.e., when a back file allocation request is made, the first parameter storage area is checked to see if it is fully allocated. If the first parameter storage area is full, i.e., there are no free pointers in the first parameter storage area, the secondary pointer is set to a null pointer and returned to the user program, informing the user program that the memory is exhausted. At this point, the back file may not be exhausted (i.e., new back file blocks may be allocated), but because the pointer storage area is exhausted, even if a new back file block is allocated, no primary pointer can be provided to bind to the newly allocated back file block.

[0244] In a possible implementation method, if there is no free pointer in the first parameter storage area, a memory exhaustion indication is returned to the user program; if there is a free pointer in the first parameter storage area, step 1303 is executed.

[0245] Step 1303: query the backup file allocation table to determine whether there is a continuous area in the backup file that is larger than the required memory.

[0246] In one possible implementation method, if the backup file has such a continuous area, step 1306 is executed; if the backup file does not have such a continuous area, step 1304 is executed.

[0247] In one possible implementation, when the pointer storage area is not full, the backing file still needs to be checked to see if it meets the allocation requirements. The backing file allocation table is consulted to find a contiguous area in the backing file that is larger than the requested memory. If the total remaining space in the backing file does not meet the allocation requirements, the backing file memory has been exhausted. If the remaining space is larger than the requested memory size but not contiguous, the backing file space is defragmented. By moving the allocated backing file blocks within the backing file, the gaps between the backing file segments are eliminated, creating sufficient contiguous backing file free space to meet the backing file memory allocation requirements. It should be noted that defragmenting the backing file affects the positions of the allocated backing file blocks within the backing file (they move them). Therefore, the backing file allocation table must be updated to record the locations of these allocated backing file blocks within the backing file. Furthermore, if a backing memory mapping already exists for some of the allocated backing file blocks, the corresponding named memory mappings must be updated so that their named memory mapping targets fall at the new locations of the backing file blocks.

[0248] Step 1304: determine whether the total remaining space of the backup file meets the memory request size.

[0249] In one possible implementation method, if the total remaining space of the backup file does not meet the memory request size, step 1305 is executed; if the total remaining space of the backup file meets the memory request size, a memory exhaustion indication is returned to the user program.

[0250] Step 1305: Defragment the backup file.

[0251] In one possible implementation method, if the defragmented backup file meets the memory request size, step 1306 is executed; if the defragmented backup file does not meet the memory request size, a backup file exhaustion indication is returned to the user program.

[0252] Step 1306: Apply to the first parameter storage area for allocation of the first storage space.

[0253] In a possible implementation method, if the application for allocating the first storage space from the first parameter storage area is unsuccessful, a memory exhaustion indication is returned to the user program.

[0254] In a possible implementation method, if the application to allocate the first storage space to the first parameter storage area is successful, the first storage space is used as a first-level pointer, that is, the first parameter; and the value of the first parameter is set to null.

[0255] Step 1307: Modify the backup file allocation table.

[0256] In one possible implementation, when the backup file size meets the allocation criteria, an unused pointer is retrieved from the pointer storage area as a first-level pointer. The backup file allocation table is modified to accurately reflect the current allocation. The user can then choose whether to create a mapping (lazy allocation, in which case the first-level pointer is set to NULL, indicating that the corresponding backup memory mapping does not exist) or to create a mapping immediately (active allocation, in which case a backup memory mapping creation request is immediately called, which creates the corresponding backup memory mapping and sets the first-level pointer appropriately).

[0257] Step 1308: Return the address of the first parameter to the user program.

[0258] In one possible implementation, if the user program no longer needs a section of backing file memory, it should call the backing memory mapping release request to release it. If the released backing file memory still has a backing memory mapping window, it is also necessary to unmap the named memory. This is an important step to release resources and ensure data integrity.

[0259] When the user program calls the backup memory mapping release request to request the release of the backup file memory, the secondary pointer is passed as an input parameter. The backup file allocation table is queried to find the backup file block corresponding to the value of the secondary pointer (that is, the address of the primary pointer itself). If a backup memory mapping has been established for this area, the munmap() system call must be used to cancel the memory mapping first. Regardless of whether a backup memory mapping has been established, the allocation of this area must be cleared in the backup file allocation table. The space occupied by the primary pointer in the pointer storage area must also be reclaimed so that subsequent new backup file memory allocations can reuse this space to store new primary pointers. After these steps are completed, the corresponding file backup file memory is successfully released.

[0260] In one possible implementation, the difference between this embodiment and the method for processing a backup memory mapping release request from steps 1001 to 1006 described above lies in step 1006. In step 1006, the first parameter storage area does not exist in the virtual memory, and the first parameter is determined by ordinary memory allocation, so the ordinary memory allocation corresponding to the first parameter needs to be released. However, in this embodiment, the first parameter storage area exists, so only the space occupied by the first parameter in the pointer storage area needs to be reclaimed.

[0261] In some possible implementations, the backup memory mapping release request directly includes a first-level pointer, and the second-level pointer in the backup memory mapping release request is replaced with a first-level pointer. The core idea of ​​this embodiment does not change, but the step of deciphering the second-level pointer to obtain the first-level pointer is omitted.

[0262] In one embodiment, the specific implementation method for establishing the backup memory mapping request for the first backup file block is as follows: Figure 14 As shown, the process includes the following steps:

[0263] Step 1401: trigger a backup memory mapping establishment request for a first backup file block.

[0264] In one possible implementation method, the backup memory mapping establishment request includes a secondary pointer, the secondary pointer is decrypted to obtain the primary pointer, and it is determined whether the value of the primary pointer is empty. If it is not empty, it means that the corresponding named memory mapping already exists in the first backup file block, and an indication of successful backup memory mapping establishment can be directly returned to the user program; if it is empty, step 1402 is executed.

[0265] In one possible implementation, when a user program calls a backup memory mapping setup request, it should pass in a secondary pointer as a parameter. This secondary pointer can be the one returned by a previous call to the backup file memory allocation request, or it can be a copy of the previous one (due to parameter passing in the function call or other reasons), but this application does not limit this.

[0266] In one possible implementation method, a first-level pointer is directly passed into the backup memory mapping establishment request.

[0267] Step 1402: query the backup file allocation table to determine the first backup file block corresponding to the second parameter.

[0268] In a possible implementation method, the backup file allocation table is queried according to the second parameter to determine the size of the first backup file block.

[0269] Step 1403 , determining whether there is a free virtual memory block in the backup memory mapping area with a continuous remaining area that meets the size of the first backup file block.

[0270] In one possible implementation method, if the backup memory mapping area does not have a free virtual memory block with a continuous remaining area that meets the size of the first backup file block, step 1404 is executed; if the backup memory mapping area does have a free virtual memory block with a continuous remaining area that meets the size of the first backup file block, step 1405 is executed.

[0271] Step 1404: reclaim and / or defragment the backup memory mapping area.

[0272] In one possible implementation method, after the backup memory mapping area is recycled and defragmented, if there is still no continuous remaining area in the backup memory mapping area that meets the size of the first backup file block, an indication of failure to establish the backup memory mapping is returned to the user program.

[0273] In one possible implementation method, after the backup memory mapping area is recycled and defragmented, if there is a continuous remaining area in the backup memory mapping area that meets the size of the first backup file block, the starting address of the continuous remaining area is used as the starting address of the second mapping window.

[0274] In one possible implementation method, the backup file mapping area is first recycled. If no free virtual memory blocks that meet the first backup file block size exist in the backup memory mapping area after recycling, the fragments in the backup memory mapping area are defragmented. If no free virtual memory blocks that meet the first backup file block size exist in the backup memory mapping area after recycling, defragmentation is not performed.

[0275] In one possible implementation method, it is determined whether there is a free virtual memory block that meets the first backup file block size in the backup memory mapping area after recovery and defragmentation; if so, the starting address of the free virtual memory block that meets the first backup file block size in the backup memory mapping area is used as the value of the first parameter, the first parameter is stored, and a named memory mapping between the first backup file block and the free virtual memory block is established through the kernel.

[0276] In a possible implementation method, after defragmenting the fragments in the backup memory mapping area, the method further includes: updating the value of the first parameter corresponding to each historical backup file block according to the virtual memory after defragmentation.

[0277] Step 1405 , requesting the kernel to establish a named memory mapping between the first backup file block and the virtual memory block.

[0278] In one possible implementation method, the backup file, the offset address of the backup file, the size of the backup file and the starting address of the second mapping window are passed to the kernel as parameters, requesting the kernel to establish a named memory mapping between the first backup file block and the virtual memory block.

[0279] In a possible implementation method, if the kernel cannot establish a named memory mapping between the first backup file block and the virtual memory block, a named memory mapping establishment failure indication message is returned to the user program.

[0280] In one possible implementation, if the kernel successfully establishes a named memory mapping between the first backup file block and the virtual memory block, step 1406 is executed.

[0281] Step 1406: Modify the value of the first parameter to point to the starting address of the second mapping window.

[0282] Step 1407: Return the starting address of the second mapping window to the user program.

[0283] In one embodiment, the above step 1404, the method for recycling and / or defragmenting the backup memory mapping area is as follows: Figure 15 As shown, the method includes the following steps:

[0284] Step 1501: trigger a backup memory mapping reclaim request.

[0285] Step 1502: query the backup file allocation table to obtain a backup memory mapping that has been established but not locked.

[0286] Step 1503: Analyze the sizes of these backup memory mappings, their locations in the backup memory mapping area, and the spaces between the mappings.

[0287] Step 1504 : Plan the rearrangement and / or recycling of some mapping windows according to the input required target size.

[0288] Step 1505 , determining whether the reclaimable and / or rearranged mapping window satisfies the memory request size.

[0289] In one possible implementation method, if the reclaimable and / or rearranged mapping window meets the memory request size, step 1506 is executed; if the reclaimable and / or rearranged mapping window does not meet the memory request size, a memory exhaustion indication message is returned to the user program.

[0290] Step 1506: reclaim the reclaimable backup memory mapping and / or rearrange the mapping window.

[0291] In a possible implementation method, the starting address of the reclaimable backup memory mapping and the size of the reclaimable backup memory mapping are sent to the kernel as parameters, and the kernel calls the munmap() system call processing function to reclaim the corresponding mapping window.

[0292] In one possible implementation, the starting address and size of the re-arrangeable mapping window are sent as parameters to the kernel, which then calls the memory remapping mremap() system call handler to reclaim the corresponding mapping window. Optionally, the above parameters may also include an additional parameter, namely, the new starting address of the re-arrangeable mapping window.

[0293] In one possible implementation method, if there are multiple backup memory mappings that need to be reclaimed, the memory mapping cancellation munmap() system call processing function needs to be called multiple times.

[0294] In a possible implementation method, if there are multiple mapping windows that need to be rearranged, the memory remapping mremap() system call processing function needs to be called multiple times.

[0295] In one possible implementation method, if the memory remapping mremap() system call is not available, the starting address and size of the remapping window are first sent to the kernel as parameters, and the kernel calls the munmap() system call to reclaim the corresponding mapping window; then the new starting address and size of the remapping window are sent to the kernel as parameters, and the kernel calls the mmap() system call to create a new mapping window. This new mapping window is the remapping window.

[0296] In one possible implementation method, if the backup memory mapping is recovered successfully and the mapping window is rearranged successfully, step 1507 is executed; if the backup memory mapping is recovered failed or the mapping window is rearranged failed, a failure indication is returned to the user program.

[0297] Step 1507: Update the value of the first parameter corresponding to the recovered or rearranged mapping window.

[0298] In one possible implementation, when the system call is running normally, the backup file allocation table and the first-level pointers should be updated promptly to reflect the latest state of the mapping windows. (If a mapping window is reclaimed, the first-level pointer value should be updated to indicate that the corresponding backup file block does not yet have a mapping window, such as updating it to NULL; if a mapping window is moved due to defragmentation, the first-level pointers should be updated to record the latest mapping window starting address.) At this point, the mapping windows have been defragmented / reclaimed, and a contiguous area of ​​at least the size of the first backup file block has been obtained in the backup memory mapping area.

[0299] In one possible implementation method, if an error occurs in the system call during this process, the process is considered to have failed. For example, this may cause the program to crash, or may return an indication of the failure of the backup memory mapping recovery to the user program.

[0300] In a possible implementation method, in the case of rearrangement of mapping windows, the value of the first-level pointer corresponding to the mapping window in question is modified to the new mapping window address.

[0301] In a possible implementation method, in the case of recycling the backup memory mapping, the value of the first-level pointer corresponding to the mapping window involved is modified to be null.

[0302] In one possible implementation method, an indication that the recycling and / or defragmentation is successful is returned to the user program.

[0303] In one embodiment, since recycling or fragmentation of historical backup memory mappings may occur automatically when a new backup memory mapping is established, in some special cases, the user program may want to lock a backup memory mapping so that it will not be recycled or fragmented in the above scenario.

[0304] For example, as shown in Figures 16(a) and 16(b), function func1() already holds a secondary pointer p1 obtained from a fallback memory allocation, and the corresponding fallback memory mapping has been established and used by func1(). func1() is a non-leaf function (a function that calls other functions) and calls func2(). func2() will use a different fallback memory allocation. This fallback memory allocation may be newly allocated by func2() during execution or obtained from elsewhere. The corresponding secondary pointer is denoted as p2.

[0305] When func2() uses p2, after dereferencing it once, it is found that the first-level pointer *p2 is a null pointer, that is, the backup memory mapping corresponding to p2 has not been established, and a backup file memory mapping establishment request is triggered to establish a backup memory mapping. If the backup memory mapping area has been exhausted at this time, but sufficient continuous free backup memory mapping area space can be obtained by recycling the mapping window corresponding to p1, the mapping window corresponding to p1 may be recycled and used to establish the backup memory mapping corresponding to p2 for use by func2().

[0306] After func2() returns, if func1() still needs to use the backup memory corresponding to p1, the following situations may occur:

[0307] Case 1: func1 believes that its corresponding mapping window still exists, and directly dereferences p1 twice (or dereferences *p1 once) to obtain the corresponding backup file. However, since the corresponding mapping window may no longer exist, a null pointer dereference may occur. This is a memory misuse and will cause the program to crash.

[0308] Case 2: func1() believes its corresponding mapping window still exists. Before calling func2(), func1() somehow records the starting address of the old mapping window, for example, void *ap1 = *p1. At this point, even though *p1 == NULL, ap1 still points to the old address pointed to by *p1, meaning it still points to the old mapping window. In this case, directly dereferencing ap1 to access the backing memory likely won't cause an immediate program crash. This is because the backing memory corresponding to p1 was freed up to create the mapping window for p2. Therefore, p2's mapping window is likely to be created at the location of p1's old mapping window. In other words, it's very likely that ap1 == *p2. Dereferencing ap1 might actually use the mapping window created by the backing memory corresponding to p2, thus causing func1() to inadvertently modify the backing memory belonging to func2(). While this won't cause a program crash immediately, the misidentification could lead to further issues later, ultimately causing a program crash.

[0309] In order to solve the above problems, the following methods can be used.

[0310] Method 1: For non-leaf functions, if the backup memory needs to be continued to be used, determine whether the first-level pointer is empty. If it is empty, trigger the backup memory mapping establishment request again.

[0311] Method 2: For non-leaf functions, or during program execution, if you hope that the allocated backup memory mapping will not be recycled (or defragmented), set the lock flag for the corresponding backup memory mapping. When a new backup memory mapping establishment request is triggered, if the existing mapping window needs to be recycled (or defragmented), the locked mapping window will be excluded, and only the unlocked mapping window will be planned and recycled (or defragmented). This ensures that the mapping window is still valid after calling other functions that will use the backup memory (such as func2() in this example). At this time, after the other functions that will use the backup memory return, this mapping window can still be used directly without re-verification (for example, func1() in this example can still use p1 or *p1 or ap1 directly after func2() returns).

[0312] In a possible implementation method, the specific implementation process of the above method 1 is as follows: Figure 17 As shown, the method includes the following steps:

[0313] Step 1701: Determine whether the value of the first parameter is empty.

[0314] In one possible implementation method, each time the first function in the user program needs to use the allocated backup file memory, the second parameter corresponding to the first function is obtained, the second parameter is dereferenced, the first parameter is obtained, and it is determined whether the value of the first parameter is empty.

[0315] In a possible implementation method, if the value of the first parameter is empty, step 1702 is executed after triggering the backup memory mapping establishment request; if the value of the first parameter is not empty, step 1702 is executed.

[0316] Step 1702: dereference the first parameter and access the corresponding backup file block through the corresponding backup memory mapping in the first function.

[0317] In one possible implementation, dereferencing the first parameter obtains the value of the first parameter, and passing the value of the first parameter to an existing function that does not support fallback file memory. The existing function can access the corresponding fallback file block through the corresponding fallback memory mapping based on the value of the first parameter.

[0318] Step 1703: Determine whether the first function needs to call other functions.

[0319] In one possible implementation method, if the first function does not need to call other functions, the process ends; if the first function still needs to call other functions, step 1704 is executed.

[0320] Step 1704, determine whether other functions will establish backup file mappings themselves.

[0321] In one possible implementation method, if other functions do not establish backup file mappings themselves, then other functions are executed; after the other functions are executed, determine whether the first function still needs to continue to use the backup memory mapping corresponding to the first function, that is, execute step 1705; if the first function still needs to continue to use the backup memory mapping corresponding to the first function, then re-execute step 1702; if the first function does not need to continue to use the backup memory mapping corresponding to the first function, then end.

[0322] In one possible implementation method, other functions will establish backup file mappings themselves, and then execute other functions. The execution process may involve the recovery or defragmentation of the mapping window. After the execution of other functions is completed, determine whether the first function still needs to continue to use the backup memory mapping corresponding to the first function, that is, execute step 1705. If the first function still needs to continue to use the backup memory mapping corresponding to the first function, re-execute step 1701; if the first function does not need to continue to use the backup memory mapping corresponding to the first function, then end.

[0323] Step 1705 , determining whether the first function still needs to continue using the backup memory mapping corresponding to the first function.

[0324] In a possible implementation method, the specific implementation process of the above method 2 is as follows: Figure 18 As shown, the method includes the following steps:

[0325] Step 1801: trigger a backup memory mapping lock request according to the address of the first parameter.

[0326] In a possible implementation method, each time a first function in a user program needs to use the allocated backup file memory, the second parameter corresponding to the first function is obtained, and the second parameter is dereferenced to obtain the first parameter.

[0327] Step 1802: dereference the first parameter and access the corresponding backup file block through the corresponding backup memory mapping in the first function.

[0328] In one possible implementation, dereferencing the first parameter obtains the value of the first parameter, and passing the value of the first parameter to an existing function that does not support fallback file memory. The existing function can access the corresponding fallback file block through the corresponding fallback memory mapping based on the value of the first parameter.

[0329] Step 1803: Determine whether the first function needs to call other functions.

[0330] In a possible implementation method, if the first function does not need to call other functions, the process ends after triggering the backup memory mapping unlock request, that is, executing step 1805.

[0331] In a possible implementation method, if the first function needs to call other functions, the other functions are executed without caring whether the other functions will create a new backup memory mapping; after the other functions are executed, step 1804 is executed.

[0332] Step 1804 , determining whether the first function still needs to use the backup memory mapping corresponding to the first function.

[0333] A possible implementation method is that if the first function still needs to use the backup memory mapping corresponding to the first function, step 1802 is executed again; otherwise, the process ends after triggering the backup memory mapping unlock request, that is, step 1805 is executed.

[0334] In a possible implementation method, when a mapping window no longer needs to be locked, the mapping window should also be unlocked, otherwise it will continue to occupy the backup memory mapping area, thereby affecting other backup memory mapping establishment requests.

[0335] In one possible implementation method, when a user program requests to lock a backup memory mapping, if the backup memory mapping has not been established, a backup memory mapping is implicitly established for it first.

[0336] In one possible implementation, locking or unlocking a backing memory mapping may mark the corresponding area as locked or unlocked in the backing file allocation table.

[0337] Step 1805, triggering the backup memory mapping unlock request and ending.

[0338] In one embodiment, a method for processing a backup memory mapped lock request is as follows: Figure 19 As shown, the method includes the following steps:

[0339] Step 1901: trigger a backup memory mapping lock request.

[0340] The backup memory mapping lock request includes a second parameter.

[0341] Step 1902: query the backup file allocation table to determine the backup file block corresponding to the second parameter.

[0342] Step 1903: Determine whether a backup memory mapping has been established for the backup file block corresponding to the second parameter.

[0343] In a possible implementation method, if a backup memory mapping has been established for the backup file block corresponding to the second parameter, step 1905 is executed; otherwise, step 1904 is executed.

[0344] In a possible implementation method, the first parameter corresponding to the second parameter is determined according to the second parameter; and the backup memory mapping is determined to be established for the backup file block corresponding to the second parameter according to the value of the first parameter.

[0345] Step 1904: trigger a backup memory mapping establishment request.

[0346] In a possible implementation method, if the backup memory mapping establishment request fails to be triggered, or an error occurs in the backup memory mapping establishment request process, a backup memory mapping lock request failure indication message is returned to the user program.

[0347] In a possible implementation method, after the backup memory mapping establishment request is successful, step 1905 is executed.

[0348] Step 1905: Set a lock flag for the block corresponding to the second parameter of the backup file allocation table.

[0349] In one possible implementation method, a backup memory mapping lock request success indication is returned to the user program.

[0350] In one embodiment, a method for processing a backup memory map unlock request is as follows: Figure 20 As shown, the method includes the following steps:

[0351] Step 2001: trigger a backup memory mapping unlock request.

[0352] The backup memory mapping unlock request includes a second parameter.

[0353] Step 2002: query the backup file allocation table to determine the backup file block corresponding to the second parameter.

[0354] Step 2003: cancel the lock flag of the block corresponding to the second parameter of the backup file allocation table.

[0355] In a possible implementation method, a backup memory mapping unlock request success indication is returned to the user program.

[0356] In one embodiment, if a function accepts a common memory allocation, such as a malloc()-style first-level pointer, a second-level pointer for the backup file memory allocation described in this application cannot be forcibly passed to it. Otherwise, it will mistakenly access the first-level pointer, and then, if a write occurs, it may damage the first-level pointer and even the pointer storage area. Modifying existing function libraries to accept the second-level pointer for the backup file memory allocation described in this application is also unrealistic because the workload is very high. Moreover, some function libraries do not provide source code, making it impossible to modify them. Therefore, how to enable existing functions to safely access the backup memory without modification.

[0357] As mentioned earlier, when a fallback memory mapping has been established, accessing the first-level pointer is as simple as accessing the first-level pointer returned by malloc() (in other words, as long as the corresponding fallback memory mapping exists, the first-level pointer corresponding to this fallback memory can be treated as a first-level pointer in the style of ordinary memory allocation (such as malloc())); this is not the case when the fallback memory mapping does not exist. Under certain conditions, after confirming the existence of the fallback memory mapping (that is, performing a null pointer test on the first-level pointer and calling the fallback memory mapping creation function as needed), the first-level pointer can be passed to existing library functions for function calls without modifying the existing functions.

[0358] Existing library functions cannot directly use any backup file memory (nor can they use it recursively, i.e., they cannot be used for calls to other functions within the function). How do we define direct use? A very simple definition is to only use first-level pointers that are equivalent to ordinary memory allocation (such as malloc()), and never use second-level pointers in the style of this application. Or, never call any new functions introduced in this application. By imposing the above conditions, existing library functions will not have any impact on the allocation and mapping of backup file memory during their execution. As a result, existing library functions can safely use the first-level pointers that have been established for the corresponding backup memory mapping throughout their execution. Simply put, as long as the existing library function meets the above conditions, in order for it to be able to process data in the backup file memory, it only needs to add one more step before calling the existing library function: confirming the existence of the mapping (i.e., performing a null pointer check on the first-level pointer and calling the backup memory mapping establishment function as needed).

[0359] However, sometimes not all library functions can meet the above conditions. Therefore, the method of first calling the backup memory mapping lock request, then calling the existing library function, and finally calling the backup memory mapping unlock request can be used to solve the problem that the existing function can safely access the backup memory without modification.

[0360] The following details the advantages and disadvantages of setting the first parameter storage area and the backup file mapping area in virtual memory.

[0361] The benefits of setting up a partition such as the backup memory mapping area are:

[0362] (1) By reserving a backup file mapping area, it is ensured that normal memory allocation will not excessively occupy the heap / file mapping area, so that when the user space pressure is high (that is, the user space is about to be full), there is still enough memory area to safely use for establishing a backup memory mapping.

[0363] (2) The backup memory mapping windows are centralized and managed so that they can be defragmented when necessary to free up the small free spaces between the mapping windows to form new large continuous free spaces. If the backup memory mapping area is not set up and ordinary memory allocations and backup memory mapping windows are mixed, it will be difficult to defragment (because ordinary memory allocations cannot be moved at will).

[0364] The disadvantages of setting up a partition such as the backup memory map area are:

[0365] (1) When the usage rate of the backup memory mapping area is low, the free area cannot be provided for normal memory allocation or used to allocate first-level pointers.

[0366] (2) In the case of normal memory allocation and / or fewer first-level pointers, the free area cannot be provided for establishing a backup memory mapping window.

[0367] (3) Management is more complicated. It is necessary to reserve a backup memory mapping area in advance. When establishing a backup memory mapping later, it is necessary to analyze the utilization of the backup memory mapping area, reclaim the backup memory mapping as needed, and obtain the target mapping start address. The target mapping start address is then passed to the system call mmap() to establish a named memory mapping at the specified address.

[0368] The benefits of setting up a partition like the first parameter storage area are:

[0369] (1) Since the first-level pointers are stored in one place, memory fragmentation will not be caused by the scattered allocation of pointers. As mentioned earlier, avoiding fragmentation also avoids the problem of not having enough continuous free space when needed due to discontinuous free space.

[0370] (2) There is no need to allocate backup file memory every time, especially through ordinary memory allocation (such as malloc()) to obtain the memory space required to store the first-level pointer. It is only necessary to reserve the pointer storage area once, and there is no need to allocate memory for the storage of the first-level pointer. Later, you only need to manage the use of the pointer storage area.

[0371] (3) When recording the first-level pointer addresses in the backup file allocation table, since the first-level pointers are concentrated in the pointer storage area, such addresses will have a common prefix. Therefore, it is unnecessary to record this common prefix, thereby saving storage space in the backup file allocation table.

[0372] The disadvantages of setting up a partition like the first parameter storage area are:

[0373] (1) When the pointer storage area usage is low, the free area in the pointer storage area cannot be provided for normal memory allocation and / or backup memory mapping window use.

[0374] (2) When there are few normal memory allocations and / or backup memory mapping windows, these free areas cannot be used to allocate first-level pointers.

[0375] (3) Management is more complicated. It is necessary to reserve the area in advance and then manage the existing first-level pointers and free space in the area when allocating and releasing the backup file memory.

[0376] Not setting the backup memory mapping area and the first parameter storage area has the following advantages:

[0377] (1) When there are fewer first-level pointers, the extra free area can be used for normal memory allocation and can be used to establish a backup memory mapping window.

[0378] (2) When there are fewer backup memory mapping windows, the extra free area can be used by ordinary memory allocation and can be used to allocate first-level pointers.

[0379] (3) When the normal memory allocation is small, the extra free area can be used to allocate the first-level pointer and to establish a backup memory mapping window.

[0380] (4) When the allocation of a first-level pointer fails, sufficient space can be obtained for allocating a first-level pointer by calling the backup memory mapping recovery function.

[0381] (5) It is relatively simple to manage. There is no need to reserve any area in advance. When allocating and releasing the backup file memory later, you only need to allocate the first-level pointer as ordinary memory as needed (for example, allocate the first-level pointer through malloc() and release the first-level pointer through free()). When establishing the backup memory mapping later, there is no need to analyze the status of the backup memory mapping window, nor is there any need to pass the target mapping start address (in fact, NULL is passed, and the flag bit indicates that the kernel will select the backup memory mapping start address by itself) to the system call mmap(). The kernel will analyze the free area of ​​virtual memory when processing the system call, use a continuous free area with sufficient space to establish the mapping and return the starting address of the area. When there is no such free area, the kernel returns NULL, and the backup memory mapping recovery request is triggered at this time. After success, the mmap() system call processing function can be retried.

[0382] The disadvantages of not setting the backup memory mapping area and the first parameter storage area are:

[0383] (1) When user space pressure is high (that is, when user space is about to be full), there may not be enough memory area to safely allocate first-level pointers, nor may there be enough memory area to safely create backup memory mappings.

[0384] (2) The first-level pointers and / or mapping windows are likely to be scattered throughout the mixed-use area, causing memory fragmentation, which further leads to the inability of subsequent first-level pointers, normal memory allocations and / or backup memory mappings to find sufficient continuous free space.

[0385] (3) It is not possible to defragment the backup memory mapping (mapping window). Existing backup memory mappings can only be canceled on demand. This is because ordinary memory allocations cannot be moved arbitrarily and should not be overwritten by mapping windows, which makes it difficult to move mapping windows.

[0386] Based on the same technical concept, Figure 21 The embodiment of the present application provides an exemplary device 2100 for establishing a mapping relationship between a backup file and a virtual memory. Figure 21 As shown, it includes: a triggering unit 2101, a determining unit 2102, a judging unit 2103 and a recycling unit 2104.

[0387] The trigger unit 2101 is configured to trigger a backup memory mapping establishment request for a first backup file block; wherein the backup file is any file that can be mounted on a file system; the first backup file block is a continuous area in the backup file; and the backup memory mapping establishment request is configured to establish a named memory mapping between the backup file block and the virtual memory block.

[0388] The determining unit 2102 is configured to determine the size of the first backup file block from the backup file allocation table according to the second parameter in the backup memory mapping establishment request; the second parameter is used to indicate the address of the first parameter of the first backup file block; the value of the first parameter is used to indicate the starting address on the virtual memory to which the first backup file block is mapped by the named memory mapping; the backup file allocation table includes the address of the first parameter and the size of the first backup file block; the starting address of the free virtual memory block that meets the size of the first backup file block is used as the value of the first parameter, the first parameter is stored, and a named memory mapping between the first backup file block and the free virtual memory block is established through the kernel.

[0389] The determining unit 2103 is configured to determine whether there is a free virtual memory block in the virtual memory that meets the first backup file block size; if not, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; and determining whether there is a free virtual memory block in the virtual memory after the recovery is completed that meets the first backup file block size;

[0390] The recycling unit 2104 is configured to recycle the reclaimable historical virtual memory block if the reclaimable historical virtual memory block exists, and release the named memory mapping corresponding to the reclaimable historical virtual memory block.

[0391] In one possible implementation method, the determination unit 2102 is used to traverse the backup file allocation table to determine the address of the first parameter corresponding to the historical backup file block; determine the value of the first parameter corresponding to the historical backup file block according to the address of the first parameter corresponding to the historical backup file block; if the value of the first parameter corresponding to the historical backup file block is not empty, and the historical virtual memory block indicated by the first parameter corresponding to the historical backup file block is not locked, then determine that the historical virtual memory block is a reclaimable historical virtual memory block.

[0392] In one possible implementation method, the determination unit 2102 is used to request the kernel to establish a named memory mapping from the first backup file block to any virtual memory block; if the kernel fails to establish the named memory mapping, it is determined that there is no free virtual memory block in the virtual memory that meets the size of the first backup file block; if the kernel successfully establishes the named memory mapping, the starting address of the virtual memory block corresponding to the named memory mapping is used as the value of the first parameter, and the first parameter is stored.

[0393] In a possible implementation method, the trigger unit 2101 is used to trigger a backup memory allocation request for the first backup file block; the backup memory allocation request includes a memory request size; the judgment unit 2103 is used to judge whether there is a continuous area in the backup file that meets the memory request size; if so, the determination unit 2102 is used to determine the continuous area in the backup file that meets the memory request size as the first backup file block, and apply for a first storage space from the virtual memory, and return the address of the first storage space as the address of the first parameter of the first backup file block to the user program; the first storage space is used to store the value of the first parameter of the first backup file block; and the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0394] In one possible implementation method, the judgment unit 2103 is used to determine whether there is a reclaimable historical virtual memory block based on the backup file allocation table if the first storage space is not applied for from the virtual memory; the recovery unit 2104 is used to reclaim the reclaimable historical virtual memory block if it exists, and release the named memory mapping corresponding to the reclaimable historical virtual memory block; the determination unit 2102 is used to apply for a second storage space from the virtual memory after the recovery is completed, and return the address of the second storage space as the address of the first parameter of the first backup file block to the user program; the second storage space is used to store the value of the first parameter of the first backup file block; and the address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

[0395] In a possible implementation method, the trigger unit 2101 is used to trigger a backup memory mapping release request; the backup memory mapping release request is used to request the release of the virtual memory block mapped to the second backup file block; the determination unit 2102 is used to determine the starting address of the virtual memory block corresponding to the second backup file block according to the second parameter in the backup memory mapping release request; determine the size of the second backup file block from the backup file allocation table according to the second parameter in the backup memory mapping release request; pass the starting address of the virtual memory block corresponding to the second backup file block and the size of the second backup file block to the kernel, and cancel the named memory mapping through the kernel; after receiving the indication information sent by the kernel that the named memory mapping is successfully canceled, update the value of the first parameter corresponding to the second backup file block.

[0396] In a possible implementation method, the determining unit 2102 is configured to trigger a backup memory allocation request when determining that a memory access requirement of a user program meets a set condition.

[0397] In a possible implementation method, the above-mentioned device further includes an access unit 2105, and the access unit 2105 is used to access the data in the first backup file block through a named memory mapping between the first backup file block and the free virtual memory block.

[0398] In a possible implementation method, the determining unit 2102 is configured to set a lock flag for the virtual memory block corresponding to the first backup file block according to a first parameter.

[0399] In a possible implementation method, the determining unit 2102 is configured to: provide a first parameter storage area in the virtual memory; store multiple values ​​of first parameters in the first parameter storage area; and apply to the first parameter storage area for allocation of first storage space.

[0400] In a possible implementation method, the determining unit 2102 is configured to return a memory exhaustion indication to the user program if the application for allocating the first storage space from the first parameter storage area is unsuccessful.

[0401] In one possible implementation method, a backup memory mapping area is set in the virtual memory; the backup file mapping area is the virtual memory block to which the backup file block recorded in the backup file allocation table is mapped; the judgment unit 2103 is used to judge whether there is a free virtual memory block that meets the size of the first backup file block in the backup file mapping area through the backup file allocation table.

[0402] In one possible implementation method, a backup memory mapping area is set in the virtual memory; the determining unit 2102 is used to defragment the fragments in the backup memory mapping area if there are no free virtual memory blocks that meet the first backup file block size in the backup memory mapping area after recovery; the judging unit 2103 is used to judge whether there are free virtual memory blocks that meet the first backup file block size in the backup memory mapping area after recovery and defragmentation; if so, the determining unit 2102 is used to use the starting address of the free virtual memory block that meets the first backup file block size in the backup memory mapping area as the value of the first parameter, store the first parameter, and establish a named memory mapping between the first backup file block and the free virtual memory block through the kernel.

[0403] In a possible implementation method, the determining unit 2102 is configured to update the value of the first parameter corresponding to each historical backup file block according to the defragmented virtual memory.

[0404] In one possible implementation method, the recycling unit 2104 is used to defragment the fragments in the backup file if there is no continuous area in the backup file that meets the memory request size; the judgment unit 2103 is used to judge whether the backup file after defragmentation meets the continuous area of ​​the memory request size; if not, return a backup file exhaustion indication to the user program.

[0405] Based on the same technical concept, the embodiment of the present application provides a device 2200 for establishing a mapping relationship between a backup file and a virtual memory. The device 2200 for establishing a mapping relationship between a backup file and a virtual memory may be a computing device, for example. Figure 22 As shown, a device 2200 for establishing a mapping relationship between a backup file and a virtual memory includes at least one processor 2201 and a memory 2202 connected to the at least one processor. The specific connection medium between the processor 2201 and the memory 2202 is not limited in the embodiment of the present application. Figure 22 For example, the processor 2201 and the memory 2202 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, and the like.

[0406] In an embodiment of the present application, the memory 2202 stores instructions that can be executed by at least one processor 2201. At least one processor 2201 can execute the above-mentioned method of establishing a mapping relationship between a backup file and virtual memory by executing the instructions stored in the memory 2202.

[0407] The processor 2201 is the control center of the device 2200 for establishing a mapping relationship between a backup file and virtual memory. It can connect various parts of the computer device using various interfaces and lines, and perform resource settings by running or executing instructions stored in the memory 2202 and calling data stored in the memory 2202. Optionally, the processor 2201 may include one or more determination units. The processor 2201 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understood that the modem processor may not be integrated into the processor 2201. In some embodiments, the processor 2201 and the memory 2202 may be implemented on the same chip. In some embodiments, they may also be implemented on separate chips.

[0408] Processor 2201 can be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of this application. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly implemented as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor.

[0409] Memory 2202, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs, and modules. Memory 2202 can include at least one type of storage medium, such as flash memory, a hard disk, a multimedia card, a card-type memory, random access memory (RAM), static random access memory (SRAM), programmable read-only memory (PROM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), magnetic storage, a magnetic disk, an optical disk, and the like. Memory 2202 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. Memory 2202 in the embodiments of the present application can also be a circuit or any other device capable of performing a storage function, used to store program instructions and / or data.

[0410] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer-executable program. The computer-executable program is used to enable a computer to execute a method for establishing a mapping relationship between a backup file and virtual memory listed in any of the above methods.

[0411] An embodiment of the present application provides a computer program product, including a computer program executable by a computer device. When the program is run on the computer device, the computer device executes a method for establishing a mapping relationship between a backup file and virtual memory listed in any of the above methods.

[0412] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0413] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0414] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0415] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0416] Obviously, those skilled in the art may make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalents, this application is intended to include these modifications and variations.

Claims

1. A method for establishing a mapping relationship between a backup file and a virtual memory, characterized in that: include: triggering a backup memory mapping establishment request for a first backup file block; wherein the backup file is any file that can be mounted on a file system; the first backup file block is a continuous area in the backup file; the backup memory mapping establishment request is used to establish a named memory mapping between the backup file block and the virtual memory block; determining, from a backup file allocation table, a size of the first backup file block according to a second parameter in the backup memory mapping establishment request; the second parameter being used to indicate an address of the first parameter of the first backup file block; a value of the first parameter being used to indicate a starting address on a virtual memory to which the first backup file block is mapped by the named memory mapping; the first parameter and the second parameter being used to represent a virtual memory address; the backup file allocation table including the address of the first parameter and the size of the first backup file block; wherein the first parameter is a first-level pointer and the second parameter is a second-level pointer; a first parameter storage area being provided in the virtual memory; a plurality of first parameter values ​​being stored in the first parameter storage area; and the backup file allocation table being stored in a user program; Determining whether there is a free virtual memory block that meets the size of the first backup file block in the backup memory mapping area through the backup file allocation table; wherein the backup memory mapping area is set in the virtual memory; the backup memory mapping area is the virtual memory block to which the backup file block recorded in the backup file allocation table is mapped; If not, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; If the reclaimable historical virtual memory block exists, reclaiming the reclaimable historical virtual memory block and releasing the named memory mapping corresponding to the reclaimable historical virtual memory block; If there is no free virtual memory block that meets the first backup file block size in the backup memory mapping area after the recovery is completed, then arranging the fragments in the backup memory mapping area; Determining whether there is a free virtual memory block that meets the first backup file block size in the backup memory mapping area after recycling and defragmentation; Using the starting address of the free virtual memory block that meets the first backup file block size as the value of the first parameter, storing the first parameter, and establishing a named memory mapping between the first backup file block and the free virtual memory block by calling mmap() provided by the kernel; According to the first parameter, a lock flag is set on the virtual memory block corresponding to the first backup file block as needed.

2. The method according to claim 1, wherein The determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table includes: Traversing the backup file allocation table to determine the address of the first parameter corresponding to the historical backup file block; Determining a value of the first parameter corresponding to the historical backup file block according to an address where the first parameter corresponding to the historical backup file block is located; If the value of the first parameter corresponding to the historical backup file block is not empty, and the historical virtual memory block indicated by the first parameter corresponding to the historical backup file block is not locked, the historical virtual memory block is determined to be the reclaimable historical virtual memory block.

3. The method according to claim 1, wherein The determining whether there is a free virtual memory block in the backup memory mapping area that meets the first backup file block size includes: Requesting the kernel to create a named memory mapping of the first backup file block to an arbitrary virtual memory block; If the kernel fails to establish the named memory mapping, determining that there is no free virtual memory block in the virtual memory that meets the first backup file block size; If the kernel successfully establishes the named memory mapping, the starting address of the virtual memory block corresponding to the named memory mapping is used as the value of the first parameter, and the first parameter is stored.

4. The method according to claim 1, wherein Before triggering the backup memory mapping establishment request for the first backup file block, the method further includes: triggering a backup memory allocation request for the first backup file block; the backup memory allocation request includes a memory request size; Determine whether there is a continuous area in the backup file that meets the memory request size; If so, determining a continuous area in the backup file that meets the memory request size as the first backup file block, applying for a first storage space from the virtual memory, and returning the address of the first storage space as the address of the first parameter of the first backup file block to the user program; the first storage space is used to store the value of the first parameter of the first backup file block; The address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

5. The method according to claim 4, wherein The method further comprises: If the first storage space is not applied for from the virtual memory, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; If the reclaimable historical virtual memory block exists, reclaiming the reclaimable historical virtual memory block and releasing the named memory mapping corresponding to the reclaimable historical virtual memory block; Applying for a second storage space from the virtual memory after the recovery is completed, and returning the address of the second storage space as the address of the first parameter of the first backup file block to the user program; the second storage space is used to store the value of the first parameter of the first backup file block; The address of the first parameter of the first backup file block and the memory request size are added to the backup file allocation table.

6. The method according to claim 1, wherein The method further comprises: Triggering a backup memory mapping release request; the backup memory mapping release request is used to request the release of the virtual memory block to which the second backup file block is mapped; Determining, according to a second parameter in the backup memory mapping release request, a starting address of a virtual memory block corresponding to the second backup file block; Determining the size of the second backup file block from the backup file allocation table according to the second parameter in the backup memory mapping release request; Passing the starting address of the virtual memory block corresponding to the second backup file block and the size of the second backup file block to the kernel, and canceling the named memory mapping through the kernel; After receiving the indication information sent by the kernel that the named memory mapping is successfully cancelled, the value of the first parameter corresponding to the second backup file block is updated.

7. The method according to claim 4, wherein Before triggering the backup memory allocation request for the first backup file block, the method further includes: When it is determined that the memory access requirement of the user program meets the set condition, the backup memory allocation request is triggered.

8. The method according to claim 1, wherein After the kernel establishes the named memory mapping between the first backup file block and the free virtual memory block, the method further includes: Data in the first backup file block is accessed through a named memory mapping between the first backup file block and the free virtual memory block.

9. The method according to claim 4, wherein The applying for the first storage space from the virtual memory includes: Apply to the first parameter storage area for allocating the first storage space.

10. The method according to claim 9, wherein The method further comprises: If the application for allocating the first storage space from the first parameter storage area is unsuccessful, a memory exhaustion indication is returned to the user program.

11. The method according to claim 1, wherein After the fragments in the backup memory mapping area are sorted, the method further includes: According to the defragmented virtual memory, the value of the first parameter corresponding to each historical backup file block is updated.

12. The method according to claim 4, wherein The method further comprises: If there is no continuous area that meets the memory request size in the backup file, defragmenting the fragments in the backup file, and determining whether the backup file after defragmentation meets the continuous area of ​​the memory request size; If not satisfied, a backup file exhaustion indication is returned to the user program.

13. A device for establishing a mapping relationship between a backup file and a virtual memory, characterized in that: It includes trigger unit, determination unit, judgment unit and recovery unit: The trigger unit is configured to trigger a backup memory mapping establishment request for a first backup file block; wherein the backup file is any file that can be mounted on a file system; the first backup file block is a continuous area in the backup file; and the backup memory mapping establishment request is configured to establish a named memory mapping between the backup file block and the virtual memory block; The determining unit is configured to determine the size of the first backup file block from a backup file allocation table according to a second parameter in the backup memory mapping establishment request; the second parameter is configured to indicate the address of the first parameter of the first backup file block; the value of the first parameter is configured to indicate the starting address of the virtual memory to which the first backup file block is mapped by the named memory mapping; the first parameter and the second parameter are configured to represent the virtual memory address; the backup file allocation table includes the address of the first parameter and the size of the first backup file block; wherein the first parameter is a first-level pointer and the second parameter is a second-level pointer; a first parameter storage area is provided in the virtual memory; the first parameter storage area stores multiple values ​​of the first parameters; the backup file allocation table is stored in a user program; the starting address of a free virtual memory block that meets the size of the first backup file block is used as the value of the first parameter, the first parameter is stored, and a named memory mapping is established between the first backup file block and the free virtual memory block by calling mmap() provided by the kernel; and a lock flag is set on the virtual memory block corresponding to the first backup file block as needed according to the first parameter; The judging unit is configured to judge whether there is a free virtual memory block that meets the first backup file block size in the backup memory mapping area through the backup file allocation table; wherein the backup memory mapping area is set in the virtual memory; the backup memory mapping area includes the virtual memory blocks to which the backup file blocks recorded in the backup file allocation table are mapped; if not, determining whether there is a reclaimable historical virtual memory block according to the backup file allocation table; if there is no free virtual memory block that meets the first backup file block size in the backup memory mapping area after recovery, defragmenting the fragments in the backup memory mapping area; and judging whether there is a free virtual memory block that meets the first backup file block size in the backup memory mapping area after recovery and defragmentation; The recycling unit is configured to recycle the recyclable historical virtual memory block if the recyclable historical virtual memory block exists, and release the named memory mapping corresponding to the recyclable historical virtual memory block.

14. A computing device, characterized in that include: a memory for storing program instructions; A processor is configured to call the program instructions stored in the memory, and execute the method according to any one of claims 1 to 12 according to the obtained program instructions.

15. A computer-readable storage medium, characterized in that The method comprises computer-readable instructions, which, when read and executed by a computer, enable the method according to any one of claims 1 to 12 to be implemented.

16. A computer program product, characterized in that The invention comprises a computer program executable by a computer device, and when the program is run on the computer device, the computer device is caused to execute the steps of the method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Method and device used for memory space reservation and management

    CN108694014A

  • Interprocess memory sharing method and device

    CN114217982A

  • Virtual memory address space allocation method and device and electronic equipment

    CN115437774A