A method and device for clearing space of a high-speed cache memory

By traversing nodes in cache memory to determine and change the life cycle of invalid tags, and writing the linked list header to the super block, the deadlock problem during memory space cleaning is solved, and a smooth space release is achieved.

CN114443512BActive Publication Date: 2024-12-10CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111619704.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2024-12-10
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

In the prior art, the cache memory cannot update data due to fixed log files when cleaning space, resulting in a deadlock state of the process and cannot complete the cleaning.

Method used

When writing metadata in metadata B+ tree, if the storage space is insufficient, the traversal node determines the invalid mark, changes its life cycle, and writes a new linked list header to the super block to free up space to avoid deadlocks.

Benefits of technology

It effectively avoids deadlock status in the cleaning process and ensures smooth cleaning of cache memory space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443512B_ABST
    Figure CN114443512B_ABST
Patent Text Reader

Abstract

The present application provides a space clearing method and device for a cache memory, which are used to avoid a deadlock state in the space clearing process. The method includes: in the process of writing metadata in a metadata B+ tree, if the metadata storage space is insufficient, traversing the nodes in the metadata B+ tree in turn to determine the mark of the metadata stored in the node; according to the mark of the metadata, determining the mark of the metadata storage space corresponding to the metadata; changing the life cycle of the metadata storage space marked as invalid; storing the life cycle of each metadata storage space in the form of a linked list to obtain a new linked list; writing the linked list header of the new linked list into a super block, and releasing the metadata storage space. Since the present application writes the linked list header of the new linked list into the super block, rather than writing it into a log that is fixed when performing a space clearing operation, a deadlock state in the space clearing process is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer storage technology, and in particular to a method and device for clearing space of a cache memory. Background Art

[0002] "Digital transformation" has recently become a hot word in all walks of life. It redefines business (processes, scenarios, relationships, participants), involving Internet Technology (IT) technologies such as computing, storage, transmission, and interaction. Storage is the IT foundation of digital transformation, and digital transformation has a huge demand for storage.

[0003] In the prior art, a small-capacity solid-state disk (SSD) is often used as a high-speed cache memory of a large-capacity hard disk drive (HDD) to meet the requirements of low-cost storage and high performance of business systems. Specifically, when the cache stores metadata of application data and there is insufficient metadata storage space, the cache space will be cleaned up. However, when cleaning up the space, the log file is often fixed and the data cannot be updated, resulting in the inability to complete the cleaning process and entering a process deadlock state. Summary of the invention

[0004] The present application provides a method and device for clearing space of a cache memory, a cache memory and a storage medium, so as to improve the ability to avoid deadlock in a clearing process.

[0005] In a first aspect, an embodiment of the present application provides a method for clearing space of a cache memory, the method comprising:

[0006] In the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, the nodes in the metadata B+ tree are traversed in sequence to determine the tags of the metadata stored in the nodes; the metadata is an index of the data stored in the metadata storage space; the tags include an invalid tag and a valid tag;

[0007] Determining, according to the tag of the metadata, a tag of the metadata storage space corresponding to the metadata;

[0008] Changing the life cycle of the metadata storage space marked as invalid;

[0009] The life cycle of each metadata storage space is stored in the form of a linked list to obtain a new linked list;

[0010] The linked list header of the new linked list is written into the super block, and the metadata storage space marked as invalid is released.

[0011] Since the embodiment of the present application writes the list header of the new list into the super block instead of into the log that is fixedly pinned when performing the space cleaning operation, a deadlock state is avoided during the execution of the cleaning process.

[0012] In an optional implementation manner, the method further comprises:

[0013] In the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, the root nodes in the metadata B+ tree are traversed in sequence to determine the invalid ratio of the root nodes; the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node;

[0014] If the invalidity ratio is greater than a set threshold, a new root node is created in the metadata B+ tree, and the valid metadata in the root node is copied to the new root node;

[0015] The location information of the storage space corresponding to the new root node is written into the super block.

[0016] Since the embodiment of the present application writes the location information of the storage space corresponding to the new root node into the super block instead of the log, the occurrence of a deadlock situation is avoided.

[0017] An optional implementation manner is to determine the invalid metadata and the valid metadata in the root node in the following manner:

[0018] Determining the life cycle of the metadata stored in the root node and the life cycle of the metadata storage space corresponding to the metadata;

[0019] If the life cycle of the metadata is different from the life cycle of the metadata storage space, determining that the metadata is the invalid metadata;

[0020] If the life cycle of the metadata is the same as the life cycle of the metadata storage space, the metadata is determined to be the valid metadata.

[0021] In an optional implementation manner, the super block includes a first storage area and a second storage area; and writing the linked list header of the linked list into the super block includes:

[0022] After writing the link header of the new link list into the first storage area and overwriting the historical link header stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the link header of the new link list; the second storage area is a storage area for storing the link header of the old link list.

[0023] Since the embodiment of the present application performs ping-pong conversion between the first storage area and the second storage area after writing the new linked list header into the first storage area, thereby realizing the storage of new and old data at the same time, when a power failure occurs during the storage of the new linked list header, data can be restored based on the old linked list header stored in the second storage area to prevent data loss.

