Shared memory management method, product, equipment and medium

By managing shared memory through multi-level linked lists, the problem of allocation failure caused by the lack of continuous large blocks is solved, efficient memory utilization and system stability are achieved, and the flexibility of memory management and resource utilization are improved.

CN120670332AInactive Publication Date: 2025-09-19LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202511164581.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-20
Publication Date
2025-09-19
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In existing shared memory management technologies, although the total free capacity is sufficient, allocation fails due to the lack of continuous large blocks of memory, resulting in resource waste and system instability.

Method used

A multi-level linked list structure is used to manage shared memory. Free blocks are divided exponentially according to the physical page size. Through independent linked list management, single-level continuous blocks are matched first. If there are insufficient blocks, multi-level non-continuous block splicing allocation is automatically triggered to achieve classification and efficient utilization of fragments.

Benefits of technology

Significantly improve memory utilization, ensure allocation success rate, maintain long-term stable operation of the system, reduce memory waste and fragmentation, and improve system performance and resource management efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120670332A_ABST
    Figure CN120670332A_ABST
Patent Text Reader

Abstract

The invention discloses a shared memory management method, a product, equipment and a medium, and relates to the technical field of data sharing, and the method comprises the following steps: dividing free blocks of a shared memory according to a physical page size index, managing the free blocks by using an independent linked list, realizing classified management of fragments, preferentially matching single-order continuous blocks during allocation, when the continuous blocks are insufficient, the splicing distribution of the multi-order discontinuous blocks is automatically triggered, and small discrete free blocks can be combined and reused, so that the problem that the total free blocks are sufficient but the distribution fails due to the lack of continuous large blocks in the related technology is solved, and the beneficial effects of remarkably improving the memory utilization rate, ensuring the distribution success rate and maintaining the long-term stable operation of the system are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data sharing technology, and in particular to a shared memory management method, product, device and medium. Background Art

[0002] Current shared memory-based multi-host data sharing technologies, such as file system solutions like FamFS (Fast Access Multi-host File System), format shared memory areas as specific file systems and provide standard file interfaces, allowing multiple hosts to simultaneously mount and access the same memory pool. However, when allocating memory space, these file systems require that each file be allocated data blocks with contiguous physical addresses. As the system operates over time and files undergo frequent dynamic changes (creation, deletion, and resizing), a large number of discrete, small free blocks accumulate in the shared memory. This fragmented space is difficult to reuse because it cannot meet the needs of new files for large, contiguous blocks of memory. Even if the total free capacity of the memory pool is sufficient, allocation may fail due to a lack of sufficiently large contiguous space, ultimately wasting resources.

[0003] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve at present. Summary of the Invention

[0004] The present application provides a shared memory management method, product, device and medium to at least solve the problem in the related art that there is sufficient total free space but allocation fails due to lack of continuous large blocks.

[0005] The present application provides a shared memory management method, in which the shared memory is divided into multiple data blocks consisting of several physical pages, including: obtaining a free memory table corresponding to the shared memory; the free memory table is a multi-order linked list structure, each order linked list stores free data blocks corresponding to its unit storage capacity, and the unit storage capacity of the multi-order linked list increases exponentially according to the size of the physical pages divided in the shared memory; determining the size of the memory to be allocated in the allocation request sent by any client; in response to the presence of a target linked list in the free memory table with a unit storage capacity not less than the memory size to be allocated and being non-empty, allocating free data blocks to the client from the target linked list; in response to the absence of the target linked list in the free memory table and the total capacity of the free memory blocks in the free memory table not less than the memory size to be allocated, allocating multiple free data blocks to the client from the non-empty multi-order linked list, so that the size of the spliced ​​free data blocks is equal to the memory size to be allocated.

[0006] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of the above-mentioned shared memory management method when executing the computer program.

[0007] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned shared memory management method are implemented.

[0008] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned shared memory management method when executed by a processor.

[0009] Through this application, the free blocks of shared memory are divided into levels according to the physical page size index and managed with an independent linked list, so that fragments can be classified and managed. Single-level continuous blocks are matched first during allocation. When continuous blocks are insufficient, multi-level non-continuous block splicing allocation is automatically triggered, so that discrete small free blocks can be combined and reused, thereby solving the problem in related technologies that there is sufficient total free space but allocation fails due to lack of continuous large blocks, and achieving the beneficial effects of significantly improving memory utilization, ensuring allocation success rate, and maintaining long-term stable operation of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0011] Figure 1 A schematic diagram of the structure of a FamFS system provided in an embodiment of the present application.

[0012] Figure 2 A schematic diagram of shared memory partitioning provided in an embodiment of the present application.

[0013] Figure 3 This is a flowchart of an execution of a shared memory management method provided in an embodiment of the present application.

[0014] Figure 4 A schematic diagram of the structure of an allocation memory table provided in an embodiment of the present application.

[0015] Figure 5 A flowchart of the first allocation method provided in an embodiment of the present application.

[0016] Figure 6 A flowchart of the second allocation method provided in an embodiment of the present application.

[0017] Figure 7 This is a flowchart of the first insertion method provided in an embodiment of the present application.

[0018] Figure 8This is a flowchart of the second insertion method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0019] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0020] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.

[0021] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0022] The embodiment of the present application provides a shared memory management method. To facilitate understanding of the solution of this embodiment, the following describes in detail the area division of the shared memory and the structure of the shared memory object. First, refer to Figure 1 , Figure 1 The FamFS file system solution is shown, including a mount point set on the client host, a hidden metadata file mounted under the mount point, a super block divided from the shared memory is memory-mapped to the super block under the hidden metadata file of the client host, and the log metadata is memory-mapped to the log under the hidden metadata file of the client host. The log is repeated to obtain the first file, the second file, and the first directory. The log entry area includes multiple log entry types, including at least the first log entry type, the second log entry type, and the third log entry type. The allocation unit includes multiple data blocks, and the first file and the second file correspond to two data blocks of the allocation unit respectively. By formatting the shared memory area as a specific file system and providing a standard file interface, multiple hosts are allowed to mount and access the same memory at the same time, wherein the shared memory can specifically be a CXL (Compute express link) memory device. The shared memory is divided into a metadata area and a data area from low address to high address, as shown in FIG. Figure 2As shown, the metadata area is used to store metadata information such as bitmaps, and the data area is used to store several physical pages. This embodiment provides the client with the right to use the shared memory through a shared memory object. The storage area of ​​the shared memory object is actually composed of several data blocks, and each data block is composed of several consecutive physical pages. Specifically, the data block describes a continuous physical address on the shared memory, which is composed of two parameters: the starting address and the offset. Among them, the bitmap and the physical page correspond one to one, and the value of the bitmap represents the usage status of the corresponding physical page. When the value of the bitmap is 1, it means that the physical page is used. When the value of the bitmap is 0, it means that the physical page is not used. Based on the value of each bitmap, it can be determined that the data blocks to which several consecutive physical pages belong can be divided into two types, namely used data blocks and free data blocks. If the values ​​of the bitmaps corresponding to several consecutive physical pages included in a data block are all 1, it means that the data block is a used data block. If the values ​​of the bitmaps corresponding to several consecutive physical pages included in a data block are all 0, it means that the data block is a free data block. As shown Figure 2 As shown, the first used data block (starting position is 0M, data size is 6M) includes three consecutive physical pages, and the bitmap values ​​corresponding to these three consecutive physical pages are all 1. The first free data block (starting position is 6M, data size is 4M) includes two consecutive physical pages, and the bitmap values ​​corresponding to these two consecutive physical pages are all 0. The second free data block (starting position is 10M, data size is 2M) includes one physical page, and the bitmap values ​​corresponding to this physical page are all 0. The second used data block (starting position is 12M, data size is 15M) includes two consecutive physical pages, and the bitmap values ​​corresponding to these two consecutive physical pages are all 1. It can be understood that data blocks are the basis of CXL shared memory management. In addition to some basic fields in the shared memory object structure (including but not limited to name, size, type, and reference count), it also holds a data block list (i.e., extension list) for associating the data blocks of the current shared memory object in the CXL memory device, such as Figure 2 As shown in the figure, the extended list of the first shared memory object is associated with the first used data block (starting at 0MB and data size 6MB), while the extended list of the second shared memory object is associated with the second used data block (starting at 12MB and data size 15MB). Shared memory objects are stored across multiple data blocks, so the key to creating and deleting shared memory objects lies in managing data blocks.

