Transaction persistence method and system for asynchronously writing back to persistent memory

By adopting the asynchronous writeback method in the persistent transaction memory system, the data persistence operations are moved to the background thread and merged and written back, the problems of extended transaction execution time and low throughput in traditional systems are solved, and high scalability is achieved and the effect of low persistence overhead.

CN113220490BActive Publication Date: 2024-11-26TSINGHUA UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110605179.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-31
Publication Date
2024-11-26
Estimated Expiration
2041-05-31

Smart Images

  • Figure CN113220490B_ABST
    Figure CN113220490B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for persisting memory transactions and a persistent transaction memory system constructed based on the method, and mainly relates to the field of system software technology. The main feature of the method is to construct and persist a log and update data on a volatile memory during the transaction commit phase. The data update on the persistent memory is periodically executed by a dedicated thread. The thread determines the cache blocks that may be in an inconsistent state in the volatile memory and the persistent memory through a bitmap mechanism, calls the write-back primitive to synchronize the data, and reclaims the log entry space that is no longer needed. Because the read-write granularity and the write-back granularity of the persistent memory are different, and the actual load has spatial locality, the above method can effectively reduce the number of write-back primitives required and improve transaction processing efficiency. Compared with the existing system, the system implemented based on this method can significantly shorten the transaction execution time relative to similar implementations, and is scalable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of system software, and in particular to a transaction persistence method and system for persistent memory. Background Art

[0002] For a long time, most software has relied on memory to complete efficient processing and disks to complete data storage. The introduction of persistent memory has changed the inherent storage architecture. Persistent memory has the characteristics of persistence, byte addressing, low latency and high bandwidth. It allows the use of conventional read and write instructions to directly modify data, effectively absorbing the advantages of traditional memory and disk. With the advent of commercial persistent memory products developed by Intel, it is foreseeable that more software will make full use of persistent memory. However, it is difficult to use persistent memory correctly, because modifications to persistent memory (note: using instructions such as MOV) will be temporarily stored in the cache, and this part of the data will disappear after power failure; these modifications may be written back to persistent memory in advance due to the cache elimination mechanism. In order to ensure the consistency of persistent memory data, it is necessary to use writeback (such as CLWB) and fence instructions (such as MFENCE) reasonably to ensure that the latest data has been synchronized to persistent memory.

[0003] Transactional memory (TM) provides a shared memory concurrency control mechanism that simulates database transactions. A transaction is a piece of code that reads and writes memory. These read and write operations are logically an independent unit, and the intermediate state is invisible to other transactions. Summary of the invention

[0004] 1. Technical problems to be solved

[0005] Traditionally, in order to simplify the programming of persistent memory, the common method is to modify and expand the functions of traditional software transactional memory to achieve persistent transactional memory functions. Transactional memory treats a set of memory read and write operations as a whole and implements complete ACID semantics like a database transaction. Typical systems include Mnemosyne [ASPLOS11], DudeTM [ASPLOS 17], Pisces [USENIX ATC 19], etc. Traditional databases usually append entries to the log file during commit. At regular intervals, the checkpoint thread snapshots the current database state (writes all key data structures in memory to disk) and recycles logs that are no longer needed. Compared with traditional databases, transactional memory systems generally use redo logging technology, which is usually divided into three stages: (P1) build and persist the log (including transaction sequence number, modification address and new value), (P2) update data, (P3) persist the data updated in the previous step, and then delete the log. Traditionally, after these three processes, the transaction is considered committed. Specifically, (T1) after the commit time, all threads can see the values ​​updated by the transaction; (T2) after the commit time, if the system shuts down, after completing the necessary recovery process, the values ​​updated by the transaction or subsequent committed transactions can be seen.

[0006] The existing architecture uses cache line as the granularity to implement data persistence in transactional memory systems. In many application scenarios, the (P3) stage takes longer than the (P1) stage. Some systems (such as Mnemosyne) arrange the above three stages to be completed sequentially during the transaction commit phase, which significantly reduces the transaction processing efficiency. Some systems (such as DudeTM) separate the (P2) and (P3) stages from the transaction commit and implement them through independent asynchronous threads, which has obvious poor scalability problems, and the property (T2) of the committed transaction cannot be guaranteed. Some other systems (such as Pisces) reduce the transaction isolation level (snapshot isolation), so pure read transactions are non-blocking in many cases, but this system does not solve the problem of long persistent memory changes in write transactions, and requires a certain degree of modification to the application.

