A Data Management Method for Persistent Memory and a Persistent Memory Controller

Through the combination of dynamic multi-layer hash tables and announcement arrays, the concurrency and consistency problems of hash tables in high concurrency scenarios under persistent memory are solved, and the hash table access with high throughput and low latency is achieved and the strong consistency guarantee of linearization is achieved.

CN115329141BActive Publication Date: 2025-07-25HUAZHONG UNIV OF SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210883333.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-26
Publication Date
2025-07-25
Estimated Expiration
2042-07-26

AI Technical Summary

Technical Problem

The hash table construction method under existing persistent memory has problems such as insufficient concurrency scalability, high access latency, low concurrency throughput and insufficient crash consistency guarantee in high concurrency scenarios.

Method used

The dynamic multi-layer hash table structure is adopted, combined with announcement array and ring buffer management, and the index of element pointers is realized through lock-free mode, and the persistence mark bits are used to coordinate persistence to ensure linearization and consistency of operations.

Benefits of technology

High concurrency and low latency hash table access is achieved, ensuring linearization and consistency in persistent memory, improving system throughput and reducing operational latency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115329141B_ABST
    Figure CN115329141B_ABST
Patent Text Reader

Abstract

The present invention discloses a data management method for persistent memory and a persistent memory controller, belonging to the field of data storage, including: constructing a dynamic multi-level hash table and an announcement array in persistent memory and volatile memory respectively; after storing an element in persistent memory, a pointer p for it is created in the announcement array n Search for a matching hash bucket H. If there is a pointer p in H o , then p o After inserting into the dynamic multi-level hash table, atomically replace the element pointer in H with p n , p n After inserting into the dynamic multi-level hash table, clear H; if H is empty, then p n After inserting into the dynamic multi-level hash table, clear H; the pointer insertion method includes: when there is no element pointer in the dynamic multi-level hash table with the same key as the pointer of the element to be inserted, traverse the visible layer from top to bottom to find a matching alternative bucket, and atomically insert the pointer into the free slot of the matching alternative bucket. The present invention can achieve high-throughput and low-latency hash table access and linearizable strong consistency guarantee.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of data storage, and more specifically, relates to a data management method for persistent memory and a persistent memory controller. Background Art

[0002] The new persistent memory technology has both byte access performance close to volatile memory and the persistence of a disk. Currently, the single - capacity of the Optane persistent memory released by Intel reaches 512GB, which is expected to provide high - performance storage services for massive data. However, the currently widely used Asynchronous DRAM Refresh (ADR) mechanism for persistent memory only guarantees the persistence of the write queue in the memory controller, while the data in the CPU cache line and volatile memory is still power - loss volatile. Therefore, persistent memory applications need to ensure that they can resume to a consistent state after the program restarts, which is called crash consistency. In addition, persistent memory has read - write asymmetry. For example, the write bandwidth of Optane persistent memory is only one - third of the read bandwidth.

[0003] The index structure is one of the key technologies in the storage system. Different from tree - based indexes, hash indexes can directly locate the alternative positions of data through hash functions, and related operations have a constant - level time complexity. Therefore, they are widely used in storage systems. Existing server platforms are often multi - core. For example, a single Xeon CPU that supports Optane persistent memory generally has dozens of threads, and the rich hardware parallel resources can support the performance of concurrent storage systems. Therefore, establishing a suitable hash index structure is of great significance for data management in persistent memory.

[0004] The existing methods and systems for constructing hash tables under persistent memory mainly focus on write optimization and crash consistency, and have limitations in high concurrency and correctness guarantee: on the one hand, many existing construction schemes use locks for concurrent control. However, locks limit the concurrent scalability of hash tables in high - concurrency scenarios, resulting in high access latency. Among them, the hash table expansion operation based on coarse - grained locks seriously blocks other concurrent threads, resulting in low throughput; on the other hand, the existing lock - free hash table construction schemes for persistent memory lack a correctness guarantee mechanism, and a persistent memory index that meets strong consistency needs to ensure that the completed operations still exist and the data is consistent after a crash and restart, that is, achieve linearizability under persistent memory; in addition, in terms of persistent memory management, the existing hash table construction schemes adopt a general allocator scheme, and the write - ahead log and other verification technologies used to ensure crash consistency result in high persistent memory management overhead in a concurrent environment. Summary of the Invention

[0005] In view of the defects and improvement needs of the prior art, the present invention provides a data management method and a persistent memory controller for persistent memory, which aims to achieve high-throughput and low-latency hash table access and strong linearizable consistency guarantee.

[0006] To achieve the above objective, according to one aspect of the present invention, a data management method for persistent memory is provided, wherein the data is a key-value pair element, including:

[0007] Initialization steps: construct a dynamic multi-layer hash table in persistent memory, which includes a multi-layer hash table. Each layer of the hash table consists of multiple hash buckets for storing a specified number of element pointers. Each pointer has X candidate buckets in each layer of the hash table. The higher the level, the more hash buckets there are in the hash table. The accessible hash table is the visible layer; construct a notice array in volatile memory, and the array elements are hash buckets; X is a positive integer;

[0008] Pointer insertion step: determine whether there is an element pointer with the same key as the element pointer to be inserted in the dynamic multi-layer hash table. If so, exit the pointer insertion step; otherwise, traverse all visible layers from top to bottom to find a matching candidate bucket for the element pointer to be inserted. If there is a free slot in the matching candidate bucket, the pointer is atomically inserted into the matching candidate bucket; if there is no free slot in the matching candidate bucket, allocate a new top-level hash table for the dynamic multi-layer hash table and re-execute the pointer insertion step;

[0009] Synchronization step: After storing the element to be stored in persistent memory, a pointer p to the element is added to the announcement array. n Find the hash bucket, if the old element pointer p already exists in the matching hash bucket H o , then the pointer p is inserted into o After inserting into the dynamic multi-layer hash table, atomically replace the element pointer in the hash bucket H with the pointer p n , through the pointer insertion step, the pointer p n Insert into the dynamic multi-layer hash table, then clear the hash bucket H; if the hash bucket H is empty, insert the pointer p through the pointer insertion step n Insert into the dynamic multi-layer hash table and then clear the hash bucket H.

[0010] The present invention creates a dynamically extensible multi-layer hash table structure to index element pointers, which can manage element pointers in a lock-free manner and achieve high concurrency. At the same time, the coordination of concurrent insertion operations is realized through the announcement array. Specifically, before an element pointer is inserted into the dynamic multi-layer hash table, it will first try to insert it into the announcement array. If there is already an old element pointer in the matching hash bucket, the element pointer will be inserted into the dynamic multi-layer hash table first, and then the new element pointer will be inserted into the announcement array through an atomic replacement operation, and then the new pointer will be inserted, thus ensuring that each operation can be executed in a strict order, achieving linearizability under persistent memory and ensuring strong consistency. Generally speaking, the present invention realizes high concurrency in persistent memory while achieving linearizability under persistent memory.

[0011] Furthermore, the data management method for persistent memory provided by the present invention further includes:

[0012] Pointer migration step: Traverse all visible layers except the bottom layer from top to bottom to find a matching alternative bucket for the element pointer to be migrated. If there is an idle slot in the matching alternative bucket, the pointer is atomically inserted into the matching alternative bucket; if there is no idle slot in the matching alternative bucket, a new top-layer hash table is allocated for the dynamic multi-layer hash table, and then the pointer migration step is executed again;

[0013] Rehashing step executed in the background: When the number of visible layers exceeds two, all element pointers in the bottom-layer hash table are migrated to other visible layers through the pointer migration step. After the migration is completed, the storage space occupied by the bottom-layer hash table is released;

[0014] Moreover, in the pointer insertion step, if the number of visible layers is greater than 2, the bottom layer is not traversed when looking for a matching alternative bucket for the element pointer to be inserted; if the number of visible layers is 2 before inserting the element pointer and a new visible layer appears after inserting the element pointer, the pointer insertion step is executed again.

[0015] Through the rehashing operation executed in the background, the present invention can effectively control the number of layers of the dynamic multi-layer hash table and ensure the query efficiency.

[0016] Since the rehashing operation causes the pointers of the underlying elements to migrate, in the pointer insertion operation of the present invention, when the number of visible layers is greater than 2, inserting the pointer into the underlying layer is not allowed, which can effectively prevent the pointer from migrating due to the rehashing operation after being inserted into the underlying layer, ultimately resulting in the failure of insertion; when the number of visible layers is 2, the pointer may be inserted into the underlying layer. Before inserting the element pointer, the number of visible layers is 2 in the present invention, and after insertion, a new visible layer appears. Then, the inserted element pointer may migrate due to the rehashing operation after being inserted into the underlying layer, resulting in the failure of insertion. The present invention re-executes the pointer insertion operation at this time, which can effectively avoid this situation.

[0017] Further, the initialization step further includes: establishing a circular buffer in the persistent memory for storing the head addresses of each layer of hash tables in the order from low to high in terms of levels.

[0018] The present invention manages each layer of hash tables in the dynamic multi-layer hash table by using a circular buffer. Compared with the existing lock-free hash table construction scheme that manages each layer of hash tables through a linked list, it can effectively reduce the time and space overhead of management.

[0019] Further, the data management method provided by the present invention for persistent memory further includes: a pre-allocation step executed in the background;