[0023] Combined with Figure 3 The execution flow of the shared memory management method is shown and the method is described in detail.

[0024] S101: Obtain a free memory table corresponding to the shared memory; the free memory table is a multi-level linked list structure, each level of the linked list stores free data blocks corresponding to its unit storage capacity, and the unit storage capacity of the multi-level linked list increases exponentially according to the size of the physical pages divided in the shared memory.

[0025] In this embodiment, the free memory table corresponding to the shared memory is first obtained. The free memory table is used to organize and maintain the relationship between free data blocks. The free memory table is an array linked list structure. The array items are orders of different sizes. The unit storage capacity corresponding to these orders starts from the physical page size and increases exponentially. Specifically, it can increase exponentially to 2G. Each order defines a linked list for storing data blocks of the unit storage capacity corresponding to the order. The unit storage capacity corresponding to the last order is defined as Big, which is used to store data blocks larger than 2G. For example, since each free data block can be composed of different numbers of continuous physical pages, such as the first free data block d1 is composed of 4 continuous physical pages, and the second free data block d2 and the third free data block d3 are both composed of 2 continuous physical pages, if the size of each physical page is 2M, then the size of the first free data block d1 is 8M, the size of the second free data block d2 and the size of the third free data block d3 are 4M, and the multiple orders increase exponentially according to the size of the physical pages divided in the shared memory. Then the multi-stages can be 2M, 4M, 8M, 16M..., 2G, Big respectively. It can be understood that 2M, 4M, 8M, 16M..., 2G, Big are the unit storage capacities corresponding to each stage in this embodiment, that is, the stage size of each stage. The multi-stage linked list includes a 2M linked list, a 4M linked list, an 8M linked list, a 16M linked list..., a 2G linked list, and a Big linked list. The first free data block d1 is inserted into the 8M linked list, and the second free data block d2 and the third free data block d3 are both inserted into the 4M linked list.

[0026] The multi-level linked list structure in this embodiment divides the physical page size into exponentially increasing levels (e.g., 2M, 4M, 8M, etc.) and stores free data blocks of corresponding sizes in independent linked lists. This size-tiered management establishes a fast retrieval channel, allowing allocations to jump directly to the target level linked list (e.g., a 6M request would locate the 8M level), avoiding traversing all fragments and reducing matching complexity. This also creates a fragment isolation mechanism to prevent small fragments from being mixed into the large block linked list (e.g., a 4M data block would only be stored in the 4M level linked list), reducing contamination of the large block linked list and increasing the reuse rate of small fragments. The exponential level design dynamically adapts to memory requests, efficiently handling both small (e.g., 2M) and large (e.g., 2G) block requests. By defining the Big level, free data blocks exceeding the maximum unit storage capacity can be flexibly handled, ensuring the system can effectively manage large memory blocks. For example, free data blocks exceeding 2G can be placed in the Big list, avoiding the inability to manage large memory blocks due to linked list limitations. Through this multi-level linked list structure of the free memory table, the system can more efficiently manage and utilize shared memory, thereby improving memory utilization and system performance.

[0027] S102: Determine the size of the memory to be allocated in the allocation request sent by any client.

[0028] In this embodiment, when any client needs to create a shared memory object, the client initiates an allocation request, which includes at least the size of the memory to be allocated. For example, if client A needs to create a shared memory object that requires 12MB of memory space, client A will initiate an allocation request, including the size of the memory to be allocated as 12MB.

[0029] S103: In response to the existence of a target linked list in the free memory table with a unit storage capacity not less than the memory size to be allocated and being non-empty, allocate a free data block to the client from the target linked list.

[0030] In this embodiment, it is first determined in the free memory table whether there is a target linked list with a unit storage capacity not less than the memory size to be allocated and which is not empty. Assume that client A requests to allocate 12M of memory. The structure of the free memory table is as follows: 2M linked list: empty; 4M linked list: d1, d3, d5; 8M linked list: d2, d4; 16M linked list: d6, d10; 32M linked list: empty; 2G linked list: d7, d8; Big linked list: d9. Among them, d1-d10 are all free data blocks. The free memory table is searched for a linked list with a unit storage capacity not less than 12M and which is not empty. 12M is greater than 8M and less than 16M, so the target linked list exists in the free memory table. In this case, a single-stage allocation method is adopted. The target linked list is a 16M linked list. The 16M linked list includes d6 and d10. In this embodiment, a free data block is allocated to client A from the free data blocks in the 16M linked list, such as allocating d10 to client A.

[0031] In this embodiment, by allocating free data blocks to clients from a target linked list that meets the requirements, efficient and accurate memory allocation can be achieved, allowing for rapid location of appropriate free data blocks, reducing memory allocation wait time and significantly improving response speed. This embodiment also effectively reduces memory fragmentation by selecting the free data block closest to the requested size for allocation, avoiding memory waste caused by allocating overly large memory blocks and improving memory utilization. Appropriate free data blocks are dynamically selected based on different client requests, supporting memory requests of various sizes and enhancing the system's adaptability and stability.

[0032] S104: In response to the absence of the target linked list in the free memory table and the total capacity of the free memory blocks in the free memory table is not less than the memory size to be allocated, multiple free data blocks are allocated to the client from a non-empty multi-order linked list so that the size of the spliced ​​free data blocks is equal to the memory size to be allocated.

[0033] In this embodiment, if the free memory table does not contain a target linked list with a unit storage capacity no less than the memory size to be allocated and is not empty, but the total size of all free memory blocks in the free memory table is no less than the total size of all free memory blocks in the free memory table, a multi-stage allocation method is used. At least one free data block is selected from each of the multiple stage linked lists, so that the combined size of all selected free data blocks meets the memory size to be allocated. For example, assume that a client requests 12MB of memory. The free memory table is structured as follows: 2MB linked list: empty; 4MB linked list: d1, d3, d5; 8MB linked list: d2, d4; 16MB linked list: empty; 32MB linked list: empty; 2GB linked list: empty; Big linked list: empty. First, a linked list is searched for a non-empty linked list with a unit storage capacity no less than 12MB. Since the 16MB linked list is empty, there is no target linked list that meets the requirements. The free memory table then checks whether the total capacity of all free memory blocks is no less than 12MB. The total capacity of the current free memory blocks is 4MB + 4MB + 4MB + 8MB + 8MB = 28MB, which meets the requirements. Then select multiple free data blocks from the non-empty multi-order linked list so that the total size after splicing is equal to 12M. For example, d1 can be selected from the 4M linked list and d2 can be selected from the 8M linked list. The total size after splicing is 12M.