[0024] In an optional implementation manner, the super block includes a first storage area and a second storage area; and writing the address of the storage space corresponding to the new root node into the super block includes:

[0025] After writing the location information of the storage space corresponding to the new root node into the first storage area and overwriting the historical location information stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the location information of the new root node; the second storage area is a storage area for storing the location information of the old root node.

[0026] Since the embodiment of the present application performs ping-pong conversion between the first storage area and the second storage area after writing the location information of the storage space corresponding to the new root node into the first storage area, the storage of new and old data can be achieved at the same time. When a power outage occurs while the new location information is being stored, data can be restored based on the old location information stored in the second storage area to prevent data loss.

[0027] In an optional implementation manner, after releasing the metadata storage space marked as invalid, the method further includes:

[0028] According to the offset position information of the metadata, the position for inserting the metadata is searched in the metadata B+ tree; and the metadata is inserted into the node corresponding to the position; the offset position information is used to represent the position where the metadata starts to be stored in the hard disk.

[0029] In a second aspect, an embodiment of the present application provides a space clearing device for a cache memory, comprising:

[0030] A traversal unit, used for, during the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, traversing the nodes in the metadata B+ tree in sequence to determine the mark of the metadata stored in the node; the metadata is an index of the data stored in the metadata storage space; the mark includes an invalid mark and a valid mark;

[0031] a determining unit, configured to determine a tag of a metadata storage space corresponding to the metadata according to the tag of the metadata;

[0032] A changing unit, used for changing the life cycle of the metadata storage space marked as the invalid mark;

[0033] A storage unit, used to store the life cycle of each metadata storage space in a linked list form to obtain a new linked list;

[0034] A release unit is used to write the link list header of the new link list into the super block and release the metadata storage space marked as invalid.

[0035] In an optional implementation manner, the traversal unit is further used for:

[0036] In the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, the root nodes in the metadata B+ tree are traversed in sequence to determine the invalid ratio of the root nodes; the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node;

[0037] If the invalidity ratio is greater than a set threshold, a new root node is created in the metadata B+ tree, and the valid metadata in the root node is copied to the new root node;

[0038] The location information of the storage space corresponding to the new root node is written into the super block.

[0039] An optional implementation manner is to determine the invalid metadata and the valid metadata in the root node in the following manner:

[0040] Determining the life cycle of the metadata stored in the root node and the life cycle of the metadata storage space corresponding to the metadata;

[0041] If the life cycle of the metadata is different from the life cycle of the metadata storage space, determining that the metadata is the invalid metadata;

[0042] If the life cycle of the metadata is the same as the life cycle of the metadata storage space, the metadata is determined to be the valid metadata.

[0043] In an optional implementation manner, the super block includes a first storage area and a second storage area; and the release unit is specifically used for:

[0044] After writing the link header of the new link list into the first storage area and overwriting the historical link header stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the link header of the new link list; the second storage area is a storage area for storing the link header of the old link list.

[0045] In an optional implementation manner, the super block includes a first storage area and a second storage area; and the traversal unit is specifically used for:

[0046] After writing the location information of the storage space corresponding to the new root node into the first storage area and overwriting the historical location information stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the location information of the new root node; the second storage area is a storage area for storing the location information of the old root node.

[0047] An optional implementation manner is that after releasing the metadata storage space marked as invalid, the storage unit is further used to:

[0048] According to the offset position information of the metadata, the position for inserting the metadata is searched in the metadata B+ tree; and the metadata is inserted into the node corresponding to the position; the offset position information is used to represent the position where the metadata starts to be stored in the hard disk.

[0049] In a third aspect, an embodiment of the present application provides a cache memory, including a storage unit and a controller, wherein the storage unit is used to store data; and the controller is used to execute the cache memory space clearing method as described in the first aspect on the cache memory.

[0050] In a fourth aspect, an embodiment of the present application further provides a computer storage medium, wherein the computer storage medium stores computer program instructions, and when the instructions are executed on a computer, the computer executes the cache memory space clearing method as described in the first aspect.

[0051] The technical effects brought about by any one of the implementation methods in the second to fourth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0053] Figure 1 A schematic diagram of an application scenario of a method for clearing space of a cache memory provided by an embodiment of the present application;

[0054] Figure 2A schematic diagram of a flow chart of a method for clearing space of a cache memory provided in an embodiment of the present application;

[0055] Figure 3 A schematic diagram of a process of writing metadata into a metadata B+ tree provided in an embodiment of the present application;

[0056] Figure 4 A schematic diagram of the structure of a super block provided in an embodiment of the present application;

[0057] Figure 5 A schematic diagram of a process of performing GC operation on a cache provided in an embodiment of the present application;

[0058] Figure 6 A schematic diagram of a process of performing a cache elimination operation provided in an embodiment of the present application;

[0059] Figure 7 A schematic diagram of a cache data layout provided in an embodiment of the present application;

[0060] Figure 8 A complete flow chart of a method for clearing space of a cache memory provided by an embodiment of the present application;