[0020] The initialization step further includes: pre-allocating M layers of hash tables for the dynamic multi-layer hash table as inaccessible levels, and storing the head addresses of each layer of hash tables in order in the circular buffer;

[0021] Moreover, in the pointer insertion step, by allocating the hash table with the lowest pre-allocated level to the dynamic multi-layer hash table as the visible layer, a new hash table is added as the top-level hash table to the dynamic multi-layer hash table;

[0022] The pre-allocation step includes: when the number of pre-allocated inaccessible hash table layers is less than M, pre-allocating hash tables for the dynamic multi-layer hash table as inaccessible hash tables, and storing the head addresses of each layer of hash tables in order in the circular buffer to make the number of pre-allocated inaccessible hash tables be M;

[0023] Wherein, M is a positive integer.

[0024] The present invention pre-allocates a part of the storage space for the dynamic multi-layer hash table. When the dynamic multi-layer hash table needs to be expanded, directly setting the pre-allocated level as the visible layer can complete the expansion, which can achieve the rapid expansion of the dynamic multi-layer hash table and ensure the execution efficiency of the pointer insertion operation.

[0025] Furthermore, in the data management method for persistent memory provided by the present invention, hierarchical metadata <Lt, Lb> is also maintained in volatile memory, where Lt and Lb are respectively used to store the numbers of the top - level hash table and the bottom - level hash table in the circular buffer; the hash tables with numbers within the range of [Lt, Lb] are the accessible hash tables in the dynamic multi - level hash table;

[0026] Moreover, in the pointer insertion step, when adding a new layer of hash table as the top - level hash table to the dynamic multi - level hash table, the values of the hierarchical metadata <Lt, Lb> will be atomically updated; in the re - hashing step, when releasing the storage space occupied by the bottom - level hash table, the values of the hierarchical metadata <Lt, Lb> will be atomically updated.

[0027] In traditional lock - free hash table construction schemes, the top - level pointer, bottom - level pointer, and a flag indicating whether to expand are maintained as metadata, and this metadata exceeds 8 bytes and cannot be updated using atomic operations; in the present invention, only Lt and Lb used to store the numbers of the top - level hash table and the bottom - level hash table in the circular buffer are maintained as hierarchical metadata, and this hierarchical metadata does not exceed 8 bytes and can be updated through atomic operations. Therefore, when the visible layer in the dynamic multi - level hash table changes, by atomically updating the hierarchical metadata, the visible layer can be controlled in real - time and accurately.

[0028] Furthermore, the data management method for persistent memory provided by the present invention further includes:

[0029] Element insertion step: Atomically allocate a frame with an appropriate size for the element to be inserted, so that after storing the element into one block or multiple consecutive blocks within the frame, the difference between the allocated storage space size and the storage space size required by the element is minimized; insert the element to be inserted into the allocated frame in sequence;

[0030] Wherein, the frame is a continuous space in persistent memory, and each frame includes multiple blocks with a fixed size; for different types of frames, the block sizes are different.

[0031] The present invention manages the elements inserted into persistent memory using frames with different block granularities, which can effectively improve the space utilization rate of persistent memory.

[0032] Furthermore, the dynamic storage hash table and the frames dynamically allocate space in persistent memory without logging. The dynamic storage hash table atomically allocates storage space in the order from high to low addresses, and the frames atomically allocate storage space in the order from low to high addresses;

[0033] Or, the dynamic storage hash table atomically allocates storage space in the order from low to high addresses, and the frames atomically allocate storage space in the order from high to low addresses.

[0034] In the present invention, the required storage space sizes of the dynamic multi-layer hash table and the content stored in the frame are different. The present invention stores the two at the high-address end and the low-address end of the persistent memory respectively for centralized storage, which can reduce space fragmentation and improve space utilization.

[0035] Furthermore, the data management method for persistent memory provided by the present invention further includes:

[0036] Update step: After inserting a new element into the persistent memory, obtain its element pointer p1; traverse the accessible layers in the dynamic multi-layer hash table from bottom to top, find all matching element pointers, only retain the last matching pointer p2 and delete the remaining matching pointers, and atomically replace pointer p2 with pointer p1; if the number of accessible layers in the dynamic multi-layer hash table changes before and after the update step is executed, then re-execute the update step;

[0037] Deletion step: Traverse the accessible layers in the dynamic multi-layer hash table from bottom to top, atomically delete all matching pointers one by one, and release the corresponding elements; if the number of accessible layers in the dynamic multi-layer hash table changes before and after the deletion step is executed, then re-execute the deletion step;

[0038] Query step: Traverse all accessible layers in the dynamic multi-layer hash table from bottom to top until the first matching element pointer is found, and return the element to be searched according to this pointer.