[0034] In this embodiment, when there is no single-order linked list in the free memory table that meets the allocation request, the client's allocation request can be met by combining multiple smaller free data blocks. This not only improves the flexibility of memory allocation, but also effectively utilizes existing free memory resources, avoids allocation failures caused by insufficient free memory of a single large block, and can better manage memory fragmentation and reduce memory waste. At the same time, it ensures that the client's request is responded to in a timely manner, thereby improving the overall performance and resource utilization of the system.

[0035] Through this application, the free blocks of shared memory are divided into levels according to the physical page size index and managed with an independent linked list, so that fragments can be classified and managed. Single-level continuous blocks are matched first during allocation. When continuous blocks are insufficient, multi-level non-continuous block splicing allocation is automatically triggered, so that discrete small free blocks can be combined and reused, thereby solving the problem in related technologies that there is sufficient total free space but allocation fails due to lack of continuous large blocks, and achieving the beneficial effects of significantly improving memory utilization, ensuring allocation success rate, and maintaining long-term stable operation of the system.

[0036] In an exemplary embodiment, in response to the presence of a target linked list in a free memory table whose unit storage capacity is not less than the memory size to be allocated and is not empty, the process of allocating free data blocks to the client from the target linked list includes: if the difference between the unit storage capacity corresponding to the target linked list and the memory size to be allocated is less than the physical page size; determining the target free data block in at least one free data block in the target linked list, and returning the target free data block to the client; if the difference between the unit storage capacity corresponding to the target linked list and the memory size to be allocated is not less than the physical page size; determining the target free data block in at least one free data block in the target linked list; splitting a first data block of the memory size to be allocated from the target free data block, and returning the first data block to the client.

[0037] In this embodiment, it is first determined whether the difference between the unit storage capacity corresponding to the target linked list and the memory size to be allocated is less than the physical page size. If so, the target free data block is determined in at least one free data block in the target linked list, and the target free data block is directly returned to the client. If not, the target free data block is determined in at least one free data block in the target linked list. In order to avoid memory waste, it is also necessary to split the first data block of the memory size to be allocated from the target free data block, and return the first data block to the client.

[0038] It can be understood that if the difference between the unit storage capacity of the target linked list and the size of the memory to be allocated is less than the physical page size, allocating a memory block with that unit storage capacity will result in a small amount of memory waste. For example, if the physical page size is 2MB, the size of the memory to be allocated is 15MB, and the unit storage capacity of the target linked list is 16MB, the difference is 1MB. In this case, allocating a 16MB memory block will only waste 1MB. If the difference is greater than the physical page size, for example, if the size of the memory to be allocated is 10MB and the unit storage capacity of the target linked list is 16MB, the difference is 6MB. Directly allocating a 16MB data block will result in a large amount of memory waste. Therefore, it is necessary to split the target free data block selected in the target linked list.

[0039] Exemplarily, the structure of the free memory table is as follows: 2M linked list: d6; 4M linked list: d1, d3, d5; 8M linked list: d2, d4; 16M linked list: d7; 32M linked list: empty; 2G linked list: empty; Big linked list: empty; assuming that the client requests to allocate 15M of memory, first search for a linked list with a unit storage capacity of not less than 15M and not empty. The 16M linked list meets the conditions, so the target linked list is the 16M linked list. The unit storage capacity corresponding to the target linked list is 16M, the size of the memory to be allocated is 15M, the difference is 16M-15M=1M, the physical page size is assumed to be 2M, the difference 1M is less than the physical page size 2M, and d7 will be directly selected to be allocated to the client.

[0040] As you can understand, when the difference between the target linked list's unit storage capacity and the size of the memory to be allocated is less than the physical page size, the target free data block is directly allocated to the client. This allocation method can quickly respond to the client's memory request and reduce the complexity and time overhead of memory allocation. Because the difference is small, direct allocation does not result in significant memory waste. It also avoids the additional operations and potential memory fragmentation that may be introduced by splitting memory blocks, improving overall system performance and responsiveness.

[0041] Assume that the client requests to allocate 10M of memory. First, search for a linked list with a unit storage capacity of not less than 10M and not empty. The 16M linked list meets the conditions, so the target linked list is the 16M linked list. The unit storage capacity corresponding to the target linked list is 16M, and the size of the memory to be allocated is 10M. The difference is 16M-10M=6M. The physical page size is assumed to be 2M. The difference of 6M is greater than the physical page size of 2M. At this time, split d7 in the 16M linked list, first split out the first data block d71 of 10M, and allocate d71 to client A.

[0042] It can be understood that when the difference between the unit storage capacity corresponding to the target linked list and the size of the memory to be allocated is not less than the physical page size, the first data block of the memory size to be allocated is split from the target free data block and allocated to the client. This allocation method can effectively reduce memory waste and improve memory resource utilization. By precisely splitting free data blocks to meet client memory requests, the system can avoid memory waste caused by allocating oversized memory blocks. This not only optimizes memory resource allocation but also reduces memory fragmentation, enabling the system to manage memory resources more efficiently. This can significantly improve system resource utilization efficiency and stability, especially when processing a large number of memory requests of varying sizes.

[0043] In an exemplary embodiment, after splitting the first data block of the memory size to be allocated from the target free data block, the shared memory management method also includes: determining the unit storage capacity corresponding to the second data block remaining in the target free data block; and inserting the second data block into a linked list of the corresponding unit storage capacity.

[0044] In this embodiment, after splitting the target free data block into the first data block, the remaining portion is determined as the second data block, and the second data block is inserted into a linked list of corresponding unit storage capacities according to the unit storage capacity of the second data block.

[0045] For example, assuming that the client requests to allocate 12M of memory, first search for a linked list with a unit storage capacity of not less than 12M and not empty. The 16M linked list meets the conditions, so the target linked list is the 16M linked list. The unit storage capacity corresponding to the target linked list is 16M, and the memory size to be allocated is 12M. The difference is 16M-12M=4M. The physical page size is assumed to be 2M. The difference 4M is greater than the physical page size 2M. At this time, d7 in the 16M linked list is split, and the first data block d71 of 12M is split first. d71 is allocated to client A. The remaining second data block d72 is 4M. The unit storage capacity corresponding to the second data block d72 is 4M, so the linked list corresponding to the unit storage capacity is a 4M linked list, and the second data block d72 is inserted into the 4M linked list.

[0046] In this embodiment, by reinserting the remaining portion (the second data block) after the split into the linked list of the corresponding unit storage capacity, the remaining memory resources can be effectively managed and utilized. This not only avoids the waste of the remaining memory blocks, but also maintains the integrity and orderliness of the free memory table, allowing these remaining memory blocks to be reused for subsequent memory requests. For example, in the above example, the 4M memory block remaining after the split is reinserted into the 4M linked list and can be used by clients that subsequently request 4M or less memory. This improves the utilization rate of memory resources, reduces the waste of resources caused by idle memory blocks, and also optimizes the flexibility of memory allocation, allowing the system to more efficiently respond to memory requests of various sizes, further improving the overall performance and resource management efficiency of the system.

