WO2016041401A1 - Method and device for writing data to cache - Google Patents

Method and device for writing data to cache Download PDF

Info

Publication number
WO2016041401A1
WO2016041401A1 PCT/CN2015/083383 CN2015083383W WO2016041401A1 WO 2016041401 A1 WO2016041401 A1 WO 2016041401A1 CN 2015083383 W CN2015083383 W CN 2015083383W WO 2016041401 A1 WO2016041401 A1 WO 2016041401A1
Authority
WO
WIPO (PCT)
Prior art keywords
metadata
group
metadata group
block
data
Prior art date
Application number
PCT/CN2015/083383
Other languages
French (fr)
Chinese (zh)
Inventor
黄福堂
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2016041401A1 publication Critical patent/WO2016041401A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems

Definitions

  • the present invention relates to the field of data storage, and in particular, to a method and apparatus for writing data to a cache.
  • Non-Volatile Dual In-line Memory Module NVDIMM
  • Non-Volatile Random Access Memory NVRAM
  • the capacity of the write cache is usually small, and it is difficult to cope with a large number of random write pressure scenarios.
  • Flash Flash
  • MLC Multi-Level Cell
  • the size of the metadata is generally between 30B and 64B. If each metadata is directly IO according to the size of the metadata, the performance of the Flash cannot be fully utilized. If the metadata is IO according to the size of 4K alignment, there may be write amplification. The problem will have a big impact on the lifetime of the entire Flash.
  • Embodiments of the present invention provide a method and an apparatus for writing data into a cache, which can solve frequently Write metadata to Flash, which affects the life of Flash.
  • a method for writing data to a cache cache includes a plurality of storage block chunks, and the chunk includes a chunk metadata area and a chunk data area.
  • the one chunk metadata area includes at least one metadata block
  • the one chunk data area includes at least one data area corresponding to the at least one metadata block
  • the metadata block includes a plurality of metadata
  • the data includes a plurality of data blocks
  • the metadata blocks are in one-to-one correspondence with the data area
  • the metadata is in one-to-one correspondence with the data blocks
  • the method includes:
  • the write IO request command including metadata of data to be written
  • the second metadata group is a metadata group that is not currently processed, if the second If the metadata group has remaining free blocks, the second metadata group is acquired, and the metadata of the data to be written is written to one of the remaining free blocks of the second metadata group;
  • the metadata of the data to be written is written into a metadata block corresponding to the second metadata group.
  • the number of the free blocks included in the metadata group is based on a size of the metadata block and a size of the metadata corresponding to the data block. Calculated.
  • the free blocks included in the metadata group are consecutively arranged by address.
  • the number of the free blocks included in the metadata group is recorded in a multi-level queue of the memory, where each queue in the multi-level queue The number of free blocks included in the recorded second metadata group is different.
  • the second metadata group is recorded according to the number of the free blocks included in the second metadata group In each queue of the level queue, the queues further include a total number of free blocks included in each second metadata group recorded by the queue;
  • the determining whether the second metadata group has remaining free blocks includes:
  • the method further includes:
  • splitting splitting the write IO request command according to the size of the data block, and obtaining a plurality of first write IO request commands
  • a sixth implementation manner of the first aspect when any one of the plurality of queues records a plurality of second metadata groups, according to the second element The number of free blocks included in the data group is arranged for the plurality of second metadata groups.
  • the method further includes:
  • the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group;
  • the metadata group is a second metadata group, determining a free block included in the second metadata group Whether the number is greater than a second threshold, and if so, deleting the second metadata group from the queue in which the second metadata group is recorded, and adding the free block to the second metadata group,
  • the second metadata group is recorded in other queues of the multi-level queue, and if not, the free block is added to the second metadata group.
  • the recording, by the second metadata group, into another queue of the multi-level queue includes:
  • the second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
  • the method further includes:
  • the method further includes:
  • an embodiment of the present invention provides an apparatus for writing data to a cache cache.
  • the storage area of the flash memory of the apparatus includes a plurality of storage blocks chunk, and the chunk includes a chunk metadata area and a a chunk data area, the one chunk metadata area including at least one metadata block, the one chunk data area including at least one data area corresponding to the at least one metadata block, the metadata block including a plurality of metadata
  • the data area includes a plurality of data blocks, the metadata block is in one-to-one correspondence with the data area, and the metadata is in one-to-one correspondence with the data block, and the apparatus includes: a receiving unit, and a first acquiring unit a determining unit, a first writing unit, a second obtaining unit, and a second writing unit;
  • the receiving unit is configured to receive a write IO request command, where the write IO request command includes metadata of data to be written;
  • the first obtaining unit is configured to acquire a metadata group currently being processed into a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory;
  • the determining unit is configured to determine whether there is any remaining free block in the first metadata group acquired by the first acquiring unit;
  • the first writing unit is configured to: when the determining unit determines that there are remaining free blocks in the first metadata group, write the data to be written to one of the remaining free blocks Metadata, and writing metadata of the data to be written into a metadata block corresponding to the first metadata group;
  • the second obtaining unit is configured to: when the determining unit determines that there are no free blocks in the first metadata group, determine whether the second metadata group has remaining free blocks, where the second metadata group is a metadata group currently not being processed, if the second metadata group has remaining free blocks, acquiring the second metadata group, and to a free block in the remaining free blocks of the second metadata group Writing metadata of the data to be written;
  • the second writing unit is configured to write metadata of the data to be written into a metadata block corresponding to the second metadata group.
  • the number of the free blocks included in the metadata group is calculated according to a size of the metadata block and a size of the metadata corresponding to the data block. owned.
  • the free blocks included in the metadata group are consecutively arranged by address.
  • the number of the free blocks included in the metadata group is recorded in a multi-level queue of the memory, where each queue in the multi-level queue The number of free blocks included in the recorded second metadata group is different.
  • the device further includes: a recording unit, configured to use, according to the number of free blocks included in the second metadata group, Recording the second metadata group into each queue of the multi-level queue, where each queue further includes a total number of free blocks included in each second metadata group recorded by the queue;
  • the second acquiring unit is specifically configured to: determine, according to the total number of free blocks included in each second metadata group recorded in each queue, whether the second metadata group has remaining free blocks.
  • the device further includes: a splitting unit;
  • the determining unit is further configured to determine, according to the size of the data block, whether the write IO request command needs to be split;
  • the splitting unit is configured to: if the determining unit determines that splitting is required, split the write IO request command according to the size of the data block, to obtain a plurality of first write IO request commands ;
  • the determining unit is further configured to determine, by the splitting unit, the plurality of first write IO request commands, respectively, whether the metadata of the data to be written included in each first write IO request command has been
  • the cache is in the memory, if yes, the write operation is directly performed, and if not, the step of acquiring the metadata group currently being processed is the first metadata group.
  • the device further includes: an arranging unit, configured to record a plurality of second elements in any one of the multi-level queues In the case of the data group, the plurality of second metadata groups are arranged according to the number of free blocks included in the second metadata group.
  • the unit is added;
  • the receiving unit is further configured to receive a recovery metadata instruction, where the recovery metadata instruction includes an address of an associated free block of the metadata to be recovered;
  • the first obtaining unit is further configured to acquire, according to an address of the free block received by the receiving unit, a metadata group to which the free block belongs;
  • the joining unit is configured to add the free block to the first metadata group if the metadata group acquired by the first acquiring unit is a first metadata group, and add the first Free block reordering in the metadata group;
  • the determining unit is further configured to: if the metadata group acquired by the first acquiring unit is a second metadata group, determine whether the number of free blocks included in the second metadata group is greater than a second threshold, If yes, deleting the second metadata group from the queue that records the second metadata group, adding the free block to the second metadata group, and recording the second metadata group to a plurality of In other queues of the level queue, if not, the free block is added to the second metadata group.
  • the determining unit is specifically configured to:
  • the second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
  • the device further includes: an updating unit, configured to update a queue that records the second metadata group The total number of free blocks recorded, and the total number of free blocks recorded in the queue to which the second metadata group is added is updated.
  • a method and apparatus for writing data into a cache provided by an embodiment of the present invention. Recording a free block in the memory by the metadata group, when receiving the write IO request command, acquiring the free block from the above metadata group, and writing the metadata of the data to be written included in the IO request command Into the obtained free block, thereby increasing the merge probability of the metadata, thereby solving the problem of frequently writing metadata to the Flash, resulting in write amplification, which affects the life of the Flash.
  • FIG. 1 is a schematic diagram of a data layout of a Flash provided by the present invention.
  • FIG. 2 is a schematic diagram of another data layout of the Flash provided by the present invention.
  • FIG. 3 is a schematic diagram showing relationship between a location of a metadata in an in-memory and an actual persistent location in Flash according to the present invention
  • FIG. 5 is a schematic diagram of a relationship between a multi-level queue and a second metadata group
  • FIG. 6 is a schematic diagram of an apparatus for writing data to a Cache according to Embodiment 2 of the present invention.
  • FIG. 7 is a schematic structural diagram of a computing and storage integrated machine according to an embodiment of the present invention.
  • FIG. 1 is a schematic diagram of a data layout of a Flash provided by the present invention.
  • the storage area of the Flash may include three parts: a super block, a metadata area, and a data area.
  • the super block is used to store the global data in the Cache, mainly for the data needed for recovery after the system is down.
  • the global data may include a size of a metadata block, a size of a data block, and the like.
  • Metadata (data), which maintains the data of the data blocks in the storage system, and describes and organizes the relationship of the data blocks.
  • the size is determined according to the size of the data structure defined in the system.
  • Metadata area refers to the area used to store metadata.
  • the data area is used to store real data in the Cache, and may include multiple data blocks below.
  • the Flash includes a super block and a plurality of chunks, each chunk includes a chunk metadata area and a chunk data area, and each chunk metadata area includes one or more metadata blocks, each of which The chunk data area includes a data area corresponding to the one or more metadata blocks.
  • the data area under each chunk data area has a one-to-one correspondence with the metadata block under the corresponding chunk metadata area.
  • a metadata block maintains a corresponding data area.
  • each metadata area includes a plurality of metadata, and each metadata corresponds to one data block under the data area.
  • 1 chunk metadata area contains 4 metadata blocks, it does not mean that 1 chunk metadata area can only contain 4 metadata blocks, and can also be 1, 2 or other values. .
  • the number of chunks shown in FIG. 2 the number of data areas in the chunk data area, the number of metadata in the metadata area, and the number of data blocks in the data area are not limited to the values shown in FIG. .
  • Each data area corresponds to a different metadata block, and the data blocks corresponding to the metadata in one metadata block constitute a data area. That is to say, one data area contains data corresponding to metadata of a metadata block size, the size of one data area is determined by the number of metadata in one metadata block and one The size of the data block is determined.
  • the size of a page write is 4K. Therefore, in a preferred solution, the size of one metadata block is 4K. Let's assume that the size of a metadata is 32B, and the size of a data block is 16K, then the size of a data area is 2M (16K*(4K/32B)).
  • a chunk metadata area may include one or more metadata blocks, and the size of one chunk metadata area is variable.
  • a preferred solution can take the size of a data block as the size of a chunk metadata area, so that when the Flash load is initialized, the storage area of the Flash is divided according to the size of the data block. For example, if the size of a data block is 4K, the size of a chunk metadata area is also 4K, and the number of metadata blocks is 1 (4K/4K). For another example, if the size of one data block is 16K, the size of one chunk metadata area is also 16K, and the number of metadata blocks is 4 (16K/4K).
  • the size of the data block can be configured by the operating system or the storage device, and the size of the data block can be 4K, 8K, 16K, 32K, or 64K, etc., and the embodiment of the present invention is not limited herein.
  • the size of the data block can also be different from the size of the chunk metadata area.
  • the size of the data block may also be 512B, 1K, 2K, etc.
  • the chunk metadata area includes at least one metadata block, which is obviously larger than one data block.
  • the size of the chunk metadata area may be smaller than the size of the data block, for example, only one metadata block is included in the chunk metadata area.
  • FIG. 3 is a schematic diagram showing the relationship between the location of the metadata in the memory and the actual persistent location in the Flash provided by the present invention.
  • a metadata in memory corresponds to an element of the p_head array, and its data structure flashcache_wbhead has the following meaning:
  • a metadata group in Flash corresponds to a metadata group in memory, corresponding to an element in the metadata_head array.
  • the data structure metadata_head and its meaning can be as follows:
  • Dsw_u8 is_writing; / / mark head is IO operation
  • the metadata information of a data block is stored in the memory by flashCache_wbhead, and the information of the same group metadata (ie, one metadata block) is stored according to the metadata_head, so as to facilitate the writing according to the metadata block.
  • FIG. 4 is a flowchart of a method for writing data to a Cache according to Embodiment 1 of the present invention.
  • the execution body of the method may be a cache device, and the cache device includes a flash memory Falsh.
  • FIG. 4 can also be applied to other manners of the layout of the Flash data including the plurality of metadata areas, which are not limited herein.
  • S410 Receive a write IO request command, where the write IO request command includes metadata of data to be written.
  • the method may further include the following steps:
  • splitting splitting the write IO request command according to the size of the data block, and obtaining a plurality of first write IO request commands
  • the cache device pre-acquires the size of the data block in the Flash.
  • the size of the acquired data block may be 16K.
  • the write IO request command needs to be split.
  • splitting when the offset of the write IO request command is 0, the IO request command is split into two first write IO request commands, wherein each first write IO request command The size is 16K; when the offset of the write IO request command is not 0, the IO request command is split into three first write IO request commands. This step can ensure that the size of the data block written by the cache device to the Flash is unified with the size of the data block inside the Flash, thereby improving the efficiency of writing data to the Flash.
  • step S410 the step of determining whether the metadata of the data to be written included in the plurality of first write IO request commands is already cached in the memory may be implemented by referring to the prior art, and the implementation of the present invention is implemented. The example will not be described here.
  • the total size of the storage space used to store the metadata corresponding to the data block in the memory may be obtained in advance, and the size of the metadata corresponding to the data block in the Flash is obtained, and then the total size of the storage space is divided by the data block.
  • the size of the corresponding metadata you can get the total number of free blocks in memory. It can be understood that the size of the free block is the size of the metadata.
  • the metadata group corresponds to the metadata block in the Flash, and the number of the free blocks in the metadata group can be calculated according to the size of the metadata block in the Flash and the size of the metadata corresponding to the data block, for example,
  • the size of the metadata block is 4K
  • the size of the metadata corresponding to the data block is 64B.
  • the free blocks contained in the metadata group are consecutively arranged by address.
  • each free block is used to store metadata of data to be written.
  • the size of the metadata of the data to be written coincides with the size of the metadata corresponding to the data block in the Flash.
  • the cache device regards the metadata group currently being processed as the first metadata group and the metadata group not currently being processed as the second metadata group. It can be understood that when the cache device processes the first metadata group and starts processing the second metadata group, the second metadata group is used as the first metadata group. That is, the above name is only to distinguish whether the metadata group is being processed. S430, determining the Whether there are remaining free blocks in the first metadata group.
  • the free block is metadata for storing data to be written
  • the number of free blocks in the first metadata group is correspondingly reduced.
  • 64 metadata blocks may be included in one metadata group.
  • the cache device writes 64 metadata into the metadata group, the metadata group no longer has remaining free blocks. Therefore, each time the cache device writes metadata to the free block, it is necessary to determine whether the first metadata group has remaining free blocks. Specifically, whether there are remaining free blocks may be determined according to the metadata_head corresponding to the first metadata group.
  • the metadata block corresponding to the first metadata group in the Flash may be obtained, and the metadata of the data to be written is written into the data block.
  • the method may further include:
  • the cache device determines whether all the first write IO request commands have been processed, and if no processing is completed, continues to process the other first write IO request commands S420-S440; if the processing has been completed, the writes are judged Whether the IO request command can be merged, if it can be merged, the data is written to the Flash according to the merged IO request command.
  • each time a priority is obtained from the first metadata group since the addresses of the free blocks acquired from the same group are consecutive, the merge probability of writing the IO request command can be increased, thereby reducing The number of times the data is written to Flash.
  • the second metadata group is managed by the multi-level queue. See the relationship between the multi-level queue and the second metadata group shown in FIG. 5.
  • the data structure multi_q_node of the multi-level queue and its meaning are as follows:
  • the method may further include: recording, according to the number of free blocks included in the second metadata group, the second metadata group into each queue of the multi-level queue, where the queues are further The total number of free blocks included in each second metadata group including the queue record;
  • the determining whether the second metadata group has remaining free blocks includes:
  • the types of the queues in the multi-level queue are different, for example, the number of the free blocks in the first queue is less than or equal to 8
  • the second metadata group the second queue only records the second metadata group whose number of free blocks is greater than 8 and less than or equal to 16, and so on. Therefore, if the number of free blocks included in the second metadata group is four, the second metadata group is recorded in the first queue. In addition, the total number of free blocks included in each second metadata group needs to be recorded in the corresponding queue. For example, if the first queue records 5 second metadata groups, each second metadata.
  • the group contains 4, 3, 2, 1, and 1 free blocks, and 11 (4+3+2+1+1) needs to be recorded in the total_num of the first queue.
  • the cache device determines whether the second metadata group has remaining free blocks, it is determined according to the total_num1 of each queue record in the multi-level queue.
  • each metadata_head corresponds to a second metadata group
  • the multi-level queue includes five queues, wherein the second metadata group is recorded in the first two queues, and the first queue only records the free blocks.
  • the second metadata group recorded in the first queue includes 4, 3, 2, 1, and 1 free blocks, and finally records the total number of free blocks included in each second metadata group to the first.
  • the queue for example, it is recorded in the total_num of the first queue, and 11 is also recorded in the total_num of the first queue; similarly, the second queue only records the second metadata group whose number of free blocks is greater than 4,
  • the second metadata group of the second queue record includes 7, 6, 5, 5, and 5 free blocks, and finally the total number of free blocks included in each second metadata group in the second queue is also recorded to the second.
  • 28 (7+6+5+5+5) is also recorded in the total_num of the second queue.
  • the second element is obtained according to the number of free blocks included in the second metadata group.
  • the data sets are arranged.
  • the second metadata group is recorded in the first two queues, and the first queue records five second metadata groups, and each second metadata group includes 4, 3, 2, 1, and 1 respectively.
  • a free block, and each second metadata group in the first queue is sequentially arranged according to the number of free blocks respectively included.
  • each second metadata group in the first queue is arranged in descending order according to the number of free blocks included.
  • the second queue records five second metadata groups, each of which contains 7, 6, 5, 5, and 5 free blocks, and each second metadata group in the second queue follows The number of free blocks included in each of the blocks is sequentially arranged, that is, each second metadata group in the second queue is also arranged in descending order of the number of free blocks included.
  • the cache device when determining whether there are any remaining free blocks in the second metadata group, preferentially determines the total_num in the queue with the largest number of recorded free blocks in the multi-level queue, and if the value is 0, In the level queue, the total_num in the queue with the largest number of free blocks is recorded, and so on; if not, the second metadata group having the largest number of free blocks in the queue is obtained, as in the foregoing example.
  • the second metadata group in each queue is sequentially arranged according to the number of free blocks included in each queue. Therefore, the first second metadata group in the queue may be acquired. As shown in FIG. 5, the total_num of the second queue is first determined.
  • the first second metadata group in the queue is obtained, and the second metadata group includes 7 free blocks.
  • the cache device when it is determined that the total_num of each queue in the multi-level queue is 0, the cache device does not process the write IO request command, and adds the write IO request command to the waiting queue, when the second metadata When there are remaining free blocks in the group, the above write IO request command is processed.
  • the second metadata group obtained by the foregoing including seven free blocks, and one free block is extracted from the seven free blocks, the second metadata group includes six remaining free blocks, and the foregoing The metadata of the data to be written is written in a free block.
  • the method may further include: the cache device will determine whether all the first write IO request commands are processed, and if no processing is completed, continue to request the other first write IO requests.
  • each time a priority is obtained from the first metadata group since the addresses of the free blocks acquired from the same group are consecutive, the merge probability of writing the IO request command can be increased, thereby reducing The number of times the data is written to Flash.
  • the method for writing data to the cache provided by the embodiment of the present invention records a free block in the memory by the metadata group, and obtains a free block from the metadata group when receiving the write IO request command, and The metadata of the data to be written included in the write IO request command is written into the obtained free block, so that the merge probability of the metadata can be increased, thereby further solving the frequent writing of metadata to the Flash, and affecting the Flash.
  • the problem of life since
  • the cache device needs to reclaim the free block into the memory, specifically, re-add the free block to the free block.
  • the step of recovering the free block may include:
  • the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group;
  • the metadata group is the second metadata group, determining whether the number of free blocks included in the second metadata group is greater than a second threshold, and if yes, deleting from the queue that records the second metadata group After the second metadata group is added to the second metadata group, the second metadata group is recorded in other queues of the multi-level queue, and if not, the free block is Join the second metadata set.
  • the recording the second metadata group into other queues of the multi-level queue includes:
  • the second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group. It should be noted that the step of determining whether the number of free blocks included in the second metadata group is greater than a second threshold is to ensure that the second metadata can be determined according to the number of free blocks included in the second metadata group.
  • the group is logged to the appropriate queue. For example, suppose there are two queues in the multi-level queue, the first queue records only the second metadata group whose number of free blocks is less than or equal to 8, and the second queue records the second metadata group whose number of free blocks is greater than 8.
  • the second metadata group is recorded in the first queue, and when the second metadata group recovers a free block
  • the number of free blocks included in the second metadata group is nine, and the number of free blocks of the second metadata group recorded in the first queue is not satisfied. Therefore, the second metadata set needs to be recorded in the second queue.
  • the method further includes:
  • the reclaimed free block can be reclaimed into the metadata group to which it belongs, so that the address of the obtained free block is consecutive when the free block is obtained by the method of the present invention. Thereby, the merge probability of the metadata can be increased, and the problem that the metadata is frequently written into the Flash and affects the lifetime of the Flash can be solved.
  • the method provided by the embodiment of the invention greatly increases the probability of metadata merging, thereby greatly reducing the metadata IO, and has a significant effect on the performance of the providing system, and simultaneously constructing the IO.
  • the number of times, a large reduction in the operation of IO due to metadata, has a significant effect on improving the life of the FLASH card.
  • IO performs merge writing.
  • the number of IOs can be reduced a lot, which can greatly reduce the CPU utilization of the system.
  • CPU utilization can be reduced in large scenarios. -30%.
  • FIG. 6 is a schematic diagram of an apparatus for writing data to a Cache according to Embodiment 2 of the present invention.
  • the apparatus is for performing the method described in FIG.
  • the storage area of the flash memory of the device includes a plurality of memory blocks chunk, and the chunk includes a chunk metadata area and a chunk data.
  • a chunk metadata area including at least one metadata block, the one chunk data area including at least one data area corresponding to the at least one metadata block, the metadata block including a plurality of metadata
  • the data area includes a plurality of data blocks, the metadata block is in one-to-one correspondence with the data area, and the metadata is in one-to-one correspondence with the data block, and includes: a receiving unit 601, a first obtaining unit 602, and a determining unit. 603.
  • the receiving unit 601 is configured to receive a write IO request command, where the write IO request command includes metadata of the data to be written.
  • the first obtaining unit 602 is configured to acquire a metadata group currently being processed into a first metadata group, where the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory.
  • the determining unit 603 is configured to determine whether there are any remaining free blocks in the first metadata group acquired by the first obtaining unit 602.
  • a first writing unit 604 configured to: when the determining unit 603 determines that there are remaining free blocks in the first metadata group, write the element of the data to be written to one of the remaining free blocks Data, and writing metadata of the data to be written into a metadata block corresponding to the first metadata group.
  • the second obtaining unit 605 is configured to: when the determining unit 603 determines that there are no free blocks remaining in the first metadata group, determine whether the second metadata group has remaining free blocks, where the second metadata group is currently not In the processed metadata group, if the second metadata group has remaining free blocks, acquiring the second metadata group and writing to one of the remaining free blocks of the second metadata group The metadata of the data to be written.
  • the second writing unit 606 is configured to write the metadata of the data to be written into the metadata block corresponding to the second metadata group.
  • the number of free blocks included in the metadata group is calculated according to a size of the metadata block and a size of metadata corresponding to the data block.
  • the free blocks included in the metadata group are consecutively arranged by address.
  • the number of free blocks included in the second metadata group recorded by each queue in the multi-level queue is different.
  • the device further includes: a recording unit 607, configured to perform, according to the second metadata group package The number of the free blocks included, the second metadata group is recorded in each queue of the multi-level queue, and the queues further include the total number of free blocks included in each second metadata group recorded by the queue;
  • the second obtaining unit 605 is specifically configured to: determine, according to the total number of free blocks included in each second metadata group recorded in each queue, whether the second metadata group has remaining free blocks.
  • the device further includes: a splitting unit 608.
  • the determining unit 603 is further configured to determine, according to the size of the data block, whether the write IO request command needs to be split.
  • the splitting unit 608 is configured to, if the determining unit 603 determines that splitting is required, split the write IO request command according to the size of the data block to obtain a plurality of first write IO request commands.
  • the determining unit 603 is further configured to determine, by the splitting unit 608, the plurality of first write IO request commands, respectively, whether the metadata of the data to be written included in each of the first write IO request commands has been
  • the cache is in the memory, if yes, the write operation is directly performed, and if not, the step of acquiring the metadata group currently being processed is the first metadata group.
  • the device further includes: an arranging unit 609, configured to: when any one of the plurality of queues records a plurality of second metadata groups, according to the free blocks included in the second metadata group The plurality of second metadata groups are arranged.
  • the device further includes: an adding unit 610.
  • the receiving unit 601 is further configured to receive a reclaiming metadata instruction, where the reclaiming metadata instruction includes an address of an associated free block of the metadata to be reclaimed.
  • the first obtaining unit 602 is further configured to acquire, according to the address of the free block received by the receiving unit 601, a metadata group to which the free block belongs.
  • the joining unit 610 is configured to add the free block to the first metadata group if the metadata group acquired by the first obtaining unit 602 is a first metadata group, and add the first metadata to the first metadata group Free blocks in the group are reordered.
  • the determining unit 603 is further configured to: if the metadata group acquired by the first obtaining unit 602 is a second metadata group, determine whether the number of free blocks included in the second metadata group is greater than a second threshold, and if yes, And deleting the second metadata group from the queue that records the second metadata group, adding the free block After entering the second metadata group, the second metadata group is recorded into other queues of the multi-level queue, and if not, the free block is added to the second metadata group.
  • the determining unit 603 is specifically configured to:
  • the second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
  • the device further includes: an updating unit 611, configured to update a total number of free blocks recorded in a queue in which the second metadata group is recorded, and update a record in a queue in which the second metadata group is added The total number of free blocks.
  • an updating unit 611 configured to update a total number of free blocks recorded in a queue in which the second metadata group is recorded, and update a record in a queue in which the second metadata group is added The total number of free blocks.
  • the device for writing data to the cache provided by the embodiment of the present invention records a free block in the memory through a metadata group, and when receiving the write IO request command, acquires a free block from the metadata group, and writes the above
  • the metadata of the data to be written included in the IO request command is written into the obtained free block, thereby increasing the merge probability of the metadata, thereby solving the problem of frequently writing metadata to the Flash and affecting the life of the Flash. The problem.
  • the embodiment of the present invention further provides a computing and storage machine.
  • the cache includes a flash memory 701 (only the Flash 701 is shown), the memory 702, and the processor 703.
  • the storage area of the flash Flash 701 includes a plurality of storage block chunks, one of the chunks includes a chunk metadata area and a chunk data area, the one chunk metadata area includes at least one metadata block, and the one chunk data area includes And at least one data area corresponding to the at least one metadata block, the metadata block includes a plurality of metadata, the data area includes a plurality of data blocks, and the metadata block has a one-to-one correspondence with the data area, The metadata corresponds to the data block one-to-one.
  • the processor 703 receives a write IO request command, the write IO request command including metadata of the data to be written;
  • the processor 703 acquires a metadata group currently being processed into a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory 702;
  • the processor 703 determines whether there are any remaining free blocks in the first metadata group
  • the processor 703 When there are remaining free blocks in the first metadata group, the processor 703 writes the metadata of the data to be written to one of the remaining free blocks, and the first metadata is Group corresponding Writing metadata of the data to be written in the metadata block;
  • the processor 703 determines whether the second metadata group has remaining free blocks, and the second metadata group is a metadata group that is not currently processed, if And the second metadata group has the remaining free blocks, the second metadata group is acquired, and the metadata of the to-be-written data is written to one of the remaining free blocks of the second metadata group;
  • the processor 703 writes the metadata of the data to be written into the metadata block corresponding to the second metadata group.
  • the number of free blocks included in the metadata group is calculated by the processor 703 according to the size of the metadata block and the size of the metadata corresponding to the data block.
  • the free blocks included in the metadata group are consecutively arranged by address.
  • the number of free blocks included in the metadata group is recorded in a multi-level queue of the memory 702, wherein the second metadata group of each queue record in the multi-level queue includes a free block
  • the numbers are not the same.
  • the processor 703 records the second metadata group into each queue of the multi-level queue according to the number of free blocks included in the second metadata group, where each queue further includes the queue record. The total number of free blocks included in each second metadata group;
  • the processor 703 determines whether the second metadata group has remaining free blocks according to the total number of free blocks included in each second metadata group recorded in each queue.
  • the processor 703 After the processor 703 receives the write IO request command, and before acquiring the metadata group currently being processed as the first metadata group, the processor 703 further determines, according to the size of the data block, whether the Write the IO request command for splitting;
  • the processor 703 splits the write IO request command according to the size of the data block to obtain a plurality of first write IO request commands.
  • the processor 703 requests the plurality of first write IOs to determine whether the metadata of the data to be written included in each first write IO request command is cached in the memory, and if so, directly A write operation is performed, and if not, a step of acquiring the metadata group currently being processed as the first metadata group is performed.
  • the processor 703 pairs the plurality of second elements according to the number of free blocks included in the second metadata group.
  • the data sets are arranged.
  • the processor 703 receives the reclaimed metadata instruction, where the reclaimed metadata instruction includes an address of the associated free block of the metadata to be recovered; and acquires the metadata group to which the free block belongs according to the address of the free block; If the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group; if the metadata If the group is a second metadata group, the processor 703 determines whether the number of free blocks included in the second metadata group is greater than a second threshold, and if so, the processor 703 records from the queue that records the second metadata group.
  • the free block is added to the second metadata group.
  • the recording, by the second metadata group to the other queues of the multi-level queue, includes: according to the number of free blocks included in the second metadata group, the processor 703 records the second metadata group to In other queues of multi-level queues.
  • the processor 703 updates the total number of free blocks recorded in the queue in which the second metadata group is recorded, and updates The total number of free blocks recorded in the queue to which the second metadata group is added.
  • the computing and storage integrated machine provided by the embodiment of the present invention records a free block in the memory through the metadata group, and when receiving the write IO request command, acquires the free block from the metadata group, and writes the above IO request command.
  • the metadata included in the data to be written is written into the obtained free block, so that the merge probability of the metadata can be increased, thereby solving the problem that the metadata is frequently written into the Flash and affecting the lifetime of the Flash.
  • the steps of a method or algorithm described in connection with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both.
  • the software module can be placed in random access memory (RAM), memory, read only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or technical field. Any other form of storage medium known.