[0007] The inventors found that in actual persistent memory systems, persistent data accounts for the vast majority of additional overhead compared to persistent logs. The inventors also noticed that memory access in actual systems conforms to the characteristics of spatial locality and temporal locality, and write-back instructions are implemented at a certain memory unit granularity (cache block granularity, generally 64 bytes), so it is very likely that some cache blocks are repeatedly written back multiple times, which leads to obvious write-back amplification.

[0008] Therefore, the inventors thought that if a certain method is used to merge these flush requests, the flush amplification can be reduced and the maximum flush performance can be achieved, thereby shortening the transaction execution time and achieving performance close to that of traditional transactional memory.

[0009] The purpose of the present invention is to solve the problems of prolonged transaction execution time, reduced throughput and poor scalability caused by inefficient data persistence strategies in traditional persistent transaction memory systems, and to provide an efficient, easy-to-use and scalable persistent transaction memory system.

[0010] (II) Technical solution

[0011] In order to solve the above technical problems, the present invention proposes a persistent memory transaction persistence method based on asynchronous writeback, and implements a new persistent transaction memory system (XIHE-TM) based on this. The working method of the system includes the following steps:

[0012] S1. The system includes a working thread and a recycling thread. The function of the working thread is to build and persist the log during transaction submission. The recycling thread checks the transaction submission status according to a predefined time period and completes the persistence and log recycling work on the data address space.

[0013] Before formally executing a transaction, initialization is required. Start the recovery thread, which monitors the execution of front-end transactions. At regular intervals, after detecting that several front-end transactions have been committed, the recovery thread asynchronously batch-executes the work of persistent snapshots and log recovery. The detailed steps of these tasks are described in the S3 process.

[0014] S2, the transaction commit phase uses the Write Ahead Logging (WAL) paradigm, that is, before writing new values ​​to the memory address space, you need to prepare and persist the redo log (Redo Log). During the transaction commit phase, after locking all target write addresses and verifying the atomic consistency of the transaction, you need to complete the following steps in sequence:

[0015] S2.1. Build a redo log. For persistent transaction memory, the address and new value of each write request need to be extracted to build a log. In addition, in order to ensure correct recovery, the transaction sequence number also needs to be recorded.

[0016] S2.2. Store the logs obtained in step S2.1 in a specific area of ​​memory and ensure that they are persisted. If there is not enough log space, the transaction will continue to wait.

[0017] S2.3. Use regular read and write instructions to write new data to the specified target address, but do not use any persistence primitives.

[0018] Finally, this transaction is marked as "committed", allowing the front-end worker thread to start executing the next transaction.

[0019] S3. When the recovery thread detects a "committed" transaction, it can timely make the transaction execution effect persistent and reclaim the log space through the following steps. In order to improve performance, a method of batch processing multiple transactions at fixed time intervals is adopted.

[0020] S3.1. The recycling thread periodically checks whether there are any transactions that have been "committed" and whose logs have not been deleted. If not, it waits for a while and tries again.

[0021] S3.2, the recycling thread reads the addresses corresponding to these transactions and determines the cache block address list that needs to be flushed.

[0022] S3.3, the recycling thread persists the modifications made by this group of transactions to the persistent memory by calling the writeback (CLWB) instruction for each cache block address obtained in step S3.2.

[0023] S3.4, the recycling thread safely deletes the logs involved in step S3.1. After that, the recycling thread waits for a while and returns to step S3.1 to continue checking whether there are "committed" transactions whose logs have not been deleted.

[0024] After the S2 process, the transaction is persisted in the form of a log; after the S3 process, the transaction is persisted in the form of a data structure in persistent memory.

[0025] If a system crash occurs, a recovery process will need to be performed the next time you boot up, the steps are as follows:

[0026] S4.1. Scan all valid log records in the persistent memory and arrange them in ascending order of transaction sequence numbers.

[0027] S4.2, replay each transaction one by one, that is, for each record, write the new data to the corresponding address;

[0028] S4.3, determine the cache block address list that needs to be flushed during the above replay;

[0029] S4.4, for each cache block address obtained, persist the modification to the memory during the replay by calling a write-back instruction;

[0030] S4.5 Delete all logs.

[0031] (III) Beneficial effects

[0032] Compared with the existing transaction memory persistence method and system, the technical solution proposed by the present invention has the following advantages:

[0033] 1. The memory transaction persistence method based on asynchronous write-back of cache blocks proposed in the present invention not only shortens the transaction submission time of the working thread, but also reduces the time during address locking, and reduces the amount of data write-back, thereby avoiding data persistence from becoming a performance bottleneck of transaction memory, thereby achieving high scalability and low persistence overhead of the system. If the data is in a skewed distribution, the present invention can further reduce the demand for data write-back, which has a significant effect on performance improvement. The system implemented based on the present invention realizes persistence, and reduces write-back requests by 6.30% to 44.05% relative to DudeTM on multiple test sets. The throughput rate on the actual test set is improved by 5.82 times relative to DudeTM.

[0034] 2. The memory transaction persistence method based on asynchronous write-back of cache blocks proposed in the present invention is universal and can be used not only in systems implemented based on the present invention, but also in implementations including but not limited to other persistent transaction systems (such as persistent hardware transaction memory, databases, etc.) and other persistent data structures (such as B+ trees, etc.).

[0035] 3. The asynchronous thread of the embodiment of the present invention performs a cache write-back operation, which will not affect the correctness of the foreground thread execution. The write-back instruction mentioned in this specification is to synchronize the value on the cache to the corresponding position on the persistent memory. This operation itself will not invalidate the cache block, so it will not have an adverse effect on the cache hit rate during transaction execution. At the same time, since the data from the application's perspective will not change during this process, and the processor provides appropriate cache consistency, the asynchronous thread of the embodiment of the present invention performs a cache write-back operation, which will not affect the correctness of the foreground thread execution. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 A schematic overall process diagram of a method for persistent transactions of a persistent memory according to an embodiment of the present invention is shown.

[0037] Figure 2 It is the main flow chart of the memory transaction persistence method based on asynchronous write-back of cache blocks proposed by the present invention.

[0038] Figure 3 This is the memory allocation and data flow process in the embodiment of the present invention.

[0039] Figure 4 It is the pseudo code of the main process of thread recovery of the present invention.

[0040] Figure 5 The throughput-number of working threads curves of the system implemented by the present invention and the comparison system in the hash table, red-black tree and B+ tree loads.

[0041] Figure 6 It is a curve of the write-back amount of data per operation in the hash table load-skew distribution coefficient of the system implemented by the present invention and the comparison system.

[0042] Figure 7 It is a table of execution time-thread number of the system implemented by the present invention and the comparison system in the actual test load of the Stanford Multiprocessor Transaction Application Test Suite (STAMP). DETAILED DESCRIPTION

[0043] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments (exemplary transactions).

[0044] Figure 1 A schematic overall flow chart of a method for persistent transactions for persistent memory according to an embodiment of the present invention is shown.

[0045] like Figure 1 As shown in the left box of , for each transaction:

[0046] Log persistence step: build and persist logs in persistent memory;

[0047] The data update step updates the data on a volatile memory (including but not limited to a processor cache), and then marks the transaction as committed.

[0048] like Figure 1 As shown in the right box of , the data update of a single transaction on the persistent memory is delayed. After accumulating a group of transactions, the processor synchronizes data to the persistent memory for the group of transactions, performs the persistence operation on the data updated in the aforementioned data update step (i.e., persists it to the persistent memory), and deletes the corresponding log.

[0049] Preferably, a working thread and a recycling thread are established and maintained, and the working thread performs Figure 1 The operations shown in the left box in the figure are executed as background threads. Figure 1 For example, the recovery thread checks the transaction execution status according to a predefined time period and completes the persistence and log recovery work on the data address space.

[0050] Compared with the existing transaction atomic commit method, the transaction persistence method of the embodiment of the present invention solves the problem that the traditional persistent data occupies most of the extra overhead in the persistent memory system by moving the data persistence operation on the persistent memory out of the transaction commit phase, thereby shortening the transaction commit time. More importantly, the time that the relevant address space is protected by the transaction write lock. Other transactions (especially read transactions) need to wait for the aforementioned transaction to release the write lock to obtain the committed memory data on the same address space. Therefore, this method can also shorten the commit time of other transactions. In summary, the transaction persistence method of the embodiment of the present invention is of positive significance for improving the transaction commit throughput. In addition, the data persistence operation on the persistent memory is executed in batches for a group of transactions (generally completed by write-back instructions), and the write-back at the memory unit granularity, that is, the cache block granularity, reduces or even largely avoids the problem that the same cache block is repeatedly written back to the persistent memory multiple times in the traditional mode. The method also reduces or avoids the problem that the user's single read and write memory granularity (8 bytes) and the actual read and write granularity of the persistent memory (64 to 256 bytes) are inconsistent. Experimental results confirm that this method can achieve the maximum flushing performance, reduce the time consumed by the processor due to flushing, and also has a positive significance for improving transaction submission throughput.