[0047] In an exemplary embodiment, a process of allocating multiple free data blocks to a client from a non-empty multi-order linked list so that the size of the spliced ​​free data blocks is equal to the memory size to be allocated includes: initializing the current remaining size to be allocated as the memory size to be allocated, repeatedly performing the splicing allocation operation until the current remaining size to be allocated is 0, and returning the return value list to the client. The splicing allocation operation includes: determining a maximum linked list that is not larger than the current remaining size to be allocated and is non-empty; determining a target free data block from at least one free data block in the maximum linked list, adding the target free data block to the return value list, and updating the current remaining size to be allocated.

[0048] In this embodiment, the current remaining size to be allocated is the memory size that has not been allocated during the allocation process, and its initial value is the memory size to be allocated requested by the client. The splicing allocation operation is the process of selecting appropriate free memory blocks from the multi-level linked list, adding them to the return value list, and updating the current remaining size to be allocated. The return value list is used to store a list of target free memory blocks to be allocated to the client. The target free data blocks are the free memory blocks selected from the selected linked list during the splicing allocation operation.

[0049] For example, the free memory table structure is as follows: 2M linked list: d6; 4M linked list: d1, d3, d5; 8M linked list: d2, d4; 16M linked list: d7; 32M linked list: empty; 2G linked list: empty; Big linked list: empty. Assuming a client requests 20M of memory, the current remaining size to be allocated is initialized to 20M. The first splicing allocation operation: Determine the largest linked list that is not larger than 20M and is not empty: the 16M linked list. Select the target free data block d7 from the 16M linked list and add it to the return value list. Update the current remaining size to be allocated: 20M - 16M = 4M. The second splicing allocation operation: Determine the largest linked list that is not larger than 4M and is not empty: the 4M linked list. Select the target free data block d1 from the 4M linked list and add it to the return value list. Update the current remaining size to be allocated: 4M - 4M = 0M. Allocation is complete: The current remaining size to be allocated is 0. The return value list contains 16MB of d7 and 4MB of d1, and the total size after splicing is 20MB.

[0050] This embodiment efficiently satisfies client memory requests while minimizing memory waste by progressively selecting appropriate free memory blocks from a multi-stage linked list for splicing. By selecting the largest linked list that is not larger than the current remaining size to be allocated and is not empty, it ensures that each allocated memory block is as close to the required size as possible, thereby reducing the fragmentation problem caused by allocating overly large memory blocks. Furthermore, this embodiment improves the flexibility of memory allocation, enabling not only rapid responses to client requests but also optimized memory resource utilization, improving overall performance and resource management capabilities.

[0051] In an exemplary embodiment, the shared memory management method further includes: obtaining an allocation memory table corresponding to the shared memory; and storing the allocated free data blocks in the allocation memory table.

[0052] In this embodiment, the memory allocation table is a data structure for recording the information of the allocated memory data blocks, storing the detailed information of the allocated data blocks for easy management and query. Figure 4As shown, the free memory table management part includes the free memory table and page mapping. The allocated memory table is a hash structure, using the data block offset ej_ofs as the index K_j, j is the data block label, and each index corresponds to a serialized data block object, which contains relevant information of the data block (such as size, status, etc.). Figure 4 In the data block object, k_0:null indicates that index 0 is unallocated, k_1:e1_ofs indicates that index 1 stores the offset address of data block e1, k_2:null indicates that index 2 is unallocated, k_3:e2_ofs indicates that index 3 stores the offset address of data block e2, and k_4:e3_ofs indicates that index 4 stores the offset address of data block e3. In the data block object, hash e1_ofslen:8M indicates the hash value, offset address, and length (8M) of data block e1, hash e2_ofslen:2M indicates the hash value, offset address, and length (2M) of data block e2, and hash e3_ofslen:4M indicates the hash value, offset address, and length (4M) of data block e3. The allocation memory table provides basic query, insertion, and removal interfaces and, as a shared object, can be accessed and operated by the allocation algorithm. The allocated memory table uses a key-value database like Redis as a carrier, and performs persistent configuration and concurrent security, thereby ensuring the fault recovery capability of the used data block management structure. The serialized data block object is an object that converts the relevant information of the memory data block (such as size, status, etc.) into a format that can be stored and transmitted.

[0053] In this embodiment, the data block allocation process can be defined as a process of moving data blocks from the free memory table to the allocated memory table, and the data block recycling process is the opposite.

[0054] For example, assume the following shared memory allocation operations occur in the system: Client A requests 16MB of memory, and the system allocates a 16MB free data block from the free memory table, starting at offset 0x1000. Client B requests 8MB of memory, and the system allocates an 8MB data block from the free memory table, starting at offset 0x2000. The 16MB data block allocated to Client A is serialized and stored in the allocated memory table, with the key being 0x1000 and the value being the serialized data block object. The 8MB data block allocated to Client B is serialized and stored in the allocated memory table, with the key being 0x2000 and the value being the serialized data block object.

[0055] When you need to query the status of a data block, you can quickly query the allocated memory table through the offset. When the memory block is released, you can also quickly remove the corresponding record through the offset.

[0056] It can be seen that this embodiment provides an efficient and reliable management mechanism for allocated memory data blocks by introducing an allocation memory table. The allocation memory table adopts a hash structure, supports fast query, insertion and removal operations, and can significantly improve the efficiency of memory management. Using the data block offset as an index, a specific data block can be quickly located, and the serialized data block object is convenient for storage and transmission. Using the allocation memory table as a shared object and achieving persistence and concurrency security through a key-value database similar to Redis not only enhances the system's fault tolerance and ensures rapid recovery when a failure occurs, but also supports safe operation in a high-concurrency environment.

[0057] In an exemplary embodiment, the shared memory management method further includes: determining a data block to be reclaimed corresponding to a reclaim request sent by any client; and removing the data block to be reclaimed from the allocated memory table and inserting the data block into the free memory table.

[0058] In this embodiment, the reclaim request is a request sent by any client to release a previously allocated data block, and the data block to be reclaimed is the memory data block requested to be reclaimed by the client, that is, the data block that needs to be converted from the used type to the free type.

[0059] For example, suppose that client A previously requested 16M of memory, and the system allocated a data block with a starting offset of 0x1000. Now client A initiates a reclaim request, hoping to release this 16M data block. When receiving client A's reclaim request, the request contains the offset 0x1000 of the data block to be reclaimed. The data block information corresponding to the offset 0x1000 is searched through the allocation memory table, and it is confirmed that the size of the data block is 16M. The data block corresponding to the offset 0x1000 is removed from the allocation memory table, indicating that the data block is no longer allocated, and the value of the bitmap corresponding to the physical page included in the data block is updated. Then, this 16M free data block is inserted into the free memory table. According to the structure of the free memory table, the 16M data block will be inserted into the 16M linked list. At this time, the 16M data block becomes available again and can be used for subsequent memory allocation requests.

[0060] This embodiment achieves efficient memory recovery and reuse by removing reclaimed memory data blocks from the allocated memory table and inserting them into the free memory table. This mechanism ensures that memory resources are quickly returned to a usable state after being released by the client, improving memory turnover efficiency and reducing memory fragmentation. Furthermore, by maintaining the allocated memory table and the free memory table, the system can quickly respond to memory allocation and reclaim requests, improving overall memory management efficiency and system responsiveness.