Abstract

A method and device for writing data to a cache, comprising: receiving an I/O write request command, the command comprising metadata of data to be written (S410); acquiring a metadata group currently being processed as a first metadata group, one metadata group corresponding to one metadata block and comprising a plurality of free blocks in a memory (S420); determining whether the first metadata group has a residual free block (S430); if so, then writing, into one free block of the residual free blocks and a metadata block corresponding to the first metadata group, the metadata of the data to be written (S440); if not, then determining whether a second metadata group has a residual free block, and if so, then acquiring the second metadata group, and writing, into one free block of the residual free blocks of the second metadata group, the metadata of the data to be written (S450); and writing the metadata of the data to be written into a metadata block corresponding to the second metadata group (S460), thus solving the problem that the service life of flash memory is affected by frequently writing metadata into flash memory.

Description

向缓存中写入数据的方法及装置Method and device for writing data to cache
本申请要求于2014年9月16日提交中国专利局、申请号为201410471711.7、发明名称为“向缓存中写入数据的方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. 201410471711.7, the entire disclosure of which is hereby incorporated by reference. In this application.
技术领域Technical field
本发明涉及数据存储领域,尤其涉及一种向缓存中写入数据的方法及装置。The present invention relates to the field of data storage, and in particular, to a method and apparatus for writing data to a cache.
背景技术Background technique
在业界现有的读写缓存(Cache)中,一般采用的存储介质都是基于非易失性记忆体(A Non-Volatile Dual In-line Memory Module,NVDIMM)或者非易失性随机访问存储器(Non-Volatile Random Access Memory,NVRAM),然而基于上述设备,写Cache的容量通常比较小,难以应对大量随机写压力的场景。In the industry's existing read and write cache (Cache), the commonly used storage medium is based on A Non-Volatile Dual In-line Memory Module (NVDIMM) or non-volatile random access memory ( Non-Volatile Random Access Memory (NVRAM), however, based on the above devices, the capacity of the write cache is usually small, and it is difficult to cope with a large number of random write pressure scenarios.
现有技术中,采用闪存(Flash)设备作为Cache。由于要保证数据的安全性,每一次写请求都需要2次的IO,一次是写数据IO,另一次是写元数据IO。而Flash的寿命跟写的次数直接相关,例如,多层单元闪存(Multi-LevelCell,MLC)通常只有5000-10000次左右。而元数据的大小一般是30B-64B之间,如果每个元数据按照元数据的大小直接IO,则不能充分发挥Flash的性能,如果元数据按照4K对齐的大小下IO,则可能存在写放大的问题,对整个Flash的寿命会大大的影响。In the prior art, a flash (Flash) device is used as the Cache. Because of the security of the data, each write request requires 2 IOs, one is to write data IO, and the other is to write metadata IO. The lifetime of Flash is directly related to the number of writes. For example, Multi-Level Cell (MLC) is usually only about 5000-10000 times. The size of the metadata is generally between 30B and 64B. If each metadata is directly IO according to the size of the metadata, the performance of the Flash cannot be fully utilized. If the metadata is IO according to the size of 4K alignment, there may be write amplification. The problem will have a big impact on the lifetime of the entire Flash.
发明内容Summary of the invention
本发明实施例提供了一种向缓存中写入数据的方法及装置,可以解决频繁 向Flash中写入元数据,而影响Flash的寿命的问题。Embodiments of the present invention provide a method and an apparatus for writing data into a cache, which can solve frequently Write metadata to Flash, which affects the life of Flash.
第一方面,提供了一种向缓存Cache中写入数据的方法,所述Cache的闪存Flash的存储区域包括多个存储块chunk,一个所述chunk包括一个chunk元数据区和一个chunk数据区,所述一个chunk元数据区包括至少一个元数据块,所述一个chunk数据区包括与所述至少一个元数据块对应的至少一个数据区,所述元数据块包括多个元数据,所述数据区包括多个数据块,所述元数据块与所述数据区一一对应,所述元数据与所述数据块一一对应,所述方法包括:In a first aspect, a method for writing data to a cache cache is provided. The storage area of the flash memory of the cache includes a plurality of storage block chunks, and the chunk includes a chunk metadata area and a chunk data area. The one chunk metadata area includes at least one metadata block, the one chunk data area includes at least one data area corresponding to the at least one metadata block, and the metadata block includes a plurality of metadata, the data The area includes a plurality of data blocks, the metadata blocks are in one-to-one correspondence with the data area, and the metadata is in one-to-one correspondence with the data blocks, and the method includes:
接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据;Receiving a write IO request command, the write IO request command including metadata of data to be written;
获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存中的多个空闲块;Obtaining a metadata group currently being processed as a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory;
判断所述第一元数据组中是否有剩余空闲块;Determining whether there are any remaining free blocks in the first metadata group;
当所述第一元数据组中有剩余空闲块时,则向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据;When there are remaining free blocks in the first metadata group, write metadata of the data to be written to one of the remaining free blocks, and correspond to the first metadata group The metadata of the data to be written is written in the metadata block;
当所述第一元数据组中没有剩余空闲块时,则判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据;When there is no free block remaining in the first metadata group, it is determined whether the second metadata group has remaining free blocks, and the second metadata group is a metadata group that is not currently processed, if the second If the metadata group has remaining free blocks, the second metadata group is acquired, and the metadata of the data to be written is written to one of the remaining free blocks of the second metadata group;
向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。The metadata of the data to be written is written into a metadata block corresponding to the second metadata group.
结合第一方面,在第一方面的第一种实现方式中,所述元数据组中包含的空闲块的个数是根据所述元数据块的大小和所述数据块对应的元数据的大小计算得到的。With reference to the first aspect, in a first implementation manner of the first aspect, the number of the free blocks included in the metadata group is based on a size of the metadata block and a size of the metadata corresponding to the data block. Calculated.
结合第一方面,在第一方面的第二种实现方式中,所述元数据组中包含的空闲块是按地址连续排列的。In conjunction with the first aspect, in a second implementation of the first aspect, the free blocks included in the metadata group are consecutively arranged by address.
结合第一方面,在第一方面的第三种实现方式中,所述元数据组中包含的空闲块的个数被记录在内存的多级队列中,其中,所述多级队列中各队列记录的第二元数据组包含的空闲块的个数是不相同的。 With reference to the first aspect, in a third implementation manner of the first aspect, the number of the free blocks included in the metadata group is recorded in a multi-level queue of the memory, where each queue in the multi-level queue The number of free blocks included in the recorded second metadata group is different.
结合第一方面的第三种实现方式,在第一方面的第四种实现方式中,根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;With reference to the third implementation manner of the first aspect, in a fourth implementation manner of the first aspect, the second metadata group is recorded according to the number of the free blocks included in the second metadata group In each queue of the level queue, the queues further include a total number of free blocks included in each second metadata group recorded by the queue;
所述判断第二元数据组是否有剩余空闲块包括:The determining whether the second metadata group has remaining free blocks includes:
根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。It is determined whether the second metadata group has remaining free blocks according to the total number of free blocks included in each second metadata group recorded by each queue.
结合第一方面或第一方面的上述四种实现方式中任一种实现方式,在第一方面的第五种实现方式中,在所述接收写入IO请求命令之后,在所述获取当前正在处理的元数据组为第一元数据组之前,所述方法还包括:With reference to the first aspect, or any one of the foregoing four implementation manners of the first aspect, in the fifth implementation manner of the first aspect, after the receiving the write IO request command, the obtaining is currently being performed Before the processed metadata group is the first metadata group, the method further includes:
根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分;Determining whether the write IO request command needs to be split according to the size of the data block;
若需要进行拆分,则根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令;If the splitting is required, splitting the write IO request command according to the size of the data block, and obtaining a plurality of first write IO request commands;
对所述多个第一写入IO请求命令,分别判断各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。Determining, by the plurality of first write IO request commands, whether metadata of the data to be written included in each first write IO request command is already cached in the memory, and if so, directly performing a write operation If no, the step of obtaining the metadata group currently being processed is the first metadata group.
结合第一方面的第四种实现方式,在第一方面的第六种实现方式中,当所述多级队列中任一队列记录多个第二元数据组时,则根据所述第二元数据组包含的空闲块的个数,对所述多个第二元数据组进行排列。With reference to the fourth implementation manner of the first aspect, in a sixth implementation manner of the first aspect, when any one of the plurality of queues records a plurality of second metadata groups, according to the second element The number of free blocks included in the data group is arranged for the plurality of second metadata groups.
结合第一方面的第三种实现方式,在第一方面的第七种实现方式中,所述方法还包括:In conjunction with the third implementation of the first aspect, in a seventh implementation manner of the first aspect, the method further includes:
接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址;Receiving a recycle metadata instruction, where the recycle metadata command includes an address of a free block to which the metadata to be recovered belongs;
根据所述空闲块的地址,获取所述空闲块所属的元数据组;Obtaining, according to an address of the free block, a metadata group to which the free block belongs;
若所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序;And if the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group;
若所述元数据组为第二元数据组,则判断所述第二元数据组包含的空闲块 个数是否大于第二阈值,若是,则从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则将所述空闲块加入所述第二元数据组中。If the metadata group is a second metadata group, determining a free block included in the second metadata group Whether the number is greater than a second threshold, and if so, deleting the second metadata group from the queue in which the second metadata group is recorded, and adding the free block to the second metadata group, The second metadata group is recorded in other queues of the multi-level queue, and if not, the free block is added to the second metadata group.
结合第一方面的第七种实现方式,在第一方面的第八种实现方式中,所述将所述第二元数据组记录到多级队列的其它队列中包括:In conjunction with the seventh implementation of the first aspect, in the eighth implementation manner of the first aspect, the recording, by the second metadata group, into another queue of the multi-level queue includes:
根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的其它队列中。The second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
结合第一方面的第七种或第八种实现方式,在第一方面的第九种实现方式中,所述方法还包括:With reference to the seventh or eighth implementation manner of the first aspect, in a ninth implementation manner of the first aspect, the method further includes:
在所述从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中之后,所述方法还包括:Deleting the second metadata group from the queue for recording the second metadata group, adding the free block to the second metadata group, and recording the second metadata group to a plurality of After the other queues of the level queue, the method further includes:
更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。Updating the total number of free blocks recorded in the queue of the second metadata group, and updating the total number of free blocks recorded in the queue joined by the second metadata group.
第二方面,本发明实施例提供了一种向缓存Cache中写入数据的装置,所述装置的闪存Flash的存储区域包括多个存储块chunk,一个所述chunk包括一个chunk元数据区和一个chunk数据区,所述一个chunk元数据区包括至少一个元数据块,所述一个chunk数据区包括与所述至少一个元数据块对应的至少一个数据区,所述元数据块包括多个元数据,所述数据区包括多个数据块,所述元数据块与所述数据区一一对应,所述元数据与所述数据块一一对应,所述装置包括:接收单元、第一获取单元、判断单元、第一写入单元、第二获取单元和第二写入单元;In a second aspect, an embodiment of the present invention provides an apparatus for writing data to a cache cache. The storage area of the flash memory of the apparatus includes a plurality of storage blocks chunk, and the chunk includes a chunk metadata area and a a chunk data area, the one chunk metadata area including at least one metadata block, the one chunk data area including at least one data area corresponding to the at least one metadata block, the metadata block including a plurality of metadata The data area includes a plurality of data blocks, the metadata block is in one-to-one correspondence with the data area, and the metadata is in one-to-one correspondence with the data block, and the apparatus includes: a receiving unit, and a first acquiring unit a determining unit, a first writing unit, a second obtaining unit, and a second writing unit;
所述接收单元,用于接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据;The receiving unit is configured to receive a write IO request command, where the write IO request command includes metadata of data to be written;
所述第一获取单元,用于获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存中的多个空闲块; The first obtaining unit is configured to acquire a metadata group currently being processed into a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory;
所述判断单元,用于判断所述第一获取单元获取的所述第一元数据组中是否有剩余空闲块;The determining unit is configured to determine whether there is any remaining free block in the first metadata group acquired by the first acquiring unit;
所述第一写入单元,用于当所述判断单元判断所述第一元数据组中有剩余空闲块时,则向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据;The first writing unit is configured to: when the determining unit determines that there are remaining free blocks in the first metadata group, write the data to be written to one of the remaining free blocks Metadata, and writing metadata of the data to be written into a metadata block corresponding to the first metadata group;
所述第二获取单元,用于当所述判断单元判断所述第一元数据组中没有剩余空闲块时,则判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据;The second obtaining unit is configured to: when the determining unit determines that there are no free blocks in the first metadata group, determine whether the second metadata group has remaining free blocks, where the second metadata group is a metadata group currently not being processed, if the second metadata group has remaining free blocks, acquiring the second metadata group, and to a free block in the remaining free blocks of the second metadata group Writing metadata of the data to be written;
所述第二写入单元,用于向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。The second writing unit is configured to write metadata of the data to be written into a metadata block corresponding to the second metadata group.
结合第二方面,第二方面的第一种实现方式中,所述元数据组中包含的空闲块的个数是根据所述元数据块的大小和所述数据块对应的元数据的大小计算得到的。With reference to the second aspect, in a first implementation manner of the second aspect, the number of the free blocks included in the metadata group is calculated according to a size of the metadata block and a size of the metadata corresponding to the data block. owned.
结合第二方面,在第二方面的第二种实现方式中,所述元数据组中包含的空闲块是按地址连续排列的。In conjunction with the second aspect, in a second implementation of the second aspect, the free blocks included in the metadata group are consecutively arranged by address.
结合第二方面,在第二方面的第三种实现方式中,所述元数据组中包含的空闲块的个数被记录在内存的多级队列中,其中,所述多级队列中各队列记录的第二元数据组包含的空闲块的个数是不相同的。With reference to the second aspect, in a third implementation manner of the second aspect, the number of the free blocks included in the metadata group is recorded in a multi-level queue of the memory, where each queue in the multi-level queue The number of free blocks included in the recorded second metadata group is different.
结合第二方面的第三种实现方式,在第二方面的第四种实现方式中,所述装置还包括:记录单元,用于根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;With the third implementation of the second aspect, in a fourth implementation manner of the second aspect, the device further includes: a recording unit, configured to use, according to the number of free blocks included in the second metadata group, Recording the second metadata group into each queue of the multi-level queue, where each queue further includes a total number of free blocks included in each second metadata group recorded by the queue;
所述第二获取单元具体用于:根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。The second acquiring unit is specifically configured to: determine, according to the total number of free blocks included in each second metadata group recorded in each queue, whether the second metadata group has remaining free blocks.
结合第二方面或第二方面的上述四种实现方式中任一种实现方式,在第二 方面的第五种实现方式中,装置还包括:拆分单元;Combining the second aspect or the foregoing four implementation manners of the second aspect, in the second implementation In a fifth implementation manner of the aspect, the device further includes: a splitting unit;
所述判断单元,还用于根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分;The determining unit is further configured to determine, according to the size of the data block, whether the write IO request command needs to be split;
所述拆分单元,用于若所述判断单元判断需要进行拆分,则根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令;The splitting unit is configured to: if the determining unit determines that splitting is required, split the write IO request command according to the size of the data block, to obtain a plurality of first write IO request commands ;
所述判断单元,还用于对所述拆分单元得到的所述多个第一写入IO请求命令,分别判断各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。The determining unit is further configured to determine, by the splitting unit, the plurality of first write IO request commands, respectively, whether the metadata of the data to be written included in each first write IO request command has been The cache is in the memory, if yes, the write operation is directly performed, and if not, the step of acquiring the metadata group currently being processed is the first metadata group.
结合第二方面的第四种实现方式,在第二方面的第六种实现方式中,所述装置还包括:排列单元,用于当所述多级队列中任一队列记录多个第二元数据组时,则根据所述第二元数据组包含的空闲块的个数,对所述多个第二元数据组进行排列。With reference to the fourth implementation manner of the second aspect, in a sixth implementation manner of the second aspect, the device further includes: an arranging unit, configured to record a plurality of second elements in any one of the multi-level queues In the case of the data group, the plurality of second metadata groups are arranged according to the number of free blocks included in the second metadata group.
结合第二方面的第三种实现方式,在第二方面的第七种实现方式中,加入单元;With reference to the third implementation manner of the second aspect, in a seventh implementation manner of the second aspect, the unit is added;
所述接收单元,还用于接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址;The receiving unit is further configured to receive a recovery metadata instruction, where the recovery metadata instruction includes an address of an associated free block of the metadata to be recovered;
所述第一获取单元,还用于根据所述接收单元接收的所述空闲块的地址,获取所述空闲块所属的元数据组;The first obtaining unit is further configured to acquire, according to an address of the free block received by the receiving unit, a metadata group to which the free block belongs;
所述加入单元,用于若所述第一获取单元获取的所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序;The joining unit is configured to add the free block to the first metadata group if the metadata group acquired by the first acquiring unit is a first metadata group, and add the first Free block reordering in the metadata group;
所述判断单元,还用于若所述第一获取单元获取的所述元数据组为第二元数据组,则判断所述第二元数据组包含的空闲块个数是否大于第二阈值,若是,则从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则将所述空闲块加入所述第二元数据组中。 The determining unit is further configured to: if the metadata group acquired by the first acquiring unit is a second metadata group, determine whether the number of free blocks included in the second metadata group is greater than a second threshold, If yes, deleting the second metadata group from the queue that records the second metadata group, adding the free block to the second metadata group, and recording the second metadata group to a plurality of In other queues of the level queue, if not, the free block is added to the second metadata group.
结合第二方面的第七种实现方式,在第二方面的第八种实现方式中,所述判断单元具体用于:With reference to the seventh implementation manner of the second aspect, in the eighth implementation manner of the second aspect, the determining unit is specifically configured to:
根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的其它队列中。The second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
结合第二方面的第七种或第八种实现方式,在第二方面的第九种实现方式中,所述装置还包括:更新单元,用于更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。With reference to the seventh or eighth implementation manner of the second aspect, in a ninth implementation manner of the second aspect, the device further includes: an updating unit, configured to update a queue that records the second metadata group The total number of free blocks recorded, and the total number of free blocks recorded in the queue to which the second metadata group is added is updated.
本发明实施例提供的向缓存中写入数据的方法及装置。通过元数据组记录内存中的空闲块,当接收到写入IO请求命令时,从上述元数据组中获取空闲块,并将上述写入IO请求命令中包括的待写入数据的元数据写入获取到的空闲块中,从而可以增大元数据的合并概率,进而可以解决频繁向Flash中写入元数据,导致写放大,而影响Flash的寿命的问题。A method and apparatus for writing data into a cache provided by an embodiment of the present invention. Recording a free block in the memory by the metadata group, when receiving the write IO request command, acquiring the free block from the above metadata group, and writing the metadata of the data to be written included in the IO request command Into the obtained free block, thereby increasing the merge probability of the metadata, thereby solving the problem of frequently writing metadata to the Flash, resulting in write amplification, which affects the life of the Flash.
附图说明DRAWINGS
图1是本发明提供的Flash的一种数据布局示意图;1 is a schematic diagram of a data layout of a Flash provided by the present invention;
图2是本发明提供的Flash的另一种数据布局示意图;2 is a schematic diagram of another data layout of the Flash provided by the present invention;
图3为本发明提供的元数据在内存中位置和Flash中实际持久化的位置的一种关系示意图;FIG. 3 is a schematic diagram showing relationship between a location of a metadata in an in-memory and an actual persistent location in Flash according to the present invention; FIG.
图4为本发明实施例一提供的向Cache中写入数据的方法流程图;4 is a flowchart of a method for writing data to a Cache according to Embodiment 1 of the present invention;
图5为多级队列与第二元数据组的关系示意图;5 is a schematic diagram of a relationship between a multi-level queue and a second metadata group;
图6为本发明实施例二提供的向Cache中写入数据的装置示意图;FIG. 6 is a schematic diagram of an apparatus for writing data to a Cache according to Embodiment 2 of the present invention;
图7为本发明实施例提供的计算存储一体机的结构示意图。FIG. 7 is a schematic structural diagram of a computing and storage integrated machine according to an embodiment of the present invention.
具体实施方式detailed description
为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然, 所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. The described embodiments are a part of the embodiments of the invention, and not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.
为便于对本发明实施例的理解,下面将结合附图以具体实施例做进一步的解释说明,实施例并不构成对本发明实施例的限定。In order to facilitate the understanding of the embodiments of the present invention, the embodiments of the present invention are not to be construed as limiting.
图1是本发明提供的Flash的一种数据布局示意图。如图1所示,Flash的存储区域可包括超级块、元数据区和数据区三部分。FIG. 1 is a schematic diagram of a data layout of a Flash provided by the present invention. As shown in FIG. 1, the storage area of the Flash may include three parts: a super block, a metadata area, and a data area.
超级块,用于存储Cache中的全局数据,主要为了系统宕机后恢复时需要用的数据。其中,该全局数据可包括元数据块的大小、数据块的大小等。The super block is used to store the global data in the Cache, mainly for the data needed for recovery after the system is down. The global data may include a size of a metadata block, a size of a data block, and the like.
元数据(metadata),维护存储系统中的数据块的数据,用于描述和组织数据块的关系,其大小根据系统中定义的数据结构大小决定。Metadata (data), which maintains the data of the data blocks in the storage system, and describes and organizes the relationship of the data blocks. The size is determined according to the size of the data structure defined in the system.
元数据区,指用于存储元数据的区域。Metadata area refers to the area used to store metadata.
数据区,用于存储Cache中真实的数据,其下可包括多个数据块。The data area is used to store real data in the Cache, and may include multiple data blocks below.
图2是本发明提供的Flash的另一种数据布局示意图。如图2所示,Flash包括超级块和多个存储块(chunk),每个chunk包括一个chunk元数据区和一个chunk数据区,每个chunk元数据区包括一个或多个元数据块,每个chunk数据区包括与该一个或多个元数据块对应的数据区。每个chunk数据区下的数据区与其对应的chunk元数据区下的元数据块一一对应。一个元数据块维护一个对应的数据区,具体地,每个元数据区下包括多个元数据,每个元数据对应于数据区下的一个数据块。2 is a schematic diagram of another data layout of the Flash provided by the present invention. As shown in FIG. 2, the Flash includes a super block and a plurality of chunks, each chunk includes a chunk metadata area and a chunk data area, and each chunk metadata area includes one or more metadata blocks, each of which The chunk data area includes a data area corresponding to the one or more metadata blocks. The data area under each chunk data area has a one-to-one correspondence with the metadata block under the corresponding chunk metadata area. A metadata block maintains a corresponding data area. Specifically, each metadata area includes a plurality of metadata, and each metadata corresponds to one data block under the data area.
图2中,虽然1个chunk元数据区中包含了4个元数据块,但并不表示1个chunk元数据区只能包含4个元数据块,还可以是1个、2个或其它数值。同样的,图2所示的chunk的个数,chunk数据区内数据区的个数、元数据区内元数据的个数、数据区内数据块的个数都不限于图2所示的数值。In Figure 2, although 1 chunk metadata area contains 4 metadata blocks, it does not mean that 1 chunk metadata area can only contain 4 metadata blocks, and can also be 1, 2 or other values. . Similarly, the number of chunks shown in FIG. 2, the number of data areas in the chunk data area, the number of metadata in the metadata area, and the number of data blocks in the data area are not limited to the values shown in FIG. .
每个数据区对应于一个不同的元数据块,一个元数据块内的元数据所对应的数据块组成一个数据区。也就是说,一个数据区包含一个元数据块大小的元数据所对应的数据,一个数据区的大小由一个元数据块内元数据的个数和一个 数据块的大小来决定。Each data area corresponds to a different metadata block, and the data blocks corresponding to the metadata in one metadata block constitute a data area. That is to say, one data area contains data corresponding to metadata of a metadata block size, the size of one data area is determined by the number of metadata in one metadata block and one The size of the data block is determined.
在Flash中,一次页面写入的大小为4K。因此,一种优选的方案,一个元数据块的大小为4K。不妨假设一个元数据的大小为32B,一个数据块的大小为16K,则一个数据区的大小为2M(16K*(4K/32B))。In Flash, the size of a page write is 4K. Therefore, in a preferred solution, the size of one metadata block is 4K. Let's assume that the size of a metadata is 32B, and the size of a data block is 16K, then the size of a data area is 2M (16K*(4K/32B)).
需要说明的是,一个chunk元数据区可能包括一个或多个元数据块,一个chunk元数据区的大小是可变的。一种优选的方案,可将一个数据块的大小作为一个chunk元数据区的大小,这样,可使得在Flash加载初始化时,按照数据块的大小对Flash的存储区域进行划分。例如,一个数据块的大小为4K,则一个chunk元数据区的大小也为4K,其元数据块的个数为1(4K/4K)。又例如,一个数据块的大小为16K,则一个chunk元数据区的大小也为16K,其元数据块的个数为4(16K/4K)。数据块的大小可以由操作系统或存储装置配置,其大小可以为4K、8K、16K、32K或64K等等,本发明实施例在此不作限制。It should be noted that a chunk metadata area may include one or more metadata blocks, and the size of one chunk metadata area is variable. A preferred solution can take the size of a data block as the size of a chunk metadata area, so that when the Flash load is initialized, the storage area of the Flash is divided according to the size of the data block. For example, if the size of a data block is 4K, the size of a chunk metadata area is also 4K, and the number of metadata blocks is 1 (4K/4K). For another example, if the size of one data block is 16K, the size of one chunk metadata area is also 16K, and the number of metadata blocks is 4 (16K/4K). The size of the data block can be configured by the operating system or the storage device, and the size of the data block can be 4K, 8K, 16K, 32K, or 64K, etc., and the embodiment of the present invention is not limited herein.
当然,数据块的大小也可以与chunk元数据区的大小不同。例如,数据块的大小还可以是512B,1K,2K等,而chunk元数据区中至少包括1个元数据块,显然比一个数据块大。Of course, the size of the data block can also be different from the size of the chunk metadata area. For example, the size of the data block may also be 512B, 1K, 2K, etc., and the chunk metadata area includes at least one metadata block, which is obviously larger than one data block.
又例如,当数据块的大小为8K、16K、32K或64K等时,chunk元数据区的大小也可以比数据块的大小还小,比如chunk元数据区中只包括1个元数据块。For another example, when the size of the data block is 8K, 16K, 32K, or 64K, the size of the chunk metadata area may be smaller than the size of the data block, for example, only one metadata block is included in the chunk metadata area.
图3为本发明提供的元数据在内存中位置和Flash中实际持久化的位置的一种关系示意图。图3中,可在内存中设计一个数据结构p_head数组,存储数据区中每个数据块对应的元数据。不妨假设每个数据块所需要的元数据的大小为64个字节,那么可以将p_head数组按照64个(4K/64B=64)元数据分成一组。FIG. 3 is a schematic diagram showing the relationship between the location of the metadata in the memory and the actual persistent location in the Flash provided by the present invention. In Figure 3, a data structure p_head array can be designed in memory to store the metadata corresponding to each data block in the data area. Let's assume that the size of the metadata required for each data block is 64 bytes, then the p_head array can be grouped into 64 (4K/64B=64) metadata.
内存中一个元数据对应于p_head数组的一个元素,其数据结构flashcache_wbhead及含义如下所示:A metadata in memory corresponds to an element of the p_head array, and its data structure flashcache_wbhead has the following meaning:
Figure PCTCN2015083383-appb-000001
Figure PCTCN2015083383-appb-000001
Figure PCTCN2015083383-appb-000002
Figure PCTCN2015083383-appb-000002
如图3所示,还可在内存中设计一个数据结构metadata_head数组,维护在内存中数据的元数据和这些元数据在实际持久化设备(Flash)中的实际的存储位置(即对应的元数据块)的关系。As shown in Figure 3, you can also design a data structure metadata_head array in memory, maintain the metadata of the data in memory and the actual storage location of the metadata in the actual persistent device (Flash) (ie the corresponding metadata Block) relationship.
Flash中的一个元数据在内存中所对应的一个元数据组,对应于metadata_head数组中的一个元素,其数据结构metadata_head及含义可如下所示:A metadata group in Flash corresponds to a metadata group in memory, corresponding to an element in the metadata_head array. The data structure metadata_head and its meaning can be as follows:
typedef struct metadata_headTypedef struct metadata_head
{{
list_head_t metadata_pending_q;//等待合并的数据IO队列List_head_t metadata_pending_q; / / waiting for the merged data IO queue
list_head_t metadata_syncing_q;//同步合并元数据IO队列List_head_t metadata_syncing_q;//Synchronize merge metadata IO queue
dsw_u64metadata_lba;//指定系统中元数据在Flash卡中具体的位置Dsw_u64metadata_lba; / / specify the specific location of the metadata in the system in the flash card
void*buf_address;//指定内存中对应的4K的位置 Void*buf_address;//Specify the corresponding 4K location in memory
dsw_u8 is_writing;//标记head是否正在IO操作Dsw_u8 is_writing; / / mark head is IO operation
ptr_heap_t invalid_head_heap;//管理4K的元数据,按照元数据的地址进行排序Ptr_heap_t invalid_head_heap;//Manage 4K metadata, sort by metadata address
list_head_t invalid_q_node;//无效的节点,是为了把这个元数据管理头挂入多级队列List_head_t invalid_q_node; / / invalid node, in order to hang this metadata management head into the multi-level queue
dsw_u32 multi_q_flag;//标记当前的元数据管理头挂入到哪个多级队列中Dsw_u32 multi_q_flag; / / mark the current metadata management header into which multi-level queue
dsw_u32 free_cnt;//计数当前的元数据管理头,有多少个空闲的元数据块Dsw_u32 free_cnt; / / count the current metadata management header, how many free metadata blocks
}metadata_head_t;}metadata_head_t;
如图3所示,内存中按flashCache_wbhead存储着一个数据块的元数据信息,又按metadata_head存储着同一组元数据(即一个元数据块)的信息,以方便在写入时按照元数据块进行写入。As shown in FIG. 3, the metadata information of a data block is stored in the memory by flashCache_wbhead, and the information of the same group metadata (ie, one metadata block) is stored according to the metadata_head, so as to facilitate the writing according to the metadata block. Write.
图4为本发明实施例一提供的向Cache中写入数据的方法流程图。所述方法的执行主体可以是缓存装置,该缓存装置包括闪存Falsh。FIG. 4 is a flowchart of a method for writing data to a Cache according to Embodiment 1 of the present invention. The execution body of the method may be a cache device, and the cache device includes a flash memory Falsh.
下面,结合图3及元数据、元数据块的数据结构对图4的方法进行描述。当然图4还可应用于其它包含多个元数据区的Flash数据布局方式,本发明实施例在此不作限制。Next, the method of FIG. 4 will be described with reference to FIG. 3 and the data structure of the metadata and metadata blocks. Of course, FIG. 4 can also be applied to other manners of the layout of the Flash data including the plurality of metadata areas, which are not limited herein.
S410,接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据。S410. Receive a write IO request command, where the write IO request command includes metadata of data to be written.
可选地,在接收写入IO请求命令之后,所述方法还可以包括如下步骤:Optionally, after receiving the write IO request command, the method may further include the following steps:
根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分;Determining whether the write IO request command needs to be split according to the size of the data block;
若需要进行拆分,则根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令;If the splitting is required, splitting the write IO request command according to the size of the data block, and obtaining a plurality of first write IO request commands;
对所述多个第一写入IO请求命令,分别判断各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。 Determining, by the plurality of first write IO request commands, whether metadata of the data to be written included in each first write IO request command is already cached in the memory, and if so, directly performing a write operation If no, the step of obtaining the metadata group currently being processed is the first metadata group.
具体地,缓存装置预先获取Flash中的数据块的大小,举例来说,获取到的数据块的大小可以为16K。在接收到写入IO请求命令之后,假设该写入IO请求命令的大小为32K(数据块的2倍),则需要对上述写入IO请求命令进行拆分。在拆分时,当该写入IO请求命令的偏移为0时,则将上述IO请求命令拆分为两个第一写入IO请求命令,其中,每个第一写入IO请求命令的大小为16K;当该写入IO请求命令的偏移不为0时,则将上述IO请求命令拆分为三个第一写入IO请求命令。该步骤可以保证缓存装置向Flash中写入数据块的大小与Flash内部的数据块大小相统一,从而可以提高向Flash中写入数据的效率。Specifically, the cache device pre-acquires the size of the data block in the Flash. For example, the size of the acquired data block may be 16K. After receiving the write IO request command, assuming that the write IO request command has a size of 32K (two times the data block), the write IO request command needs to be split. When splitting, when the offset of the write IO request command is 0, the IO request command is split into two first write IO request commands, wherein each first write IO request command The size is 16K; when the offset of the write IO request command is not 0, the IO request command is split into three first write IO request commands. This step can ensure that the size of the data block written by the cache device to the Flash is unified with the size of the data block inside the Flash, thereby improving the efficiency of writing data to the Flash.
需要说明的是,步骤S410中判断所述多个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中的步骤可参考现有技术实现,本发明实施例在此不做赘述。It should be noted that, in step S410, the step of determining whether the metadata of the data to be written included in the plurality of first write IO request commands is already cached in the memory may be implemented by referring to the prior art, and the implementation of the present invention is implemented. The example will not be described here.
S420,获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存中的多个空闲块。S420. Acquire a metadata group currently being processed as a first metadata group, and one of the metadata groups corresponds to one of the metadata blocks, and include a plurality of free blocks in the memory.
需要说明的是,可以预先获取内存中用来存储数据块对应的元数据的存储空间的总大小,并获取Flash中数据块对应的元数据的大小,然后将存储空间的总大小除以数据块对应的元数据的大小,就可以得到内存中空闲块的总个数。可以理解的是,空闲块的大小即为元数据的大小。此外,元数据组对应于Flash中的元数据块,则元数据组中包含空闲块的个数可以根据Flash中元数据块的大小和数据块对应的元数据的大小计算得到,举例来说,元数据块的大小为4K,数据块对应的元数据的大小为64B,则元数据组包含空闲块的个数为4K/64B=64个,即一个元数据组可以包含64个空闲块。可选地,元数据组中包含的空闲块是按地址连续排列的。其中,每个空闲块用于存储待写入数据的元数据。在此说明,待写入数据的元数据的大小与Flash中数据块对应的元数据的大小一致。It should be noted that the total size of the storage space used to store the metadata corresponding to the data block in the memory may be obtained in advance, and the size of the metadata corresponding to the data block in the Flash is obtained, and then the total size of the storage space is divided by the data block. The size of the corresponding metadata, you can get the total number of free blocks in memory. It can be understood that the size of the free block is the size of the metadata. In addition, the metadata group corresponds to the metadata block in the Flash, and the number of the free blocks in the metadata group can be calculated according to the size of the metadata block in the Flash and the size of the metadata corresponding to the data block, for example, The size of the metadata block is 4K, and the size of the metadata corresponding to the data block is 64B. The number of metadata blocks including the number of free blocks is 4K/64B=64, that is, one metadata group can contain 64 free blocks. Optionally, the free blocks contained in the metadata group are consecutively arranged by address. Wherein, each free block is used to store metadata of data to be written. Here, it is explained that the size of the metadata of the data to be written coincides with the size of the metadata corresponding to the data block in the Flash.
在此说明,缓存装置将当前正在处理的元数据组作为第一元数据组,而将当前未在处理的元数据组作为第二元数据组。可以理解的是,当缓存装置处理完第一元数据组,而开始处理第二元数据组时,则该第二元数据组作为第一元数据组。即上述名称仅仅是为了区分元数据组是否正在处理。S430,判断所述 第一元数据组中是否有剩余空闲块。It is explained here that the cache device regards the metadata group currently being processed as the first metadata group and the metadata group not currently being processed as the second metadata group. It can be understood that when the cache device processes the first metadata group and starts processing the second metadata group, the second metadata group is used as the first metadata group. That is, the above name is only to distinguish whether the metadata group is being processed. S430, determining the Whether there are remaining free blocks in the first metadata group.
在此说明,由于空闲块是用于存储待写入数据的元数据,因此在缓存装置处理多个写入IO请求命令之后,第一元数据组中空闲块的个数就会相应的减少。如前述例子中,一个元数据组中可以包含64个空闲块,当缓存装置向该元数据组中写入64个元数据时,则该元数据组不再有剩余空闲块。因此,在缓存装置每次向空闲块中写入元数据时,需要判断第一元数据组是否有剩余空闲块。具体地,可根据第一元数据组对应的metadata_head判断是否有剩余空闲块。It is explained here that since the free block is metadata for storing data to be written, after the cache device processes the plurality of write IO request commands, the number of free blocks in the first metadata group is correspondingly reduced. As in the foregoing example, 64 metadata blocks may be included in one metadata group. When the cache device writes 64 metadata into the metadata group, the metadata group no longer has remaining free blocks. Therefore, each time the cache device writes metadata to the free block, it is necessary to determine whether the first metadata group has remaining free blocks. Specifically, whether there are remaining free blocks may be determined according to the metadata_head corresponding to the first metadata group.
S440,当所述第一元数据组中有剩余空闲块时,则向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据。S440. When there are remaining free blocks in the first metadata group, write metadata of the data to be written to one of the remaining free blocks, and send the metadata to the first metadata. The metadata of the data to be written is written in the metadata block corresponding to the group.
需要说明的是,可以根据第一元数据组对应的metadata_head,获取第一元数据组在Flash中对应的元数据块,并向该数据块中写入上述待写入数据的元数据。It should be noted that, according to the metadata_head corresponding to the first metadata group, the metadata block corresponding to the first metadata group in the Flash may be obtained, and the metadata of the data to be written is written into the data block.
可选地,在向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据之前,所述方法还可以包括:Optionally, before the metadata of the to-be-written data is written in the metadata block corresponding to the first metadata group, the method may further include:
缓存装置判断是否处理完成了所有的第一写入IO请求命令,如果没有处理完成,则继续对其他的第一写入IO请求命令作S420-S440的处理;如果已经处理完成,则判断这些写入IO请求命令是否可以合并,如果可以合并,则根据合并后的IO请求命令,向Flash中写入数据。本发明中,每次优先从第一元数据组中获取空闲块,由于从同一组中获取的空闲块的地址都是连续的,由此可以增加写入IO请求命令的合并概率,从而可以减小向Flash中写入数据的次数。The cache device determines whether all the first write IO request commands have been processed, and if no processing is completed, continues to process the other first write IO request commands S420-S440; if the processing has been completed, the writes are judged Whether the IO request command can be merged, if it can be merged, the data is written to the Flash according to the merged IO request command. In the present invention, each time a priority is obtained from the first metadata group, since the addresses of the free blocks acquired from the same group are consecutive, the merge probability of writing the IO request command can be increased, thereby reducing The number of times the data is written to Flash.
需要说明的是,判断写入IO请求命令是否可以合并可参考现有技术实现,在此不做赘述。It should be noted that whether the write IO request command can be merged can be referred to the prior art implementation, and details are not described herein.
S450,当所述第一元数据组中没有剩余空闲块时,则判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据。 S450, when there is no free block remaining in the first metadata group, determining whether the second metadata group has remaining free blocks, where the second metadata group is a metadata group that is not currently processed, if The second metadata group has remaining free blocks, then the second metadata group is acquired, and the metadata of the data to be written is written to one of the remaining free blocks of the second metadata group.
具体地,通过多级队列对第二元数据组进行管理,参见图5所示的多级队列与第二元数据组的关系示意图。图5中,多级队列的数据结构multi_q_node及含义如下所示:Specifically, the second metadata group is managed by the multi-level queue. See the relationship between the multi-level queue and the second metadata group shown in FIG. 5. In Figure 5, the data structure multi_q_node of the multi-level queue and its meaning are as follows:
Figure PCTCN2015083383-appb-000003
Figure PCTCN2015083383-appb-000003
可选地,所述方法还可以包括:根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;Optionally, the method may further include: recording, according to the number of free blocks included in the second metadata group, the second metadata group into each queue of the multi-level queue, where the queues are further The total number of free blocks included in each second metadata group including the queue record;
其中,所述判断第二元数据组是否有剩余空闲块包括:The determining whether the second metadata group has remaining free blocks includes:
根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。It is determined whether the second metadata group has remaining free blocks according to the total number of free blocks included in each second metadata group recorded by each queue.
需要说明的是,根据队列的类型的数据结构invalid_q_type可知,多级队列中各队列的类型是不同的,如第一个队列只记录空闲块的个数小于等于8 的第二元数据组,第二个队列只记录空闲块的个数大于8小于等于16的第二元数据组,这样依次类推。因此,若第二元数据组包含的空闲块的个数为4个时,则将该第二元数据组记录到第一个队列中。此外,还需要将各第二元数据组包含的空闲块的总数目记录到对应的队列中,举例来说,假如,第一个队列记录了5个第二元数据组,各第二元数据组分别包含了4、3、2、1和1个空闲块,则需要将11(4+3+2+1+1)记录到第一个队列的total_num中。当缓存装置判断第二元数据组是否有剩余空闲块时,则根据多级队列中各队列记录的total_numl来判断。It should be noted that, according to the data structure invalid_q_type of the type of the queue, the types of the queues in the multi-level queue are different, for example, the number of the free blocks in the first queue is less than or equal to 8 The second metadata group, the second queue only records the second metadata group whose number of free blocks is greater than 8 and less than or equal to 16, and so on. Therefore, if the number of free blocks included in the second metadata group is four, the second metadata group is recorded in the first queue. In addition, the total number of free blocks included in each second metadata group needs to be recorded in the corresponding queue. For example, if the first queue records 5 second metadata groups, each second metadata. The group contains 4, 3, 2, 1, and 1 free blocks, and 11 (4+3+2+1+1) needs to be recorded in the total_num of the first queue. When the cache device determines whether the second metadata group has remaining free blocks, it is determined according to the total_num1 of each queue record in the multi-level queue.
具体地,参见图5,每个metadata_head对应一个第二元数据组,多级队列包括5个队列,其中,前两个队列中记录了第二元数据组,且第一队列只记录空闲块的个数小于等于4的第二元数据组。如图5中,第一队列记录的第二元数据组分别包含了4、3、2、1和1个空闲块,最后将各第二元数据组包含的空闲块的总数目记录到第一队列中,如,记录到第一个队列的total_num中,也即将11记录到第一队列的total_num中;同理,第二队列只记录空闲块的个数大于4的第二元数据组,第二队列记录的第二元数据组分别包含了7、6、5、5和5个空闲块,最后将第二个队列中各第二元数据组包含的空闲块的总数目也记录到第二队列中,也即将28(7+6+5+5+5)记录到第二个队列的total_num中。可选地,当所述多级队列的任一队列中记录多个所述第二元数据组时,则根据所述第二元数据组包含的空闲块的个数,对所述第二元数据组进行排列。Specifically, referring to FIG. 5, each metadata_head corresponds to a second metadata group, and the multi-level queue includes five queues, wherein the second metadata group is recorded in the first two queues, and the first queue only records the free blocks. A second metadata group with a number less than or equal to 4. As shown in FIG. 5, the second metadata group recorded in the first queue includes 4, 3, 2, 1, and 1 free blocks, and finally records the total number of free blocks included in each second metadata group to the first. In the queue, for example, it is recorded in the total_num of the first queue, and 11 is also recorded in the total_num of the first queue; similarly, the second queue only records the second metadata group whose number of free blocks is greater than 4, The second metadata group of the second queue record includes 7, 6, 5, 5, and 5 free blocks, and finally the total number of free blocks included in each second metadata group in the second queue is also recorded to the second. In the queue, 28 (7+6+5+5+5) is also recorded in the total_num of the second queue. Optionally, when a plurality of the second metadata groups are recorded in any one of the queues of the multi-level queue, the second element is obtained according to the number of free blocks included in the second metadata group. The data sets are arranged.
参见图5,前两个队列中记录了第二元数据组,第一个队列记录了5个第二元数据组,各第二元数据组分别包含了4、3、2、1和1个空闲块,且第一个队列中的各第二元数据组按照各自包含的空闲块的个数依次排列。具体地,第一队列中的各第二元数据组按照包含的空闲块的个数从大到小依次排列。第二个队列记录了5个第二元数据组,各第二元数据组分别包含了7、6、5、5和5个空闲块,且第二个队列中的各第二元数据组按照各自包含的空闲块的个数依次排列,也即第二队列中的各第二元数据组也按照包含的空闲块的个数从大到小依次排列。 Referring to FIG. 5, the second metadata group is recorded in the first two queues, and the first queue records five second metadata groups, and each second metadata group includes 4, 3, 2, 1, and 1 respectively. A free block, and each second metadata group in the first queue is sequentially arranged according to the number of free blocks respectively included. Specifically, each second metadata group in the first queue is arranged in descending order according to the number of free blocks included. The second queue records five second metadata groups, each of which contains 7, 6, 5, 5, and 5 free blocks, and each second metadata group in the second queue follows The number of free blocks included in each of the blocks is sequentially arranged, that is, each second metadata group in the second queue is also arranged in descending order of the number of free blocks included.
优选地,在判断第二元数据组中是否有剩余空闲块时,缓存装置优先判断多级队列中记录空闲块的个数的范围最大的队列中的total_num,如果其值为0,再判断多级队列中记录空闲块的个数的范围次大的队列中的total_num,这样依次类推;如果不为0,则获取该队列中包含空闲块的个数最多的第二元数据组,如前述例子中,各队列中的各第二元数据组是按照各自包含的空闲块的个数依次排列的,因此获取该队列中的第一个第二元数据组即可。如图5中,先判断第二个队列的total_num,该值为28不为0,则获取该队列中的第一个第二元数据组,该第二元数据组中包含7个空闲块,同时将该第二元数据组从上述队列中删除,同时更新上述队列的total_num,也即更新后的total_num=total_num-5。Preferably, when determining whether there are any remaining free blocks in the second metadata group, the cache device preferentially determines the total_num in the queue with the largest number of recorded free blocks in the multi-level queue, and if the value is 0, In the level queue, the total_num in the queue with the largest number of free blocks is recorded, and so on; if not, the second metadata group having the largest number of free blocks in the queue is obtained, as in the foregoing example. The second metadata group in each queue is sequentially arranged according to the number of free blocks included in each queue. Therefore, the first second metadata group in the queue may be acquired. As shown in FIG. 5, the total_num of the second queue is first determined. If the value is not 0, the first second metadata group in the queue is obtained, and the second metadata group includes 7 free blocks. At the same time, the second metadata group is deleted from the queue, and the total_num of the queue is updated, that is, the updated total_num=total_num-5.
需要说明的是,在判断多级队列中各队列的total_num均为0时,则缓存装置不对写入IO请求命令进行处理,将该写入IO请求命令加入到等待队列中,当第二元数据组中有剩余空闲块时,再对上述写入IO请求命令进行处理。It should be noted that, when it is determined that the total_num of each queue in the multi-level queue is 0, the cache device does not process the write IO request command, and adds the write IO request command to the waiting queue, when the second metadata When there are remaining free blocks in the group, the above write IO request command is processed.
对于上述获取到的第二元数据组,包含7个空闲块,从该7个空闲块中摘取一个空闲块,则上述第二元数据组包含的剩余空闲块为6个,并向上述摘取的一个空闲块中写入所述待写入数据的元数据。For the second metadata group obtained by the foregoing, including seven free blocks, and one free block is extracted from the seven free blocks, the second metadata group includes six remaining free blocks, and the foregoing The metadata of the data to be written is written in a free block.
S460,向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。S460. Write metadata of the data to be written into a metadata block corresponding to the second metadata group.
可选地,在S460之前,所述方法还可以包括:缓存装置将判断是否处理完成了所有的第一写入IO请求命令,如果没有处理完成,则继续对其他的第一写入IO请求命令作S420-S450的处理;如果已经处理完成,则判断这些写入IO请求命令是否可以合并,如果可以合并,则根据合并后的写入IO请求命令,向Flash中写入数据。本发明中,每次优先从第一元数据组中获取空闲块,由于从同一组中获取的空闲块的地址都是连续的,由此可以增加写入IO请求命令的合并概率,从而可以减小向Flash中写入数据的次数。Optionally, before S460, the method may further include: the cache device will determine whether all the first write IO request commands are processed, and if no processing is completed, continue to request the other first write IO requests. The processing of S420-S450; if the processing has been completed, it is judged whether these write IO request commands can be merged, and if they can be merged, the data is written to the Flash according to the merged write IO request command. In the present invention, each time a priority is obtained from the first metadata group, since the addresses of the free blocks acquired from the same group are consecutive, the merge probability of writing the IO request command can be increased, thereby reducing The number of times the data is written to Flash.
本发明实施例提供的向缓存中写入数据的方法,通过元数据组记录内存中的空闲块,当接收到写入IO请求命令时,从上述元数据组中获取空闲块,并将 上述写入IO请求命令中包括的待写入数据的元数据写入获取到的空闲块中,从而可以增大元数据的合并概率,进而可以解决频繁向Flash中写入元数据,而影响Flash的寿命的问题。The method for writing data to the cache provided by the embodiment of the present invention records a free block in the memory by the metadata group, and obtains a free block from the metadata group when receiving the write IO request command, and The metadata of the data to be written included in the write IO request command is written into the obtained free block, so that the merge probability of the metadata can be increased, thereby further solving the frequent writing of metadata to the Flash, and affecting the Flash. The problem of life.
对通过上述方法获取到的空闲块,当写入该空闲块的元数据为无效的元数据时,则缓存装置需要将该空闲块回收到内存中,具体地,将该空闲块重新加入到其所属的元数据组中。其中,回收空闲块的步骤可以包括:For the free block obtained by the above method, when the metadata written to the free block is invalid metadata, the cache device needs to reclaim the free block into the memory, specifically, re-add the free block to the free block. In the metadata group to which it belongs. The step of recovering the free block may include:
接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址;Receiving a recycle metadata instruction, where the recycle metadata command includes an address of a free block to which the metadata to be recovered belongs;
根据所述空闲块的地址,获取所述空闲块所属的元数据组;Obtaining, according to an address of the free block, a metadata group to which the free block belongs;
若所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序;And if the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group;
若所述元数据组为第二元数据组,则判断所述第二元数据组包含的空闲块个数是否大于第二阈值,若是,则从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则将所述空闲块加入所述第二元数据组中。If the metadata group is the second metadata group, determining whether the number of free blocks included in the second metadata group is greater than a second threshold, and if yes, deleting from the queue that records the second metadata group After the second metadata group is added to the second metadata group, the second metadata group is recorded in other queues of the multi-level queue, and if not, the free block is Join the second metadata set.
具体地,所述将所述第二元数据组记录到多级队列的其它队列中包括:Specifically, the recording the second metadata group into other queues of the multi-level queue includes:
根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的其它队列中。需要说明的是,判断所述第二元数据组包含的空闲块个数是否大于第二阈值的步骤,是为了确保能够根据第二元数据组包含的空闲块的个数,将第二元数据组记录到相应的队列中。例如,假设多级队列中有两个队列,第一队列只记录空闲块的个数小于等于8的第二元数据组,而第二队列记录空闲块的个数大于8的第二元数据组,且假设某一第二元数据组开始时包含的空闲块的个数为8个,则将该第二元数据组记录到第一队列中,当该第二元数据组回收到一个空闲块时,该第二元数据组包含的空闲块的个数为9个,不满足第一队列记录的第二元数据组的空闲块的个数。因此,需要将该第二元数据组记录到第二队列中。 The second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group. It should be noted that the step of determining whether the number of free blocks included in the second metadata group is greater than a second threshold is to ensure that the second metadata can be determined according to the number of free blocks included in the second metadata group. The group is logged to the appropriate queue. For example, suppose there are two queues in the multi-level queue, the first queue records only the second metadata group whose number of free blocks is less than or equal to 8, and the second queue records the second metadata group whose number of free blocks is greater than 8. And assuming that the number of free blocks included in a certain second metadata group is eight, the second metadata group is recorded in the first queue, and when the second metadata group recovers a free block The number of free blocks included in the second metadata group is nine, and the number of free blocks of the second metadata group recorded in the first queue is not satisfied. Therefore, the second metadata set needs to be recorded in the second queue.
可选地,在所述从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中之后,所述方法还包括:Optionally, deleting the second metadata group in the queue from which the second metadata group is recorded, adding the free block to the second metadata group, and then using the second metadata After the group is recorded in other queues of the multi-level queue, the method further includes:
更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。Updating the total number of free blocks recorded in the queue of the second metadata group, and updating the total number of free blocks recorded in the queue joined by the second metadata group.
如前述例子中,更新第一队列的total_num,也即第一队列更新后的total_num=total_num-8;同时更新第二队列的total_num,也即第二队列更新后的total_num=total_num+8+1;其中,1为上述第二元数据组新回收的空闲块。As in the foregoing example, the total_num of the first queue is updated, that is, the total_num=total_num-8 after the first queue is updated; and the total_num of the second queue is updated, that is, the total_num=total_num+8+1 after the second queue is updated; Where 1 is a free block newly collected by the second metadata group.
通过上述回收空闲块的步骤,可以将回收的空闲块回收到其所属的元数据组中,从而可以保证通过本发明的方法,在获取空闲块时,获取到的空闲块的地址是连续的,由此可以增大元数据的合并概率,进而可以解决频繁向Flash中写入元数据,而影响Flash的寿命的问题。The reclaimed free block can be reclaimed into the metadata group to which it belongs, so that the address of the obtained free block is consecutive when the free block is obtained by the method of the present invention. Thereby, the merge probability of the metadata can be increased, and the problem that the metadata is frequently written into the Flash and affects the lifetime of the Flash can be solved.
本发明实施例提供了的方法,通过元数据管理,结合元数据合并,大大增加元数据合并的概率,从而可以大量的减少元数据IO,对提供系统的性能具体重大的作用,同时建设写IO的次数,大量的减少因为元数据的操作IO,对提高FLASH卡的寿命具体重大的作用。The method provided by the embodiment of the invention, through metadata management, combined with metadata merging, greatly increases the probability of metadata merging, thereby greatly reducing the metadata IO, and has a significant effect on the performance of the providing system, and simultaneously constructing the IO. The number of times, a large reduction in the operation of IO due to metadata, has a significant effect on improving the life of the FLASH card.
对于大块的IO,通过元数据管理,尽量对大块的IO,分配的空闲块在物理卡中的位置也是尽量连在一起的,这样的带来的作用,可以通过WriteV接口,把几个IO进行合并写,在大块的场景中,可以大量的减少IO的次数,可以大大的降低系统的CPU的利用率,通过实际的测试,在大块的场景中,CPU的利用率可以减少20-30%。For large IOs, through metadata management, as far as possible for large IOs, the location of allocated free blocks in the physical card is also as close as possible. This can be achieved through the WriteV interface. IO performs merge writing. In a large-scale scenario, the number of IOs can be reduced a lot, which can greatly reduce the CPU utilization of the system. Through actual testing, CPU utilization can be reduced in large scenarios. -30%.
由于在分配空闲块的时候,IO的物理位置是尽量连在一起的,所以在刷盘的时候,在大块场景中,或者顺序IO的场景中,降大大的增加读合并的效果;也可以大量的减少读IO的请求,对降低CPU的利用率作用非常大。Since the physical positions of the IOs are connected as much as possible when the free blocks are allocated, the effect of reading and merging is greatly increased in the scenes of the large blocks or in the sequential IO when the disk is swiped; A large number of requests to reduce IO read are very effective in reducing CPU utilization.
图6为本发明实施例二提供的向Cache中写入数据的装置示意图。所述装置用于执行图4所述的方法。图6中,该装置的闪存Flash的存储区域包括多个存储块chunk,一个所述chunk包括一个chunk元数据区和一个chunk数据 区,所述一个chunk元数据区包括至少一个元数据块,所述一个chunk数据区包括与所述至少一个元数据块对应的至少一个数据区,所述元数据块包括多个元数据,所述数据区包括多个数据块,所述元数据块与所述数据区一一对应,所述元数据与所述数据块一一对应,包括:接收单元601、第一获取单元602、判断单元603、第一写入单元604、第二获取单元605和第二写入单元606。FIG. 6 is a schematic diagram of an apparatus for writing data to a Cache according to Embodiment 2 of the present invention. The apparatus is for performing the method described in FIG. In FIG. 6, the storage area of the flash memory of the device includes a plurality of memory blocks chunk, and the chunk includes a chunk metadata area and a chunk data. a chunk metadata area including at least one metadata block, the one chunk data area including at least one data area corresponding to the at least one metadata block, the metadata block including a plurality of metadata, The data area includes a plurality of data blocks, the metadata block is in one-to-one correspondence with the data area, and the metadata is in one-to-one correspondence with the data block, and includes: a receiving unit 601, a first obtaining unit 602, and a determining unit. 603. A first writing unit 604, a second obtaining unit 605, and a second writing unit 606.
接收单元601,用于接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据。The receiving unit 601 is configured to receive a write IO request command, where the write IO request command includes metadata of the data to be written.
第一获取单元602,用于获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存中的多个空闲块。The first obtaining unit 602 is configured to acquire a metadata group currently being processed into a first metadata group, where the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory.
判断单元603,用于判断第一获取单元602获取的所述第一元数据组中是否有剩余空闲块。The determining unit 603 is configured to determine whether there are any remaining free blocks in the first metadata group acquired by the first obtaining unit 602.
第一写入单元604,用于当判断单元603判断所述第一元数据组中有剩余空闲块时,则向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据。a first writing unit 604, configured to: when the determining unit 603 determines that there are remaining free blocks in the first metadata group, write the element of the data to be written to one of the remaining free blocks Data, and writing metadata of the data to be written into a metadata block corresponding to the first metadata group.
第二获取单元605,用于当判断单元603判断所述第一元数据组中没有剩余空闲块时,则判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据。The second obtaining unit 605 is configured to: when the determining unit 603 determines that there are no free blocks remaining in the first metadata group, determine whether the second metadata group has remaining free blocks, where the second metadata group is currently not In the processed metadata group, if the second metadata group has remaining free blocks, acquiring the second metadata group and writing to one of the remaining free blocks of the second metadata group The metadata of the data to be written.
第二写入单元606,用于向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。The second writing unit 606 is configured to write the metadata of the data to be written into the metadata block corresponding to the second metadata group.
可选地,所述元数据组中包含的空闲块的个数是根据所述元数据块的大小和所述数据块对应的元数据的大小计算得到的。Optionally, the number of free blocks included in the metadata group is calculated according to a size of the metadata block and a size of metadata corresponding to the data block.
可选地,所述元数据组中包含的空闲块是按地址连续排列的。Optionally, the free blocks included in the metadata group are consecutively arranged by address.
可选地,所述多级队列中各队列记录的第二元数据组包含的空闲块的个数是不相同的。Optionally, the number of free blocks included in the second metadata group recorded by each queue in the multi-level queue is different.
可选地,所述装置还包括:记录单元607,用于根据所述第二元数据组包 含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;Optionally, the device further includes: a recording unit 607, configured to perform, according to the second metadata group package The number of the free blocks included, the second metadata group is recorded in each queue of the multi-level queue, and the queues further include the total number of free blocks included in each second metadata group recorded by the queue;
第二获取单元605具体用于:根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。The second obtaining unit 605 is specifically configured to: determine, according to the total number of free blocks included in each second metadata group recorded in each queue, whether the second metadata group has remaining free blocks.
可选地,装置还包括:拆分单元608。Optionally, the device further includes: a splitting unit 608.
判断单元603,还用于根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分。The determining unit 603 is further configured to determine, according to the size of the data block, whether the write IO request command needs to be split.
拆分单元608,用于若判断单元603判断需要进行拆分,则根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令。The splitting unit 608 is configured to, if the determining unit 603 determines that splitting is required, split the write IO request command according to the size of the data block to obtain a plurality of first write IO request commands.
判断单元603,还用于对拆分单元608得到的所述多个第一写入IO请求命令,分别判断所述各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。The determining unit 603 is further configured to determine, by the splitting unit 608, the plurality of first write IO request commands, respectively, whether the metadata of the data to be written included in each of the first write IO request commands has been The cache is in the memory, if yes, the write operation is directly performed, and if not, the step of acquiring the metadata group currently being processed is the first metadata group.
可选地,所述装置还包括:排列单元609,用于当所述多级队列中任一队列记录多个第二元数据组时,则根据所述第二元数据组包含的空闲块的个数,对所述多个第二元数据组进行排列。Optionally, the device further includes: an arranging unit 609, configured to: when any one of the plurality of queues records a plurality of second metadata groups, according to the free blocks included in the second metadata group The plurality of second metadata groups are arranged.
可选地,所述装置还包括:加入单元610。Optionally, the device further includes: an adding unit 610.
接收单元601,还用于接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址。The receiving unit 601 is further configured to receive a reclaiming metadata instruction, where the reclaiming metadata instruction includes an address of an associated free block of the metadata to be reclaimed.
第一获取单元602,还用于根据接收单元601接收的所述空闲块的地址,获取所述空闲块所属的元数据组。The first obtaining unit 602 is further configured to acquire, according to the address of the free block received by the receiving unit 601, a metadata group to which the free block belongs.
加入单元610,用于若第一获取单元602获取的所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序。The joining unit 610 is configured to add the free block to the first metadata group if the metadata group acquired by the first obtaining unit 602 is a first metadata group, and add the first metadata to the first metadata group Free blocks in the group are reordered.
判断单元603,还用于若第一获取单元602获取的所述元数据组为第二元数据组,则判断所述第二元数据组包含的空闲块个数是否大于第二阈值,若是,则从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加 入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则将所述空闲块加入所述第二元数据组中。The determining unit 603 is further configured to: if the metadata group acquired by the first obtaining unit 602 is a second metadata group, determine whether the number of free blocks included in the second metadata group is greater than a second threshold, and if yes, And deleting the second metadata group from the queue that records the second metadata group, adding the free block After entering the second metadata group, the second metadata group is recorded into other queues of the multi-level queue, and if not, the free block is added to the second metadata group.
可选地,判断单元603具体用于:Optionally, the determining unit 603 is specifically configured to:
根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的其它队列中。The second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
可选地,所述装置还包括:更新单元611,用于更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。Optionally, the device further includes: an updating unit 611, configured to update a total number of free blocks recorded in a queue in which the second metadata group is recorded, and update a record in a queue in which the second metadata group is added The total number of free blocks.
本发明实施例提供的向缓存中写入数据的装置,通过元数据组记录内存中的空闲块,当接收到写入IO请求命令时,从上述元数据组中获取空闲块,并将上述写入IO请求命令中包括的待写入数据的元数据写入获取到的空闲块中,从而可以增大元数据的合并概率,进而可以解决频繁向Flash中写入元数据,而影响Flash的寿命的问题。The device for writing data to the cache provided by the embodiment of the present invention records a free block in the memory through a metadata group, and when receiving the write IO request command, acquires a free block from the metadata group, and writes the above The metadata of the data to be written included in the IO request command is written into the obtained free block, thereby increasing the merge probability of the metadata, thereby solving the problem of frequently writing metadata to the Flash and affecting the life of the Flash. The problem.
相应的,本发明实施例还提供了一种计算存储一体机,如图7所示,包括使用闪存Flash 701的cache(图中仅示出Flash 701)、内存702和处理器703。Correspondingly, the embodiment of the present invention further provides a computing and storage machine. As shown in FIG. 7, the cache includes a flash memory 701 (only the Flash 701 is shown), the memory 702, and the processor 703.
闪存Flash 701的存储区域包括多个存储块chunk,一个所述chunk包括一个chunk元数据区和一个chunk数据区,所述一个chunk元数据区包括至少一个元数据块,所述一个chunk数据区包括与所述至少一个元数据块对应的至少一个数据区,所述元数据块包括多个元数据,所述数据区包括多个数据块,所述元数据块与所述数据区一一对应,所述元数据与所述数据块一一对应。The storage area of the flash Flash 701 includes a plurality of storage block chunks, one of the chunks includes a chunk metadata area and a chunk data area, the one chunk metadata area includes at least one metadata block, and the one chunk data area includes And at least one data area corresponding to the at least one metadata block, the metadata block includes a plurality of metadata, the data area includes a plurality of data blocks, and the metadata block has a one-to-one correspondence with the data area, The metadata corresponds to the data block one-to-one.
处理器703接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据;The processor 703 receives a write IO request command, the write IO request command including metadata of the data to be written;
处理器703获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存702中的多个空闲块;The processor 703 acquires a metadata group currently being processed into a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory 702;
处理器703判断所述第一元数据组中是否有剩余空闲块;The processor 703 determines whether there are any remaining free blocks in the first metadata group;
当所述第一元数据组中有剩余空闲块时,处理器703向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的 元数据块中写入所述待写入数据的元数据;When there are remaining free blocks in the first metadata group, the processor 703 writes the metadata of the data to be written to one of the remaining free blocks, and the first metadata is Group corresponding Writing metadata of the data to be written in the metadata block;
当所述第一元数据组中没有剩余空闲块时,处理器703判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据;When there is no free block remaining in the first metadata group, the processor 703 determines whether the second metadata group has remaining free blocks, and the second metadata group is a metadata group that is not currently processed, if And the second metadata group has the remaining free blocks, the second metadata group is acquired, and the metadata of the to-be-written data is written to one of the remaining free blocks of the second metadata group;
处理器703向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。The processor 703 writes the metadata of the data to be written into the metadata block corresponding to the second metadata group.
进一步的,所述元数据组中包含的空闲块的个数是处理器703根据所述元数据块的大小和所述数据块对应的元数据的大小计算得到的。Further, the number of free blocks included in the metadata group is calculated by the processor 703 according to the size of the metadata block and the size of the metadata corresponding to the data block.
进一步的,所述元数据组中包含的空闲块是按地址连续排列的。Further, the free blocks included in the metadata group are consecutively arranged by address.
进一步的,所述元数据组中包含的空闲块的个数被记录在内存702的多级队列中,其中,所述多级队列中各队列记录的第二元数据组包含的空闲块的个数是不相同的。Further, the number of free blocks included in the metadata group is recorded in a multi-level queue of the memory 702, wherein the second metadata group of each queue record in the multi-level queue includes a free block The numbers are not the same.
进一步的,处理器703根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;Further, the processor 703 records the second metadata group into each queue of the multi-level queue according to the number of free blocks included in the second metadata group, where each queue further includes the queue record. The total number of free blocks included in each second metadata group;
处理器703根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。The processor 703 determines whether the second metadata group has remaining free blocks according to the total number of free blocks included in each second metadata group recorded in each queue.
进一步的,在处理器703接收写入IO请求命令之后,并且在获取当前正在处理的元数据组为第一元数据组之前,处理器703还根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分;Further, after the processor 703 receives the write IO request command, and before acquiring the metadata group currently being processed as the first metadata group, the processor 703 further determines, according to the size of the data block, whether the Write the IO request command for splitting;
若需要进行拆分,则处理器703根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令;If the splitting is required, the processor 703 splits the write IO request command according to the size of the data block to obtain a plurality of first write IO request commands.
处理器703对所述多个第一写入IO请求命令,分别判断各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。 The processor 703 requests the plurality of first write IOs to determine whether the metadata of the data to be written included in each first write IO request command is cached in the memory, and if so, directly A write operation is performed, and if not, a step of acquiring the metadata group currently being processed as the first metadata group is performed.
进一步的,当所述多级队列中任一队列记录多个第二元数据组时,处理器703根据所述第二元数据组包含的空闲块的个数,对所述多个第二元数据组进行排列。Further, when any one of the multi-level queues records a plurality of second metadata groups, the processor 703 pairs the plurality of second elements according to the number of free blocks included in the second metadata group. The data sets are arranged.
进一步的,处理器703接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址;根据所述空闲块的地址,获取所述空闲块所属的元数据组;若所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序;若所述元数据组为第二元数据组,则处理器703判断所述第二元数据组包含的空闲块个数是否大于第二阈值,若是,则处理器703从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则处理器703将所述空闲块加入所述第二元数据组中。其中,将所述第二元数据组记录到多级队列的其它队列中包括:根据所述第二元数据组包含的空闲块的个数,处理器703将所述第二元数据组记录到多级队列的其它队列中。Further, the processor 703 receives the reclaimed metadata instruction, where the reclaimed metadata instruction includes an address of the associated free block of the metadata to be recovered; and acquires the metadata group to which the free block belongs according to the address of the free block; If the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group; if the metadata If the group is a second metadata group, the processor 703 determines whether the number of free blocks included in the second metadata group is greater than a second threshold, and if so, the processor 703 records from the queue that records the second metadata group. Deleting the second metadata group, adding the free metadata block to the second metadata group, and recording the second metadata group to other queues of the multi-level queue, if not, the processor 703 The free block is added to the second metadata group. The recording, by the second metadata group to the other queues of the multi-level queue, includes: according to the number of free blocks included in the second metadata group, the processor 703 records the second metadata group to In other queues of multi-level queues.
再进一步的,在处理器703将第二元数据组记录到多级队列的其它队列中之后,处理器703更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。Still further, after the processor 703 records the second metadata group in other queues of the multi-level queue, the processor 703 updates the total number of free blocks recorded in the queue in which the second metadata group is recorded, and updates The total number of free blocks recorded in the queue to which the second metadata group is added.
本发明实施例提供的计算存储一体机,通过元数据组记录内存中的空闲块,当接收到写入IO请求命令时,从上述元数据组中获取空闲块,并将上述写入IO请求命令中包括的待写入数据的元数据写入获取到的空闲块中,从而可以增大元数据的合并概率,进而可以解决频繁向Flash中写入元数据,而影响Flash的寿命的问题。The computing and storage integrated machine provided by the embodiment of the present invention records a free block in the memory through the metadata group, and when receiving the write IO request command, acquires the free block from the metadata group, and writes the above IO request command. The metadata included in the data to be written is written into the obtained free block, so that the merge probability of the metadata can be increased, thereby solving the problem that the metadata is frequently written into the Flash and affecting the lifetime of the Flash.
专业人员应该还可以进一步意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用 来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明的范围。A person skilled in the art should further appreciate that the elements and algorithm steps of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both, in order to clearly illustrate hardware and software. Interchangeability, the composition and steps of the various examples have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the solution. Professional technicians can apply to each specific application Different methods are used to implement the described functionality, but such implementation should not be considered to be beyond the scope of the present invention.
结合本文中所公开的实施例描述的方法或算法的步骤可以用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的存储介质中。The steps of a method or algorithm described in connection with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be placed in random access memory (RAM), memory, read only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or technical field. Any other form of storage medium known.
以上所述的具体实施方式,对本发明的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上所述仅为本发明的具体实施方式而已,并不用于限定本发明的保护范围,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。 The specific embodiments of the present invention have been described in detail with reference to the preferred embodiments of the present invention. All modifications, equivalent substitutions, improvements, etc., made within the spirit and scope of the invention are intended to be included within the scope of the invention.

