Memory compaction method and device, computer device and storage medium

By replacing scattered memory blocks with adjacent cold blocks, continuous swapped or free memory blocks are formed, thus solving the memory fragmentation problem and improving memory management efficiency.

CN116382579BActive Publication Date: 2026-08-25ALIBABA CLOUD COMPUTING CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310299813.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-20
Publication Date
2026-08-25
Estimated Expiration
2043-03-20

AI Technical Summary

Technical Problem

In existing technologies, memory swapping leads to severe memory fragmentation, making it impossible to allocate large, contiguous blocks of memory and affecting memory management efficiency.

Method used

By identifying scattered swapped-out memory blocks and the set of cold blocks adjacent to contiguous swapped-out space, as well as scattered free memory blocks and the set of cold blocks adjacent to contiguous free space, swapping is performed to form contiguous swapped-out or free memory blocks.

Benefits of technology

It achieves memory consolidation, ensuring that free memory is as contiguous as possible, improving memory management efficiency and solving the problem of memory fragmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116382579B_ABST
    Figure CN116382579B_ABST
Patent Text Reader

Abstract

The disclosure provides a memory compaction method, device, equipment and storage medium, the method comprises: determining a compaction target object and a compaction source object according to the use state and position of a memory block; the compaction target object comprises a scattered swapped-out memory block set, and the corresponding compaction source object comprises a cold block set adjacent to a continuous swapped-out space; the compaction target object comprises a scattered idle memory block set, and the corresponding compaction source object comprises a cold block set adjacent to a continuous idle space; in the scattered swapped-out memory block set, the number of continuous swapped-out memory blocks is less than a first threshold value; in the continuous swapped-out space, the number of continuous swapped-out memory blocks is greater than or equal to the first threshold value; in the scattered idle memory block set, the number of continuous idle memory blocks is less than a second threshold value; in the continuous idle space, the number of continuous idle memory blocks is greater than or equal to the second threshold value; and the use state of the compaction target object is replaced with the use state of the corresponding compaction source object.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to memory consolidation methods, apparatus, computer equipment, and storage media. Background Technology

[0002] The operating system allocates a certain number of memory blocks to each running process. To utilize memory flexibly, the operating system's memory management module records the hot / cold status information of each memory block allocated to each process. For memory that is not frequently used by a process, memory swapping can solve the problem of insufficient memory space. However, as memory swapping continues, memory fragmentation may become increasingly severe, resulting in a large number of scattered free memory blocks, making it impossible to allocate large, contiguous blocks of memory. Summary of the Invention

[0003] To overcome the problems existing in the related technologies, this disclosure provides a memory curvature method, apparatus, computer equipment, and storage medium.

[0004] According to a first aspect of the present disclosure, a memory compaction method is provided, the method comprising:

[0005] Based on the usage status of each memory block in the storage space to be regularized and its position within the storage space, a regularization target object and a corresponding regularization source object are determined; wherein, the regularization target object includes a set of scattered swapped-out memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to continuous swapped-out space; and / or, the regularization target object includes a set of scattered free memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to continuous free space; in the set of scattered swapped-out memory blocks, the number of consecutive swapped-out memory blocks is less than a first threshold; in the continuous swapped-out space, the number of consecutive swapped-out memory blocks is greater than or equal to the first threshold; in the set of scattered free memory blocks, the number of consecutive free memory blocks is less than a second threshold; in the continuous free space, the number of consecutive free memory blocks is greater than or equal to the second threshold;

[0006] The usage state of the regularization target object is swapped with the usage state of the corresponding regularization source object.

[0007] According to a second aspect of the present disclosure, a memory straightening apparatus is provided, comprising:

[0008] A determination module is used to determine a target object and a corresponding source object for regularization based on the usage status of each memory block in the storage space to be regularized and its position in the storage space to be regularized; wherein, the target object for regularization includes a set of scattered swapped-out memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to continuous swapped-out space; and / or, the target object for regularization includes a set of scattered free memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to continuous free space; in the set of scattered swapped-out memory blocks, the number of consecutive swapped-out memory blocks is less than a first threshold; in the continuous swapped-out space, the number of consecutive swapped-out memory blocks is greater than or equal to the first threshold; in the set of scattered free memory blocks, the number of consecutive free memory blocks is less than a second threshold; in the continuous free space, the number of consecutive free memory blocks is greater than or equal to the second threshold;

[0009] The replacement module is used to replace the usage state of the regularization target object with the usage state of the corresponding regularization source object.

[0010] According to a third aspect of the present disclosure, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the memory consolidation method embodiment described in the first aspect above.

[0011] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, wherein when executed by a processor, the computer program implements the steps of the memory consolidation method embodiment described in the first aspect above.

[0012] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:

[0013] In this embodiment, by acquiring the usage status of each memory block in the storage space to be consolidated and its position within the storage space, scattered swapped-out memory blocks and corresponding cold blocks adjacent to continuous swapped-out space can be identified. By swapping the two, a continuous large segment of swapped-out memory blocks is formed, which can then be reclaimed by the memory management module to allocate a continuous large segment of memory. Alternatively, this embodiment can also identify scattered free memory blocks and corresponding cold blocks adjacent to continuous free space; by swapping the two, a continuous free space can be formed. This embodiment can consolidate memory, swapping out memory in a contiguous address manner as much as possible, and actively consolidate memory to address fragmented memory, ensuring that free memory is as contiguous as possible.

[0014] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0015] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0016] Figure 1 This is a schematic diagram illustrating a reserved memory scenario according to an exemplary embodiment of this specification.

[0017] Figure 2A This is a flowchart illustrating a memory consolidation method according to an exemplary embodiment of this specification.

[0018] Figure 2B This is a schematic diagram illustrating a NUMA architecture according to an exemplary embodiment of this specification.

[0019] Figure 2C This is a schematic diagram of a segment of memory storage space illustrated in this specification according to an exemplary embodiment.

[0020] Figure 3 This is a block diagram of a device in which a memory straightening apparatus is located, according to an exemplary embodiment of this specification.

[0021] Figure 4 This is a block diagram illustrating a memory consolidation apparatus according to an exemplary embodiment of this specification. Detailed Implementation

[0022] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this specification as detailed in the appended claims.

[0023] The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of this specification. The singular forms “a,” “the,” and “the” as used in this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0024] It should be understood that although the terms first, second, third, etc., may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0025] The operating system's memory management module divides memory into defined management granularities, each called a page or block. In some cases, computer devices can use a traditional memory management architecture, where the operating system manages the entire memory. In other scenarios, such as virtual machine environments, computer devices can use a memory allocation architecture with reserved memory, such as... Figure 1 The diagram shown is a schematic representation of a reserved memory scenario illustrated in this specification. In this architecture, the host machine's memory may include various storage spaces, such as... Figure 1 The diagram illustrates two memory storage spaces using different padding methods: a non-reserved storage space (space a) used by the kernel (filled with diagonal lines) and a reserved storage space (space b) used by virtual machines (filled with grid lines). Specifically, non-reserved storage space a is used by the kernel, and the kernel typically allocates this space at a small granularity, such as 4KB (kilobyte). Applications running on the operating system (applications 1 to 3 in the example) can use non-reserved storage space a. Reserved storage space b, on the other hand, is used by virtual machines (VMs), such as VM1 to VMn (n virtual machines in total). The two storage spaces can employ different management granularities; that is, the memory can be partitioned in different ways. Figure 1 For ease of illustration, the two storage spaces are shown as contiguous in the diagram. However, in practical applications, the two storage spaces can be non-contiguous. Furthermore, in real-world applications, more storage spaces can be allocated in memory to implement a wider range of functionalities.

[0026] Reserved storage space occupies a large portion of memory and is unavailable to the host kernel. A module can be inserted into the operating system kernel specifically for managing the reserved storage space. To facilitate the management of this series of memory while avoiding the memory consumption of a large amount of metadata, and considering that the memory allocated to virtual machines is often at least several hundred MB (MByte), the reserved storage space is divided with a larger granularity, such as dividing the reserved storage space into memory sections (MS) of 2MB each. In some scenarios, large granularity is also commonly used, such as 1GB (Gigabyte), which is optional. This embodiment does not limit this.

[0027] The memory management module in the operating system is used to manage memory. When applied to reserved memory scenarios, the operating system can use different memory management modules to manage reserved storage space and non-reserved storage space respectively. For example, the operating system's reserved memory management module manages reserved storage space, while the kernel memory management module manages non-reserved storage space.

[0028] Because a computer's physical memory is limited, and a process's memory usage is unpredictable, there's always a possibility that physical memory will run out. The operating system uses memory swapping to address this issue. The kernel selects memory blocks that are in a "cold" state for release, performs memory block merging, compresses the data to other memory blocks, or swaps it out to disk. Then, it allocates the memory block to other processes with more urgent needs. When the original process needs the data, it swaps it into a new memory block and returns it to the original process.

[0029] The memory management module scans the hot and cold status of allocated memory blocks. Specifically, it continuously monitors information such as the time and frequency of process access to each memory block to determine its hot or cold status. A "hot" state indicates a memory block has recently been accessed by a process, while a "cold" state indicates a memory block has not recently been accessed. The memory management module records hot memory blocks in a hot page set and cold memory blocks in a cold page set. The cold page set contains memory blocks that haven't been accessed recently. These memory blocks can be migrated to secondary storage when memory is scarce to free up more memory for active virtual machines. Alternatively, the freed-up memory space can be used for inventory scheduling to improve host resource utilization. However, this migration is temporary. If the secondary storage is not a directly accessible device (e.g., a disk), subsequent access by a virtual machine will trigger a page fault, requiring a rapid swap-in operation. Alternatively, memory blocks swapped out to secondary storage can be actively swapped back into main memory as needed for scheduling.