[0061] In an exemplary embodiment, the method further includes: establishing a page mapping structure based on the address of the physical page, wherein the page mapping structure is used to locate the position of the data block to which the physical page belongs in the free memory table through the address of the physical page.

[0062] In this embodiment, in order to quickly find the location of the corresponding data block in the free memory table through the physical page address, a page mapping structure is introduced, which can be implemented using a giant array or a radix tree.

[0063] Specifically, in the array implementation structure, index is the physical page bitmap number, and value is the page mapping object. In the radix tree implementation structure, non-leaf nodes are the physical page offsets, and leaf nodes are page mapping objects. The page mapping object includes the following fields: a reference to the data block corresponding to the current page; the step index (stepIndex) of the data block in the free memory table, which can be used to locate the step list; and the index (extindex) of the data block in the step list, which can be used to locate the element in the corresponding step list.

[0064] By introducing a page mapping structure, this embodiment can quickly locate the location of the data block belonging to the physical page in the free memory table, thereby significantly improving the efficiency of memory management. Whether implemented using an array or a radix tree, the page mapping structure can provide fast search capabilities, reducing the time overhead of searching for data blocks in the free memory table. The array implementation structure is simple and has a fast search speed, suitable for scenarios with a small number of physical pages; the radix tree implementation structure is suitable for scenarios with a large number of physical pages and can efficiently process large-scale data. Through the fields in the page mapping object (such as data block references, order list indexes, and element indexes), data blocks can be accurately located and manipulated, further optimizing the performance of memory allocation and recycling. This mechanism not only improves the system's responsiveness, but also enhances the flexibility and reliability of memory management, ensuring that the system can efficiently manage memory resources, reduce memory fragmentation, and improve overall performance in scenarios with high concurrency and complex memory operations.

[0065] Reference Figure 5 and Figure 6 , Figure 5 shows a direct allocation flow chart provided by the above embodiment, Figure 6 The splicing allocation flow chart provided by the above embodiment is shown.

[0066] like Figure 5As shown, the input size is 6M, that is, a 6M data block needs to be allocated. The free memory table includes a 2M linked list, a 4M linked list, an 8M linked list, ..., a 2G linked list, and a Big linked list. Among them, the 2M linked list stores data blocks with a starting position of 8M and a data size of 2M and a data block with a starting position of 12M and a data size of 2M. The 8M linked list stores data blocks with a starting position of 0M and a data size of 8M, which can be divided into data blocks with a starting position of 0M and a data size of 6M and a data block with a starting position of 6M and a data size of 2M. The Big linked list stores data blocks with a starting position of 16M and a data size of the maximum value MAX. The data block with the starting position of 0M and the data size of 8M stored in the 8M linked list is divided into a data block with the starting position of 0M and the data size of 6M as the output. The data block with the starting position of 6M and the data size of 2M is adjacent to the data block with the starting position of 8M and the data size of 2M. These two data blocks can be merged into a data block with the starting position of 6M and the data size of 4M. Accordingly, the page mapping is also dynamically adjusted, such as Figure 5 As shown, 0 is adjusted from the free block ext to the null value null.

[0067] like Figure 6 As shown in the figure, the input size is 10M, that is, a data block of 10M needs to be allocated. The free memory table includes a 2M linked list, a 4M linked list, an 8M linked list, ..., a 2G linked list, and a Big linked list. Among them, the 2M linked list stores data blocks with a starting position of 8M and a data size of 2M, the 4M linked list stores data blocks with a starting position of 12M and a data size of 4M, and the 8M linked list stores data blocks with a starting position of 0M and a data size of 8M. The data block with the starting position of 0M and the data size of 8M stored in the intermediate output 8M linked list is moved to the allocation memory table, but the input requirement is not met at this time, and there is still a shortfall of 2M, that is, the intermediate input size = 2M. Therefore, the data block with the starting position of 8M and the data size of 2M stored in the 2M linked list is also output and moved to the allocation memory table. Therefore, the actual output is a data block with the starting position of 0M and the data size of 8M and a data block with the starting position of 8M and the data size of 2M. After splicing the two, the input size requirement is met, and the page mapping is also adjusted accordingly, such as Figure 6 As shown, 0, 3, and 4 are adjusted from the free block ext to the null value null respectively.

[0068] In an exemplary embodiment, the shared memory management method further includes: in response to detecting an abnormality in the free memory table or system initialization, traversing the bitmap of the metadata area to identify all maximum continuous free areas; for each identified maximum continuous free area, using the maximum continuous free area as a free data block to be inserted, and inserting the free data block to be inserted into a linked list of unit storage capacity corresponding to the free data block to be inserted.

[0069] In this embodiment, the free memory table supports reconstruction. The free memory table is effectively an in-memory management view of free physical pages, always consistent with the physical page usage in CXL memory. When the algorithm initializes, the free memory table, based on the physical page bitmap in the metadata, traverses to obtain several maximally contiguous free data blocks and inserts them sequentially into the free memory table. This process is considered the initialization of the free memory table. Based on this approach, even if the algorithm exits abnormally and the in-memory free memory table becomes invalid, it can be rebuilt using the persistent data on CXL, thus ensuring the fault resilience of the free data block management structure.

[0070] Based on the above embodiment, it can be understood that the operations on the free memory table include a remove operation and an insert operation. The following describes the two operations respectively.

[0071] In an exemplary embodiment, the removal operation is described: the shared memory management method also includes: determining the target position of the free data block allocated to the client in the free memory table according to the page mapping structure; removing the free data block at the target position in the free memory table, and updating the page mapping structure.

[0072] It can be understood that the removal operation refers to the operation of deleting an allocated free data block from the free memory table, the target position refers to the specific position of the free data block in the free memory table, including the level linked list and the index in the level linked list, and updating the page mapping structure includes modifying the page mapping structure to reflect the current memory status after removing the free data block.

[0073] For example, assuming that the client requests to allocate 8M of memory, the corresponding free data block can be found through the page mapping structure.

[0074] Assume that the free memory table structure is as follows: 2M linked list: d1; 4M linked list: d2; 8M linked list: d3, d5; 16M linked list: d4; search for the page mapping object corresponding to bitmap number 2, and find that the reference is 8M data block d3, whose position in the free memory table is: step list index (stepIndex) is 2, element index (extindex) is 0.

[0075] Remove data block d3 from the 8M-order linked list, update the free memory table, the 8M-order linked list is now empty, and update the page mapping structure at the same time. The page mapping object corresponding to bitmap number 2 is modified to null or marked as unused.

[0076] This embodiment significantly improves the efficiency and flexibility of memory management by using a page mapping structure to quickly locate and remove data blocks from the free memory table. During memory allocation, the page mapping structure can quickly find suitable free data blocks and allocate them to clients. During memory reclamation, the page mapping structure can quickly locate data blocks to be reclaimed and reinsert them into the free memory table. This mechanism not only reduces the time overhead of searching and updating data blocks in the free memory table, but also ensures the atomicity and consistency of memory management operations, avoiding potential race conditions and data inconsistencies.