Claims (20)

  1. 一种向缓存Cache中写入数据的方法,其特征在于,所述Cache的闪存Flash的存储区域包括多个存储块chunk,一个所述chunk包括一个chunk元数据区和一个chunk数据区,所述一个chunk元数据区包括至少一个元数据块,所述一个chunk数据区包括与所述至少一个元数据块对应的至少一个数据区,所述元数据块包括多个元数据,所述数据区包括多个数据块,所述元数据块与所述数据区一一对应,所述元数据与所述数据块一一对应,所述方法包括:A method for writing data to a cache cache, wherein a storage area of the flash memory of the cache includes a plurality of storage blocks chunk, and the chunk includes a chunk metadata area and a chunk data area, A chunk metadata area includes at least one metadata block, the one chunk data area includes at least one data area corresponding to the at least one metadata block, the metadata block includes a plurality of metadata, and the data area includes a plurality of data blocks, the metadata block is in one-to-one correspondence with the data area, and the metadata is in one-to-one correspondence with the data block, and the method includes:
    接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据;Receiving a write IO request command, the write IO request command including metadata of data to be written;
    获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存中的多个空闲块;Obtaining a metadata group currently being processed as a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory;
    判断所述第一元数据组中是否有剩余空闲块;Determining whether there are any remaining free blocks in the first metadata group;
    当所述第一元数据组中有剩余空闲块时,则向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据;When there are remaining free blocks in the first metadata group, write metadata of the data to be written to one of the remaining free blocks, and correspond to the first metadata group The metadata of the data to be written is written in the metadata block;
    当所述第一元数据组中没有剩余空闲块时,则判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据;When there is no free block remaining in the first metadata group, it is determined whether the second metadata group has remaining free blocks, and the second metadata group is a metadata group that is not currently processed, if the second If the metadata group has remaining free blocks, the second metadata group is acquired, and the metadata of the data to be written is written to one of the remaining free blocks of the second metadata group;
    向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。The metadata of the data to be written is written into a metadata block corresponding to the second metadata group.
  2. 根据权利要求1所述的方法,其特征在于,所述元数据组中包含的空闲块的个数是根据所述元数据块的大小和所述数据块对应的元数据的大小计算得到的。The method according to claim 1, wherein the number of free blocks included in the metadata group is calculated according to a size of the metadata block and a size of metadata corresponding to the data block.
  3. 根据权利要求1所述的方法,其特征在于,所述元数据组中包含的空闲块是按地址连续排列的。 The method according to claim 1, wherein the free blocks included in the metadata group are consecutively arranged by address.
  4. 根据权利要求1所述的方法,其特征在于,所述元数据组中包含的空闲块的个数被记录在内存的多级队列中,其中,所述多级队列中各队列记录的第二元数据组包含的空闲块的个数是不相同的。The method according to claim 1, wherein the number of free blocks included in the metadata group is recorded in a multi-level queue of a memory, wherein a second record of each queue in the multi-level queue The number of free blocks contained in the metadata group is different.
  5. 根据权利要求4所述的方法,其特征在于,所述方法还包括:The method of claim 4, wherein the method further comprises:
    根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;And the second metadata group is recorded in each queue of the multi-level queue according to the number of the free blocks included in the second metadata group, where each queue further includes each second metadata group recorded by the queue The total number of free blocks included;
    所述判断第二元数据组是否有剩余空闲块包括:The determining whether the second metadata group has remaining free blocks includes:
    根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。It is determined whether the second metadata group has remaining free blocks according to the total number of free blocks included in each second metadata group recorded by each queue.
  6. 根据权利要求1-5任一所述的方法,其特征在于,在所述接收写入IO请求命令之后,在所述获取当前正在处理的元数据组为第一元数据组之前,所述方法还包括:The method according to any one of claims 1 to 5, characterized in that, after the receiving a write IO request command, before the acquiring the metadata group currently being processed is the first metadata group, the method Also includes:
    根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分;Determining whether the write IO request command needs to be split according to the size of the data block;
    若需要进行拆分,则根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令;If the splitting is required, splitting the write IO request command according to the size of the data block, and obtaining a plurality of first write IO request commands;
    对所述多个第一写入IO请求命令,分别判断各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。Determining, by the plurality of first write IO request commands, whether metadata of the data to be written included in each first write IO request command is already cached in the memory, and if so, directly performing a write operation If no, the step of obtaining the metadata group currently being processed is the first metadata group.
  7. 根据权利要求5所述的方法,其特征在于,当所述多级队列中任一队列记录多个第二元数据组时,则根据所述第二元数据组包含的空闲块的个数,对所述多个第二元数据组进行排列。 The method according to claim 5, wherein when any one of the plurality of queues records a plurality of second metadata groups, according to the number of free blocks included in the second metadata group, Arranging the plurality of second metadata groups.
  8. 根据权利要求4所述的方法,其特征在于,所述方法还包括:The method of claim 4, wherein the method further comprises:
    接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址;Receiving a recycle metadata instruction, where the recycle metadata command includes an address of a free block to which the metadata to be recovered belongs;
    根据所述空闲块的地址,获取所述空闲块所属的元数据组;Obtaining, according to an address of the free block, a metadata group to which the free block belongs;
    若所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序;And if the metadata group is a first metadata group, adding the free block to the first metadata group, and reordering the free blocks in the first metadata group;
    若所述元数据组为第二元数据组,则判断所述第二元数据组包含的空闲块个数是否大于第二阈值,若是,则从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则将所述空闲块加入所述第二元数据组中。If the metadata group is the second metadata group, determining whether the number of free blocks included in the second metadata group is greater than a second threshold, and if yes, deleting from the queue that records the second metadata group After the second metadata group is added to the second metadata group, the second metadata group is recorded in other queues of the multi-level queue, and if not, the free block is Join the second metadata set.
  9. 根据权利要求8所述的方法,其特征在于,所述将所述第二元数据组记录到多级队列的其它队列中包括:The method according to claim 8, wherein the recording the second metadata group to other queues of the multi-level queue comprises:
    根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的其它队列中。The second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
  10. 根据权利要求8或9所述的方法,其特征在于,在所述从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中之后,所述方法还包括:The method according to claim 8 or 9, wherein said second metadata group is deleted from said queue for recording said second metadata group, said free block being added to said second element After the data group is recorded in the other queues of the multi-level queue, the method further includes:
    更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。Updating the total number of free blocks recorded in the queue of the second metadata group, and updating the total number of free blocks recorded in the queue joined by the second metadata group.
  11. 一种向缓存Cache中写入数据的装置,其特征在于,所述装置的闪存Flash的存储区域包括多个存储块chunk,一个所述chunk包括一个chunk元数据区和一个chunk数据区,所述一个chunk元数据区包括至少一个元数据 块,所述一个chunk数据区包括与所述至少一个元数据块对应的至少一个数据区,所述元数据块包括多个元数据,所述数据区包括多个数据块,所述元数据块与所述数据区一一对应,所述元数据与所述数据块一一对应,所述装置包括:接收单元、第一获取单元、判断单元、第一写入单元、第二获取单元和第二写入单元;An apparatus for writing data to a cache cache, wherein a storage area of a flash memory of the device includes a plurality of storage blocks chunk, and the chunk includes a chunk metadata area and a chunk data area, A chunk metadata area includes at least one metadata Block, the one chunk data area includes at least one data area corresponding to the at least one metadata block, the metadata block includes a plurality of metadata, and the data area includes a plurality of data blocks, the metadata block Corresponding to the data area, the metadata is in one-to-one correspondence with the data block, and the apparatus includes: a receiving unit, a first acquiring unit, a determining unit, a first writing unit, a second acquiring unit, and a first Two write units;
    所述接收单元,用于接收写入IO请求命令,所述写入IO请求命令包括待写入数据的元数据;The receiving unit is configured to receive a write IO request command, where the write IO request command includes metadata of data to be written;
    所述第一获取单元,用于获取当前正在处理的元数据组为第一元数据组,一个所述元数据组对应于一个所述元数据块,包含内存中的多个空闲块;The first obtaining unit is configured to acquire a metadata group currently being processed into a first metadata group, and the one metadata group corresponds to one of the metadata blocks, and includes a plurality of free blocks in the memory;
    所述判断单元,用于判断所述第一获取单元获取的所述第一元数据组中是否有剩余空闲块;The determining unit is configured to determine whether there is any remaining free block in the first metadata group acquired by the first acquiring unit;
    所述第一写入单元,用于当所述判断单元判断所述第一元数据组中有剩余空闲块时,则向所述剩余空闲块中的一个空闲块写入所述待写入数据的元数据,并向与所述第一元数据组对应的元数据块中写入所述待写入数据的元数据;The first writing unit is configured to: when the determining unit determines that there are remaining free blocks in the first metadata group, write the data to be written to one of the remaining free blocks Metadata, and writing metadata of the data to be written into a metadata block corresponding to the first metadata group;
    所述第二获取单元,用于当所述判断单元判断所述第一元数据组中没有剩余空闲块时,则判断第二元数据组是否有剩余空闲块,所述第二元数据组为当前未在处理的元数据组,若所述第二元数据组有剩余空闲块,则获取所述第二元数据组,并向所述第二元数据组的剩余空闲块中的一个空闲块写入所述待写入数据的元数据;The second obtaining unit is configured to: when the determining unit determines that there are no free blocks in the first metadata group, determine whether the second metadata group has remaining free blocks, where the second metadata group is a metadata group currently not being processed, if the second metadata group has remaining free blocks, acquiring the second metadata group, and to a free block in the remaining free blocks of the second metadata group Writing metadata of the data to be written;
    所述第二写入单元,用于向与所述第二元数据组对应的元数据块中写入所述待写入数据的元数据。The second writing unit is configured to write metadata of the data to be written into a metadata block corresponding to the second metadata group.
  12. 根据权利要求11所述的装置,其特征在于,所述元数据组中包含的空闲块的个数是根据所述元数据块的大小和所述数据块对应的元数据的大小计算得到的。The apparatus according to claim 11, wherein the number of free blocks included in the metadata group is calculated according to a size of the metadata block and a size of metadata corresponding to the data block.
  13. 根据权利要求11所述的装置,其特征在于,所述元数据组中包含的空 闲块是按地址连续排列的。The apparatus according to claim 11, wherein said metadata group contains an empty space The free blocks are arranged consecutively by address.
  14. 根据权利要求11所述的方法,其特征在于,所述元数据组中包含的空闲块的个数被记录在内存的多级队列中,其中,所述多级队列中各队列记录的第二元数据组包含的空闲块的个数是不相同的。The method according to claim 11, wherein the number of free blocks included in the metadata group is recorded in a multi-level queue of the memory, wherein the second record of each queue in the multi-level queue The number of free blocks contained in the metadata group is different.
  15. 根据权利要求14所述的装置,其特征在于,所述装置还包括:记录单元,用于根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的各队列中,所述各队列还包括该队列记录的各第二元数据组包含的空闲块的总数目;The apparatus according to claim 14, wherein the apparatus further comprises: a recording unit, configured to record the second metadata group according to the number of free blocks included in the second metadata group In each queue of the multi-level queue, the queues further include a total number of free blocks included in each second metadata group recorded by the queue;
    所述第二获取单元具体用于:根据各队列记录的各第二元数据组包含的空闲块的总数目,判断第二元数据组是否有剩余空闲块。The second acquiring unit is specifically configured to: determine, according to the total number of free blocks included in each second metadata group recorded in each queue, whether the second metadata group has remaining free blocks.
  16. 根据权利要求11-15任一所述的装置,其特征在于,装置还包括:拆分单元;The device according to any one of claims 11-15, wherein the device further comprises: a splitting unit;
    所述判断单元,还用于根据所述数据块的大小,判断是否需要对所述写入IO请求命令进行拆分;The determining unit is further configured to determine, according to the size of the data block, whether the write IO request command needs to be split;
    所述拆分单元,用于若所述判断单元判断需要进行拆分,则根据所述数据块的大小,对所述写入IO请求命令进行拆分,得到多个第一写入IO请求命令;The splitting unit is configured to: if the determining unit determines that splitting is required, split the write IO request command according to the size of the data block, to obtain a plurality of first write IO request commands ;
    所述判断单元,还用于对所述拆分单元得到的所述多个第一写入IO请求命令,分别判断各个第一写入IO请求命令中包括的待写入数据的元数据是否已缓存在所述内存中,如果是,则直接进行写操作,如果否,则执行获取当前正在处理的元数据组为第一元数据组的步骤。The determining unit is further configured to determine, by the splitting unit, the plurality of first write IO request commands, respectively, whether the metadata of the data to be written included in each first write IO request command has been The cache is in the memory, if yes, the write operation is directly performed, and if not, the step of acquiring the metadata group currently being processed is the first metadata group.
  17. 根据权利要求15所述的装置,其特征在于,所述装置还包括:排列单元,用于当所述多级队列中任一队列记录多个第二元数据组时,则根据所述第二元数据组包含的空闲块的个数,对所述多个第二元数据组进行排列。 The device according to claim 15, wherein the device further comprises: an arranging unit, configured to: when any one of the plurality of queues records a plurality of second metadata groups, according to the second The number of free blocks included in the metadata group is arranged for the plurality of second metadata groups.
  18. 根据权利要求14所述的装置,其特征在于,所述装置还包括:加入单元;The device according to claim 14, wherein the device further comprises: a joining unit;
    所述接收单元,还用于接收回收元数据指令,所述回收元数据指令包括待回收元数据的所属的空闲块的地址;The receiving unit is further configured to receive a recovery metadata instruction, where the recovery metadata instruction includes an address of an associated free block of the metadata to be recovered;
    所述第一获取单元,还用于根据所述接收单元接收的所述空闲块的地址,获取所述空闲块所属的元数据组;The first obtaining unit is further configured to acquire, according to an address of the free block received by the receiving unit, a metadata group to which the free block belongs;
    所述加入单元,用于若所述第一获取单元获取的所述元数据组为第一元数据组,则将所述空闲块加入所述第一元数据组中,并对所述第一元数据组中的空闲块重新排序;The joining unit is configured to add the free block to the first metadata group if the metadata group acquired by the first acquiring unit is a first metadata group, and add the first Free block reordering in the metadata group;
    所述判断单元,还用于若所述第一获取单元获取的所述元数据组为第二元数据组,则判断所述第二元数据组包含的空闲块个数是否大于第二阈值,若是,则从记录所述第二元数据组的队列中删除所述第二元数据组,将所述空闲块加入所述第二元数据组后,将所述第二元数据组记录到多级队列的其它队列中,若否,则将所述空闲块加入所述第二元数据组中。The determining unit is further configured to: if the metadata group acquired by the first acquiring unit is a second metadata group, determine whether the number of free blocks included in the second metadata group is greater than a second threshold, If yes, deleting the second metadata group from the queue that records the second metadata group, adding the free block to the second metadata group, and recording the second metadata group to a plurality of In other queues of the level queue, if not, the free block is added to the second metadata group.
  19. 根据权利要求18所述的装置,其特征在于,所述判断单元具体用于:The device according to claim 18, wherein the determining unit is specifically configured to:
    根据所述第二元数据组包含的空闲块的个数,将所述第二元数据组记录到多级队列的其它队列中。The second metadata group is recorded into other queues of the multi-level queue according to the number of free blocks included in the second metadata group.
  20. 根据权利要求18或19所述的装置,其特征在于,所述装置还包括:更新单元,用于更新记录所述第二元数据组的队列中记录的空闲块的总数目,并更新所述第二元数据组加入的队列中记录的空闲块的总数目。 The apparatus according to claim 18 or 19, wherein the apparatus further comprises: an updating unit, configured to update a total number of free blocks recorded in a queue in which the second metadata group is recorded, and update the The total number of free blocks recorded in the queue joined by the second metadata group.