[0051] It should be noted that group commit is a common technology for optimizing transaction commits in the database field. The idea is to merge the actions written by multiple transaction logs to reduce disk sequential writes. Compared with traditional group commits, the present invention still requires each transaction to persist the logs it creates separately, and only the data involved in the first (P3) of the three stages in the redo log technology introduced in the previous invention content section is merged and written back. Therefore, unlike group commit, which requires the accumulation of a certain number of transactions and the submission of the group of transactions together at the end, in the present invention, the transactions are immediately submitted after completing the first (P1) and (P2) stages in the aforementioned redo log technology.

[0052] Figure 2 A more detailed overall flow chart of a method for persisting memory transactions based on asynchronous write-back of cache blocks according to an embodiment of the present invention is shown.

[0053] Figure 3 The memory allocation and data flow process in the embodiment of the present invention is shown.

[0054] For ease of understanding, an example transaction is used for illustration below. The example transaction requires that the data at addresses a, b, and c in the persistent memory be modified to X1, Y3, and Z2, respectively, and the atomicity, consistency, isolation, and persistence (ACID characteristics) of the transaction must be met. This embodiment is used to illustrate the present invention, but is not intended to limit the scope of the present invention.

[0055] like Figure 2 As shown, in step S1, the working thread and the data persistence thread (hereinafter sometimes referred to as the data persistence thread as the recycling thread) are initialized; then in the second stage, the working thread executes steps S2.1, S2.2, and S2.3 in the foreground, specifically in step S2.1, a log is created, in step S2.2 the log is persisted, and in step S2.3 the data update is completed and marked as submitted; in the third stage, the background thread executes steps S3.1, S3.2, S3.3, and S3.4, specifically in step S3.1, a committed transaction is detected, in step S3.2 the cache block to be flushed is determined; in step S3.3 the cache block is flushed; in step S3.4 the log is deleted. It should be noted that there is no sequential relationship between the third stage and the second stage in time, that is, the two can be executed sequentially or in parallel.

[0056] Figure 3 The memory allocation and data flow process of an example transaction according to an embodiment of the present invention is given. Figure 3 As shown, the persistent memory is divided into two areas as needed: the data structure area and the redo log area, where (1) the data structure area is visible to the user and can store data structures. Users can use the specified transaction interface to complete operations on this part of data according to their own wishes; (2) the redo log area contains log records of each completed and committed transaction for control by this system.

[0057] From the perspective of the layers above the operating system (including the application and the system implemented based on the present invention), each data structure has only one copy in the address space where the persistent memory is located. However, due to the existence of the volatile cache in the CPU, two data versions are actually formed: data version V1 in the persistent memory ( Figure 3 lower part) and the application-visible version V2 ( Figure 3 Upper part). When a system failure occurs, only V1 is retained because the cache block data is lost, and this becomes the version visible to the application the next time it is executed (note that it is different from V2 above). If a memory word has just been modified, V2 must be modified accordingly, but V1 may not be modified (or may be modified). When the processor eliminates the cache block (the operating system cannot know whether the cache block is eliminated) or actively calls the CLWB instruction, it can ensure that V1 is modified to be consistent with V2. Figure 3 The process marked ② and ④ is essentially the process implemented by the present invention in which the system explicitly calls the CLWB instruction to ensure that V1 and V2 are consistent.

[0058] Traditional databases often use DRAM as a large-capacity cache to avoid repeated reading and writing of disks. Therefore, the database module can sense whether the page is located in the database cache, and can actively participate in the process of allocating and eliminating pages to ensure the consistency of the page content from the application's perspective and the corresponding page content on the disk. In contrast, after issuing a write memory instruction, the processor cache based on the write-back mode may store the updated data only in the cache block without writing it to the persistent memory; it may also be written back to the persistent memory at any time thereafter. This process is invisible to the software. The system implemented based on the present invention can only ensure that a cache block has been written to the persistent memory by explicitly calling the cache line write-back instruction (CLWB) provided by the processor, but cannot detect cache block elimination events. Due to the above constraints, the transaction submission method of the present invention is essentially different from that of the traditional database.