[0061] Fig. 9 A schematic diagram of the structure of a space clearing device for a cache memory provided by an embodiment of the present application;

[0062] Fig.10 A structural block diagram of a cache memory provided in an embodiment of the present application. DETAILED DESCRIPTION

[0063] In order to make the purpose, technical solutions and advantages of this application clearer, this application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0064] The following are explanations of some of the terms that appear in this article:

[0065] (1) B+ tree: It is a tree data structure, usually used in databases and operating system file systems. The characteristic of B+ tree is that it can keep data stable and orderly, and its insertion and modification have a relatively stable logarithmic time complexity.

[0066] The nodes in a B+ tree include root nodes, tree nodes, and leaf nodes. Tree nodes are child nodes of root nodes, and leaf nodes are child nodes of tree nodes. For an m-order B+ tree, each node has at most m child nodes. Except for the root node, each node has at least m / 2 child nodes, and the root node has at least two child nodes. A node with k child nodes must have k keywords.

[0067] (2) Cache memory: Cache memory is located between the central processing unit (CPU) and the main memory (Dynamic Random Access Memory, DRAM). It is a small-scale but high-speed memory, usually composed of static random access memory (SRAM). It is a small-capacity but high-speed memory located between the CPU and the main memory. The speed of the CPU is much higher than that of the main memory. When the CPU directly accesses data from the main memory, it has to wait for a certain period of time. The cache can save part of the data that the CPU has just used or recycled. If the CPU needs to use this part of the data again, it can directly call it from the cache. This avoids repeated access to data, reduces the CPU's waiting time, and thus improves the efficiency of the system.

[0068] (3) Cache dirty data: refers to data that is only stored in the cache disk and not stored in the hard disk.

[0069] (4) Garbage collection (GC) operation is an operation to reclaim used space when the available storage space (blank storage space or free storage space) in the storage space is small. The specific operation includes: reading out the valid data in the selected metadata storage space to be reclaimed and migrating it to the metadata storage space in the available storage space, and then erasing all the data in the metadata storage space to be reclaimed, thereby reclaiming the metadata storage space through the GC operation.

[0070] The word “exemplary” is used hereinafter to mean “serving as an example, example, or illustration.” Any embodiment described as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0071] The terms "first" and "second" in this document are used for descriptive purposes only and should not be understood as explicitly or implicitly indicating relative importance or implicitly indicating the number of technical features indicated. Therefore, features defined as "first" and "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.

[0072] In the prior art, when the cache stores metadata of application data and the metadata storage space is insufficient, the cache space will be cleaned up. However, when cleaning up the space, the log files are often fixed and the data cannot be updated, resulting in the inability to complete the cleaning process and entering a process deadlock state.

[0073] Based on the above problems, an embodiment of the present application provides a space clearing method, device, cache memory and storage medium of a cache memory, the method comprising: in the process of writing metadata in a metadata B+ tree, if the metadata storage space is insufficient, traversing the nodes in the metadata B+ tree in sequence, determining the mark of the metadata stored in the node, and determining the mark of the metadata storage space corresponding to the metadata based on the mark of the metadata; then, changing the life cycle of the metadata storage space marked as invalid; storing the life cycle of each metadata storage space in the form of a linked list to obtain a new linked list, and writing the linked list header of the new linked list into a super block, and releasing the metadata storage space marked as invalid.

[0074] like Figure 1 As shown, the embodiment of the present application provides an application scenario of a method for clearing space of a cache memory, which includes a processor 10 , a cache memory cache 20 , and a hard disk 30 .

[0075] The hard disk can be an HDD; the cache can be a high-speed medium SSD. In addition, the cache supports three modes: writeback, writethrough, and writearound. In the writeback mode, the data in the cache disk is organized in a sequence that is friendly to the HDD as much as possible, and the cache dirty data in the writeback mode is written to the HDD disk according to an elevator algorithm. The data mapping method between the cache and the HDD is a fully associative mapping. The negotiation storage space in the cache except the metadata storage space may be mapped to any space of the HDD.

[0076] In a specific implementation, when the processor 10 writes data to the hard disk 30, the processor 10 first writes the data to the cache 20, and then writes the data to the hard disk 30 through the cache 20. After the cache 20 successfully writes the data sent by the processor 10 in the storage space, the metadata is written in the metadata B+ tree. If it is found that the metadata storage space is insufficient during the process of writing metadata in the metadata B+ tree, the nodes in the B+ tree are traversed in turn to determine the metadata storage space marked as invalid, and the metadata storage space is released, so as to find the corresponding position in the metadata B+ tree and insert the metadata in the B+ tree.

[0077] like Figure 2 As shown, the embodiment of the present application provides a method for clearing space of a cache memory, comprising the following steps:

[0078] Step S201, during the process of writing metadata into the metadata B+ tree, if the metadata storage space is insufficient, the nodes in the metadata B+ tree are traversed in sequence to determine the tags of the metadata stored in the nodes.

[0079] It should be noted that metadata is an index of data stored in the metadata storage space; and a mark includes an invalid mark and a valid mark.