PCT/CN2015/083383 2014-09-16 2015-07-06 Method and device for writing data to cache WO2016041401A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410471711.7 2014-09-16
CN201410471711.7A CN104238962B (en) 2014-09-16 2014-09-16 The method and device of data is write into caching

Publications (1)

Publication Number Publication Date
WO2016041401A1 true WO2016041401A1 (en) 2016-03-24

Family

ID=52227129

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/083383 WO2016041401A1 (en) 2014-09-16 2015-07-06 Method and device for writing data to cache

Country Status (2)

Country Link
CN (1) CN104238962B (en)
WO (1) WO2016041401A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035065A (en) * 2020-08-28 2020-12-04 北京浪潮数据技术有限公司 Data writing method, device and equipment and computer readable storage medium
TWI793644B (en) * 2020-07-23 2023-02-21 英商Arm股份有限公司 Cache arrangements for data processing systems

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104238962B (en) * 2014-09-16 2018-02-06 华为技术有限公司 The method and device of data is write into caching
CN104778131B (en) * 2015-04-29 2017-07-21 浪潮电子信息产业股份有限公司 A kind of data cache method and a kind of buffer storage
CN106445405B (en) * 2015-08-13 2020-02-07 北京忆恒创源科技有限公司 Data access method and device for flash memory storage
CN105117351B (en) * 2015-09-08 2018-07-03 华为技术有限公司 To the method and device of buffering write data
CN107250992B (en) * 2015-11-13 2020-08-07 华为技术有限公司 File writing method and file server
KR20190032809A (en) * 2017-09-20 2019-03-28 에스케이하이닉스 주식회사 Memory system and operating method thereof
CN109683823B (en) * 2018-12-20 2022-02-11 湖南国科微电子股份有限公司 Method and device for managing multiple concurrent requests of memory
CN110007853B (en) * 2019-01-30 2022-06-28 镕铭微电子(济南)有限公司 Nandflash command processing method, Nandflash command processing device, terminal and storage medium
CN110968268B (en) * 2019-11-15 2023-03-17 成都智邦科技有限公司 Storage management method and storage structure based on spiflash
CN113467698A (en) * 2020-03-30 2021-10-01 珠海全志科技股份有限公司 Writing method and device based on file system, computer equipment and storage medium
CN113050893B (en) * 2021-03-30 2022-08-30 重庆紫光华山智安科技有限公司 High-concurrency file storage method, system, medium and electronic terminal

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120079231A1 (en) * 2010-09-23 2012-03-29 Phison Electronics Corp. Data writing method, memory controller, and memory storage apparatus
CN103049394A (en) * 2012-11-30 2013-04-17 记忆科技(深圳)有限公司 Method and system for data caching of solid state disk
CN103425438A (en) * 2013-07-15 2013-12-04 记忆科技(深圳)有限公司 Solid state disk and method for optimizing write request of solid state disk
CN103473185A (en) * 2013-09-06 2013-12-25 华为数字技术(苏州)有限公司 Cache writing method, caching device and storing system
CN104238962A (en) * 2014-09-16 2014-12-24 华为技术有限公司 Method and device for writing data into cache

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1277213C (en) * 2004-12-31 2006-09-27 大唐微电子技术有限公司 A flash memory file system management method
CN101493794B (en) * 2009-01-19 2011-12-21 成都市华为赛门铁克科技有限公司 Flash memory data processing method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120079231A1 (en) * 2010-09-23 2012-03-29 Phison Electronics Corp. Data writing method, memory controller, and memory storage apparatus
CN103049394A (en) * 2012-11-30 2013-04-17 记忆科技(深圳)有限公司 Method and system for data caching of solid state disk
CN103425438A (en) * 2013-07-15 2013-12-04 记忆科技(深圳)有限公司 Solid state disk and method for optimizing write request of solid state disk
CN103473185A (en) * 2013-09-06 2013-12-25 华为数字技术(苏州)有限公司 Cache writing method, caching device and storing system
CN104238962A (en) * 2014-09-16 2014-12-24 华为技术有限公司 Method and device for writing data into cache

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
TWI793644B (en) * 2020-07-23 2023-02-21 英商Arm股份有限公司 Cache arrangements for data processing systems
US11586554B2 (en) 2020-07-23 2023-02-21 Arm Limited Cache arrangements for data processing systems
CN112035065A (en) * 2020-08-28 2020-12-04 北京浪潮数据技术有限公司 Data writing method, device and equipment and computer readable storage medium
CN112035065B (en) * 2020-08-28 2022-06-07 北京浪潮数据技术有限公司 Data writing method, device and equipment and computer readable storage medium