[0059] Combine the following Figure 2 and Figure 3 A system working method according to an embodiment of the present invention is described.

[0060] S1, initialization phase. Worker threads, that is, threads that execute transactions and complete transaction submission, are set by the transaction memory user. The system establishes several recycling threads as needed, and each recycling thread processes transactions and logs generated by several worker threads. Each recycling thread regularly checks whether there are transactions that have been submitted and not processed according to the prescribed cycle. If so, one of the threads will execute the process described in step S3 to complete the operation of the asynchronous processing phase.

[0061] As an example, during the initialization phase, each recycling thread also needs to establish a private bitmap (not visible to other threads to avoid synchronization overhead) and set it to zero. Use regular read and write instructions to operate on it. The persistent memory address space is divided into cache blocks (usually 64 bytes) in granularity, and each block corresponds to a bit on the bitmap. Currently, an independent bitmap is allocated to each recycling thread. For example, if the size of the persistent memory address space is 4GB, the bitmap space requirement is 4096 / 64 / 8=8MB, so the storage overhead is acceptable. The bitmap can be stored in conventional memory such as DRAM, and it does not need to be persistent.

[0062] S2, the transaction execution phase, can be further divided into two sub-phases. The first phase is from the start of the transaction (TX_BEGIN) to the transaction commit (TX_COMMIT). This phase adopts the same concurrency control method as traditional transaction memory. For transaction write (TX_STORE) operations, the address and new value need to be added to the write set (Write Set) located on DRAM. At this time, the old value is still retained at the target address. During the second phase of transaction commit (TX_COMMIT), write locks are added to all write addresses in the first phase to prevent other transactions from reading and writing the same variables; after verifying the atomic consistency of the transaction, complete the following steps in sequence:

[0063] S2.1. Construct the redo log obtained during the transaction execution. The system constructs the log by extracting the address and new value of each write request. For example, for the embodiment, (a, X1), (b, Y3) and (c, Z2) need to be extracted from the aforementioned write set. In addition, in order to ensure correct recovery, the transaction sequence number (T11) needs to be recorded as well to form a log record ( Figure 3 Step 1 is shown in the figure, indicated by label ①). The transaction sequence number is a 64-bit long unsigned integer. If there is a dependency between two transactions, that is, transaction b is submitted after transaction a, and transaction b reads (or writes) the variables written by transaction a, then the sequence number of transaction b must be greater than that of transaction a. In addition, the sequence number order of all transactions under the same thread is consistent with the submission time. This information helps to achieve correct transaction recovery.

[0064] S2.2. Generate a redo log data structure and append it to the log container to which the current corresponding working thread belongs. When there is no free space in the log container to insert a new record, the corresponding working thread will wait for the background recycling thread to complete the work of reclaiming space. After that, these records will be persisted. The log container adopts a circular queue mode, and the log unit between the head pointer and the tail pointer of the queue is regarded as a valid log unit. The modification and persistence operations of the head pointer and the tail pointer are inseparable, which can be achieved through technologies such as Link-and-persist. By modifying the head pointer of the log and writing it back to the persistent memory, the redo log generated in this step is included in the valid log unit, thereby indicating that this transaction has been persisted ( Figure 3 Step 2 is shown, indicated by label ②).

[0065] S2.3, the transaction is guaranteed to be persistent after the previous stage, and this stage requires the execution of these write operations, but does not require persistence. After this stage is completed, other transactions can access the values ​​updated by this transaction, so the transaction commit (T1) condition is met: after the commit point, all threads can see the values ​​updated by the transaction. At this time, it is not guaranteed that the new value has been persisted, but because the log provides sufficient information, even if a crash occurs, we can still restore to the state of complete execution of this transaction by replaying the log, ensuring the atomicity of the transaction ( Figure 3 Step 3 is shown in the figure, indicated by label ③), that is, all memory write operations of a single transaction can be fully executed. This shows that the transaction commit condition (T2) is met: after the commit time, if the system stops, after completing the necessary recovery process, the values ​​updated by the transaction or subsequent committed transactions can be seen. After the above process is completed, it means that the transaction is committed.