[0080] When writing metadata in the metadata B+ tree, the embodiment of the present application searches for the metadata writing location on the metadata B+ tree, and when it is determined that the node of the metadata B+ tree needs to be split, determines whether the metadata storage space is sufficient.

[0081] In some embodiments, if the embodiment of the present application determines that the metadata storage space is insufficient, the nodes of the metadata B+ tree are traversed in sequence to determine the tags of the metadata stored in the nodes.

[0082] Step S202: determining the tag of the metadata storage space corresponding to the metadata according to the tag of the metadata.

[0083] In the embodiment of the present application, when determining that the mark of metadata is a valid mark, the mark of the metadata storage space corresponding to the metadata is a valid mark.

[0084] For example, dirty is a valid mark. When the metadata is marked as dirty, it is determined that the metadata is only stored in the cache and is not saved to the disk. Further, the metadata storage space corresponding to the metadata is marked as a valid mark, and the metadata storage space cannot be released.

[0085] Step S203: Change the life cycle of the metadata storage space marked as invalid.

[0086] The embodiment of the present application can change the life cycle of the metadata storage space marked as invalid, so that the metadata storage space and the life cycle of the corresponding metadata in the metadata B+ tree are not matched, and the metadata becomes invalid metadata, thereby achieving the effect of quickly eliminating the metadata storage space.

[0087] Step S204, storing the life cycle of each metadata storage space in the form of a linked list to obtain a new linked list.

[0088] Step S205, write the linked list header of the new linked list into the super block, and release the metadata storage space marked as invalid.

[0089] Since the embodiment of the present application writes the list header of the new list into the super block instead of into the log that is pinned when performing the space cleaning operation, a deadlock state is avoided during the execution of the cleaning process.

[0090] like Figure 3 As shown, in the embodiment of the present application, metadata can be written into the metadata B+ tree in the following manner, including the following steps:

[0091] Step S301, writing data sent by the processor into the storage space.

[0092] In some embodiments, after receiving data sent by the processor, the embodiment of the present application writes the data into the storage space.

[0093] Step S302, writing metadata into the log file, and fixing the log files after the log file.

[0094] In some embodiments, after writing data, the embodiments of the present application need to update metadata information corresponding to the data in the log file.

[0095] In a specific implementation, the embodiment of the present application can write metadata in the log file through the following method.

[0096] When triggering a log writing operation, the embodiment of the present application needs to determine whether the log storage space is sufficient; when it is determined that the log storage space is sufficient, the metadata is directly written into the log storage space.

[0097] In other embodiments, after determining that the log space is insufficient, the embodiments of the present application force the metadata in the current log storage space to be stored in the hard disk.

[0098] In a specific implementation, the embodiment of the present application removes the PIN of the log storage space with the longest existence time in the metadata B+ tree, and stores the metadata stored in the log storage space to the hard disk to complete the disk operation. Then, the log storage space is recycled and the metadata is written to the log storage space.

[0099] In some embodiments, after writing metadata to the log storage space, the embodiment of the present application determines whether a forced log flush is required. If yes, the metadata written in the log storage space is directly written to the hard disk; if no, the metadata stored in the current log storage space is subsequently flushed to the hard disk at a scheduled time.

[0100] Step S303: determine the offset position information of the metadata, and search for the position of the metadata in the metadata B+ tree.

[0101] It should be noted that the offset position information is used to indicate the position where the metadata starts to be stored in the hard disk.

[0102] In a specific implementation, the embodiment of the present application determines the location where the metadata starts to be stored in the hard disk based on the offset position information of the metadata; determines the location interval corresponding to the root node in the metadata B+ tree where the location is located, and selects the node corresponding to the location from the B+ tree.

[0103] For example, the offset position information of the metadata is 100, and it is determined that the offset position information is located in the position interval 1 to 1000 corresponding to the first root node of the B+ tree node; then, it is determined that the node containing the offset position information in the position interval corresponding to the first child node of the root node is tree node 1 to 500, and the position where the metadata is inserted in the metadata B+ tree is determined to be the first child node of the first root node.

[0104] Step S304, determine whether it is necessary to split the metadata B+ tree node; if so, execute step S305; if not, execute step S306.

[0105] In some embodiments, after the embodiment of the present application finds the location where the metadata is inserted in the metadata B+ tree, it determines whether the amount of metadata data can be completely written to the determined node; if so, it determines that the metadata B+ tree does not need to be split; if not, it determines the node of the metadata B+ tree that needs to be split.

[0106] Step S305, determine whether the metadata storage space is sufficient; if so, execute step S306; if not, execute step S307.

[0107] Step S306: insert metadata into the node corresponding to the position.

[0108] Step S307, set the thread D state until it is awakened by the elimination process, and execute step S303.

[0109] In some embodiments, a thread in the cache in the D state has the following two behaviors:

[0110] 1. The data cannot be indexed, that is, the metadata cannot be obtained.

[0111] 2. The log storage space is pinned and can only be read but not written.