Also Published As

Publication number Publication date
CN104238962A (en) 2014-12-24
CN104238962B (en) 2018-02-06

Similar Documents

Publication Publication Date Title
WO2016041401A1 (en) Method and device for writing data to cache
WO2017041570A1 (en) Method and apparatus for writing data to cache
US10379954B2 (en) Method and apparatus for cache management of transaction processing in persistent memory
US10025669B2 (en) Maintaining data-set coherency in non-volatile memory across power interruptions
US11301379B2 (en) Access request processing method and apparatus, and computer device
CN105843551B (en) Data integrity and loss resistance in high performance and large capacity storage deduplication
US8924664B2 (en) Logical object deletion
US11232073B2 (en) Method and apparatus for file compaction in key-value store system
US10467044B2 (en) Transaction processing method and apparatus, and computer system
US10108359B2 (en) Method and system for efficient cache buffering in a system having parity arms to enable hardware acceleration
US9921954B1 (en) Method and system for split flash memory management between host and storage controller
WO2015145647A1 (en) Storage device, data processing method, and storage system
JP2017079053A (en) Methods and systems for improving storage journaling
US10007436B2 (en) Storage control apparatus and control method of storage control apparatus
US20240020240A1 (en) Method for storing l2p table, system, device, and medium
JP2017084338A (en) Methods and systems for improving flash memory flushing
WO2017113211A1 (en) Method and device for processing access request, and computer system
US10282116B2 (en) Method and system for hardware accelerated cache flush
US10282301B2 (en) Method and system for hardware accelerated read-ahead caching
CN109002265B (en) Data processing method and related device
CN107506156B (en) Io optimization method of block device
CN112162950B (en) Data processing method and device based on file system and computer equipment
Song et al. CADedup: High-performance Consistency-aware Deduplication Based on Persistent Memory
CN117632776A (en) Processing system and processing method
CN115729439A (en) Data management method and device and solid state disk

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15842073

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15842073

Country of ref document: EP

Kind code of ref document: A1