[0066] Each worker thread has a private "most recently committed transaction sequence number" field, and this variable itself does not require persistence. As mentioned earlier, the sequence number order of all transactions under the same thread is consistent with the submission time, so the "most recently committed transaction sequence number" field only stores one value, indicating that transactions less than or equal to this value in the worker thread have been submitted, and can therefore be processed by the recycling thread. This does not mean that transactions less than or equal to this value in other worker threads have been submitted. The background recycling thread will query this value to determine which transactions have completed steps S2.1 to S2.3 (that is, which "committed" transactions are there) and safely recycle the logs. After completing step S2.3, the "most recently committed transaction sequence number" field of the corresponding worker thread needs to be updated.

[0067] S3. When the recovery thread detects a "committed" transaction, it can timely persist the execution effect of the transaction and recycle the log space through the following steps. As an example, in order to improve performance, a method of batch processing multiple transactions at a fixed time interval can be adopted.

[0068] Log records can be safely deleted, provided that the transactions that created these log records and the transactions that these transactions depend on (earlier committed transactions with read-write or write-write conflicts) have been persisted. The reason why the latter (earlier committed transactions with read-write or write-write conflicts) is guaranteed is that the persistence and write-back processes are protected by concurrency control, and it is impossible for the dependent transaction to be persisted later than the current transaction. Therefore, it is only necessary to ensure the former (that is, the transaction that created these log records has been persisted). This process includes the following three stages.