[0077] In an exemplary embodiment, the shared memory management method further includes: in response to the existence of a data block to be inserted, judging whether there is a free data block to be spliced ​​based on the page mapping structure and the value of the bitmap, where the free data block to be spliced ​​is a free data block adjacent to the data block to be inserted; if so, splicing the data block to be inserted and the free data block to be spliced ​​to obtain a continuous free data block, removing the free data block to be spliced ​​from the corresponding linked list, inserting the continuous free data block into the linked list of the unit storage capacity corresponding to the continuous free data block, and updating the page mapping structure; if not, inserting the data block to be inserted into the linked list of the unit storage capacity corresponding to the data block to be inserted, and updating the page mapping structure.

[0078] It can be understood that the data block to be inserted in this embodiment is an idle data block that is about to be inserted into the free memory table, which can be the second data block and the data block to be recovered in the above embodiment, and the idle data block to be spliced ​​is an idle data block adjacent to the data block to be inserted, which can be merged with the data block to be inserted into a larger continuous idle data block.

[0079] First, the starting and ending page addresses of the data block to be inserted are obtained. The bitmap is then traversed from the starting page address to the left and from the ending page address to the right. Based on the page mapping, the data blocks adjacent to the left and / or right of the data block to be inserted are quickly determined to be free data blocks. If so, the data blocks adjacent to the left and / or right of the data block to be inserted are determined to be free data blocks to be spliced. This process continues until a non-free data block is traversed. Each time a free data block to be spliced ​​is traversed, it is removed from the free memory table and spliced ​​into the data block to be inserted. Ultimately, this step will obtain the largest continuous free data block that contains the current data block.

[0080] Exemplarily, it is assumed that the free memory table structure is as follows: 2M linked list: d1, d4; 4M linked list: d2; 8M linked list: d3; 16M linked list: empty.

[0081] Suppose there is a 4M data block to be inserted (d5), whose starting page number is 1 and ending page number is 2. Traverse from the starting page number 1 to the left, check the status of page number 0, and find that page number 0 is free. The corresponding free data block is d1 (2M). Call the removal process of the free memory table, remove d1 from the 2M-order linked list, and splice d1 into d5 to obtain a 6M continuous free data block (d1+d5). Traverse from the ending page number 2 to the right, check the status of page number 3, and find that page number 3 is free. The corresponding free data block is d3 (8M). Call the removal process of the free memory table, remove d3 from the 8M-order linked list, and splice d3 into the current In the 6M continuous free data block, a 14M continuous free data block (d1+d5+d3) is obtained. Check the status of page number 4 and find that page number 4 is also free. The corresponding free data block is d4 (2M). Remove d4 from the 2M-order linked list and splice d4 into the current 14M continuous free data block to obtain a 16M continuous free data block (d1+d4+d3+d5). Then check the status of page number 5 and find that page number 5 is in used state. At this time, the continuous free data obtained is 16M, the starting page number of the continuous free data block is 0, and the ending page number is 4. The page mapping structure is updated and 16M is directly inserted into the 16M linked list.

[0082] The above example uses a data block including one physical page as an example. The example of a data block with multiple physical pages is as follows: Assume that the free memory table structure is as follows: 2M linked list: d1 (page number 0-1), d4 (page number 4-5); 4M linked list: d2 (page number 2-3); 8M linked list: d3 (page number 6-9); 16M linked list: empty.

[0083] There is currently a 6M data block to be inserted (d5), with a starting page number of 2 and an ending page number of 5. This data block spans three physical pages. The length to be inserted is initialized to 6M. Traverse the bitmap to the left: traverse from the starting page number 2 to the left, check the status of page number 1, and find that page number 1 is free. The corresponding free data block is d1 (2M, page numbers 0-1). Call the removal process of the free memory table, remove d1 from the 2M-order linked list, and splice d1 into d5 to obtain an 8M continuous free data block (d1+d5), covering pages 0-5. Traverse the bitmap to the right: traverse from the ending page number 5 to the right, check the status of page number 6, and find that page number 6 is free. The corresponding free data block is d3 (8M, pages 6-9). The free memory table removal process is called to remove d3 from the 8M-order linked list. D3 is then appended to the current 8M-order continuous free data block, resulting in a 16M-order continuous free data block (d1+d5+d3), covering pages 0-9. The page mapping structure is updated to record the new 16M-order continuous free data block, starting at page 0 and ending at page 9. The 16M-order continuous free data block is then inserted into the 16M-order linked list.

[0084] This embodiment can effectively reduce memory fragmentation and improve memory utilization by determining whether there are free data blocks to be spliced ​​based on the page mapping structure and the value of the bitmap, and performing a splicing operation. By traversing the bitmap to the left and right, free data blocks adjacent to the data block to be inserted can be quickly found and spliced ​​into a larger continuous free data block. This method not only optimizes memory management, but also reduces the problem of memory waste caused by memory fragmentation. Through the splicing operation, the system can better meet subsequent large-block memory allocation requests, improving the flexibility and response speed of the system. In addition, updating the page mapping structure ensures the consistency of the memory state, further enhancing the reliability and stability of the system.

[0085] In an exemplary embodiment, the process of inserting continuous free data blocks into a linked list of unit storage capacity corresponding to the continuous free data blocks includes: determining the size of the continuous free data blocks as the current unit storage capacity; determining a maximum unit storage capacity that is not greater than the current unit storage capacity in the free memory table; if the maximum unit storage capacity is equal to the current unit storage capacity, inserting the continuous free data blocks into the linked list corresponding to the maximum unit storage capacity; if the maximum unit storage capacity is less than the current unit storage capacity, inserting the free data blocks of the maximum unit storage capacity split from the continuous free data blocks into the linked list of the maximum unit storage capacity, and using the remaining free data blocks in the continuous free data blocks as new continuous free data blocks, and repeating the operation of determining the size of the continuous free data blocks as the current unit storage capacity until the current unit storage capacity is 0.

[0086] In this embodiment, the length to be inserted is first defined as the size of the continuous idle data blocks, and a loop is entered until the length to be inserted is zero.

[0087] First, calculate the length to be inserted this time and initialize the current unit storage capacity to the current length to be inserted; traverse the free memory table downward along the order until the maximum unit storage capacity that is not greater than the current unit storage capacity is found and returned. Split the continuous free data blocks based on the length to be inserted, and the data blocks that meet the length to be inserted will be inserted into the linked list of the corresponding order, and the page mapping structure will be updated. The remaining data blocks will be used as the new maximum free data blocks and enter the next loop.

[0088] For example, the free memory table has the following structure: 2M linked list: d6; 4M linked list: d1, d3, d5; 8M linked list: d2, d4; 16M linked list: d7; 32M linked list: empty; 2G linked list: empty; Big linked list: empty. Currently, there is a 14M continuous free data block that needs to be inserted into the free memory table. Initialize the length to be inserted to 14M and the current unit storage capacity to 14M. Traverse the free memory table downwards to find the maximum unit storage capacity no greater than 14M. The maximum unit storage capacity is 8M. Split an 8M data block from the 14M continuous free data block and insert it into the 8M-order linked list. Update the page mapping structure to record the information of the 8M data block. The remaining free data block size is 14M-8M=6M. Update the length to be inserted to 6M and initialize the current unit storage capacity to 6M. Traverse the free memory table downwards to find the maximum unit storage capacity no greater than 6M. The maximum unit storage capacity is 4M. A 4M data block is split from the 6M continuous free data block and inserted into the 4M-order linked list. The page mapping structure is updated to record the information of the 4M data block. The remaining free data block size is 6M-4M=2M. The length to be inserted is updated to 2M. The free memory table is traversed downwards to find the maximum unit storage capacity no greater than 2M. The maximum unit storage capacity is 2M. The remaining 2M data block is inserted into the 2M-order linked list. The page mapping structure is updated to record the information of the 2M data block. Finally, the 14M continuous free data block is split into 8M, 4M, and 2M data blocks, which are inserted into the corresponding order linked lists respectively.