[0039] When the number of accessible layers in the dynamic multi-layer hash table changes before and after the update step is executed in the present invention, the update step will be re-executed, which can avoid the update failure caused by the rehashing operation after a new pointer is inserted into the bottom layer; when the number of accessible layers in the dynamic multi-layer hash table changes before and after the deletion step is executed in the present invention, the deletion step will be re-executed, which can avoid the bottom-layer matching pointer not being deleted because it has been migrated to a new visible layer.

[0040] Furthermore, a persistent mark bit is set in the element pointer to indicate whether it has been persisted;

[0041] And, the pointer insertion step further includes: setting its persistent mark bit before insertion to indicate not being persisted, refreshing the corresponding cache line after inserting the pointer into the dynamic multi-layer hash table, and then atomically setting the persistent mark bit to indicate being persisted;

[0042] When any thread reads a pointer with the persistent mark bit indicating not being persisted, it refreshes the corresponding cache line and atomically sets the persistent mark bit to indicate being persisted.

[0043] The present invention realizes collaborative persistence by setting a persistent flag bit in the element pointer. Specifically, the persistent flag of the element pointer will be set to "persisted" only after it is successfully inserted into the dynamic multi-level hash table. Any thread that reads an unpersisted pointer will first flush the corresponding cache line and atomically set its persistent flag bit to "persisted", effectively ensuring the persistent storage of the pointer and the consistency of the persistent memory.

[0044] According to another aspect of the present invention, a persistent memory controller is provided, including: a processor and a computer-readable storage medium;

[0045] A computer program is stored in the computer-readable storage medium; the processor is configured to read the computer program and execute the data management method for persistent memory provided by the present invention.

[0046] Generally speaking, through the above technical solutions conceived by the present invention, the following beneficial effects can be achieved:

[0047] (1) The present invention designs a bulletin array and a coordination mechanism to coordinate concurrent insertion operations, realizes linearizable concurrent access to the hash table, and ensures strong consistency.

[0048] (2) The present invention conducts collaborative design on persistent memory management and hash table construction. The element pointer in the hash table serves as an indicator for the completion of key-value data storage, realizing lock-free and log-free persistent memory management and concurrent access, significantly improving the system throughput and reducing the operation latency.

[0049] (3) The present invention implements a dynamic multi-level hash table module through a hierarchical circular buffer in persistent memory, and uses hierarchical metadata in volatile memory to control the visibility of the hash table levels, which can ensure a high hash table load rate and reduce the overhead of crash consistency. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 It is a schematic diagram of the data management method for persistent memory provided by an embodiment of the present invention;

[0051] Figure 2 It is a flowchart of the bulletin array and coordination mechanism provided by an embodiment of the present invention;

[0052] Figure 3 It is a schematic diagram of the persistent memory allocation scheme provided by an embodiment of the present invention;

[0053] Figure 4 It is a schematic diagram of the frame structure provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0054] In order to make the objectives, technical solutions and advantages of the present invention more clear and understandable, the present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0055] In the present invention, terms such as "first" and "second" in the present invention and the accompanying drawings (if any) are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence.

[0056] In order to solve the technical problem that the existing lock-free hash table construction scheme for persistent memory cannot achieve linearizability under persistent memory, the present invention provides a data management method for persistent memory. The overall idea is as follows: use a dynamic multi-layer hash table to index element pointers to achieve lock-free persistent memory management and concurrent access, and use an announcement array system to coordinate the concurrent insertion operations of element pointers to achieve high-throughput and low-latency hash table access and strong consistency guarantee of linearizability.

[0057] The following are embodiments.

[0058] Embodiment 1:

[0059] A data management method for persistent memory. In this embodiment, the data is key-value pair elements. As Figure 1 shown, this embodiment includes:

[0060] Initialization step: construct a dynamic multi-layer hash table in persistent memory and construct an announcement array in volatile memory.

[0061] As Figure 1 shown, the dynamic multi-layer hash table includes multiple layers of hash tables. Each layer of hash table consists of multiple hash buckets. Optionally, in this embodiment, each hash bucket is used to store 8 element pointers. In order to improve parallelism and comprehensively consider the calculation overhead of the hash function, in this embodiment, each pointer has 2 alternative buckets in the hash table, and the positions of the alternative buckets are calculated by hash functions H1() and H2() respectively. The hash function can be selected according to actual application requirements to minimize the collision rate; in some other embodiments of the present invention, the number of alternative bucket positions of the element pointer in each layer can also be adjusted to other integers. In the dynamic multi-layer hash table, the higher the level of the hash table, the more the number of hash buckets in the hash table. In this embodiment, in two adjacent layers, the number of hash buckets in the higher layer is twice the number of hash buckets in the lower layer. In the dynamic multi-layer hash table, the accessible hash table is the visible layer.