[0030] However, considering that the memory usage of a virtual machine can change dynamically, after running for a period of time, the swapped-out memory may be scattered across different parts of the memory space allocated to the virtual machine. At the same time, for the host machine's overall memory, reclaiming many scattered memory blocks from virtual machines will also cause the free memory in the host machine to be broken into multiple small segments, making it difficult to allocate large, contiguous blocks of memory.

[0031] Based on this, the memory consolidation scheme provided in the embodiments of this specification can consolidate memory, swap out memory in a contiguous address manner as much as possible according to changes in memory usage (whether it's hot or cold), and actively consolidate fragmented memory to ensure that free memory is as contiguous as possible. A detailed explanation follows.

[0032] like Figure 2A The diagram shown is a schematic representation of a memory consolidation method according to an exemplary embodiment of this specification, comprising the following steps:

[0033] In step 202, the target object and the corresponding source object for regularization are determined based on the usage status of each memory block in the storage space to be regularized and its position in the storage space to be regularized.

[0034] Wherein, the target object for regularization includes a set of scattered swapped-out memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to contiguous swapped-out space; and / or, the target object for regularization includes a set of scattered free memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to contiguous free space; in the set of scattered swapped-out memory blocks, the number of contiguous swapped-out memory blocks is less than a first threshold; in the contiguous swapped-out space, the number of contiguous swapped-out memory blocks is greater than or equal to the first threshold; in the set of scattered free memory blocks, the number of contiguous free memory blocks is less than a second threshold; in the contiguous free space, the number of contiguous free memory blocks is greater than or equal to the second threshold.

[0035] In step 204, the usage state of the regularization target object is swapped with the usage state of the corresponding regularization source object.

[0036] The solution in this embodiment can be applied to any computer device. The computer device can be a single-core CPU (Central Processing Unit) device or a device including multiple physical CPUs. Depending on the needs, a Non-Uniform Memory Access Architecture (NUMA) can be used. A NUMA architecture includes at least two NUMA nodes, such as... Figure 2BAs shown, using two NUMA nodes as an example, the host machine can include NUMA node 1 and NUMA node 2. In a NUMA architecture, multiple physical CPUs and multiple memory modules of the host machine belong to different NUMA nodes. Each NUMA node includes at least one physical CPU and at least one physical memory module. Figure 2B Taking a NUMA node consisting of one physical CPU and one physical memory as an example. Within a NUMA node, the physical CPU and physical memory communicate using the Integrated Memory Controller Bus (IMC Bus), while NUMA nodes communicate with each other using Quick Path Interconnect (QPI). Because the latency of QPI is higher than that of the IMC Bus, the physical CPU's access to memory on the host machine differs in terms of distance (remote / local). The physical CPU can access the physical memory of its own node faster, while accessing the physical memory of other NUMA nodes is slower.

[0037] In a NUMA architecture scenario, the memory in this embodiment may include any of the aforementioned physical memory. Optionally, any physical memory in a NUMA architecture may also employ a reserved memory architecture. Based on this, the storage space managed in this embodiment may also refer to the reserved storage space within any physical memory in a NUMA architecture.

[0038] It is understood that in practical applications, computer devices may also adopt other architectures. Depending on actual needs, the memory referred to in this embodiment may have multiple implementation methods depending on the actual application scenario, which will not be listed one by one here.

[0039] The method described in this embodiment can be applied to the memory management module of the operating system of any computer device. As in the aforementioned reserved memory scenario, it can be applied to the reserved memory management module of the operating system. This method can run continuously after the computer device starts up, continuously making decisions regarding memory swapping; alternatively, it can be started and run when needed, for example, it can run after receiving a startup command, which can be initiated by a technician or automatically initiated according to preset rules, etc.

[0040] The process in this embodiment may include any process running in a computer device, such as the aforementioned virtual machine, etc.

[0041] The memory swapping in this embodiment can be understood as exchanging data from main memory to secondary storage. It can include various swapping methods, such as memory merging (or memory block merging), memory compression (or memory block data compression), and data exchange with external storage. As an example, memory merging refers to the operating system's memory merging module retrieving cold-state memory blocks to be released, initially as candidate memory blocks. Subsequent retrieved memory blocks are compared with the data stored in each candidate memory block to determine if there is a mergeable block, until a mergeable candidate block is found or all candidate memory blocks have been traversed. If a mergeable candidate block is found, the virtual address of the memory block to be released is mapped to the physical address of the found candidate block, thus releasing the physical address of the memory block to be released. Memory compression refers to compressing the data of the original memory block using a compression algorithm and storing it in a smaller memory block, thereby releasing the original memory block. Data exchange with external storage refers to storing the memory block data in external storage, such as a disk, to release the memory block. When needed, the data is retrieved from the external storage, stored in the memory block, and returned to the process.

[0042] The memory swapping in this embodiment includes memory swapping out and memory swapping in. Memory swapping out refers to releasing the memory block that has been allocated to the process and reclaiming it by the operating system's memory management module. Memory swapping in refers to storing the data of the memory block that was swapped out into a memory block and returning it to the process.

[0043] The storage space to be standardized in this embodiment can be flexibly configured according to actual needs. For example, in implementation, a standardization process can be used as the standardization object. For instance, if multiple virtual machines are running in a computer device, standardization is performed once for each virtual machine, and the storage space to be standardized can be the storage space allocated to the process. In other examples, standardization is performed from a global memory perspective, and the storage space to be standardized can be all or part of the storage space in memory.

[0044] The usage status of memory blocks in this embodiment, from the perspective of whether they have been swapped out, can include swapped out and not swapped out; from the perspective of whether they have been allocated to processes, it can include idle and allocated. For example... Figure 2C The diagram shown is a schematic representation of the usage status of multiple memory blocks within a storage space of memory, according to one embodiment of this specification. Each square in the diagram represents a memory block, numbered 16 to 16 from left to right. Assuming this storage space belongs to a specific process and its usage status is categorized as swapped out or not swapped out, squares filled with grid lines represent memory blocks that have not been swapped out, while unfilled squares represent swapped-out memory blocks. Figure 2CAs can be seen, the swapped-out memory blocks of the process are scattered, such as the 12th and 16th blocks in the figure. There are 3 unswapped positions before the 4th block, and there are also 2 unswapped positions between the 4th and 8th blocks. If there are suitable positions to swap out (only cold pages are suitable for swapping out), the 12th and 16th swapped-out positions can be swapped back in. For example, swapping out the 6th and 7th bits and swapping in the 12th and 16th bits to the 6th and 7th bits will form a continuous swapped-out position from the 4th to the 10th bits, forming a large continuous swapped-out memory block. This large swapped-out memory block can then be reclaimed by the memory management module to allocate a large continuous block of memory.

[0045] The same applies when the usage status is idle or allocated. Figure 2C In the diagram, squares filled with grid lines represent allocated memory blocks, and unfilled squares represent free memory blocks. The 12th and 16th squares in the diagram are scattered free memory blocks. Suitable memory blocks can be found from other allocated memory blocks. For example, if the 12th and 16th squares are swapped with the 6th and 7th squares, then the 4th to 10th squares can form a continuous free space.

[0046] Based on this, this embodiment involves two methods of routine processing. In actual implementation, it can be a routine function under the memory management module, which can execute both routine processes simultaneously; or it can be two routine functions under the memory management module. In implementation, both routine functions can be started, or either one can be started, i.e., either routine process can be executed as needed. In this embodiment, the routine can be performed on a process-by-process basis. For example, if multiple virtual machines are running in a computer device, routine processing is performed once for each virtual machine. In other examples, from a global memory perspective, routine processing of all or part of the storage space in memory is also optional.

[0047] Regarding step 202, obtaining the usage status and location of each memory block in memory can be achieved through memory metadata. In practical applications, the memory management module creates one or more metadata methods to facilitate memory management during the memory management process. These may include metadata recording allocation information for each allocation, metadata recording the hot / cold status of memory blocks, etc. For example, each time the reserved memory management module allocates storage space to a process, it creates a dedicated metadata mmap. This dedicated metadata is a special structure that manages the memory information allocated to the process, recording the physical address range of the allocation and process information, such as process identification information, process virtual address range, etc. All dedicated metadata mmaps are placed in a linked list maintaining the mmaps. Each mmap is uniquely identified by a physical address and corresponds one-to-one with the process identifier pid. In this embodiment, by traversing the mmap linked list, the usage status of each memory block can be obtained; and, based on the address of the memory block, its location in memory can be determined. Optionally, other methods, such as traversing each memory block in the storage space to be organized, can also be used.

[0048] The target object for regularization includes a set of scattered swapped-out memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to contiguous swapped-out spaces. Based on this, this embodiment can swap scattered swapped-out memory blocks into memory and then swap out the cold blocks adjacent to contiguous swapped-out spaces. This embodiment can find the set of scattered swapped-out memory blocks and the set of cold blocks adjacent to contiguous swapped-out spaces that meet the conditions by scanning the usage status of each memory block in memory. The set of scattered swapped-out memory blocks may include one or more scattered swapped-out memory blocks, and the set of cold blocks adjacent to contiguous swapped-out spaces may include one or more cold blocks adjacent to contiguous swapped-out spaces. In the set of scattered swapped-out memory blocks, the number of consecutive swapped-out memory blocks is less than a first threshold. That is, for a single scattered swapped-out memory block, the number of its consecutive swapped-out memory blocks is less than the difference between the first threshold and 1. In the continuous swapped-out space, the number of consecutive swapped-out memory blocks is greater than or equal to a first threshold. In practical applications, the first threshold can be flexibly configured as needed, for example, it can be a positive integer such as 2, 3 or 5. This embodiment does not limit this.

[0049] Similarly, the regularization target object includes a set of scattered free memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to the contiguous free space; wherein, the set of scattered free memory blocks may include one or more scattered free memory blocks, and the set of cold blocks adjacent to the contiguous free space may include one or more cold blocks. In the set of scattered free memory blocks, the number of contiguous free memory blocks is less than a second threshold. That is, for a scattered free memory block, the number of its contiguous free memory blocks is less than the difference between the first threshold and 1. In the contiguous free space, the number of contiguous free memory blocks is greater than or equal to the second threshold; in practical applications, this second threshold can be flexibly configured as needed, for example, it can be a positive integer such as 2, 3, or 5, and this embodiment does not limit it in this way.

[0050] Since there are a large number of memory blocks in the memory, in order to reduce the memory space occupied and improve efficiency in the process of determining the regularization target object and the corresponding regularization source object, in some examples, the regularization target object and the corresponding regularization source object are determined according to the usage status and location of each memory block in the memory.

[0051] Generate an unset bitmap based on the number of memory blocks in memory;

[0052] Obtain the metadata of the memory, determine the corresponding bit of the memory block in the bitmap according to the location of the memory block in the memory recorded in the metadata, and set the corresponding bit of the memory block in the bitmap according to the usage status of the memory block recorded in the metadata.

[0053] Based on each bit of the bitmap, determine the source object and the corresponding target object for normalization.

[0054] A bitmap is a graph that records and indexes the state of an object bit by bit. That is, each bit stores a certain state of each object (for example, using 0 and 1 to represent two states of the same object). Setting a bit and clearing a bit are two operations of a bitmap. Setting a bit means that the bit is set to 1, and clearing a bit means that the bit is set to 0.

[0055] In this embodiment, an unset bitmap is generated based on the number of memory blocks in memory, meaning the number of bits in the bitmap is the same as the number of memory blocks. The size of the memory blocks and the range to be regularized can be determined by the ratio of these two values ​​to the number of memory blocks. If regularization is performed once per process, the memory range to be regularized is the storage space allocated to the process.

[0056] In an unset bitmap, all bits are 0. The corresponding bit in the bitmap is determined based on the memory block's location in memory as recorded in the metadata. Then, the corresponding bit in the bitmap is set based on the memory block's usage status as recorded in the metadata. For example, Figure 2C The bitmap corresponding to the illustrated embodiment can be:

[0057] 0001 1001 1101 0001; where 1 indicates that it was swapped out, and 0 indicates that it was not swapped out.

[0058] In practical applications, a bitmap can be generated based on the usage status of swapped-out memory blocks. This bitmap identifies scattered swapped-out memory blocks and cold blocks adjacent to contiguous swapped-out space. Similarly, a bitmap can be generated based on the free / idle memory blocks, identifying scattered free memory blocks and cold blocks adjacent to contiguous free space. Recording the usage status and memory location of each memory block using bitmaps when retrieving metadata reduces memory space usage and allows for faster identification of target and source objects for memory consolidation.

[0059] In some examples, the bitmap includes a swap bitmap indicating the swapped state of memory blocks, wherein whether a bit in the swap bitmap is set indicates whether the corresponding memory block is a swapped memory block;

[0060] The target object for regularization is determined in the following way:

[0061] Based on the swapped bitmap, a scattered swapped bitmap is generated; wherein the number of bits in the scattered swapped bitmap is the same as the number of bits in the swapped bitmap, and the bits set in the scattered swapped bitmap correspond to the bits in the swapped bitmap whose consecutive set bit length is less than a first threshold.

[0062] The set of scattered swapped-out memory blocks is determined based on the bits set in the scattered swapped-out bitmap.

[0063] And / or,

[0064] The bitmap includes a free bitmap indicating that the memory block is in a free state, and the set bits in the free bitmap indicate that the corresponding memory block is a free memory block;

[0065] The target object for regularization is determined in the following way:

[0066] A scattered idle bitmap is generated based on the idle bitmap; wherein the number of bits in the scattered idle bitmap is the same as the number of bits in the idle bitmap, and the bits set in the scattered idle bitmap correspond to the bits in the idle bitmap whose consecutive set bit length is less than a first threshold.

[0067] The set of scattered free memory blocks is determined based on the bits set in the scattered free bit map.

[0068] As an example, swap bitmap1: 0001 1001 1101 0001, where a set bit (i.e., a bit of 1) indicates that it has been swapped out, and 0 indicates that it has not been swapped out. Taking a first threshold of 2 as an example, bits 12 and 16 have only one consecutive bit, which is less than the threshold. The number of bits in the scattered swapped-out bitmap2 is the same as that in Bitmap1. The corresponding bits in Bitmap2 (also bits 12 and 16) are set to 1, and the others are set to 0. That is, the positions of the set bits in Bitmap2 are the same as the positions of the bits in Bitmap1 where the number of consecutive set bits is less than the first threshold. Based on this, the scattered swapped-out bitmap2 is: 0000 0000 0001 0001. Through this step, scattered swapped-out memory blocks can be found. For example, the set of set bits in Bitmap2 is the set of candidate memory consolidation objects, which includes candidate memory consolidation objects, i.e., scattered swapped-out memory blocks. If all bits in Bitmap2 are 0, then there are no scattered swapped-out memory blocks. As can be seen from the above examples, a scattered swapped-out bitmap can be quickly generated by swapping bitmaps, thereby quickly analyzing scattered swapped-out memory blocks.

[0069] Similarly, the free bitmap Bitmap1 is 0001 1001 1101 0001, where a set bit (i.e., a bit of 1) indicates free space, and a bit of 0 indicates that the memory has been swapped out. Taking a first threshold of 2 as an example, bits 12 and 16 have only one consecutive bit, which is less than the threshold. The scattered free bitmap Bitmap2 has the same number of bits as Bitmap1, but the corresponding bits (also bits 12 and 16) in Bitmap2 are set to 1, and the others are set to 0. That is, the positions of the set bits in Bitmap2 are the same as the positions of the bits in Bitmap1 where the number of consecutive set bits is less than the first threshold. Based on this, the scattered free bitmap Bitmap2 is 0000 0000 00010001. Through this step, scattered free memory blocks can be found. For example, the set of bits set to 1 in Bitmap2 is a set of candidate memory consolidation objects, which includes candidate memory consolidation objects, i.e., scattered free memory blocks. If all bits in Bitmap2 are 0, then there are no scattered free memory blocks. As can be seen from the above examples, scattered free bitmaps can be quickly generated using free bitmaps, thereby quickly analyzing scattered free memory blocks.

[0070] In some examples, the regularized source object can be determined in the following way:

[0071] Using the swapped bitmap and the scattered swapped-out bitmap, a continuous swapped-out bitmap is generated, wherein the set bits in the continuous swapped-out bitmap represent the continuous swapped-out space;

[0072] For the unset bits in the swapped bitmap, query whether the corresponding memory block is a cold block, and generate a first cold block bitmap based on the query result; the set bits in the first cold block bitmap indicate that the corresponding memory block is a cold block;

[0073] Based on the continuous swapped-out bitmap and the first cold block bitmap, determine the set of cold blocks adjacent to the continuous swapped-out space;

[0074] And / or,

[0075] Using the free bitmap and the scattered free bitmap, a continuous free bitmap is generated, wherein the set bits in the continuous free bitmap represent the continuous free space;

[0076] For the unset bits in the free bitmap, query whether the corresponding memory block is a cold block, and generate a second cold block bitmap based on the query result; the set bits in the second cold block bitmap indicate that the corresponding memory block is a cold block;

[0077] Based on the continuous free space bitmap and the second cold block bitmap, a set of cold blocks adjacent to the continuous free space is determined.

[0078] In this embodiment, a continuous swapped bitmap Bitmap3 can be generated based on the swapped bitmap Bitmap1 and the scattered swapped bitmap Bitmap2. The positions set to 1 in Bitmap3 refer to the continuous swapped positions in Bitmap1, which are used to find cold blocks adjacent to these continuous swapped positions in Bitmap3 for swapping.

[0079] There are several ways to generate Bitmap3. In some examples, Bitmap3 can be generated by taking the bits that are set to 1 in Bitmap1 and the bits that are set to 0 in Bitmap2. That is, the bits that are set to 1 in Bitmap3 are the bits that are set to 1 in Bitmap1 and 0 in Bitmap2, and the other bits are 0.

[0080] To achieve more efficient processing, in some examples, it is achieved through the calculation of two bitmaps. The step of generating a continuous swapped bitmap using the swapped bitmap and the scattered swapped bitmap includes: inverting each bit in the scattered swapped bitmap and performing a logical AND operation with the swapped bitmap to obtain the continuous swapped bitmap.

[0081] For example, Bitmap2 can be inverted and then ANDed with Bitmap1 to obtain Bitmap3.

[0082] Bitmap1 is: 0001 1001 1101 0001

[0083] Bitmap2 is: 0000 0000 0001 0001, which, when inverted, becomes: 1111 1111 1110 1110;

[0084] Bitmap3 is: 0001 1001 1100 0000.

[0085] As can be seen from Bitmap3, if a block needs to be swapped out later, the memory block at the adjacent position of the position set to 1 in Bitmap3 can be determined to be a cold block. If it is a cold block, it can be swapped out so that the swapped-out position is adjacent to the consecutive swapped-out positions.

[0086] Furthermore, for Bitmap1: 0001 1001 1101 0001, for memory blocks with 0 positions that have not been swapped out, we can check whether they are cold blocks from the cold page set. Assuming that the 1st, 7th, and 15th positions that have not been swapped out are all cold blocks, then the first cold block bitmap Bitmap4 is: 1000 0010 0000 0010. Therefore, cold blocks can be found through the first cold block bitmap Bitmap4.

[0087] Therefore, by using the continuously swapped-out bitmap (Bitmap3) and the first cold block bitmap (Bitmap4), the cold blocks with adjacent continuously swapped-out spaces can be determined. For example, the 7th bit, which is adjacent to the 8th to 10th bits in Bitmap3, is set in Bitmap4 (cold block), so the 7th bit is the cold block with adjacent continuously swapped-out spaces.

[0088] As can be seen from the above embodiments, by swapping bitmaps and scattered swapped-out bitmaps, a continuous swapped-out bitmap can be quickly generated, thereby quickly analyzing the continuous swapped-out space. By swapping the unset bits in the bitmap, it is possible to query whether the corresponding memory block belongs to a cold block, and a first cold block bitmap can be quickly generated. Therefore, by using the continuous swapped-out bitmap and the first cold block bitmap, cold blocks adjacent to the continuous swapped-out space can be quickly analyzed.

[0089] Similarly, a continuous free bitmap can be generated based on the free bitmap and the scattered free bitmap. Positions set to 1 in the continuous free bitmap represent consecutive swapped-out positions, used to subsequently identify cold blocks adjacent to these consecutive free spaces for swapping with scattered free memory blocks. Furthermore, for the unset bits in the free bitmap, a query is performed to determine if the corresponding memory block is a cold block. Based on the query result, a second cold block bitmap can be quickly generated. Set bits in the second cold block bitmap indicate that the corresponding memory block is a cold block, thus quickly identifying cold blocks adjacent to the continuous free space.

[0090] In practical applications, there may be multiple set bits in the scattered swapped-out bitmap, meaning there are multiple scattered swapped-out memory blocks; similarly, there may also be multiple corresponding regularization source objects. In some examples, to obtain multiple regularization source objects, a first candidate regularization source object bitmap can be generated based on the positions of the set bits in the continuous swapped-out bitmap and the positions of the set bits in the first cold block bitmap. The set bits in the first candidate regularization source object bitmap represent one or more cold blocks that are contiguous with the continuous swapped-out space. Based on the first candidate regularization source object bitmap, a set of cold blocks adjacent to the continuous swapped-out space is determined.

[0091] In this embodiment, a first candidate regularization source object bitmap can be generated by combining the continuously swapped-out bitmap and the first cold block bitmap. Multiple candidate regularization source objects can be obtained through a single first candidate regularization source object bitmap. For example:

[0092] Bitmap1: 0001 1001 1101 0001 indicates whether each memory block has been swapped out.

[0093] Bitmap2: 0000 0000 0001 0001 indicates that scattered memory blocks have been swapped out.

[0094] Bitmap3: 0001 1001 1100 0000 indicates consecutive swapped-out memory spaces.

[0095] Bitmap4: 1110 0000 0000 0010 indicates a cold block.

[0096] As shown in the bitmaps above, Bitmap3 includes two consecutive swapped-out spaces: bits 4 to 5, and bits 8 to 10. Combining this with the cold blocks in Bitmap4 (bits 1 to 3), we know that the memory block corresponding to bit 3 is a regularization source object. If there are multiple scattered swapped-out memory blocks, swapping bit 3 with one of these blocks will create a consecutive swapped-out space from bit 3 to bit 5; then bit 2 can also be considered a regularization source object. In practical applications, this embodiment can be executed multiple times, finding only one memory block as a regularization source object each time. To improve efficiency, this embodiment can also find multiple memory blocks as regularization source objects at once. For example, by generating a first candidate regularization source object bitmap, the set bits in this bitmap represent one or more cold blocks consecutive with the consecutive swapped-out space. For example, the third position is a cold block. Since the third position is adjacent to the second position, and the second position is adjacent to the first position, the three consecutive cold blocks from the first to the third position can be continuous with the adjacent consecutive swapped-out space, thus allowing us to find three candidate regular source objects.

[0097] In practical applications, the first candidate regularized source object bitmap can be obtained by analyzing the continuous swapped-out bitmap and the first cold block bitmap. As an example:

[0098] Using the continuously swapped-out bitmap Bitmap3 as a base, copy bitmap Bitmap5, find its set-to-1 transition positions (i.e., bits that change between being set to 0 and 1 in Bitmap5), and determine if that bit is set in the first cold block bitmap Bitmap4. If it is set, set that bit to 1 in Bitmap5; simultaneously, generate a Bitmap6 (initially, all bits in Bitmap6 are zero), where the positions set to 1 are the newly set positions in Bitmap5, and the others are set to 0. As an example:

[0099] Bitmap1: 0001 1001 1101 0001 indicates whether each memory block has been swapped out.

[0100] Bitmap2: 0000 0000 0001 0001 indicates that scattered memory blocks have been swapped out.

[0101] Bitmap3: 0001 1001 1100 0000 indicates consecutive swapped-out memory spaces.

[0102] Bitmap4: 1110 0000 0000 0010 indicates a cold block.

[0103] Bitmap5: 0001 1001 1100 0000 was copied from Bitmap3.

[0104] Bitmap6: 0000 0000 0000 0000 In the initial Bitmap6, all bits are zero.

[0105] First, find the position where the bit is set to 1 in Bitmap5, for example, the 3rd bit; since the 3rd bit is set in Bitmap4, the 3rd bit in Bitmap5 is set to 1 and updated as follows:

[0106] Bitmap5: 0011 1001 1100 0000 Since the 3rd bit of Bitmap5 is set to 1, the corresponding 3rd bit of Bitmap6 is also set to 1; Bitmap6 is updated to:

[0107] Bitmap6: 0010 0000 0000 0000 At this point, a candidate regular source object has been found.

[0108] Since not all bits have been traversed, a second query is performed. After updating Bitmap5, the query checks whether the second bit is set in Bitmap4, and the same process is executed.

[0109] Bitmap5, position 2 (1), updated to: 0111 1001 1100 0000

[0110] Bitmap6 has also been updated accordingly to: 0110 0000 0000 0000

[0111] Upon further querying, after updating Bitmap5, check if the second bit is set in Bitmap4, and perform the same processing:

[0112] Bitmap5, position 1: 1111 1001 1100 0000

[0113] Bitmap6: 1110 0000 0000 0000, end the query, get the first candidate regularized source object bitmap Bitmap6, where the set bits are the candidate regularized source object set, and each set to 1 is a source memory block that can be regularized.

[0114] In some examples, determining the set of cold blocks adjacent to the continuous free space based on the continuous free bitmap and the second cold block bitmap may include:

[0115] Based on the positions of the bits set in the continuous free bitmap and the positions of the bits set in the second cold block bitmap, a second candidate regularization source object bitmap is generated; the bits set in the second candidate regularization source object bitmap represent one or more cold blocks that are continuous with the continuous free space.

[0116] Based on the second candidate regularized source object bitmap, determine the set of cold blocks adjacent to the continuous free space.

[0117] Similar to the aforementioned acquisition of the first candidate regularization source object bitmap, this embodiment can generate a second candidate regularization source object bitmap by combining a continuous free bitmap and a second cold block bitmap. Multiple candidate regularization source objects can be acquired using a single second candidate regularization source object bitmap. Specific implementation details can be found in the aforementioned embodiments, and will not be repeated here.

[0118] In some examples, the process of replacing the usage state of the target object with the usage state of the corresponding source object may include:

[0119] Swap out the data stored in the cold blocks in the set of cold blocks adjacent to the continuous swapped-out space, changing the cold blocks with swapped-out data into swapped-out memory blocks; swap in the data corresponding to the scattered swapped-out memory blocks in the set of scattered swapped-out memory blocks, changing the scattered swapped-out memory blocks into non-swapped-out memory blocks; and / or,

[0120] The data stored in the cold blocks in the set of cold blocks adjacent to the continuous free space is replaced by the scattered free memory blocks in the set of scattered free memory blocks, so that the replaced cold blocks become free memory blocks, and the scattered free memory blocks become allocated memory blocks.

[0121] To consolidate scattered swapped-out memory blocks, this embodiment can obtain a cold block adjacent to a contiguous swapped-out space, swap out its stored data, and change the usage status of the swapped-out cold block to swapped out. This swapped-out memory block is then reclaimed by the memory management module and can be converted into a free memory block. After swapping out, another scattered free memory block is retrieved and swapped in. The memory swapping function of the memory management module typically sets a memory swapping threshold (i.e., the proportion of memory swapped out). This embodiment ensures that the memory consolidation process does not affect the memory swapping function and consolidates the scattered swapped-out memory blocks, forming a contiguous swapped-out space. In practical applications, the set of scattered swapped-out memory blocks may contain multiple memory blocks, and there may also be multiple sets of cold blocks adjacent to the contiguous swapped-out space. In this embodiment, the steps can be implemented by taking one memory block from the set of cold blocks adjacent to the contiguous swapped-out space each time, processing its swapping out, and then taking another memory block from the set of scattered swapped-out memory blocks for swapping in.

[0122] In this embodiment, the consolidation of scattered free memory blocks does not require data swapping. Instead, the data stored in the cold blocks adjacent to the continuous free space is swapped to the scattered free memory blocks, thus changing the cold blocks adjacent to the continuous free space into free memory blocks and the scattered free memory blocks into allocated memory blocks. Therefore, the swapping can be completed quickly, consolidating the scattered free memory blocks and forming continuous free space.

[0123] The following examples will further illustrate this.

[0124] Example 1: Memory consolidation of the host machine's reserved memory and swapped memory;

[0125] This embodiment takes a reserved memory scenario as an example. The goal of the regularization is to swap in memory blocks when they are scattered across the process's swapped memory blocks, and to find cold blocks in the process's unswapped memory blocks, selecting those adjacent to the swapped-out memory blocks and swapping them out. This can include the following steps:

[0126] 1. Traverse the metadata mmap. Based on the memory allocation information recorded in mmap, each memory block is treated as a bit in a Bitmap with a granularity of ms. Obtain the swapping status of the memory blocks. Generate a swap bitmap Bitmap1 for the memory swapping status, where swapped-out blocks are set to 1 and non-swapped blocks are set to 0.

[0127] Taking the reserved memory scenario as an example, when the virtual machine starts running, the reserved memory management module allocates a contiguous storage space (including one or more memory blocks) to the virtual machine from the reserved storage space it manages. At the same time, it creates a metadata mmap representing the storage space allocated this time. The mmap is uniquely identified by a physical address and records the physical address range and process information allocated this time, such as process identification information, virtual address range of the process, etc. All proprietary metadata mmaps are placed in a linked list that maintains mmaps. Each mmap is uniquely identified by a physical address and corresponds one-to-one with the process identifier pid.

[0128] Subsequently, these memory blocks allocated to the virtual machine may undergo memory swapping. In this embodiment, the swapping in and swapping out of each memory block can be determined by scanning the metadata that records the memory swapping information.

[0129] As an example Figure 2C This diagram illustrates a segment of storage space allocated to a process, where each square represents a memory block. As the process runs, this storage space undergoes memory swapping; a square set to 1 indicates that the memory block has been swapped out. Using a swap bitmap (Bitmap1), this can be represented as: 0001 1001 1101 0001; where 1 indicates swapped out and 0 indicates not swapped out.

[0130] From Bitmap1: 0001 1001 1101 0001, we can see that bits 12 and 16 are scattered swapped-out positions, meaning scattered swapped-out memory blocks. There are 3 unswapped memory blocks before bit 4, and 2 unswapped memory blocks between bit 4 and bit 8. If there are suitable swapped-out positions (only cold blocks are suitable for swapping out), the two swapped-out memory blocks at bits 12 and 16 can be swapped back in. For example, swapping out bits 6 and 7, and swapping in bits 12 and 16 to bits 6 and 7, will create a continuous swapped-out space from bit 4 to bit 10, forming a large continuous free memory block.

[0131] 2. Based on a preset threshold (e.g., setting the threshold to 2), the positions where the number of consecutive bits set to 1 is less than the threshold are the candidate memory consolidation objects, i.e., the candidate swapped-in objects; based on this, a scattered swapped-out bitmap Bitmap2 is generated, which is based on Bitmap1, where bits less than the threshold are set to 1, and otherwise set to 0.

[0132] In other words, the memory block corresponding to the bit set to 1 in Bitmap2 is the candidate memory consolidation object (the candidate needs to be swapped into the memory block). For example:

[0133] Bitmap1: 0001 1001 1101 0001 has only one consecutive bit at the 12th and 16th positions, which is less than the threshold, so it is set to 1, and the others are set to 0; Bitmap2 is: 0000 0000 0001 0001.

[0134] Therefore, this step can identify scattered swapped-out memory blocks, thus obtaining candidate memory consolidation objects.

[0135] 3. Generate a continuous swapped bitmap Bitmap3 based on Bitmap1 and Bitmap2; the positions set to 1 in Bitmap3 refer to the continuous swapped spaces in Bitmap1, which are used to find cold blocks adjacent to these continuous swapped spaces in Bitmap3 for swapping.

[0136] There are several ways to generate a continuous swapped bitmap (Bitmap3). For example, you can invert Bitmap2 and then perform a logical AND operation with Bitmap1 to get Bitmap3.

[0137] Bitmap1: 0001 1001 1101 0001

[0138] Bitmap2: 0000 0000 0001 0001, inverted to: 1111 1111 1110 1110

[0139] Bitmap3: 0001 1001 1100 0000.

[0140] In other examples, there could be other methods, such as generating Bitmap3 by setting the position with 1 in Bitmap1 and 0 in Bitmap2. That is, the position with 1 in Bitmap3 is the position with 1 in Bitmap1 and 0 in Bitmap2, and the other positions are set to 0.

[0141] As can be seen from Bitmap3, if a block needs to be swapped out later, the memory block at the adjacent position of the position set to 1 in Bitmap3 can be determined to be a cold block. If it is a cold block, it can be swapped out so that the swapped-out position is adjacent to the consecutive swapped-out positions.

[0142] 4. For all memory blocks that have not been swapped out (i.e., those set to 0 in Bitmap1), query the hot and cold memory sets to generate a first cold block bitmap (Bitmap4). In Bitmap4, blocks set to 1 represent cold blocks, while all other blocks, whether hot or swapped out, are set to 0. For example:

[0143] For Bitmap1: 0001 1001 1101 0001, for the memory blocks with 0 positions that haven't been swapped out, check if they are cold blocks from the cold page set. Assuming the 1st, 7th, and 15th positions are all cold blocks, then Bitmap4 would be: 1000 0010 0000 0010. Therefore, the cold blocks are found using Bitmap4, and the memory blocks that can be swapped out are obtained.

[0144] 5. If Bitmap3 is not empty, proceed to step 7; if Bitmap3 is empty, the smoothing process can be terminated; optionally, multiple (if any) scattered swapped-out memory blocks in Bitmap2 can be smoothed to form consecutive positions.

[0145] For example, since Bitmap3 is empty, meaning all bits are zero, it indicates that there is currently no consecutive swapped space; therefore, iterate through Bitmap2, select the position where it is set to 1, and set the adjacent bits (i.e., before and after) to 1 in Bitmap4, and at the same time clear that bit from Bitmap2 (i.e., clear the bit that is set to 1 to zero).

[0146] As an example ①:

[0147] Bitmap1: 0001 0001 0001 0001 1 indicates swapping out, and the current 4 swapped-out memory blocks are all scattered;

[0148] Bitmap2: 0001 0001 0001 0001 1 indicates a fragmented memory block that has been swapped out and is suitable for swapping in;

[0149] Bitmap3: 0000 0000 0000 0000 are all zero, indicating that there are no consecutive swapped-out memory blocks.

[0150] Bitmap4: 0000 0000 0000 0010 1 indicates a cold block;

[0151] Since the 15th bit of Bitmap4 is adjacent to the 16th bit of Bitmap2, the 16th bit of Bitmap2 is cleared, and Bitmap2 is updated to: 0001 0001 0001 0000.

[0152] Because Bitmap2 is updated, Bitmap3 is also updated to: 0000 0000 0000 0001.

[0153] As an example ②:

[0154] Bitmap1: 0001 0001 0001 0001 1 indicates swapping out, and the current 4 swapped-out memory blocks are all scattered;

[0155] Bitmap2: 0001 0001 0001 0001 1 indicates a fragmented memory block that has been swapped out and is suitable for swapping in;

[0156] Bitmap3: 0000 0000 0000 0000 are all zero, indicating that there are no consecutive swapped-out memory blocks.

[0157] Bitmap4: 0000 0000 0100 0000 1 indicates a cold block;

[0158] Since Bitmap4 has a 1 at position 10, and Bitmap2 does not have a 1 position adjacent to position 10, Bitmap2 does not need to be updated, and Bitmap3 remains zero. Proceed to step 6.

[0159] 6. If Bitmap3 is still zero, it means there is no Bitmap that can be normalized, so return directly. If Bitmap3 is not zero after adjustment, but Bitmap2 is zero, then Bitmap3 and Bitmap2 are randomly allocated, each occupying half.

[0160] As an example:

[0161] Bitmap2: 0000 0000 0000 0000 1 indicates a scattered area that has been swapped out and is suitable for swapping in; at this time, there are no 1s, only zeros.

[0162] Bitmap3: 0000 0100 0000 1000 1 indicates a continuous swapped area. You can try to find cold blocks in its adjacent positions to swap out.

[0163] At this point, all the elements in Bitmap2 that are not set to 1 have been moved to Bitmap3. This means that the elements in Bitmap3 that are set to 1 all have adjacent cold blocks, and these elements are scattered. If Bitmap3 contains only one 1, the data cannot be neatly organized, and the process returns immediately. If there are more than 1 elements set to 1 in Bitmap3, then i random 1s can be taken and assigned to Bitmap2. The value of i is the integer part of the number of elements set to 1 in Bitmap3 divided by 2, and either rounded up or down is acceptable.

[0164] For example, in Bitmap3 above, if the 6th and 13th bits are both set to 1, and a random bit is set to 0 (e.g., the 6th bit is 0), then the 6th bit of Bitmap2 is set to 1, resulting in the following update:

[0165] Bitmap2: 0000 0100 0000 0000

[0166] Bitmap3: 0000 0000 0000 1000.

[0167] 7. Using Bitmap3 as a base, copy Bitmap5 and find its 1-transition positions (i.e., bits that change between being set to 0 and 1 in Bitmap5). Determine if this bit is set in the first cold block bitmap, Bitmap4. If it is set, set that bit to 1 in Bitmap5. Simultaneously, generate Bitmap6 (initially, all bits in Bitmap6 are zero), where the positions set to 1 are the newly set positions in Bitmap5, and the others are set to 0. For example:

[0168] Bitmap1: 0001 1001 1101 0001 indicates whether each memory block has been swapped out.

[0169] Bitmap2: 0000 0000 0001 0001 indicates that scattered memory blocks have been swapped out.

[0170] Bitmap3: 0001 1001 1100 0000 indicates consecutive swapped-out memory spaces.

[0171] Bitmap4: 1110 0000 0000 0010 indicates a cold block.

[0172] Bitmap5: 0001 1001 1100 0000 was copied from Bitmap3;

[0173] Bitmap6: 0000 0000 0000 0000 In the initial Bitmap6, all bits are zero.

[0174] First, find the position where the bit is set to 1 in Bitmap5, for example, the 3rd bit; since the 3rd bit is set in Bitmap4, the 3rd bit in Bitmap5 is set to 1 and updated as follows:

[0175] Bitmap5: 0011 1001 1100 0000 Since the 3rd bit of Bitmap5 is set to 1, the corresponding 3rd bit of Bitmap6 is also set to 1; Bitmap6 is updated to:

[0176] Bitmap6: 0010 0000 0000 0000 At this point, a candidate regular source object has been found.

[0177] Since not all bits have been traversed, a second query is performed. After updating Bitmap5, the query checks whether the second bit is set in Bitmap4, and the same process is executed.

[0178] Bitmap5, position 2 (1), updated to: 0111 1001 1100 0000

[0179] Bitmap6 has also been updated accordingly to: 0110 0000 0000 0000

[0180] Upon further querying, after updating Bitmap5, check if the second bit is set in Bitmap4, and perform the same processing:

[0181] Bitmap5, position 1: 1111 1001 1100 0000

[0182] Bitmap6: 1110 0000 0000 0000, the query ends, and the first candidate regular source object bitmap Bitmap6 is obtained, where the set bits are the candidate regular source objects.

[0183] 8. At this point, Bitmap6 is the candidate set of regularized object sources (i.e., memory blocks suitable for swapping out, which are all cold blocks and can be contiguous with the swapped-out space during the swapping process), while Bitmap2 is the candidate set of regularized target objects (i.e., scattered swapped-out memory blocks that need to be swapped in).

[0184] In this embodiment, the number of objects in each of the two sets can be calculated and the minimum value num can be taken. If num is 0, it means that Bitmap6 does not have a suitable memory block to swap out or Bitmap2 does not have a suitable memory block to swap in, so exit directly; otherwise, continue to the next step.

[0185] 9. Select a set bit position 'a' from Bitmap6 that is adjacent to the set bit position in Bitmap3; if not found, end memory consolidation and return; otherwise, continue.

[0186] 10. Check again whether a is still in the cold page set. If yes, continue; otherwise, return to step 9 and find the next memory consolidation location.

[0187] Since the set of cold pages may change during the process from step 4 to this step, the original cold block may be accessed by the process during this process and become a hot block. Therefore, checking whether the corresponding memory block is a cold block at position a can prevent hot blocks from being swapped out and affecting the operation of the process.

[0188] 11. Swap the memory block ms1 corresponding to location a to the secondary storage location (there are many ways to do this, but we will take the disk as an example here);

[0189] a) Begin a memory block swap, with the swap size in granularity of one memory block (e.g., 2MB), and select a storage space ds (device section) from secondary storage;