[0112] In some embodiments, after setting the thread D state, the embodiment of the present application waits for the elimination process to wake up; and before executing the elimination process, the embodiment of the present application needs to perform a GC operation to reclaim the storage space of the cache.

[0113] In a specific implementation, the embodiment of the present application performs GC operations mainly to clean up invalid metadata on the metadata B+ tree, and to determine metadata storage space marked as invalid in the cache.

[0114] In some embodiments, the embodiments of the present application can perform GC operations in the following manner.

[0115] The embodiment of the present application sequentially traverses the nodes in the metadata B+ tree, determines the metadata tags stored in the nodes, and determines the tags of the metadata storage space corresponding to the metadata based on the tags of the metadata.

[0116] In other embodiments, the embodiments of the present application determine the invalidity ratio of the root nodes when traversing the root nodes in the metadata B+ tree in sequence, and determine whether the invalidity ratio is greater than a set threshold.

[0117] It should be noted that the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node.

[0118] In some embodiments, the embodiments of the present application may determine valid metadata and invalid metadata in the root node in the following manner:

[0119] Determine the life cycle of the metadata stored in the root node and the life cycle of the metadata storage space corresponding to the metadata; and determine invalid metadata and valid metadata in the root node according to the life cycle.

[0120] In some embodiments, if the life cycle of the metadata is different from the life cycle of the metadata storage space, the metadata is determined to be invalid metadata.

[0121] In other embodiments, if the life cycle of the metadata is the same as the life cycle of the metadata storage space, the metadata is determined to be valid metadata.

[0122] When it is determined that the invalid ratio is greater than a set threshold, the embodiment of the present application creates a new root node in the metadata B+ tree, and copies the valid metadata in the root node to the new root node.

[0123] In a specific implementation, after creating a new root node, the embodiment of the present application writes the location information of the storage space corresponding to the new root node into the super block; and copies the valid metadata in the root node to the new root node through a real-write copy.

[0124] In some embodiments, the embodiments of the present application write the location information of the storage space corresponding to the new root node into the first storage area, and after overwriting the historical location information of the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area.

[0125] It should be noted that the first storage area is a storage area for storing the location information of the new root node, and the second storage area is a storage area for storing the location information of the old root node.

[0126] For example, Figure 4As shown, an embodiment of the present application provides a structural schematic diagram of a super block; wherein, it includes a first storage area and a second storage area; a ping-pong conversion is performed between the first storage area and the second storage area; wherein, the first storage area is used to store the location information of the new root node and the new linked list header; and the second storage area is used to store the location information of the old root node and the old linked list header.

[0127] In some embodiments, after writing the location information of the storage space corresponding to the new root node in the super block, the embodiments of the present application traverse the tree nodes and leaf nodes of the metadata B+ tree to determine whether the tree nodes and leaf nodes need to be updated. If the invalid metadata stored in the tree nodes or leaf nodes is greater than the set threshold, the valid metadata in the tree nodes or leaf nodes is copied to other nodes under the same root node or the same tree node.

[0128] If the embodiment of the present application copies valid metadata to other nodes and the remaining metadata storage space of the other nodes cannot store all the valid metadata, the node is split and the remaining valid metadata is copied to the node obtained by the split.

[0129] After determining that all nodes of the metadata B+ tree have been traversed, the embodiment of the present application sets a mark of the metadata storage space according to the marks of the determined nodes.

[0130] like Figure 5 As shown, the embodiment of the present application provides a schematic diagram of a process of performing a GC operation on a cache, including the following steps:

[0131] Step S501 , traverse the root nodes of the metadata B+ tree in sequence, determine the tags of the metadata stored in the root nodes, and the invalidity ratio of the root nodes.

[0132] Step S502: Determine the tag of the metadata storage space corresponding to the metadata according to the tag of the metadata.

[0133] Step S503, determine whether the invalidity ratio of the root node is greater than a set threshold; if so, execute step S504; if not, execute step S507.

[0134] Step S504: create a new root node in the metadata B+ tree, and copy the valid metadata in the root node to the new root node.

[0135] In a specific implementation, the embodiment of the present application deletes the metadata stored in the root node after copying the valid data in the root node to the new root node.

[0136] Step S505, writing the location information of the storage space corresponding to the new root node into the first storage area of ​​the super block, and overwriting the historical location information stored in the first storage area.

[0137] Step S506, switching the first storage area to the second storage area, and switching the second storage area to the first storage area.

[0138] Step S507, determine whether the root node traversal is complete; if so, execute step S508; if not, execute step S501.

[0139] Step S508, traverse the remaining nodes of the metadata B+ tree in sequence to determine the invalid ratio of the remaining nodes.

[0140] It should be noted that the remaining nodes are all nodes except the root node in the metadata B+ tree.

[0141] Step S509, determine whether the invalid ratio is greater than a set threshold; if so, execute step S510; if not, execute step S511.

[0142] Step S510, the remaining nodes are deleted, and the valid metadata of the remaining nodes are copied to the remaining nodes of the same parent node.

[0143] Step S511, determine whether the remaining nodes have been traversed; if so, execute step S512; if not, execute step S508.