[0062] In the announcement array, the elements are hash buckets.

[0063] As Figure 1 shown, in this embodiment, a circular buffer is used to manage the dynamic multi-level buffer; correspondingly, the initialization step further includes: establishing a circular buffer in the persistent memory for storing the head addresses of hash tables at each level in ascending order of levels;

[0064] This embodiment further includes:

[0065] The pre-allocation step executed in the background includes: when the number of inaccessible hash table levels pre-allocated is less than 3, pre-allocating hash tables for the dynamic multi-level hash table as inaccessible hash tables, and storing the head addresses of hash tables at each level into the circular buffer in order, so that the number of pre-allocated inaccessible hash tables is 3;

[0066] It should be noted that in some other embodiments of the present invention, the pre-allocated number of levels can be flexibly adjusted according to actual situations.

[0067] As Figure 1 shown, in this embodiment, hierarchical metadata <Lt, Lb> is also maintained in the volatile memory, where Lt and Lb are respectively used to store the numbers of the top-level hash table and the bottom-level hash table in the circular buffer; the hash tables with numbers within the range of [Lt, Lb] are the accessible hash tables in the dynamic multi-level hash table; the present invention uses the numbers Lt and Lb of the top-level hash table and the bottom-level hash table in the circular buffer as metadata to control the visible levels in the dynamic multi-level hash table. Since the hierarchical metadata <Lt, Lb> does not exceed 8 bytes, it can be updated through atomic operations. Therefore, in this embodiment, when the visible levels in the dynamic multi-level hash table change, the hierarchical metadata is updated through atomic operations, so as to control the visible levels in real time and accurately.

[0068] Based on the above structure, in this embodiment, operations such as inserting, updating, deleting, and querying element pointers for the hash table are respectively completed through a pointer insertion step, an update step, a deletion step, and a query step.

[0069] In this embodiment, the pointer insertion step includes: determining whether there is an element pointer with the same key as the element pointer to be inserted in the dynamic multi-level hash table. If so, the pointer insertion step is exited; otherwise, traversing all visible levels from top to bottom to find a matching alternative bucket for the element pointer to be inserted. If there is an idle slot in the matching alternative bucket, the pointer is atomically inserted into the matching alternative bucket;

[0070] Before inserting an element pointer, this embodiment first determines whether there is an element pointer with the same key as the element pointer to be inserted in the dynamic multi-level hash table. If so, it determines that the insertion fails and directly exits the pointer insertion operation, thereby ensuring that there is at most one value for the same key in the dynamic multi-level hash table and guaranteeing the accuracy of subsequent query operations. The specific determination method is as follows: Traverse all visible layers from bottom to top to find a matching alternative bucket for the element pointer to be inserted, and obtain the keys corresponding to the inserted element pointers in each alternative bucket. Compare these keys with the key corresponding to the element pointer to be inserted. If the comparison results are all different, the insertion can be performed; otherwise, the insertion is determined to fail.

[0071] This embodiment traverses the visible layers in the top-down order, which can preferentially find free slots in the matching alternative buckets at a higher level and atomically insert pointers, facilitating the improvement of subsequent query efficiency. To further improve the efficiency, as a preferred embodiment, in this embodiment, if there are free slots in multiple matching alternative buckets in the same layer, the alternative bucket with a smaller offset of the free slot in the bucket is selected, and the pointer is atomically inserted, thereby balancing the load of the multiple matching alternative buckets, reducing the collision rate, and further improving the efficiency.

[0072] If there are no free slots in the matching alternative buckets, after allocating a new top-level hash table for the dynamic multi-level hash table, the pointer insertion step is re-executed.

[0073] To achieve the rapid expansion of the dynamic multi-level hash table and improve the efficiency of the pointer insertion operation, as a preferred implementation method, the initialization step of this embodiment further includes: pre-allocating 3 layers of hash tables for the dynamic multi-level hash table as inaccessible layers, and storing the starting addresses of each layer of hash tables in the circular buffer in sequence. Since the layers are pre-allocated, in the pointer insertion step, by allocating the hash table with the lowest pre-allocated layer to the dynamic multi-level hash table as the visible layer, a new hash table can be added to the dynamic multi-level hash table as the top-level hash table. Specifically, by atomically updating the value of the layer metadata <Lt, Lb> so that Lt is the same as the number of the newly allocated layer in the circular buffer, the expansion can be completed.

[0074] As the element pointers are inserted, the number of layers of the dynamic multi-level hash table may gradually increase. To avoid affecting the query efficiency due to too many layers, this embodiment further includes:

[0075] Pointer migration step: Traverse all visible layers except the bottom layer from top to bottom to find a matching alternative bucket for the element pointer to be migrated. If there is a free slot in the matching alternative bucket, the pointer is atomically inserted into the matching alternative bucket; if there are no free slots in the matching alternative buckets, after allocating a new top-level hash table for the dynamic multi-level hash table, the pointer migration step is re-executed.

[0076] The rehashing step executed in the background: When the number of visible layers exceeds two, all the element pointers in the bottom-layer hash table are migrated to other visible layers through the pointer migration step. After the migration is completed, the storage space occupied by the bottom-layer hash table is released; Through the rehashing operation executed in the background, the number of layers of the dynamic multi-layer hash table can be effectively controlled to ensure the query efficiency.

[0077] Since the rehashing operation will cause the migration of the bottom-layer element pointers, in order to avoid the insertion failure caused by the rehashing operation, in the pointer insertion step of this embodiment, if the number of visible layers is greater than 2, when looking for an alternative bucket that matches the element pointer to be inserted, the bottom layer is not traversed; This can ensure that there are enough alternative buckets to ensure successful insertion, and at the same time, it is not allowed to insert the pointer into the bottom layer, which can effectively avoid the migration of the pointer after being inserted into the bottom layer due to the rehashing operation, resulting in insertion failure;

[0078] Since before inserting the element pointer, the number of visible layers is 2, and after insertion, a new visible layer appears, the inserted element pointer may migrate due to the rehashing operation after being inserted into the bottom layer, resulting in insertion failure. To avoid this situation, in this embodiment, if before inserting the element pointer, the number of visible layers is 2, and after inserting the element pointer, a new visible layer appears, the pointer insertion step is re-executed.

[0079] In this embodiment, the update step includes: After inserting a new element into the persistent memory, obtain its element pointer p1; Traverse the accessible layers in the dynamic multi-layer hash table from bottom to top, find all matching element pointers, only retain the last matching pointer p2 and delete the remaining matching pointers, and atomically replace pointer p2 with pointer p1;

[0080] To avoid the update failure caused by the rehashing operation after a new pointer is inserted into the bottom layer, this embodiment further includes: If the number of accessible layers in the dynamic multi-layer hash table changes before and after the update step is executed, the update step is re-executed.

[0081] In this embodiment, the deletion operation includes: Traverse the accessible layers in the dynamic multi-layer hash table from bottom to top, and atomically delete all matching pointers one by one and release the corresponding elements;

[0082] To avoid the bottom-layer matching pointers not being deleted because they are migrated to a new visible layer, this embodiment further includes: If the number of accessible layers in the dynamic multi-layer hash table changes before and after the deletion step is executed, the deletion step is re-executed.

[0083] In this embodiment, the query operation includes: traversing all accessible layers in the dynamic multi-layer hash table from bottom to top until the first matching element pointer is found, and returning the element to be searched according to this pointer.

[0084] To further ensure the consistency of persistent memory, in this embodiment, the most significant bit of the element pointer is set as the persistence flag bit, where "1" indicates that it has been persisted and "0" indicates that it has not been persisted;

[0085] Moreover, the pointer insertion step further includes: setting its persistence flag bit before insertion to indicate that it has not been persisted, that is, setting it to "0", flushing the corresponding cache line after inserting the pointer into the dynamic multi-layer hash table, and then atomically setting the persistence flag bit to indicate that it has been persisted, that is, setting it to "1";

[0086] When any thread reads a pointer with the persistence flag bit indicating that it has not been persisted, it flushes the corresponding cache line and atomically sets the persistence flag bit to indicate that it has been persisted; based on this operation, this embodiment realizes the cooperative persistence of element pointers.

[0087] To achieve linearizability under persistent memory to ensure strong consistency, this embodiment further includes:

[0088] Synchronization step: As Figure 2 shown, after storing the element to be stored in persistent memory, look for the hash bucket for the pointer p of this element in the announcement array n If the old element pointer p already exists in the matching hash bucket H o , then after inserting the pointer p into the dynamic multi-layer hash table through the pointer insertion step, atomically replace the element pointer in the hash bucket H with the pointer p o , insert the pointer p into the dynamic multi-layer hash table through the pointer insertion step, and then empty the hash bucket H; if the hash bucket H is empty, insert the pointer p into the dynamic multi-layer hash table through the pointer insertion step, and then empty the hash bucket H; based on this operation, this embodiment realizes the cooperative concurrent insertion operation, ensures that each operation can be executed in a strict order, realizes linearizability under persistent memory, and ensures strong consistency. n Insert the pointer p into the dynamic multi-layer hash table through the pointer insertion step n , and then empty the hash bucket H; if the hash bucket H is empty, insert the pointer p into the dynamic multi-layer hash table through the pointer insertion step n , and then empty the hash bucket H; based on this operation, this embodiment realizes the cooperative concurrent insertion operation, ensures that each operation can be executed in a strict order, realizes linearizability under persistent memory, and ensures strong consistency.