[0190] b) Select a memory block ms1 to be swapped out. When ms1 is obtained from the cold and hot set, it is the physical address information paddr (physical memory address). According to the metadata mmap that records the memory allocation information, query its corresponding virtual address vaddr (virtual memory address).

[0191] c) Set the page table entry corresponding to the virtual address vaddr to read-only to prevent the contents of the memory block from being changed during the swapping process, which could lead to data inconsistency;

[0192] d) Call the write function of the secondary storage to write the contents of the virtual address vaddr (i.e. the data stored in paddr) to the secondary storage ds location;

[0193] e) Wait for the write to complete. If an error occurs or the write process is canceled, the read-only state of the page table entry corresponding to vaddr needs to be restored to the read-write state.

[0194] f) If the swap is successful, update the page table entry corresponding to vaddr and record its location ds information in the secondary storage into the page table entry; at the same time, if it is secondary storage that can be directly read and written by persistent memory through the page table (such as the aforementioned method of merging into other memory blocks), then make the page table writable; otherwise, it is necessary to set the present flag of the page table, such as clearing the present flag, to facilitate recovery when accessed by subsequent processes.

[0195] g) Obtain the protection lock of the memory allocation information mmap, update the memory allocation information mmap, and record the secondary storage and its location ds into mmap;

[0196] h) Release memory block ms1;