[0144] Step S512, end.

[0145] In some embodiments, after determining the mark of the metadata storage space, the embodiments of the present application change the life cycle of the metadata storage space marked as invalid so that the metadata does not match its corresponding metadata storage space, thereby achieving the effect of eliminating the metadata storage space.

[0146] In a specific implementation, after changing the life cycle, the embodiment of the present application stores the life cycle of each metadata storage space in the form of a linked list to obtain a new linked list; writes the linked list header of the obtained new linked list into the super block, and releases the metadata storage space marked as invalid.

[0147] In some embodiments, the embodiments of the present application write the list header of the new linked list into the first storage area in the super block, and after overwriting the historical list header of the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area.

[0148] It should be noted that the first storage area is a storage area for storing the link list header of the new link list; and the second storage area is a storage area for storing the link list header of the old link list.

[0149] The GC operation and the elimination operation in the embodiment of the present application are two operations performed in parallel, and only one operation can be performed at the same time; for example, when the GC operation is performed, the elimination operation cannot be performed; when the elimination operation is performed, the GC operation cannot be performed.

[0150] like Figure 6 As shown, the embodiment of the present application provides a schematic diagram of a process of performing a cache elimination operation, including the following steps:

[0151] Step S601, changing the life cycle of the metadata storage space marked as invalid.

[0152] Step S602: Store the lifecycle of each metadata storage space in a linked list format to obtain a new linked list.

[0153] Step S603, write the link list header of the new link list into the first storage area of ​​the super block, and overwrite the historical link list header stored in the first storage area.

[0154] Step S604: Switch the first storage area to the second storage area, and switch the second storage area to the first storage area.

[0155] Step S605: releasing the metadata storage space marked as invalid.

[0156] In some embodiments, Figure 7 As shown, an embodiment of the present application also provides a schematic diagram of the data layout of a cache; wherein the storage space of the cache includes a super block, a log storage space, a data storage space, a metadata storage space, a priority, and a life cycle storage space. The super block can store the location information of the root node of the metadata B+ tree, as well as the linked list header of the linked list of the life cycle of the metadata storage space. The minimum number of log storage spaces is 2, and the maximum number is 256. The positions of the storage spaces occupied by the data storage space, the metadata storage space, the priority, and the life cycle storage space in the cache are random.

[0157] In some embodiments, after adopting the cache data layout provided by the embodiments of the present application, the user can also restore the data layout to the original layout.

[0158] Through a specific embodiment, the embodiment of the present application is explained in which the data layout of the cache is changed to the data layout provided by the embodiment of the present application.

[0159] Step 1: Get the Bcache code.

[0160] Users can send emails to com.cn to obtain the bcache source code and the accompanying compilation guide documents.

[0161] Step 2: Compile and deploy bcache.

[0162] Confirm that the kernel compilation switch has enabled Bcache support. You can check it by running the following command cat / boot / config-`uname-r`|grep-i bcache:

[0163] [root@localhost~]#cat / boot / config-`unam–r`|grep–I bcache

[0164] CONFIG_BCACHE=m

[0165] #CONFIG_BCACHE_DEBUG is not set

[0166] #CONFIG_BCACHE_CLOSURES_DEBUG is not set

[0167] CONFIG_FS_MBCACHE=y

[0168] The embodiment of the present application compiles the bcache source code according to the compilation guidance document and executes the following command:

[0169] modprobe bcache> / dev / null 1>&1

[0170] Check the loading of bcache.ko. If successful, the following information will be output:

[0171] [root@localhost~]#lsmod|grep bcache

[0172] bcache 209305 0

[0173] Step 3: Format the HDD as a backing device (data device)

[0174] Format the HDD using the following code:

[0175] bcache make-B / dev / nvme0n1--wipe-bcache

[0176] If the format is successful, you can see the following status through bcache show:

[0177] [root@localhost~]#bcache show

[0178]

[0179] View through lsblk:

[0180] [root@localhost~]#lsblk / dev / sdb

[0181]

[0182] Step 4: Format the SSD as a cache device

[0183] Format the SSD using the following code:

[0184] bcache make-C / dev / nvme0n1--wipe-bcache

[0185] If the format is successful, you can see the following status through bcache show:

[0186] [root@localhost~]#bcache show

[0187]

[0188] It should be noted that / dev / nvme0n1 is the cache device and / dev / sdb is the backend device.

[0189] Step 5: Connect the backend device (data device) to the cache device

[0190] Connect by executing the following code:

[0191] bcache attach / dev / nvme0n1 / dev / sdb

[0192] If the connection is successful, you can see the following status through bcache show and bcache tree:

[0193] [root@localhost~]#bcache show

[0194]

[0195] [root@localhost~]#bcache tree