[0089] Reference Figure 7 and Figure 8 As shown, this embodiment can efficiently manage and utilize idle memory resources by gradually splitting continuous free data blocks and inserting them into corresponding rank linked lists. This embodiment not only improves the flexibility and efficiency of memory management, but also optimizes the performance of memory allocation and recycling. Through the rank-finding operation, the appropriate unit storage capacity can be quickly found to ensure that each split data block can be inserted into the most appropriate linked list, avoiding memory waste and fragmentation problems. In addition, through the gradual splitting and insertion operations, the system can better adapt to memory requests of different sizes, ensuring that memory resources can be efficiently utilized in scenarios with high concurrency and frequent memory operations, thereby improving the overall performance and resource management capabilities of the system.

[0090] In summary, this embodiment uses dynamic-length data blocks to represent memory allocations, allowing shared memory objects to be bound to multiple data blocks. This effectively utilizes fragmented memory and improves CXL memory utilization. A data block allocation and recovery algorithm is proposed. Based on the free memory table and the allocated memory table, this algorithm dynamically manages the splicing and splitting of data blocks, significantly reducing CXL memory fragmentation. Physical page bitmaps and page mapping techniques are used to accelerate the search process from physical pages to data blocks, improving memory allocation and recovery performance. The free memory table supports rebuild actions, and the allocated memory table supports persistence, providing reliable fault recovery capabilities.

[0091] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.

[0092] An embodiment of the present application also provides a shared memory management device, in which the shared memory is divided into data blocks consisting of multiple continuous physical pages. The shared memory management device includes: an acquisition module, used to obtain a free memory table corresponding to the shared memory; the free memory table is a multi-order linked list structure, each order linked list stores free data blocks corresponding to its unit storage capacity, and the unit storage capacity of the multi-order linked list increases exponentially according to the size of the physical pages divided in the shared memory; a first determination module, used to determine the size of the memory to be allocated in the allocation request sent by any client; a first allocation module, used to allocate free data blocks to the client from the target linked list in response to the presence of a target linked list in the free memory table whose unit storage capacity is not less than the memory size to be allocated and is non-empty; a second allocation module, used to allocate multiple free data blocks to the client from the non-empty multi-order linked list in response to the absence of the target linked list in the free memory table and the total capacity of the free memory blocks in the free memory table is not less than the memory size to be allocated, so that the size of the spliced ​​free data blocks is equal to the memory size to be allocated.

[0093] In an exemplary embodiment, in response to the presence of a target linked list in the free memory table whose unit storage capacity is not less than the memory size to be allocated and is not empty, the process of allocating free data blocks to the client from the target linked list includes: if the difference between the unit storage capacity corresponding to the target linked list and the memory size to be allocated is less than the physical page size; determining the target free data block in at least one free data block in the target linked list, and returning the target free data block to the client.

[0094] In an exemplary embodiment, in response to the presence of a target linked list in a free memory table whose unit storage capacity is not less than the memory size to be allocated and is not empty, the process of allocating free data blocks to the client from the target linked list includes: if the difference between the unit storage capacity corresponding to the target linked list and the memory size to be allocated is not less than the physical page size; determining a target free data block in at least one free data block in the target linked list; splitting a first data block of the memory size to be allocated from the target free data block, and returning the first data block to the client.

[0095] In an exemplary embodiment, after splitting the first data block of the memory size to be allocated from the target free data block, the shared memory management device also includes: a second determination module for determining the unit storage capacity corresponding to the second data block remaining in the target free data block; and an insertion module for inserting the second data block into a linked list of the corresponding unit storage capacity.

[0096] In an exemplary embodiment, a process of allocating multiple free data blocks to a client from a non-empty multi-order linked list so that the size of the spliced ​​free data blocks is equal to the memory size to be allocated includes: initializing the current remaining size to be allocated as the memory size to be allocated, repeatedly performing the splicing allocation operation until the current remaining size to be allocated is 0, and returning the return value list to the client. The splicing allocation operation includes: determining a maximum linked list that is not larger than the current remaining size to be allocated and is non-empty; determining a target free data block from at least one free data block in the maximum linked list, adding the target free data block to the return value list, and updating the current remaining size to be allocated.

[0097] In an exemplary embodiment, the acquisition module is further configured to acquire an allocation memory table corresponding to the shared memory; and the storage module is configured to store the allocated free data blocks into the allocation memory table.

[0098] In an exemplary embodiment, the shared memory management device also includes: a third determination module, used to determine the data block to be reclaimed corresponding to the reclaim request sent by any client; the insertion module is also used to remove the data block to be reclaimed from the allocated memory table and insert it into the free memory table.

[0099] In an exemplary embodiment, the method further includes: dividing the shared memory into a metadata area and a data area, the data area is configured to store physical pages, and the metadata area is configured to store a bitmap, the value of the bitmap represents the usage status of the corresponding physical page; establishing a page mapping structure based on the address of the physical page, the page mapping structure is used to locate the position of the data block to which the physical page belongs in the free memory table through the address of the physical page.

[0100] In an exemplary embodiment, the shared memory management device also includes: an identification module for traversing the bitmap of the metadata area and identifying all maximum continuous free areas in response to detecting an abnormality in the free memory table or system initialization; the insertion module is also used to, for each identified maximum continuous free area, use the maximum continuous free area as a free data block to be inserted, and insert the free data block to be inserted into a linked list of unit storage capacity corresponding to the free data block to be inserted.

[0101] In an exemplary embodiment, the shared memory management device also includes: a fourth determination module, which is used to determine the target position of the free data block allocated to the client in the free memory table based on the page mapping structure; remove the free data block at the target position in the free memory table, and update the page mapping structure.

[0102] In an exemplary embodiment, the shared memory management device also includes: in response to the existence of a data block to be inserted, judging whether there is a free data block to be spliced ​​based on the page mapping structure and the value of the bitmap, the free data block to be spliced ​​being a free data block adjacent to the data block to be inserted; if so, splicing the data block to be inserted and the free data block to be spliced ​​to obtain a continuous free data block, removing the free data block to be spliced ​​from the corresponding linked list, inserting the continuous free data block into the linked list of the unit storage capacity corresponding to the continuous free data block, and updating the page mapping structure; if not, inserting the data block to be inserted into the linked list of the unit storage capacity corresponding to the data block to be inserted, and updating the page mapping structure.