[0089] To make full use of the storage space, in this embodiment, the storage area of elements in persistent memory is managed in the form of frames; a frame is a continuous space in persistent memory, and each frame includes a fixed number of blocks of the same size. When storing elements, one or more blocks are allocated for each block. The internal structure of the frame is as Figure 3 shown, its header records the signature, the size of the blocks in the frame, and reserved bits are reserved. As Figure 4As shown, in this embodiment, 16 types of frames are pre-determined, namely frame class 0 to frame class 15. The sizes of the blocks in different types of frames are different. Each foreground thread has a persistent memory allocator for managing the 16 types of frames.

[0090] Based on the above persistent memory allocation scheme, this embodiment further includes:

[0091] Element insertion step: Atomically allocate a frame with an appropriate size for the element to be inserted, so that after storing the element into one or more consecutive blocks within the frame, the difference between the allocated storage space size and the storage space size required by the element is minimized; Insert the element to be inserted into the allocated frame in sequence.

[0092] As Figure 4 shown, in this embodiment, the persistent memory allocator dynamically allocates space for the elements and levels of the hash table without logging in the persistent memory. Among them, the dynamic allocation range of the elements extends from the low address to the high address, and the extension granularity is a frame of a fixed size, and the space is extended atomically through a global frame pointer; The allocation range of the levels extends from the high address to the low address, and the recycled levels can be re-allocated to new elements, and new levels are allocated atomically through a global level pointer;

[0093] Since the space sizes occupied by the elements and pointers are different, this embodiment centrally stores the dynamic multi-level hash table and the frames at the high address end and the low address end of the persistent memory respectively, which can reduce space fragmentation and improve space utilization. It should be noted that in some other embodiments of the present invention, the storage positions of the dynamic multi-level hash table and the frames can also be interchanged, that is, the dynamic allocation range of the elements extends from the high address to the low address, while the allocation range of the levels extends from the low address to the high address.

[0094] Embodiment 2:

[0095] A persistent memory controller includes: a processor and a computer-readable storage medium;

[0096] The computer-readable storage medium stores a computer program; the processor is used to read the computer program and execute the data management method for persistent memory provided in the above Embodiment 1.

[0097] Embodiment 3:

[0098] A persistent memory system includes: persistent memory and the persistent memory controller provided in the above Embodiment 2.

[0099] Those skilled in the art can easily understand that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent replacements, and improvements made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A data management method for persistent memory, where the data is key-value pair elements, characterized in that, Including: Initialization step: Build a dynamic multi-layer hash table in persistent memory, which includes multi-layer hash tables. Each layer of hash table consists of multiple hash buckets for storing pointers to a specified number of elements. Each pointer has X alternative buckets in each layer of the hash table. The number of hash buckets in the hash table with a higher level is more. The accessible hash table is the visible layer. Build an announcement array in volatile memory, and the array elements are hash buckets. X is a positive integer. Pointer insertion step: Determine whether there is an element pointer with the same key as the element pointer to be inserted in the dynamic multi-layer hash table. If so, exit the pointer insertion step. Otherwise, traverse all visible layers from top to bottom to find a matching alternative bucket for the element pointer to be inserted. If there is an empty slot in the matching alternative bucket, atomically insert the pointer into the matching alternative bucket. If there is no empty slot in the matching alternative bucket, allocate a new top layer hash table for the dynamic multi-layer hash table and then re-execute the pointer insertion step. Synchronization step: After storing the element to be stored into the persistent memory, for the pointer p of the element in the announcement array n Search for a hash bucket. If there is an old element pointer p already in the matching hash bucket H o , then insert the pointer p through the pointer insertion step o After inserting the pointer p into the dynamic multi-level hash table, atomically replace the element pointer in the hash bucket H with the pointer p n , insert the pointer p through the pointer insertion step n Insert the pointer p into the dynamic multi-level hash table, and then empty the hash bucket H; if the hash bucket H is empty, insert the pointer p through the pointer insertion step n Insert the pointer p into the dynamic multi-level hash table, and then empty the hash bucket H; Pointer Migration step: Traverse all visible layers except the bottom layer from top to bottom to find a matching alternative bucket for the element pointer to be migrated. If there is an empty slot in the matching alternative bucket, atomically insert the pointer into the matching alternative bucket. If there is no empty slot in the matching alternative bucket, allocate a new top layer hash table for the dynamic multi-layer hash table and then re-execute the pointer migration step. Rehashing step executed in the background: When the number of visible layers exceeds two, migrate all element pointers in the bottom layer hash table to other visible layers through the pointer migration step. After migration is completed, release the storage space occupied by the bottom layer hash table. Moreover, in the pointer insertion step, if the number of visible layers is greater than 2, when finding a matching alternative bucket for the element pointer to be inserted, do not traverse the bottom layer. If the number of visible layers is 2 before inserting the element pointer and a new visible layer appears after inserting the element pointer, re-execute the pointer insertion step. The initialization step further includes: Establish a circular buffer in the persistent memory for storing the starting addresses of each layer of hash table in ascending order of levels.