[0197] 12. Swapping successful. Set bit position 'a' in Bitmap3 and clear it from Bitmap6.

[0198] Through the above steps, position a in Bitmap6 can be swapped out; optionally, in order to ensure the stability of the swapping level (i.e., the ratio of the number of swapped memory blocks to the number of memory blocks in the process), after swapping out a memory block, a suitable position is found to swap in a memory block.

[0199] 13. In Bitmap2, select a set position b and try to allocate a memory block ms2 that is connected to the physical address of the memory block before or after it. If the contiguous requirement cannot be met, then allocate any memory block ms2.

[0200] 14. Swap its contents from the secondary storage location into the newly allocated memory block ms2;

[0201] a) Establish a temporary mapping relationship between the physical address paddr of ms2 and the kernel-mode virtual address vaddr1 (used by the kernel, not a relationship in the process page table);

[0202] b) Based on the swap-out location information recorded by mmap, obtain the secondary storage location ds of the swapped-out memory block;

[0203] c) Call the read function of the secondary storage to read the data stored at the ds location of the secondary storage, and write the data to memory using the kernel virtual address vaddr1.

[0204] d) Wait for the reading to complete, or for an error to occur;

[0205] e) Cancel the temporary mapping of vaddr1 and paddr. If a read error occurs or the write process is canceled, the swapping fails and the memory block ms2 is released.