[0103] In an exemplary embodiment, the process of inserting continuous free data blocks into a linked list of unit storage capacity corresponding to the continuous free data blocks includes: determining the size of the continuous free data blocks as the current unit storage capacity; determining a maximum unit storage capacity that is not greater than the current unit storage capacity in the free memory table; if the maximum unit storage capacity is equal to the current unit storage capacity, inserting the continuous free data blocks into the linked list corresponding to the maximum unit storage capacity; if the maximum unit storage capacity is less than the current unit storage capacity, inserting the free data blocks of the maximum unit storage capacity split from the continuous free data blocks into the linked list of the maximum unit storage capacity, and using the remaining free data blocks in the continuous free data blocks as new continuous free data blocks, and repeating the operation of determining the size of the continuous free data blocks as the current unit storage capacity until the current unit storage capacity is 0.

[0104] For the description of the features in the embodiment corresponding to the shared memory management device, please refer to the relevant description of the embodiment corresponding to the shared memory management method, and will not be repeated here.

[0105] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned shared memory management method embodiments.

[0106] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above-mentioned shared memory management method embodiments when running.

[0107] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.

[0108] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of any of the above-mentioned shared memory management method embodiments are implemented.

[0109] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above-mentioned shared memory management method embodiments are implemented.

[0110] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0111] The above is a detailed introduction to the shared memory management method, product, device and medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

Claims

1. A shared memory management method, characterized in that: Shared memory is divided into multiple data blocks consisting of several physical pages, including: Obtaining a free memory table corresponding to the shared memory; the free memory table is a multi-stage linked list structure, each stage linked list stores free data blocks corresponding to its unit storage capacity, and the unit storage capacity of the multi-stage linked list increases exponentially according to the size of the physical pages divided in the shared memory; Determine the size of memory to be allocated in any allocation request sent by the client; In response to the existence of a target linked list in the free memory table with a unit storage capacity not less than the memory size to be allocated and being non-empty, allocating a free data block to the client from the target linked list; In response to the target linked list not existing in the free memory table and the total capacity of the free memory blocks in the free memory table is not less than the memory size to be allocated, multiple free data blocks are allocated to the client from a non-empty multi-order linked list so that the size of the spliced ​​free data blocks is equal to the memory size to be allocated.

2. The shared memory management method according to claim 1, wherein: In response to the presence of a target linked list in the free memory table whose unit storage capacity is not less than the memory size to be allocated and is non-empty, a process of allocating free data blocks to the client from the target linked list includes: If the difference between the unit storage capacity corresponding to the target linked list and the size of the memory to be allocated is smaller than the physical page size; A target free data block is determined from at least one free data block in the target linked list, and the target free data block is returned to the client.

3. The shared memory management method according to claim 1, wherein: In response to the presence of a target linked list in the free memory table whose unit storage capacity is not less than the memory size to be allocated and is non-empty, a process of allocating free data blocks to the client from the target linked list includes: If the difference between the unit storage capacity corresponding to the target linked list and the size of the memory to be allocated is not less than the physical page size; Determining a target free data block in at least one free data block in the target linked list; A first data block of the memory size to be allocated is split from the target free data block, and the first data block is returned to the client.

4. The shared memory management method according to claim 3, wherein: After splitting the first data block of the memory size to be allocated from the target free data block, the shared memory management method further includes: Determining a unit storage capacity corresponding to a second data block remaining in the target free data block; Insert the second data block into the linked list of the corresponding unit storage capacity.

5. The shared memory management method according to claim 1, wherein: The process of allocating a plurality of free data blocks to the client from a non-empty multi-order linked list so that the size of the spliced ​​free data blocks is equal to the size of the memory to be allocated includes: Initialize the current remaining size to be allocated as the memory size to be allocated, repeatedly perform the splicing allocation operation until the current remaining size to be allocated is 0, and return the return value list to the client. The splicing allocation operation includes: Determine the largest linked list that is not larger than the current remaining size to be allocated and is not empty; A target free data block is determined in at least one free data block in the maximum linked list, the target free data block is added to the return value list, and the current remaining size to be allocated is updated.

6. The shared memory management method according to claim 1, wherein: The shared memory management method further comprises: Obtaining an allocated memory table corresponding to the shared memory; The allocated free data blocks are stored in the allocation memory table.

7. The shared memory management method according to claim 6, wherein: The shared memory management method further comprises: Determine the data blocks to be recycled corresponding to the recycling request sent by any client; After removing the data block to be recycled from the allocated memory table, the data block is inserted into the free memory table.

8. The shared memory management method according to any one of claims 1 to 7, characterized in that: Also includes: Dividing the shared memory into a metadata area and a data area, wherein the data area is configured to store physical pages, and the metadata area is configured to store a bitmap, wherein a value of the bitmap represents a usage status of a corresponding physical page; A page mapping structure is established based on the address of the physical page, and the page mapping structure is used to locate the position of the data block to which the physical page belongs in the free memory table through the address of the physical page.

9. The shared memory management method according to claim 8, wherein: The shared memory management method further comprises: In response to detecting an abnormality in the free memory table or system initialization, traversing the bitmap of the metadata area to identify all maximum continuous free areas; For each identified maximum continuous free area, the maximum continuous free area is used as a free data block to be inserted, and the free data block to be inserted is inserted into a linked list of unit storage capacity corresponding to the free data block to be inserted.

10. The shared memory management method according to claim 8, wherein: The shared memory management method further comprises: Determining, according to the page mapping structure, a target location of the free data block allocated to the client in the free memory table; The free data block at the target location of the free memory table is removed, and the page mapping structure is updated.

11. The shared memory management method according to claim 8, wherein: The shared memory management method further comprises: In response to the existence of the data block to be inserted, determining whether there is an idle data block to be spliced ​​based on the page mapping structure and the value of the bitmap, the idle data block to be spliced ​​being an idle data block adjacent to the data block to be inserted; If so, splicing the data block to be inserted and the free data block to be spliced ​​to obtain a continuous free data block, removing the free data block to be spliced ​​from the corresponding linked list, inserting the continuous free data block into the linked list of the unit storage capacity corresponding to the continuous free data block, and updating the page mapping structure; If not, the data block to be inserted is inserted into a linked list of unit storage capacity corresponding to the data block to be inserted, and the page mapping structure is updated.

12. The shared memory management method according to claim 11, wherein: The process of inserting the continuous free data blocks into a linked list of unit storage capacity corresponding to the continuous free data blocks includes: Determine the size of the continuous free data blocks as the current unit storage capacity; Determining a maximum unit storage capacity in the free memory table that is not greater than the current unit storage capacity; If the maximum unit storage capacity is equal to the current unit storage capacity, inserting the continuous free data blocks into the linked list corresponding to the maximum unit storage capacity; If the maximum unit storage capacity is smaller than the current unit storage capacity, the free data blocks of the maximum unit storage capacity split from the continuous free data blocks are inserted into the linked list of the maximum unit storage capacity, and the remaining free data blocks in the continuous free data blocks are used as new continuous free data blocks, and the operation of determining the size of the continuous free data blocks as the current unit storage capacity is repeated until the current unit storage capacity is 0.

13. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the shared memory management method according to any one of claims 1 to 12 are implemented.

14. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the shared memory management method according to any one of claims 1 to 12 when executing the computer program.

15. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the shared memory management method according to any one of claims 1 to 12 are implemented.

Citation Information

Patent Citations

  • Memory management method and system

    CN102063385A

  • Method and device for data storage

    CN102446139A

  • Memory dynamic management method and device

    CN109375985A

  • Shared memory management method and device

    CN110109763A

  • RDMA memory management method and device, equipment and medium

    CN115858184A