[0196] `

[0197] / dev / nvme0n1

[0198] / dev / sdb bcache0

[0199] like Figure 8As shown, the embodiment of the present application provides a complete flow diagram of a method for clearing space of a cache memory, including the following steps:

[0200] Step S801, searching for a location to insert metadata in the metadata B+ tree according to the offset location information of the metadata.

[0201] It should be noted that the offset position information is used to indicate the position where the metadata starts to be stored in the hard disk.

[0202] Step S802, determine whether the metadata storage space is sufficient; if not, execute step S803; if so, execute step S815.

[0203] Step S803, traverse the root nodes in the metadata B+ tree in sequence, determine the tags of the metadata stored in the root nodes, and the invalid ratio of the root nodes.

[0204] It should be noted that metadata is the index of data stored in the metadata storage space; the mark includes an invalid mark and a valid mark; and the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node.

[0205] The embodiment of the present application can determine the invalid metadata and valid metadata in the root node in the following manner:

[0206] Determine the life cycle of the metadata stored in the root node and the life cycle of the metadata storage space corresponding to the metadata;

[0207] If the life cycle of the metadata is different from the life cycle of the metadata storage space, the metadata is determined to be invalid metadata;

[0208] If the life cycle of the metadata is the same as the life cycle of the metadata storage space, the metadata is determined to be valid metadata.

[0209] Step S804, determine whether the invalid ratio is greater than a set threshold; if so, execute step S805; if not, execute step S808.

[0210] Step S805: create a new root node in the metadata B+ tree, and copy the valid metadata in the root node to the new root node.

[0211] Step S806: write the location information of the storage space corresponding to the new root node into the first storage area, and overwrite the historical location information stored in the first storage area.

[0212] It should be noted that the first storage area is a storage area for storing the location information of the new root node.

[0213] Step S807: Switch the first storage area to the second storage area, and switch the second storage area to the first storage area.

[0214] Step S808, determine whether the root node traversal is complete; if so, execute step S809; if not, execute step S803.

[0215] Step S809: determining the tag of the metadata storage space corresponding to the metadata according to the tag of the metadata.

[0216] Step S810: Change the life cycle of the metadata storage space marked as invalid.

[0217] Step S811, storing the life cycle of each metadata storage space in the form of a linked list to obtain a new linked list.

[0218] Step S812, write the link list header of the new link list into the first storage area in the super block, and overwrite the historical link list header stored in the first storage area.

[0219] It should be noted that the first storage area is a storage area for storing the link list header of the new link list.

[0220] Step S813, switching the first storage area to the second storage area, and switching the second storage area to the first storage area.

[0221] It should be noted that the second storage area is a storage area for storing the link list header of the old link list.

[0222] Step S814: releasing the metadata storage space marked as invalid.

[0223] Step S815: insert metadata into the node corresponding to the position.

[0224] Based on the same inventive concept, a space clearing device for a cache memory is also provided in an embodiment of the present application. Since the principle of solving the problem by the device is similar to the space clearing method for the cache memory mentioned above, the device can be implemented with reference to the above method embodiment, and the repeated parts will not be repeated.

[0225] like Fig. 9 As shown, a structural block diagram of a space cleaning device for a cache memory provided by an embodiment of the present application, the device includes:

[0226] The traversal unit 901 is used for, during the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, traversing the nodes in the metadata B+ tree in sequence to determine the mark of the metadata stored in the node; the metadata is the index of the data stored in the metadata storage space; the mark includes the invalid mark and the valid mark;

[0227] A determining unit 902, configured to determine a tag of a metadata storage space corresponding to the metadata according to the tag of the metadata;

[0228] A changing unit 903, used for changing the life cycle of the metadata storage space marked as invalid;

[0229] The storage unit 904 is used to store the life cycle of each metadata storage space in the form of a linked list to obtain a new linked list;

[0230] The release unit 905 is used to write the link list header of the new link list into the super block and release the metadata storage space marked as invalid.

[0231] In an optional implementation manner, the traversal unit 901 is further configured to:

[0232] In the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, the root nodes in the metadata B+ tree are traversed in sequence to determine the invalid ratio of the root nodes; the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node;

[0233] If the invalidity ratio is greater than a set threshold, a new root node is created in the metadata B+ tree, and the valid metadata in the root node is copied to the new root node;

[0234] The location information of the storage space corresponding to the new root node is written into the super block.

[0235] An optional implementation manner is to determine the invalid metadata and the valid metadata in the root node in the following manner:

[0236] Determining the life cycle of the metadata stored in the root node and the life cycle of the metadata storage space corresponding to the metadata;

[0237] If the life cycle of the metadata is different from the life cycle of the metadata storage space, determining that the metadata is the invalid metadata;

[0238] If the life cycle of the metadata is the same as the life cycle of the metadata storage space, the metadata is determined to be the valid metadata.

[0239] In an optional implementation manner, the super block includes a first storage area and a second storage area; and the release unit 905 is specifically used for:

[0240] After writing the link header of the new link list into the first storage area and overwriting the historical link header stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the link header of the new link list; the second storage area is a storage area for storing the link header of the old link list.

[0241] In an optional implementation manner, the super block includes a first storage area and a second storage area; and the traversal unit 901 is specifically used for:

[0242] After writing the location information of the storage space corresponding to the new root node into the first storage area and overwriting the historical location information stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the location information of the new root node; the second storage area is a storage area for storing the location information of the old root node.

[0243] In an optional implementation manner, after releasing the metadata storage space marked as invalid, the storage unit 904 is further used to:

[0244] According to the offset position information of the metadata, the position for inserting the metadata is searched in the metadata B+ tree; and the metadata is inserted into the node corresponding to the position; the offset position information is used to represent the position where the metadata starts to be stored in the hard disk.

[0245] Based on the above embodiments and the same concept, the present application embodiment also provides a high-speed cache memory, such as Fig.10 As shown, the cache memory includes a controller 100 and a storage unit 200;

[0246] The storage unit 200 is used to store data;

[0247] The controller 100 is used to execute the cache memory space clearing method provided by the above embodiment on the cache memory.

[0248] The embodiment of the present application also provides a computing device readable storage medium for the space clearing method of the cache memory, that is, the content is not lost after power failure. The storage medium stores a software program, including program code, and when the program code is run on the computing device, the software program can implement any of the above solutions of the space clearing method of the cache memory in the embodiment of the present application when it is read and executed by one or more processors.

[0249] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

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

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

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

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

Claims

1. A method for clearing space of a cache memory, characterized in that: include: During the process of writing metadata into the metadata B+ tree, if the metadata storage space is insufficient, traverse the nodes in the metadata B+ tree in sequence to determine the tags of the metadata stored in the nodes; The metadata is an index of the data stored in the metadata storage space; The mark includes an invalid mark and a valid mark; Determining, according to the tag of the metadata, a tag of the metadata storage space corresponding to the metadata; Changing the life cycle of the metadata storage space marked as the invalid mark; The life cycle of each metadata storage space is stored in the form of a linked list to obtain a new linked list; The linked list header of the new linked list is written into the super block, and the metadata storage space marked as invalid is released.

2. The method according to claim 1, characterized in that: The method further comprises: In the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, the root nodes in the metadata B+ tree are traversed in sequence to determine the invalid ratio of the root nodes; the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node; If the invalidity ratio is greater than a set threshold, a new root node is created in the metadata B+ tree, and the valid metadata in the root node is copied to the new root node; The location information of the storage space corresponding to the new root node is written into the super block.

3. The method according to claim 2, characterized in that The invalid metadata and the valid metadata in the root node are determined by: Determining the life cycle of the metadata stored in the root node and the life cycle of the metadata storage space corresponding to the metadata; If the life cycle of the metadata is different from the life cycle of the metadata storage space, determining that the metadata is the invalid metadata; If the life cycle of the metadata is the same as the life cycle of the metadata storage space, the metadata is determined to be the valid metadata.

4. The method according to claim 1, characterized in that: The super block includes a first storage area and a second storage area; and writing the linked list header of the new linked list into the super block includes: After writing the link header of the new link list into the first storage area and overwriting the historical link header stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the link header of the new link list; the second storage area is a storage area for storing the link header of the old link list.

5. The method according to claim 2, characterized in that: The super block includes a first storage area and a second storage area; and writing the location information of the storage space corresponding to the new root node into the super block includes: After writing the location information of the storage space corresponding to the new root node into the first storage area and overwriting the historical location information stored in the first storage area, the first storage area is switched to the second storage area, and the second storage area is switched to the first storage area; the first storage area is a storage area for storing the location information of the new root node; the second storage area is a storage area for storing the location information of the old root node.

6. The method according to any one of claims 1 to 5, characterized in that: After releasing the metadata storage space marked as invalid, the method further includes: According to the offset position information of the metadata, the position for inserting the metadata is searched in the metadata B+ tree; and the metadata is inserted into the node corresponding to the position; the offset position information is used to represent the position where the metadata starts to be stored in the hard disk.

7. A space clearing device for a cache memory, characterized in that: The device comprises: A traversal unit, used for, during the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, traversing the nodes in the metadata B+ tree in sequence to determine the mark of the metadata stored in the node; the metadata is an index of the data stored in the metadata storage space; the mark includes an invalid mark and a valid mark; a determining unit, configured to determine a tag of a metadata storage space corresponding to the metadata according to the tag of the metadata; A changing unit, used for changing the life cycle of the metadata storage space marked as the invalid mark; A storage unit, used to store the life cycle of each metadata storage space in a linked list form to obtain a new linked list; A release unit is used to write the link list header of the new link list into the super block and release the metadata storage space marked as invalid.

8. The device according to claim 7, characterized in that The traversal unit is also used for: In the process of writing metadata in the metadata B+ tree, if the metadata storage space is insufficient, the root nodes in the metadata B+ tree are traversed in sequence to determine the invalid ratio of the root nodes; the invalid ratio is the ratio of invalid metadata in the root node to the storage space of the root node; If the invalidity ratio is greater than a set threshold, a new root node is created in the metadata B+ tree, and the valid metadata in the root node is copied to the new root node; The address of the storage space corresponding to the new root node is written into the super block.

9. A cache memory, characterized in that: including a storage unit and a controller; The storage unit is used to store data; The controller is configured to execute the method according to any one of claims 1 to 6 on the cache memory.

10. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.