[0206] f) If the swap is successful, the page table corresponding to process vaddr needs to be updated to establish the association with paddr;

[0207] g) Obtain the memory allocation information protection lock, update the memory allocation information mmap, and record paddr in the position corresponding to vaddr in mmap;

[0208] h) Release the secondary storage location ds;

[0209] 15. If the swap is successful, the bit position b in Bitmap2 will be cleared to zero.

[0210] 16. Loop through num times to see if it ends. If it does not end, proceed to step 9; otherwise, end and return.

[0211] II. Implementation Example of Non-Contiguous Memory Consolidation in Host Machine Reserved Memory

[0212] This embodiment targets free memory blocks, specifically memory blocks not allocated to processes and managed by the reserved memory management module. If these memory blocks are scattered across the storage space managed by the reserved memory management module, they need to be regularized to group them together. The regularization method involves swapping data stored in allocated memory blocks to these scattered free memory blocks, thus replacing them with allocated memory blocks and making them contiguous with other allocated memory blocks.

[0213] For example, taking the following bitmap: 0001 1001 1101 0001 as an example, setting 1 indicates a free memory block, and 0 indicates an allocated memory block; it can be seen that the two free memory blocks at bits 12 and 16 are relatively scattered. If they can be swapped to bits 6 and 7, bits 3 to 10 will form a continuous large segment of free space. Based on this, the method of this embodiment may include the following steps:

[0214] 1. Traverse all memory blocks ms, and use each memory block ms granularity as a bit of the free bitmap Bitmap1 to obtain the free status of the memory block; generate a free bitmap Bitmap1 based on the memory free status, in which memory blocks existing in main memory are set to 1 (located in main memory, indicating unallocated free memory blocks), and those not existing are set to 0 (indicating that they are not free and have been allocated to the process).

[0215] 2. Based on the preset threshold (e.g., set the threshold to 2), the memory contiguous regions in Bitmap1 with a physical address set to 1 whose length is less than the threshold are memory consolidation target objects. Set the memory regions in Bitmap1 with a length less than the threshold to 1, otherwise set them to 0, and generate a scattered free bitmap Bitmap2.

[0216] In other words, the positions marked with 1 in Bitmap2 represent candidate squared target objects (candidate free memory blocks to be replaced). For example:

[0217] Bitmap1: 0001 1001 1101 0001 has only one consecutive bit at the 12th and 16th positions, which is less than the threshold, so it is set to 1, and the others are set to 0; Bitmap2 is: 0000 0000 0001 0001.

[0218] Therefore, this step can identify scattered free memory blocks, thereby obtaining candidate regularized target objects.

[0219] 3. Generate a continuous free bitmap Bitmap3 based on Bitmap1 and Bitmap2; the positions set to 1 in Bitmap3 refer to the continuous free memory blocks in Bitmap1, which are used to find cold blocks that are related to these continuous free memory blocks in Bitmap3 in the future, so as to replace them with the free memory blocks that need to be replaced.

[0220] There are several ways to generate Bitmap3. For example, you can invert Bitmap2 and then perform a logical AND operation with Bitmap1 to get Bitmap3.

[0221] Bitmap1: 0001 1001 1101 0001

[0222] Bitmap2: 0000 0000 0001 0001, inverted to: 1111 1111 1110 1110

[0223] Bitmap3: 0001 1001 1100 0000.

[0224] In other examples, Bitmap3 could be generated by setting the position in Bitmap1 to 1 and the position in Bitmap2 to 0. That is, the position in Bitmap3 where the position is set to 1 is the position in Bitmap1 where the position is set to 1 and the position in Bitmap2 where the position is set to 0, and the other positions are set to 0.