2. The data management method for persistent memory according to claim 1, wherein Also including: Pre-allocation step executed in the background; The initialization step further includes: Pre-allocate M layers of hash tables for the dynamic multi-layer hash table as inaccessible levels, and store the starting addresses of each layer of hash table in order into the circular buffer. Moreover, in the pointer insertion step, by allocating the hash table with the lowest pre-allocated level to the dynamic multi-layer hash table as the visible layer, add a new layer of hash table as the top layer hash table for the dynamic multi-layer hash table. The pre-allocation step includes: When the number of pre-allocated inaccessible hash table layers is less than M, pre-allocate hash tables for the dynamic multi-layer hash table as inaccessible hash tables, and store the starting addresses of each layer of hash table in order into the circular buffer to make the number of pre-allocated inaccessible hash tables be M. Wherein, M is a positive integer.

3. The data management method for persistent memory according to claim 2, characterized in that, Hierarchical metadata <Lt, Lb> is also maintained in the volatile memory, where Lt and Lb are respectively used to store the numbers of the top-level hash table and the bottom-level hash table in the circular buffer; the hash tables with numbers within the range of [Lt, Lb] are the accessible hash tables in the dynamic multi-level hash table; Moreover, in the pointer insertion step, when adding a new layer of hash table to the dynamic multi-level hash table as the top-level hash table, the value of the hierarchical metadata <Lt, Lb> will be atomically updated; in the rehashing step, when releasing the storage space occupied by the bottom-level hash table, the value of the hierarchical metadata <Lt, Lb> will be atomically updated.

4. The data management method for persistent memory according to any one of claims 1 to 3, characterized in that It further includes: Element insertion step: Atomically allocate a frame with a suitable size for the element to be inserted, such that after storing the element into one or more consecutive blocks within the frame, the difference between the allocated storage space size and the storage space size required by the element is minimized; insert the element to be inserted into the allocated frame in sequence; Wherein, a frame is a continuous space in the persistent memory, and each frame includes a plurality of blocks with a fixed size; for different types of frames, the block sizes are different.

5. The data management method for persistent memory according to claim 4, characterized in that, The dynamic multi-level hash table and the frames dynamically allocate space in the persistent memory without logging. The dynamic multi-level hash table atomically allocates storage space in the order from high to low addresses, and the frames atomically allocate storage space in the order from low to high addresses; Alternatively, the dynamic multi-level hash table atomically allocates storage space in the order from low to high addresses, and the frames atomically allocate storage space in the order from high to low addresses.

6. The data management method for persistent memory according to any one of claims 1 to 3, characterized in that It further includes: Update step: After inserting a new element into the persistent memory, obtain its element pointer p1; Traverse the accessible layers in the dynamic multi-level hash table from bottom to top, find all matching element pointers, only retain the last matching pointer p2 and delete the remaining matching pointers, and atomically replace the pointer p2 with the pointer p1; if the number of accessible layers in the dynamic multi-level hash table changes before and after executing the update step, then re-execute the update step; Deletion step: Traverse the accessible layers in the dynamic multi-level hash table from bottom to top, atomically delete all matching pointers one by one, and release the corresponding elements; if the number of accessible layers in the dynamic multi-level hash table changes before and after executing the deletion step, then re-execute the deletion step; Query step: Traverse all accessible layers in the dynamic multi-level hash table from bottom to top until the first matching element pointer is found, and return the element to be searched according to this pointer.

7. The data management method for persistent memory according to claim 6, wherein, A persistence flag bit is set in the element pointer to indicate whether it has been persisted; Moreover, the pointer insertion step further includes: setting its persistence flag bit before insertion to indicate not persisted, flushing the corresponding cache line after inserting the pointer into the dynamic multi-level hash table, and then atomically setting the persistence flag bit to indicate persisted; When any thread reads a pointer with the persistence flag bit indicating not persisted, it flushes the corresponding cache line and atomically sets the persistence flag bit to indicate persisted.

8. A persistent memory controller, characterized in that, It includes: Processor and computer-readable storage medium; A computer program is stored in the computer-readable storage medium; the processor is configured to read the computer program and execute the data management method for persistent memory according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Read-optimized memory database Trie tree index method

    CN105117417A

  • Index tree construction method and system for key value storage system

    CN110083601A