[0069] S3.1, preparation phase. This phase requires collecting the "most recently submitted transaction sequence number" ( Figure 4Finally, the memory fence (MFENCE) and the next stage are used to complete the distinction and avoid reordering ( Figure 4 4).

[0070] In one example, each target worker thread has an independent "most recently committed transaction sequence number", indicating that among all transactions initiated by the worker thread, transactions less than or equal to this value are "committed" (the transaction sequence numbers within each thread are arranged in monotonically increasing order according to the actual running order), so its log can be safely deleted in step S3.4.

[0071] In the preparation phase, the "most recently committed transaction sequence number" of all target worker threads is uniformly obtained. This is because during the entire recovery process, transactions are still committed normally and will not be suspended. If a transaction initiates a commit after the start of S3.2 (tracking phase) and completes the commit before the end of S3.3 (flush phase), the data structure in the cache may be modified, but the flush of the corresponding cache block has been completed before this process, so the latest value is not written back to the persistent memory, and the log is deleted, which damages the consistency. This situation needs to be avoided, so we must determine the scope of the transaction involved before starting the flush.

[0072] S3.2, Tracking phase. The recycling thread finds the log records of all committed transactions based on the "most recently committed transaction sequence number" of each worker thread and scans the log container. Each transaction includes several regular records, including the modified address and new value, but this phase only needs to read the address information. Different from the basic approach of calling the writeback primitive (such as CLWB) for each address, the recycling thread sets the value of the corresponding position on the bitmap to 1 ( Figure 4 ), indicating that the cache block is about to be flushed. Persistence at the cache block granularity not only affects the latest value of the address where the current log record is located, but also flushes nearby addresses back to the persistent memory device. In this way, multiple modifications to the same cache block can be merged into one, which not only shortens the transaction submission time of the worker thread, but also reduces the time during the address locking period, and reduces the amount of data writeback, avoiding data persistence from becoming a performance bottleneck of transactional memory, thereby achieving high scalability and low persistence overhead of the system.

[0073] S3.3, flushing phase. The recycling thread retrieves the bitmap, and when a cache block is hit, a write-back (CLWB) operation is issued for the cache block. Finally, a persistent fence is introduced to ensure that the flushing task is completed before the next phase.

[0074] S3.4, truncation phase. Because the effects of these transactions have been persisted to persistent memory (unless subsequent transactions modify the value at the same location, but the updated data can be obtained from the log, so the consistency of the data will not be compromised), the log records scanned in the previous phase can be safely truncated. In one example, a simple method of modifying the tail pointer is adopted, and the tail pointer is persisted to indicate the truncation of the log, and the corresponding log unit is no longer a valid log unit. In addition, the bitmap needs to be reset to clear all of them. At this point, the recycling thread can suspend its work and wait for the next cycle, that is, start again from step S3.1 until the application exits.

[0075] After the S2 process, the transaction is persisted in the form of a log; after the S3 process, the transaction is persisted in the form of a data structure in persistent memory.

[0076] The behavior of the recycling thread is essentially to ensure that the data structure has been correctly written back to the persistent memory device and the log is safely deleted. The similar work in traditional databases is snapshot generation, which writes the cache on DRAM back to the disk. The key differences between the two are: (1) Traditional databases write new data to database files at a coarse granularity (such as pages) through file I / O operations, with a large amount of data transferred and a long time interval; while the present invention synchronizes data to the persistent memory device at the granularity of cache blocks through processor instructions. This process does not require kernel intervention and has a short time interval; (2) Traditional databases need to carefully handle the executing transactions during snapshot generation to avoid destroying the database consistency, while the present invention allows any write transaction to be submitted during the execution of the recycling thread (that is, the write transaction thread will not be blocked by the recycling thread).

[0077] If a system crash occurs, the next time you start the system, you only need to read the data structure in the persistent memory and replay the valid logs in sequence to obtain a consistent data structure.

[0078] The steps of the recovery process are as follows:

[0079] S4.1. During the recovery phase, only the transaction sequence number can be used to determine a serializable order of transactions. The transactions must be correct if they are arranged in the order of increasing transaction sequence numbers. The order required to complete correct execution is generally looser than the order of increasing transaction sequence numbers, but the cost of reconstruction is often greater than reordering. Therefore, it is required to scan all valid log records in persistent memory and arrange them in the order of increasing transaction sequence numbers.

[0080] Transaction sequence numbers may not be consecutive because the corresponding transaction was aborted or crashed before the persistent log was written. Both of these situations will not affect the data structure and can be safely ignored.

[0081] S4.2. Replay transactions one by one in the order of S4.1, that is, for each record, write new data to the corresponding address.

[0082] S4.3. Determine the cache block address list that needs to be flushed during the above replay.

[0083] S4.4. For each cache block address obtained in step S4.3, the modification to the memory in step S4.2 is made permanent by calling a write-back instruction.

[0084] Since memory accesses in real systems are generally local, this optimization can also significantly improve recovery performance.

[0085] S4.5. Delete all logs.

[0086] The memory transaction persistence method based on asynchronous write-back of cache blocks proposed in the present invention not only shortens the transaction submission time of the working thread, but also reduces the time during address locking, and reduces the amount of data write-back, thereby avoiding data persistence from becoming a performance bottleneck of transaction memory, thereby achieving high scalability and low persistence overhead of the system. If the data is in a skewed distribution, the present invention can further reduce the data write-back demand, which has a significant effect on performance improvement. Finally, this method is universal and can also be used for other transaction processing systems and persistent data structure implementations. In particular, the method proposed in the present invention can not only build persistent transaction memory on software transaction memory, but also build persistent transaction memory on general hardware transaction memory.

[0087] In order to verify the actual use effect of the method proposed in the present invention, the inventor designed an experimental environment based on Intel Optane memory and four processors with a total of 72 cores. In order to avoid the impact of asymmetric memory access (NUMA) effects on performance, the test was performed only on fixed processor nodes. In the system (hereinafter referred to as XIHE-TM) implemented according to an embodiment of the present invention, three data structures, B+ tree, red-black tree and hash table, were implemented, and their write performance in two loads of uniform insertion and Zipf skewed distribution update was tested respectively, and the Stanford multiprocessor transaction application test set (STAMP) test software was transplanted to adapt it to the requirements of persistent transaction memory. By default, the log space for each working thread is 2MB.

[0088] The selected comparison systems include: volatile implementation (a non-persistent transactional memory implementation based on TinySTM [PPoPP 08], but nodes are still allocated from persistent memory, representing the theoretical performance upper limit of all persistent transactional memories), DudeTM, RomulusLR, etc. The following data are the average values ​​obtained from 10 measurements.

[0089] Figure 5 The throughput-number of worker threads curves of XIHE-TM and the above-mentioned comparison systems in hash table, red-black tree and B+ tree loads are shown. The key and value are both 64-bit integers, the key range is 2M, and the read-write ratio is 2:8. RomulusLR does not support concurrent execution of two or more write transactions, so it does not have performance scalability and has the lowest throughput; DudeTM performs better than other implementations when the number of threads is small, and sometimes even better than volatile implementations, because transaction execution is completed on DRAM. However, as the number of threads increases and there is still only one reconstruction thread, the reconstruction thread becomes the system bottleneck and its scalability is still greatly limited. Compared with the first two works, XIHE-TM avoids the adverse effects of a single recovery thread on the overall performance and uses the existing lock mechanism of transaction memory to achieve read-write transaction parallelism and fault consistency, so it has good scalability. The maximum throughput of XIHE-TM is 3.22 times that of DudeTM and 11.4 times that of RomulusLR. In addition, if the data distribution is more concentrated, XIHE-TM can also achieve higher throughput.

[0090] Figure 6 It is a curve of the amount of data written back per operation in the hash table load-skewed distribution coefficient of the system XIHE-TM implemented according to an embodiment of the present invention and the comparison system. In RomulusLR, each transaction write operation requires an average of 2.125 data flushes, while DudeTM requires an average of 1.43 times, and the influence of data distribution on the amount of flushes is limited. The number of flushes of XIHE-TM is smaller than that of DudeTM, and when the data is concentrated, that is, the Zipf distribution coefficient increases, the number of flushes of XIHE-TM is further reduced, and the minimum can reach 55% of DudeTM (the skewed distribution coefficient is 0.99 at this time). If the log size is further expanded, that is, the flush cycle is extended, the curve moves downward, and there will be a higher probability of cache block merging, thereby reducing the number of flushes.

[0091] Figure 7 The table is a table of execution time-number of threads in various loads of the system implemented by the present invention and the comparison system under the Stanford Multiprocessor Transaction Application Test Set (STAMP). The inventor analyzed two test sets, namely Vacation and SSCA2. In the Vacation test set, since DudeTM transaction execution is completed on DRAM, it has higher efficiency when the number of cores is less than 8, while XIHE-TM performs better when there are 16 cores. There are not many codes in SSCA2 that are protected by the transaction mechanism, and it is mainly based on calculation. The processing time of XIHE-TM is shorter than that of DudeTM when there are 2 cores or more, and the maximum performance increase can be 5.82 times.

[0092] The inventors also measured and analyzed the recovery time required under this mechanism. The recovery time is related to the number of valid logs stored at the time of failure, which is affected by the runtime state, the maximum log capacity, etc. Under the default configuration, the time to restore the hash table data structure is about 335 milliseconds.

[0093] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this field, several improvements and substitutions can be made without departing from the technical principles of the present invention. These improvements and substitutions should also be regarded as the scope of protection of the present invention.

Claims

1. A method for persisting memory transactions, characterized in that: The method comprises: Before formally executing a transaction, the system establishes and maintains a working thread and a recycling thread. The working thread is used to build and persist logs during transaction submission, and the recycling thread checks the execution status of front-end transactions according to a predefined time period. After detecting that several front-end transactions have been submitted, it asynchronously and batch-completes the work of persistent snapshots and log recycling on the data address space. Transaction commit adopts the Write Ahead Logging (WAL) paradigm. After locking all target write addresses and verifying the atomic consistency of the transaction, the worker thread first builds a redo log, then writes the redo log to a specific area of ​​persistent memory and ensures that it has been persisted. Next, the new data is written to the specified target address using conventional read and write instructions, but no persistence primitives are used. Finally, the transaction is marked as "committed", allowing the front-end worker thread to start executing the next transaction. The recycling thread periodically checks whether there are "committed" transactions whose logs have not been deleted. If not, it will wait for a period of time and try again. When the recycling thread detects "committed" transactions, it first reads the addresses corresponding to these transactions and determines the cache block address list that needs to be flushed. Then, for each cache block address in the address list, it calls the write back (CLWB) instruction to persist the transaction's modifications to the persistent memory. Finally, the recycling thread safely deletes the redo logs corresponding to these transactions, waits for a period of time, and enters the next check cycle.

2. The method according to claim 1, characterized in that The redo log contains the address, new value, and transaction sequence number of each write request; during the process of writing the redo log to persistent memory, if there is not enough log space, the transaction will continue to wait.

3. The method according to claim 1, characterized in that: The flag indicating whether the transaction is committed is stored in a bitmap. The bitmap is created by the recycling thread and is only visible to the recycling thread. Each cache block on the persistent memory corresponds to a bit on the bitmap. The bitmap is stored in DRAM.

4. The method according to claim 1, characterized in that: After the recycling thread determines the cache block to be flushed, it sets the value of the corresponding position on the corresponding bitmap; And after flashing, reset the bitmap.

5. A computing device having a processor, a volatile memory and a persistent memory, wherein the processor is operative to perform the method according to any one of claims 1 to 4.

6. A non-volatile computer-readable medium having computer instructions stored thereon, wherein when the instructions are executed by a computer, the method according to any one of claims 1 to 4 is performed.