[0225] As can be seen from Bitmap3, if a replacement is to be performed later, the memory block corresponding to the position set to 1 in Bitmap3 can be determined to be a cold block. If it is a cold block, it can be replaced so that the replaced position is adjacent to a continuous free memory block.

[0226] 4. For all allocated memory blocks (the part set to 0 in Bitmap1), query the hot and cold memory set to generate a second cold block bitmap Bitmap4, where the cold blocks are set to 1, and all other blocks, whether hot pages or swapped-out memory blocks, are set to 0.

[0227] 5. If Bitmap3 is not empty, proceed to step 7; if Bitmap3 is empty, the smoothing process can be terminated; optionally, multiple (if any) scattered free memory blocks in Bitmap2 can be smoothed to form consecutive positions.

[0228] 6. If Bitmap3 is still zero, it means there is no memory block that can be regularized, so return directly; if Bitmap3 is not zero after adjustment, but Bitmap2 is zero, then Bitmap3 and Bitmap2 will each occupy half randomly.

[0229] 7. Using Bitmap3 as a base, copy Bitmap5 and find its 1-to-1 transition position (i.e., the bit that changes between being set to 0 and 1 in Bitmap5). Determine whether this bit is set in the second cold block bitmap Bitmap4. If it is set, set the bit to 1 in Bitmap5. At the same time, generate a Bitmap6 (initially, all bits in Bitmap6 are zero), where the position set to 1 is the new position set to 1 in Bitmap5, and the others are set to 0.

[0230] 8. At this point, Bitmap6 is the candidate set of regularized objects (i.e., allocated memory blocks suitable for replacement, which are cold blocks and can be contiguous with free space during the replacement process), while Bitmap2 is the candidate set of regularized target objects (i.e., scattered free memory blocks). Calculate the number of each and take the minimum value num. If num is 0, exit directly; otherwise, continue.

[0231] 9. Select a set bit position 'a' from Bitmap6 that is adjacent to the set bit position in Bitmap3; if not found, end memory consolidation and return; otherwise, continue.

[0232] 10. Select a position b in Bitmap2. If the condition is not met, proceed to the next candidate position in step 9; otherwise, continue.

[0233] 11. Check again whether a is still in the cold page set. If yes, continue; otherwise, return to step 9 and find the next memory consolidation location.

[0234] 12. Replace the data in memory block ms1 corresponding to position a with the data in memory block ms2 corresponding to position b;

[0235] a) Begin a formal memory block consolidation process by selecting the already allocated contiguous memory block ms2 in main memory;

[0236] b) Select the memory block to be regularized, ms1. When ms1 is obtained from the cold and hot set, it is the physical address information paddr. According to the memory allocation information mmap, it is converted into the virtual address vaddr.

[0237] c) Change the page table of the virtual machine vaddr to read-only to avoid the memory contents being changed during the defragmentation process, which could lead to data inconsistency;

[0238] d) Call the main memory write function to write the contents of virtual address vaddr to the target memory location ms2;

[0239] e) Wait for the write to complete. If an error occurs or the write process is canceled, the read-only state of the page table corresponding to vaddr needs to be canceled and changed back to read-write state.

[0240] f) If the regularization is successful, the page table corresponding to vaddr needs to be updated, and its position ms2 in the main storage needs to be recorded in the page table entry.

[0241] g) Obtain the memory allocation information protection lock, update the memory allocation information mmap corresponding to the original ms1, and record the main storage and its location ms2 into mmap;

[0242] h) Release memory block ms1.

[0243] 13. Once the normalization is successful, set bit position 'a' in Bitmap3 and clear it from Bitmap6.

[0244] 14. If the data stored at position b in Bitmap2 has changed to the data originally stored in ms1, then clear bit position b in Bitmap2.

[0245] 15. Check if the loop has ended after num iterations. If it has not ended, return to step 9; otherwise, end the loop.

[0246] Corresponding to the embodiments of the aforementioned memory warping method, this specification also provides embodiments of a memory warping apparatus and the computer equipment on which it is applied.

[0247] The embodiments of the memory consolidation device described in this specification can be applied to computer devices, such as servers or terminal devices. The device embodiments can be implemented in software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by its processor reading the corresponding computer program instructions from non-volatile memory into memory for execution. From a hardware perspective, such as... Figure 3 The diagram shown is a hardware structure diagram of a computer device containing the memory consolidation device described in this manual. (Except for...) Figure 3 In addition to the processor 310, memory 330, network interface 320, and non-volatile memory 340 shown, the computer device in which the memory consolidation device 331 is located in the embodiment may also include other hardware depending on the actual function of the computer device, which will not be described in detail here.

[0248] like Figure 4 As shown, Figure 4 This is a block diagram illustrating a memory straightening apparatus according to an exemplary embodiment of this specification, the apparatus comprising:

[0249] The determining module 41 is configured to: determine a regularization target object and a corresponding regularization source object based on the usage status of each memory block in the storage space to be regularized and its position in the storage space to be regularized; wherein, the regularization target object includes a set of scattered swapped-out memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to continuous swapped-out space; and / or, the regularization target object includes a set of scattered free memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to continuous free space; in the set of scattered swapped-out memory blocks, the number of consecutive swapped-out memory blocks is less than a first threshold; in the continuous swapped-out space, the number of consecutive swapped-out memory blocks is greater than or equal to the first threshold; in the set of scattered free memory blocks, the number of consecutive free memory blocks is less than a second threshold; in the continuous free space, the number of consecutive free memory blocks is greater than or equal to the second threshold;

[0250] The replacement module 42 is used to replace the usage state of the regularization target object with the usage state of the corresponding regularization source object.

[0251] In some examples, the determining module 41 is also used for:

[0252] Generate an unset bitmap based on the number of memory blocks in the storage space to be regularized;

[0253] Obtain the metadata of the storage space to be regularized, determine the corresponding bit of the memory block in the bitmap according to the location of the memory block in memory recorded in the metadata, and set the corresponding bit of the memory block in the bitmap according to the usage status of the memory block recorded in the metadata.

[0254] Based on each bit of the bitmap, determine the source object and the corresponding target object for normalization.

[0255] In some examples, the bitmap includes a swap bitmap indicating the usage status of memory blocks as swapped, wherein a set bit in the swap bitmap indicates that the corresponding memory block is a swapped memory block, and a bit not set indicates whether the corresponding memory block is a swapped memory block.

[0256] The target object for regularization is determined in the following way:

[0257] Based on the swapped bitmap, a scattered swapped bitmap is generated; wherein, the bits set in the scattered swapped bitmap correspond to the bits in the swapped bitmap where the number of consecutively set bits is less than a first threshold.

[0258] The set of scattered swapped-out memory blocks is determined based on the bits set in the scattered swapped-out bitmap;

[0259] And / or,

[0260] The bitmap includes a free bitmap indicating that the memory block is in a free state, and the set bits in the free bitmap indicate that the corresponding memory block is a free memory block;

[0261] The target object for regularization is determined in the following way:

[0262] Based on the idle bitmap, a scattered idle bitmap is generated; wherein, the bits set in the scattered idle bitmap correspond to the bits in the idle bitmap whose consecutive set bit length is less than a second threshold.

[0263] The set of scattered free memory blocks is determined based on the bits set in the scattered free bitmap.

[0264] In some examples, the regularized source object is determined in the following way:

[0265] Using the swapped bitmap and the scattered swapped-out bitmap, a continuous swapped-out bitmap is generated, wherein the set bits in the continuous swapped-out bitmap represent the continuous swapped-out space;

[0266] For the unset bits in the swapped bitmap, query whether the corresponding memory block is a cold block, and generate a first cold block bitmap based on the query result; the set bits in the first cold block bitmap indicate that the corresponding memory block is a cold block;

[0267] Based on the continuously swapped-out bitmap and the first cold block bitmap, determine the set of cold blocks that are spatially adjacent to the continuously swapped-out bitmap;

[0268] And / or,

[0269] Using the free bitmap and the scattered free bitmap, a continuous free bitmap is generated, wherein the set bits in the continuous free bitmap represent the continuous free space;

[0270] For the unset bits in the free bitmap, query whether the corresponding memory block is a cold block, and generate a second cold block bitmap based on the query result; the set bits in the second cold block bitmap indicate that the corresponding memory block is a cold block;

[0271] Based on the continuous free bitmap and the second cold block bitmap, a set of cold blocks adjacent to the continuous free space is determined.

[0272] In some examples, the determining module 41 is also used for:

[0273] include:

[0274] Invert each bit in the scattered swapped bitmap and perform a logical AND operation with the swapped bitmap to obtain a continuous swapped bitmap.

[0275] And / or,

[0276] Using the aforementioned free bitmap and the scattered free bitmaps, a continuous free bitmap is generated, including:

[0277] Invert each bit in the scattered free bitmap and perform a logical AND operation with the free bitmap to obtain a continuous free bitmap.

[0278] In some examples, the determining module 41 is also used for:

[0279] A first candidate regularization source object bitmap is generated based on the positions of the bits set in the continuous swapped-out bitmap and the positions of the bits set in the first cold block bitmap; the bits set in the first candidate regularization source object bitmap represent one or more cold blocks that are continuous with the continuous swapped-out space.

[0280] Based on the bitmap of the first candidate regularized source object, determine the set of cold blocks adjacent to the continuous swapped-out space;

[0281] And / or,

[0282] Based on the positions of the bits set in the continuous free bitmap and the positions of the bits set in the second cold block bitmap, a second candidate regularization source object bitmap is generated; the bits set in the second candidate regularization source object bitmap represent one or more cold blocks that are continuous with the continuous free space.

[0283] Based on the second candidate regularized source object bitmap, determine the set of cold blocks adjacent to the continuous free space.

[0284] In some examples, the displacement module is also used for:

[0285] Swap out the data stored in the cold blocks in the set of cold blocks adjacent to the continuous swapped-out space, changing the cold blocks with swapped-out data into swapped-out memory blocks; swap in the data corresponding to the scattered swapped-out memory blocks in the set of scattered swapped-out memory blocks, changing the scattered swapped-out memory blocks into non-swapped-out memory blocks; and / or,

[0286] The data stored in the cold blocks in the set of cold blocks adjacent to the continuous free space is replaced by the scattered free memory blocks in the set of scattered free memory blocks, so that the replaced cold blocks become free memory blocks, and the scattered free memory blocks become allocated memory blocks.

[0287] The specific implementation process of the functions and roles of each module in the above memory consolidation device can be found in the implementation process of the corresponding steps in the above memory consolidation method, and will not be repeated here.

[0288] Accordingly, embodiments of this specification also provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the aforementioned memory consolidation method embodiments.

[0289] Accordingly, embodiments of this specification also provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the memory consolidation method embodiment.

[0290] Accordingly, embodiments of this specification also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the memory consolidation method embodiments.

[0291] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the solution in this specification according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0292] The above embodiments can be applied to one or more computer devices. The computer device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The hardware of the computer device includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0293] The computer device can be any electronic product that can interact with the user, such as a personal computer, tablet computer, smartphone, personal digital assistant (PDA), game console, interactive network television (IPTV), smart wearable device, etc.

[0294] The computer equipment may also include network equipment and / or user equipment. The network equipment includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers.

[0295] The network in which the computer device is located includes, but is not limited to, the Internet, wide area network, metropolitan area network, local area network, and virtual private network (VPN).

[0296] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0297] The steps of the various methods described above are only for clarity. In practice, they can be combined into one step or some steps can be split into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, but without changing the core design of the algorithm and process, are also within the scope of protection of this application.

[0298] The terms "specific example" or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with the embodiments or examples, which are included in at least one embodiment or example of this specification. In this specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0299] Other embodiments of this specification will readily occur to those skilled in the art upon consideration of the specification and practice of the invention claimed herein. This specification is intended to cover any variations, uses, or adaptations that follow the general principles of this specification and include common knowledge or customary techniques in the art not claimed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this specification are indicated by the following claims.

[0300] It should be understood that this specification is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this specification is limited only by the appended claims.

[0301] The above description is merely a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of protection of this specification.

Claims

1. A memory compaction method, the method comprising: Based on the usage status of each memory block in the storage space to be regularized and its position within the storage space, a regularization target object and a corresponding regularization source object are determined; wherein, the regularization target object includes a set of scattered swapped-out memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to continuous swapped-out space; and / or, the regularization target object includes a set of scattered free memory blocks, and the corresponding regularization source object includes a set of cold blocks adjacent to continuous free space; in the set of scattered swapped-out memory blocks, the number of consecutive swapped-out memory blocks is less than a first threshold; in the continuous swapped-out space, the number of consecutive swapped-out memory blocks is greater than or equal to the first threshold; in the set of scattered free memory blocks, the number of consecutive free memory blocks is less than a second threshold; in the continuous free space, the number of consecutive free memory blocks is greater than or equal to the second threshold; The usage state of the regularized target object is swapped with the usage state of the corresponding regularized source object, including: swapping out the data stored in the cold blocks in the set of cold blocks adjacent to the continuous swapped-out space, and swapping in the data corresponding to the scattered swapped-out memory blocks in the set of scattered swapped-out memory blocks; and / or, swapping the data stored in the cold blocks in the set of cold blocks adjacent to the continuous free space to the scattered free memory blocks in the set of scattered free memory blocks.

2. The method according to claim 1, wherein determining the target object and the corresponding source object for normalization based on the usage status and location in memory of each memory block in the storage space to be normalized includes: Generate an unset bitmap based on the number of memory blocks in the storage space to be regularized; Obtain the metadata of the storage space to be regularized, determine the corresponding bit of the memory block in the bitmap according to the location of the memory block in memory recorded in the metadata, and set the corresponding bit of the memory block in the bitmap according to the usage status of the memory block recorded in the metadata. Based on each bit of the bitmap, determine the source object and the corresponding target object for normalization.

3. The method according to claim 2, wherein the bitmap includes a swap bitmap indicating that the memory block is in a swapped state, and whether a bit in the swap bitmap is set indicates whether the corresponding memory block is a swapped memory block; The target object for regularization is determined in the following way: Based on the swapped bitmap, a scattered swapped-out bitmap is generated; wherein... The bits that have been set in the scattered swapped bitmap correspond to the bits in the swapped bitmap where the number of consecutive set bits is less than the first threshold. The set of scattered swapped-out memory blocks is determined based on the bits set in the scattered swapped-out bitmap; And / or, The bitmap includes a free bitmap indicating that the memory block is in a free state, and the set bits in the free bitmap indicate that the corresponding memory block is a free memory block; The target object for regularization is determined in the following way: Based on the idle bitmap, a scattered idle bitmap is generated; wherein, the bits set in the scattered idle bitmap correspond to the bits in the idle bitmap whose consecutive set bit length is less than a second threshold. The set of scattered free memory blocks is determined based on the bits set in the scattered free bitmap.

4. The method according to claim 3, wherein the regularization source object is determined in the following manner: Using the swapped bitmap and the scattered swapped-out bitmap, a continuous swapped-out bitmap is generated, wherein the set bits in the continuous swapped-out bitmap represent continuous swapped-out spaces; For the unset bits in the swapped bitmap, query whether the corresponding memory block is a cold block, and generate a first cold block bitmap based on the query result; The set bits in the first cold block bitmap indicate that the corresponding memory block is a cold block; Based on the continuous swapped-out bitmap and the first cold block bitmap, determine the set of cold blocks adjacent to the continuous swapped-out space; And / or, Using the free bitmap and the scattered free bitmap, a continuous free bitmap is generated, wherein the set bits in the continuous free bitmap represent continuous free space; For the unset bits in the free bitmap, query whether the corresponding memory block belongs to a cold block, and generate a second cold block bitmap based on the query result; The set bits in the second cold block bitmap indicate that the corresponding memory block is a cold block; Based on the continuous free space bitmap and the second cold block bitmap, a set of cold blocks adjacent to the continuous free space is determined.

5. The method according to claim 4, wherein generating a continuous swapped-out bitmap using the swapped bitmap and the scattered swapped-out bitmap comprises: Invert each bit in the scattered swapped bitmap and perform a logical AND operation with the swapped bitmap to obtain a continuous swapped bitmap. And / or, Using the aforementioned free bitmap and the scattered free bitmaps, a continuous free bitmap is generated, including: Invert each bit in the scattered free bitmap and perform a logical AND operation with the free bitmap to obtain a continuous free bitmap.

6. The method according to claim 4, wherein obtaining the set of adjacent cold blocks in the continuously swapped-out bitmap and the first cold block bitmap comprises: A first candidate regularization source object bitmap is generated based on the positions of the bits set in the continuous swapped-out bitmap and the positions of the bits set in the first cold block bitmap; the bits set in the first candidate regularization source object bitmap represent one or more cold blocks that are continuous with the continuous swapped-out space. Based on the bitmap of the first candidate regularized source object, obtain the set of cold blocks adjacent to the continuous swapped-out space; And / or, Based on the continuous free bitmap and the second cold block bitmap, obtain a set of cold blocks adjacent to the continuous free space, including: Based on the positions of the bits set in the continuous free bitmap and the positions of the bits set in the second cold block bitmap, a second candidate regularization source object bitmap is generated; the bits set in the second candidate regularization source object bitmap represent one or more cold blocks that are continuous with the continuous free space. Based on the bitmap of the second candidate regularized source object, obtain the set of cold blocks adjacent to the continuous free space.

7. A memory straightening device, the device comprising: A determination module is used to determine a target object and a corresponding source object for regularization based on the usage status of each memory block in the storage space to be regularized and its position in the storage space to be regularized; wherein, the target object for regularization includes a set of scattered swapped-out memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to continuous swapped-out space; and / or, the target object for regularization includes a set of scattered free memory blocks, and the corresponding source object for regularization includes a set of cold blocks adjacent to continuous free space; in the set of scattered swapped-out memory blocks, the number of consecutive swapped-out memory blocks is less than a first threshold; in the continuous swapped-out space, the number of consecutive swapped-out memory blocks is greater than or equal to the first threshold; in the set of scattered free memory blocks, the number of consecutive free memory blocks is less than a second threshold; in the continuous free space, the number of consecutive free memory blocks is greater than or equal to the second threshold; The replacement module is used to replace the usage state of the regularized target object with the usage state of the corresponding regularized source object, including: replacing the data stored in the cold blocks in the set of cold blocks adjacent to the continuous swapped-out space, replacing the data corresponding to the scattered swapped-out memory blocks in the set of scattered swapped-out memory blocks; and / or replacing the data stored in the cold blocks in the set of cold blocks adjacent to the continuous free space with the scattered free memory blocks in the set of scattered free memory blocks.

8. A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method of any one of claims 1 to 6.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Memory dynamic management method and device

    CN109375985A

  • Heap memory management method and device

    CN112685333A