[go: up one dir, main page]

CN104281517B - Log mode based memory space management method and device - Google Patents

Log mode based memory space management method and device Download PDF

Info

Publication number
CN104281517B
CN104281517B CN201410548611.XA CN201410548611A CN104281517B CN 104281517 B CN104281517 B CN 104281517B CN 201410548611 A CN201410548611 A CN 201410548611A CN 104281517 B CN104281517 B CN 104281517B
Authority
CN
China
Prior art keywords
log
storage space
application
release
smr
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201410548611.XA
Other languages
Chinese (zh)
Other versions
CN104281517A (en
Inventor
蔡和
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Uniview Technologies Co Ltd
Original Assignee
Zhejiang Uniview Technologies Co Ltd
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 Zhejiang Uniview Technologies Co Ltd filed Critical Zhejiang Uniview Technologies Co Ltd
Priority to CN201410548611.XA priority Critical patent/CN104281517B/en
Publication of CN104281517A publication Critical patent/CN104281517A/en
Application granted granted Critical
Publication of CN104281517B publication Critical patent/CN104281517B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供一种基于日志方式的存储空间管理方法,该方法应用于存储设备,该方法包括:在申请存储空间或释放存储空间的时候,在预设大小的第二映射区域SMR中记录对应的申请或者释放日志,该申请或者释放日志记录申请或者释放存储空间的起始位置以及大小信息;按照一定的策略,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作,并在所述SMR中记录本次产生的合并日志,所述合并日志记录了空闲的存储空间的起始位置以及大小。本发明的技术方案解决了现有存储空间管理中大量随机存储空间释放导致的设备性能降低的问题,并且对存储设备的内存容量要求不高。

The present invention provides a log-based storage space management method, which is applied to storage devices, and the method includes: when applying for storage space or releasing storage space, recording the corresponding Application or release log, the application or release log records the initial location and size information of the application or release storage space; according to a certain strategy, perform the operation of merging storage space on the application or release log and the last merged log in sequence , and record the merged log generated this time in the SMR, where the merged log records the starting position and size of the free storage space. The technical scheme of the invention solves the problem of device performance degradation caused by the release of a large amount of random storage space in the existing storage space management, and does not require high memory capacity of the storage device.

Description

一种基于日志方式的存储空间管理方法和装置A log-based storage space management method and device

技术领域technical field

本发明涉及存储技术领域,尤其涉及一种基于日志方式的存储空间管理方法和装置。The present invention relates to the technical field of storage, and in particular to a storage space management method and device based on a log mode.

背景技术Background technique

无论是基于文件系统还是基于其它块设备的应用,都有两个基本的要求:1、记录数据存储在块设备的哪些块上;2、块设备的哪些块是空闲状态。Whether it is an application based on a file system or other block devices, there are two basic requirements: 1. On which blocks of the block device the record data is stored; 2. Which blocks of the block device are idle.

从原则上来说,可以不用记录块设备的哪些块是空闲的,而只记录数据存储在哪些块上即可。因为块的状态只有两种:使用状态或者空闲状态。所以,可以通过已使用的块来推算出哪些块是空闲的。但是,这又意味着需要遍历所有已使用的块。为了使申请空闲块的效率更高,绝大多数块设备都会记录哪些块是空闲的。In principle, it is not necessary to record which blocks of the block device are free, but only record which blocks the data is stored on. Because there are only two states of a block: the use state or the idle state. Therefore, which blocks are free can be deduced from the used blocks. However, this again means that all used blocks need to be traversed. In order to make the application for free blocks more efficient, most block devices will record which blocks are free.

目前记录块是空闲状态还是已使用状态主要有两种方法,一是bitmap的方式,一是b-tree的方式。当然,最常用的还是bitmap的方式。bitmap是用一段连续空间的第N个比特位来表述块设备的第N个块是空闲的还是被占用的。相对而言,bitmap的资源消耗比较小,对于4KB的块大小,其资源消耗仅为1/(4096*8)=0.003%(其8代表一个字节8个比特位)。对于1GB大小的文件系统而言,bitmap所需要的空间大小为32KB;而对于1TB大小的文件系统而言,则需要的空间大小为2MB。这个大小对于系统的内存来说,还是可以接受的,但是从查找效率的角度来说,相对就比较低了。而如果对于1PB的文件系统而言,bitmap需要的大小则变为32GB,这个大小对于大多数设备的内存来说都是不可以接受的。这就意味着每次需要获取块状态时,都需要从磁盘读取,这将严重影响文件系统的性能。At present, there are two main ways to record whether the block is in the idle state or in the used state, one is the bitmap method, and the other is the b-tree method. Of course, the most commonly used method is bitmap. The bitmap uses the Nth bit of a continuous space to indicate whether the Nth block of the block device is free or occupied. Relatively speaking, the resource consumption of the bitmap is relatively small. For a block size of 4KB, its resource consumption is only 1/(4096*8)=0.003% (8 represents 8 bits in a byte). For a file system with a size of 1GB, the required space for the bitmap is 32KB; for a file system with a size of 1TB, the required space is 2MB. This size is acceptable for the system memory, but from the perspective of search efficiency, it is relatively low. And if for a 1PB file system, the required size of the bitmap becomes 32GB, which is unacceptable for the memory of most devices. This means that every time a block state needs to be obtained, it needs to be read from disk, which will seriously affect the performance of the file system.

针对上述问题,一个比较容易想到的方法是:将bitmap分为多个小的bitmap,再用bitmap来映射划分后的小的bitmap,请参图1所示。这样就可以通过最顶层的bitmap来找出哪些小的bitmap是有空闲块的;如果小的bitmap不在内存中,则将小的bitmap从磁盘中读取出来。To solve the above problems, an easy-to-think method is to divide the bitmap into multiple small bitmaps, and then use the bitmap to map the divided small bitmaps, as shown in Figure 1. In this way, it is possible to find out which small bitmaps have free blocks through the topmost bitmap; if the small bitmap is not in the memory, read the small bitmap from the disk.

但是,这样仍会存在如下问题:不论是申请还是释放块资源,bitmap都需要更新。对于申请块资源的操作,可以对bitmap的更新进行控制,但是对于释放块资源的操作则很难进行控制,因为释放操作是上层应用触发的。频繁进行块资源的释放,就意味着频繁更新bitmap,就意味着有很多的读写IO。更甚,若bitmap的更新涉及到很多小的bitmap,即bitmap的更新具有很大的随机性时,系统将不堪重负。However, the following problem still exists in this way: whether it is to apply for or release block resources, the bitmap needs to be updated. For the operation of applying for block resources, the update of the bitmap can be controlled, but it is difficult to control the operation of releasing block resources, because the release operation is triggered by the upper layer application. Frequent release of block resources means frequent update of the bitmap, which means a lot of read and write IO. What's more, if the update of the bitmap involves many small bitmaps, that is, the update of the bitmap has great randomness, the system will be overwhelmed.

B-tree则是采用extent(一段连续的存储空间)的方式来管理连续的块(block)。Extent的方式采用偏移加长度的方法来管理空闲的块空间。但是b-tree与bitmap存在上述同样的问题。B-tree uses extent (a continuous storage space) to manage continuous blocks. The Extent method uses the method of offset plus length to manage free block space. But b-tree and bitmap have the same problems mentioned above.

发明内容Contents of the invention

有鉴于此,本发明提供一种基于日志方式的存储空间管理方法。In view of this, the present invention provides a log-based storage space management method.

该方法应用于存储设备,包括:在申请存储空间或释放存储空间的时候,在预设大小的第二映射区域SMR中记录对应的申请或者释放日志,该申请或者释放日志记录申请或者释放存储空间的起始位置以及大小信息;按照一定的策略,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作,并在所述SMR中记录本次产生的合并日志,所述合并日志记录了空闲的存储空间的起始位置以及大小。The method is applied to a storage device, and includes: when applying for storage space or releasing storage space, recording a corresponding application or release log in the second mapping area SMR of a preset size, the application or release log records the application or release of storage space The starting position and size information of the storage space; according to a certain strategy, execute the storage space consolidation operation on the application or release log and the last merged log in sequence, and record the merged log generated this time in the SMR, so The merged log above records the starting position and size of the free storage space.

优选地,日志在SMR中的记录采用循环覆盖的方式进行;所述按照一定的策略,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作包括:当上一次合并产生的合并日志以及当前未被合并的申请或释放日志总数量占SMR内容区域日志总容纳量的比值达到预设阈值时,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作;或者,在申请存储空间且没有满足该申请所需大小的存储空间时,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作。Preferably, the recording of the log in the SMR is carried out in a circular covering manner; the operation of performing storage space merging on the application or release log and the last merging log in sequence according to a certain strategy includes: when the last merging When the ratio of the generated merged logs and the total number of currently unmerged application or release logs to the total log capacity of the SMR content area reaches the preset threshold, the storage space is sequentially executed for the application or release logs and the last merged log An operation of merging; or, when the storage space is applied for and there is no storage space meeting the required size of the application, the operation of merging the storage space is sequentially performed on the application or release log and the last merged log.

优选地,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作包括:顺序针对当前每条未被合并的申请或释放日志,按照日志中记录的起始位置和大小,判断是否可以和红黑树中当前的节点进行合并,如果可以则进行合并;合并后将新生成的节点插入到红黑树中,并删除被合并的节点;该新生成的节点的内容为:本次合并后空闲存储空间的起始位置和大小。Preferably, performing the operation of merging the storage space on the application or release log and the last merged log sequentially includes: for each currently unmerged application or release log in sequence, according to the starting position and size recorded in the log , to judge whether it can be merged with the current node in the red-black tree, and if so, merge it; insert the newly generated node into the red-black tree after the merge, and delete the merged node; the content of the newly generated node is : The starting position and size of the free storage space after this merge.

优选地,所述SMR中记录的日志包括:表示是释放空间操作还是申请空间操作的信息;表示是真实申请释放操作的日志还是合并操作的日志的信息;日志的编号Cur_journal_id,该编号随着日志的增加依次增加;所述顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作为按照日志编号递增的顺序依次执行所述合并的操作。Preferably, the log recorded in the SMR includes: information indicating whether it is a space release operation or an application space operation; information indicating whether it is a log of a real application for a release operation or a log of a merge operation; the number Cur_journal_id of the log, the number follows the log increases sequentially; the sequence of performing storage space consolidation operations on the application or release log, and the last merge log is to execute the merge operations sequentially in the order of increasing log numbers.

优选地,磁盘存储空间被划分为若干个区域region,每个region包括数据区域DR和映射区域MR;其中MR包括主映射区域PMR和第二映射区域SMR;PMR包括头部区域和记录了属于该PMR管理的各SMR的位置以及下一个PMR位置的内容区域;SMR包括头部区域和记录所述日志的内容区域。Preferably, the disk storage space is divided into several regions, and each region includes a data region DR and a mapping region MR; wherein MR includes a main mapping region PMR and a second mapping region SMR; PMR includes a header region and records belonging to the The location of each SMR managed by the PMR and the content area of the next PMR location; the SMR includes a header area and a content area for recording the log.

优选地,存储设备启动工作后,将从磁盘中读取PMR信息、SMR信息到内存中,并基于内存中的PMR信息和SMR信息进行存储空间的管理。Preferably, after the storage device starts working, it will read PMR information and SMR information from the disk into the memory, and manage the storage space based on the PMR information and SMR information in the memory.

优选地,若从磁盘中读取到内存中的SMR内容区域中的编号最大的日志是合并日志,在需要进一步进行合并操作时,需要重新将所述合并日志之前的上一次合并日志、上一次合并日志之后的申请日志、释放日志重新进行一次合并操作。Preferably, if the log with the largest number in the SMR content area in the memory read from the disk is a merged log, when a further merge operation is required, the last merged log before the merged log, the last After the log is merged, the application log and release log are merged again.

优选地,在申请存储空间时,如果SMR管理的DR中存在若干个满足申请条件的连续可用的空间,则选择逻辑块地址lba小的所述可用空间。Preferably, when applying for a storage space, if there are several continuously available spaces meeting the application conditions in the DR managed by the SMR, then select the available space with a smaller logical block address lba.

相较于现有技术,本发明的技术方案解决了现有存储空间管理中大量随机存储空间释放导致的设备性能降低的问题,并且对存储设备的内存容量要求不高。Compared with the prior art, the technical solution of the present invention solves the problem of device performance degradation caused by the release of a large amount of random storage space in the existing storage space management, and does not require high memory capacity of the storage device.

附图说明Description of drawings

图1是一种多层bitmap映射示意图。Fig. 1 is a schematic diagram of multi-layer bitmap mapping.

图2是本发明实施例流程图。Fig. 2 is a flowchart of an embodiment of the present invention.

图3是本发明实施例存储空间的划分结构图。FIG. 3 is a structural diagram of division of a storage space according to an embodiment of the present invention.

图4是本发明实施例日志内容图。Fig. 4 is a log content diagram of the embodiment of the present invention.

图5是本发明实施例日志合并示例图。Fig. 5 is an example diagram of log merging according to the embodiment of the present invention.

图6(a)~图6(b)是本发明实施例另一日志合并示例图。FIG. 6( a ) to FIG. 6( b ) are diagrams illustrating another example of log merging according to the embodiment of the present invention.

具体实施方式detailed description

针对背景技术中提到的技术问题,本发明主要提供一种基于日志方式进行存储空间管理的技术方案。该技术方案解决了现有存储空间管理中大量随机存储空间释放导致的设备性能降低的问题。以下通过具体实施例详细说明。In view of the technical problems mentioned in the background art, the present invention mainly provides a technical solution for storage space management based on a log method. The technical solution solves the problem of device performance degradation caused by the release of a large amount of random storage space in the existing storage space management. It will be described in detail below through specific examples.

请参图2所示的本发明实施例流程图。Please refer to the flowchart of the embodiment of the present invention shown in FIG. 2 .

S21、在申请存储空间或释放存储空间的时候,在预设大小的第二映射区域SMR中记录对应的申请或者释放日志,该申请或者释放日志记录申请或者释放存储空间的起始位置以及大小信息。S21. When applying for storage space or releasing storage space, record the corresponding application or release log in the second mapping area SMR with a preset size, and the application or release log records the initial position and size information of the application or release storage space .

S22、按照一定的策略,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作,并在所述SMR中记录本次产生的合并日志,所述合并日志记录了空闲的存储空间的起始位置以及大小。S22. According to a certain strategy, sequentially perform storage space consolidation operations on the application or release log and the last merged log, and record the merged log generated this time in the SMR, and the merged log records the free The starting location and size of the storage space.

上述方法在进行存储空间申请或释放的时候,仅是记录对应的申请或释放操作日志;当满足一定的条件之后,再对上述申请或释放日志进行合并操作(合并操作的本质是:统计出存储空间中哪些空间已被释放,将连续已被释放的空间,即extent,进行合并,并且将该合并操作结果作为合并日志追加到SMR区域中作为一新的日志进行记录)。这样就避免了频繁的进行存储空间的管理,提升了存储设备的性能。另,该合并日志记录了空闲存储空间的起始位置和大小,新的存储空间的申请操作可以根据该起始位置和大小判断是否满足申请需求,如果满足,则直接申请该存储空间。The above method only records the corresponding application or release operation log when applying for or releasing the storage space; when certain conditions are met, the merge operation is performed on the above application or release log (the essence of the merge operation is: count the storage Which space in the space has been released, the space that has been continuously released, that is, the extent, is merged, and the result of the merge operation is appended to the SMR area as a merge log and recorded as a new log). In this way, frequent storage space management is avoided, and the performance of the storage device is improved. In addition, the merging log records the initial location and size of the free storage space, and the application operation for a new storage space can judge whether the application requirement is met according to the initial location and size, and if so, directly apply for the storage space.

请进一步参图3,作为一个例子,可以针对存储设备的存储空间按照图3的方式进行分割。存储空间被划分为若干个区域region,每个region包括数据区域DR(data region)和映射区域MR(map region);其中MR包括主映射区域PMR和第二映射区域SMR;PMR包括头部区域(map region head)和记录了属于该PMR管理的各SMR的位置(SMR Entry)以及下一个PMR位置(Next PMR Entry)的内容区域;SMR包括头部区域(Map Region Head)和记录所述日志(Map Region Journal)的内容区域。Please refer to FIG. 3 further. As an example, the storage space of the storage device may be divided in the manner shown in FIG. 3 . The storage space is divided into several regions, and each region includes a data region DR (data region) and a mapping region MR (map region); wherein MR includes a main mapping region PMR and a second mapping region SMR; PMR includes a header region ( map region head) and the content area that records the position (SMR Entry) of each SMR managed by the PMR and the next PMR position (Next PMR Entry); SMR includes the head area (Map Region Head) and records the log ( Map Region Journal) content area.

该存储空间采用的是两级映射的方式,每个区域region可以按照一定的大小进行划分,比如说128GB。这样整个存储空间将被分为若干的region,每个region均包含上述的两级映射结构,单独进行管理。The storage space adopts a two-level mapping method, and each region region can be divided according to a certain size, for example, 128GB. In this way, the entire storage space will be divided into several regions, and each region includes the above-mentioned two-level mapping structure and is managed separately.

作为一个例子,SMR的内容区域记录的日志Map Region Journal(MRJ)请参图4。每条MRJ包括:2bit的Reserved(预留)位。占2bit的Ops_flag,其中低比特位表示释放空间或申请空间的操作,比如说释放操作为0,申请操作为1;高比特位表示该日志是真实的申请/释放日志,还是合并生成的日志,比如说真实的申请/释放日志为0,合并生成的日志为1。分别占28bit的(也表示DR最大容量为(2^28-1)*4KB≈1TB)Offset及Size,该Offset表示操作涉及的空间在DR中的偏移(相对位置,以4KB为单位),Size表示操作涉及的大小。Cur_journal_id表示当前日志的id,每记一条日志该id就会自加一次。上文中日志记录的存储空间的起始位置在这个例子中用Offset来表示。As an example, please refer to Figure 4 for the log Map Region Journal (MRJ) recorded in the content area of SMR. Each MRJ includes: 2-bit Reserved (reserved) bits. Ops_flag occupies 2 bits, where the low bit indicates the operation of releasing space or applying for space. For example, the release operation is 0, and the application operation is 1; the high bit indicates whether the log is a real application/release log or a log generated by merging. For example, the real application/release log is 0, and the merged log is 1. Occupying 28 bits respectively (also means that the maximum capacity of DR is (2^28-1)*4KB≈1TB) Offset and Size, the Offset indicates the offset of the space involved in the operation in DR (relative position, in units of 4KB), Size indicates the size involved in the operation. Cur_journal_id indicates the id of the current journal, and the id will be added once for each journal. The starting position of the storage space for log records above is represented by Offset in this example.

上述PMR信息、SMR信息被保存在存储设备的内存中;其他信息则记录在磁盘空间中。由于PMR信息、SMR信息所需占用的空间较少,所以对内存大小要求较低。当然,内存中还可以进一步保存SMR对应的DR最近一次被访问的存储空间的信息,这样在后续申请存储空间时,如果该存储空间满足申请的要求,直接从该其中划取空间即可。The above PMR information and SMR information are stored in the internal memory of the storage device; other information is recorded in the disk space. Since the PMR information and the SMR information require less space, the memory size requirement is relatively low. Of course, the memory can further store the information of the last accessed storage space of the DR corresponding to the SMR, so that when applying for storage space later, if the storage space meets the requirements of the application, the space can be directly drawn from it.

由于用于记录日志的SMR内容区的大小是预先设定的,而申请操作、释放操作、合并操作对应的日志是不断增加的,所以这里采用循环覆盖的方式将日志记录在SMR中。Since the size of the SMR content area used to record logs is preset, and the logs corresponding to application operations, release operations, and merge operations are constantly increasing, so here the log is recorded in the SMR in a circular coverage manner.

为了准确的对存储空间进行管理,需要对于日志的合并采取一定的策略。策略一:当上一次合并产生的合并日志以及当前未被合并的申请或释放日志总数量占SMR内容区域日志总容纳量的比值达到预设阈值时,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作;策略二:在申请存储空间且没有满足该申请所需大小的存储空间时,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作。这里只是举例两个例子,本实施例不排除其他存储空间管理的策略。In order to manage the storage space accurately, it is necessary to adopt a certain strategy for the merging of logs. Strategy 1: When the ratio of the total number of merged logs generated by the last merge and the total number of application or release logs that have not been merged to the total capacity of the logs in the SMR content area reaches the preset threshold, the application or release logs, and the above Merge logs once to perform storage space merging operations; Strategy 2: When applying for storage space and there is no storage space that meets the required size of the application, sequentially perform storage space merging on the application or release log and the last merged log operation. Here are just two examples, and this embodiment does not exclude other storage space management strategies.

请参图5给出的一个例子,第一行中“MRJ 45”表示第45条日志,第一行中的“1”表示该第45条日志是合并生成的日志;其他各行相同的释义。从该例中可以看出,第45条日志之前的日志已经经过合并处理,并且形成了两条合并日志45和46,该45和46条合并日志是上一次合并产生的合并日志;之后,又新生成了若干条真实的(非合并的)操作日志:47、48、49、50、51、52。这样上一次合并产生的合并日志以及当前未被合并的日志即为以下日志:45~52,共8条,这里的SMR内容区域日志的总容纳量为10,所以其占比为80%。当上述策略一中的预设阈值为78%时,则当前需要对日志45~52进行合并操作。该合并策略可以及时避免有效日志未经处理而被覆盖的情况出现。Please refer to an example given in Figure 5, "MRJ 45" in the first line indicates the 45th log, and "1" in the first line indicates that the 45th log is a merged log; other lines have the same interpretation. It can be seen from this example that the logs before the 45th log have been merged, and two merged logs 45 and 46 have been formed. The 45 and 46 merged logs are the merged logs generated by the previous merge; after that, Several real (non-merged) operation logs are newly generated: 47, 48, 49, 50, 51, 52. In this way, the merged logs generated by the last merge and the currently unmerged logs are the following logs: 45 to 52, a total of 8 entries. The total capacity of the logs in the SMR content area here is 10, so its proportion is 80%. When the preset threshold in the above strategy 1 is 78%, it is currently necessary to perform a merge operation on the logs 45-52. This merging strategy can prevent valid logs from being overwritten without processing in time.

策略二在申请存储空间时,若要申请的空间大小大于当前空闲的空间大小时,则可以采用日志合并的方式看看合并得到的新日志对应的空闲空间的大小是否满足申请的要求,若是,则申请操作将成功,直接将合并后的空间的offset值反馈给上层。Strategy 2 When applying for storage space, if the space to be applied is larger than the current free space, you can use log merging to check whether the free space corresponding to the merged new log meets the application requirements. If so, Then the application operation will be successful, and the offset value of the merged space will be directly fed back to the upper layer.

本实施例针对日志进行存储空间的合并操作时,可以依赖红黑树进行该合并操作。比如说针对每条未被合并的申请或者释放日志,按照该申请或者释放日志记录空间的起始位置和大小,判断是否可以和红黑树中当前的节点进行合并,如果可以则进行合并;合并后将新生成的节点插入到红黑树中,并删除被合并的节点。该新生成的节点的内容为:合并后空闲存储空间的起始位置和大小。红黑树的每个节点均记录空闲空间的起始位置和大小信息,索引值为所述起始位置。上述可以合并的原则是,红黑树中节点记录的空闲空间信息和日志中记录的申请/释放空间重合、部分重合、连续。When this embodiment performs a storage space merging operation for logs, the merging operation may be performed by relying on a red-black tree. For example, for each application or release log that has not been merged, judge whether it can be merged with the current node in the red-black tree according to the starting position and size of the application or release log recording space, and if possible, merge; merge Then insert the newly generated nodes into the red-black tree, and delete the merged nodes. The content of the newly generated node is: the starting position and size of the free storage space after merging. Each node of the red-black tree records the starting position and size information of the free space, and the index value is the starting position. The principle that the above can be merged is that the free space information recorded by the nodes in the red-black tree and the application/release space recorded in the log overlap, partially overlap, and continue.

下面举几个例子来说明上述合并操作:Here are a few examples to illustrate the above merge operation:

例1:红黑树中已有一代表空闲空间的节点:offset值为32,size值为16K;假设每4K,offset值增加1。当前需要对offset值为36,size为4K的释放日志进行合并操作。根据上述offset值和size值,判断当前日志可以和该节点进行合并,合并后的新节点对应的offset值为32,size值为20。所以将该新节点根据其索引值32插入到红黑树中,并将原来的offset值为32,size值为16K的节点从红黑树中删除。并在SMR中生成一条合并日志,该合并日志的内容为:释放操作,offset值为32,size值为20。Example 1: There is already a node representing free space in the red-black tree: the offset value is 32, and the size value is 16K; assuming that every 4K, the offset value increases by 1. Currently, it is necessary to merge release logs with an offset value of 36 and a size of 4K. According to the above offset and size values, it is judged that the current log can be merged with this node, and the offset value corresponding to the merged new node is 32, and the size value is 20. Therefore, insert the new node into the red-black tree according to its index value of 32, and delete the node with the original offset value of 32 and the size value of 16K from the red-black tree. And generate a merge log in SMR, the content of the merge log is: release operation, offset value is 32, size value is 20.

例2、红黑树中已有一代表空闲空间的节点:offset值为32,size值为16K;假设每4K,offset值增加1。当前需要对offset值为31,size值为4KB的释放日志进行合并操作。根据上述offset值和size值,判断当前日志可以和该节点进行合并,合并后的新节点对应的offset值为31,size值为20。所以将该新节点根据其索引值31插入到红黑树中,并将原来的offset值为32,size值为16K的节点从红黑树中删除。并在SMR中生成一条合并日志,该合并日志的内容为:释放操作,offset值为31,size值为20。Example 2. There is already a node representing free space in the red-black tree: the offset value is 32, and the size value is 16K; assuming that every 4K, the offset value increases by 1. Currently, it is necessary to merge release logs with an offset value of 31 and a size value of 4KB. According to the above offset and size values, it is judged that the current log can be merged with this node, and the offset value corresponding to the merged new node is 31, and the size value is 20. Therefore, insert the new node into the red-black tree according to its index value 31, and delete the node with the original offset value of 32 and the size value of 16K from the red-black tree. And generate a merge log in SMR, the content of the merge log is: release operation, offset value is 31, size value is 20.

例3、红黑树中已有一代表空闲空间的节点:offset值为32,size值为16K;假设每4K,offset值增加1。当前需要对offset值为32,size值为16KB的释放日志进行合并操作。直接忽略该条释放日志,不需作任何处理。Example 3. There is already a node representing free space in the red-black tree: the offset value is 32, and the size value is 16K; assuming that every 4K, the offset value increases by 1. Currently, it is necessary to merge release logs with an offset value of 32 and a size value of 16KB. Ignore this release log directly without any processing.

例4、红黑树中已有一代表空闲空间的节点:offset值为32,size值为16K;假设每4K,offset值增加1。当前需要对offset值为34,size值为4KB,的申请日志进行合并。此时,需要将原有节点拆分成两个,并将原有的节点删除。新生成的节点其offset分别为32,35,size值分别为8K,4K。此时需要进一步在SMR中生成两条合并日志。Example 4. There is already a node representing free space in the red-black tree: the offset value is 32, and the size value is 16K; assuming that every 4K, the offset value increases by 1. Currently, the application logs whose offset value is 34 and size value is 4KB need to be merged. At this point, the original node needs to be split into two, and the original node should be deleted. The offsets of the newly generated nodes are 32 and 35 respectively, and the size values are 8K and 4K respectively. At this point, you need to further generate two merged logs in SMR.

例5、红黑树中已有一代表空闲空间的节点:offset值为32,size值为16K;假设每4K,offset值增加1。当前需要对offset值为35,size值为4KB的申请日志进行合并。此时,删除原节点,新生成的节点的offset值为32,size值为12K;实际上只需要把原节点的size值直接改为12K即可。进一步在SMR中生成该新节点对应的合并日志。Example 5. There is already a node representing free space in the red-black tree: the offset value is 32, and the size value is 16K; assuming that every 4K, the offset value increases by 1. Currently, the application logs whose offset value is 35 and size value is 4KB need to be merged. At this time, delete the original node, and the offset value of the newly generated node is 32, and the size value is 12K; in fact, it is only necessary to directly change the size value of the original node to 12K. Further generate a merged log corresponding to the new node in the SMR.

例6、红黑树中已有一代表空闲空间的节点:offset值为32,size值为16K;假设每4K,offset值增加1。当前需要对offset值为32,size值为4KB的申请日志进行合并。此时,删除原节点,新生成的节点的offset值为33,size值为12K。进一步在SMR中生成该新节点对应的合并日志。Example 6. There is already a node representing free space in the red-black tree: the offset value is 32, and the size value is 16K; assuming that every 4K, the offset value increases by 1. Currently, the application logs whose offset value is 32 and size value is 4KB need to be merged. At this point, the original node is deleted, and the newly generated node has an offset value of 33 and a size value of 12K. Further generate a merged log corresponding to the new node in the SMR.

这里有一种情况需要说明,在存储设备启动时,首先需要将磁盘中的PMR信息、SMR信息读取到内存中。此时可能会出现图6(a)或者图6(b)所示的情况。在图6(a)中,由于编号journal_id最大的MRJ是真实的申请或者释放日志,所以此时若要进行合并操作只需要将journal_id为09、10、11三条MRJ参与日志合并;而图6(b)中,由于编号journal_id最大的MRJ是合并日志,所以此时若要进行合并操作,则需要将journal_id为06、07、08、09的这四条日志参与合并即可。其中journal_id为06、07的日志为上一次产生的合并日志;journal_id为08、09的日志为上一次合并日志产生后新生成的真实的申请/释放日志。如果合并的结果和当前journal_id为10、11日志的结果一致,则不需要进行任何操作。若合并的结果除了当前journal_id为10、11日志的结果外,还包括其他合并结果,则进一步增加该其他合并结果的日志,这种情况有可能是系统关机或其它情况导致上次的合并未完全完成。Here is a situation that needs to be explained. When the storage device is started, it is first necessary to read the PMR information and SMR information in the disk into the memory. At this time, the situation shown in Fig. 6(a) or Fig. 6(b) may appear. In Figure 6(a), since the MRJ with the largest journal_id number is the real application or release log, so if you want to merge at this time, you only need to merge the three MRJs with journal_ids of 09, 10, and 11 to participate in the log merge; and Figure 6 ( In b), since the MRJ with the largest journal_id number is a merged log, if you want to perform a merge operation at this time, you need to merge the four logs with journal_ids of 06, 07, 08, and 09. Among them, the logs with journal_id 06 and 07 are the merged logs generated last time; the logs with journal_id 08 and 09 are the real application/release logs newly generated after the last merged log. If the merged result is consistent with the results of the current journal_id 10 and 11, no operation is required. If the merged result includes other merged results besides the results of the current journal_id 10 and 11 logs, further add the logs of the other merged results. In this case, the last merge may not be complete due to system shutdown or other circumstances Finish.

另外,还有一点需要说明,在申请存储空间时,除了考虑SMR管理的DR中连续可用空间的大小外,还需要考虑该可用空间尽可能在逻辑块地址lba小的位置。这主要是因为对于现有硬盘,小的lba对应的磁道在硬盘的外侧,在硬盘盘片旋转速率为定值时,外侧有更高的线速度,也就意味着更快的读写速率(外侧磁道与内侧磁道平均速率比为2:1)。In addition, there is another point that needs to be explained. When applying for storage space, in addition to considering the size of the continuous available space in the DR managed by the SMR, it is also necessary to consider that the available space is located where the logical block address lba is as small as possible. This is mainly because for the existing hard disk, the track corresponding to the small lba is on the outer side of the hard disk. When the rotation speed of the hard disk platter is a constant value, the outer side has a higher linear speed, which means a faster read and write rate ( The average speed ratio of the outer track to the inner track is 2:1).

以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明保护的范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the present invention. within the scope of protection.

Claims (8)

1.一种基于日志方式的存储空间管理方法,该方法应用于存储设备,其特征在于,该方法包括:1. A storage space management method based on a log mode, the method is applied to a storage device, and it is characterized in that the method comprises: 在申请存储空间或释放存储空间的时候,在预设大小的第二映射区域SMR中记录对应的申请或者释放日志,该申请或者释放日志记录申请或者释放存储空间的起始位置以及大小信息,存储设备的存储空间被划分为若干个区域region,每个region包括数据区域DR和映射区域MR;其中MR包括主映射区域PMR和所述第二映射区域SMR;When applying for storage space or releasing storage space, record the corresponding application or release log in the second mapping area SMR of the preset size. The application or release log records the initial position and size information of the application or release storage space, and stores The storage space of the device is divided into several regions, and each region includes a data region DR and a mapping region MR; wherein MR includes a main mapping region PMR and the second mapping region SMR; 当上一次合并产生的合并日志以及当前未被合并的申请或释放日志总数量占SMR内容区域日志总容纳量的比值达到预设阈值时,或者在申请存储空间且没有满足该申请所需大小的存储空间时,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作,并在所述SMR中记录本次产生的合并日志,所述合并日志记录了空闲的存储空间的起始位置以及大小。When the ratio of the combined log generated by the last merge and the total number of application or release logs that have not been merged to the total log capacity of the SMR content area reaches the preset threshold, or when the storage space is applied for and does not meet the required size of the application When storing space, sequentially execute the storage space merging operation on the application or release log and the last merging log, and record the merging log generated this time in the SMR, and the merging log records the free storage space The starting position and size of . 2.如权利要求1所述的方法,其特征在于,日志在SMR中的记录采用循环覆盖的方式进行。2. The method according to claim 1, characterized in that the recording of the log in the SMR is carried out in a circular coverage manner. 3.如权利要求1所述的方法,其特征在于,顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作包括:顺序针对当前每条未被合并的申请或释放日志,按照日志中记录的起始位置和大小,判断是否可以和红黑树中当前的节点进行合并,如果可以则进行合并;合并后将新生成的节点插入到红黑树中,并删除被合并的节点;该新生成的节点的内容为:本次合并后空闲存储空间的起始位置和大小。3. The method according to claim 1, wherein the sequentially performing the operation of merging storage space on the application or release log and the last merged log comprises: sequentially targeting each currently unmerged application or release log Log, according to the starting position and size recorded in the log, judge whether it can be merged with the current node in the red-black tree, and if so, merge it; after the merge, insert the newly generated node into the red-black tree, and delete the The merged node; the content of the newly generated node is: the starting position and size of the free storage space after this merge. 4.如权利要求1所述的方法,其特征在于,所述SMR中记录的日志包括:表示是释放空间操作还是申请空间操作的信息;表示是真实申请释放操作的日志还是合并操作的日志的信息;日志的编号Cur_journal_id,该编号随着日志的增加依次增加;4. The method according to claim 1, wherein the log recorded in the SMR includes: information indicating whether it is a space release operation or an application space operation; whether it is a log of a real application for a release operation or a log of a merge operation Information; the number Cur_journal_id of the journal, which increases sequentially with the number of logs; 所述顺序对所述申请或释放日志,以及上一次的合并日志执行存储空间合并的操作为按照日志编号递增的顺序依次执行所述合并的操作。The sequence of performing storage space merging operations on the application or release log and the last merging log is to perform the merging operation in sequence in the order of increasing log numbers. 5.如权利要求1所述的方法,其特征在于,所述PMR包括头部区域和记录了属于该PMR管理的各SMR的位置以及下一个PMR位置的内容区域;SMR包括头部区域和记录所述日志的内容区域。5. The method according to claim 1, wherein the PMR includes a header area and a content area that records the positions of each SMRs managed by the PMR and the next PMR position; the SMR includes a header area and records The content area of the log. 6.如权利要求5所述的方法,其特征在于,所述存储设备启动工作后,将从磁盘中读取PMR信息、SMR信息到内存中,并基于内存中的PMR信息和SMR信息进行存储空间的管理。6. the method for claim 5, is characterized in that, after described storage device starts work, will read PMR information, SMR information in internal memory from disk, and store based on the PMR information in internal memory and SMR information management of space. 7.如权利要求6所述的方法,其特征在于,若从磁盘中读取到内存中的SMR内容区域中的编号最大的日志是合并日志,在需要进一步进行合并操作时,需要重新将所述合并日志之前的上一次合并日志、上一次合并日志之后的申请日志、释放日志重新进行一次合并操作。7. The method according to claim 6, wherein if the log with the largest number in the SMR content area in the internal memory read from the disk is a merged log, when further merge operations are needed, it is necessary to redo the log Perform a merge operation on the last merged log before the above merged log, the application log after the last merged log, and the released log. 8.如权利要求1所述的方法,其特征在于,在申请存储空间时,如果SMR管理的DR中存在若干个满足申请条件的连续可用的空间,则选择逻辑块地址lba小的所述可用空间。8. The method according to claim 1, wherein when applying for storage space, if there are several continuously available spaces that meet the application conditions in the DR managed by SMR, then select the available space with the smallest logical block address lba space.
CN201410548611.XA 2014-10-16 2014-10-16 Log mode based memory space management method and device Active CN104281517B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410548611.XA CN104281517B (en) 2014-10-16 2014-10-16 Log mode based memory space management method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410548611.XA CN104281517B (en) 2014-10-16 2014-10-16 Log mode based memory space management method and device

Publications (2)

Publication Number Publication Date
CN104281517A CN104281517A (en) 2015-01-14
CN104281517B true CN104281517B (en) 2017-05-17

Family

ID=52256415

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410548611.XA Active CN104281517B (en) 2014-10-16 2014-10-16 Log mode based memory space management method and device

Country Status (1)

Country Link
CN (1) CN104281517B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107229664B (en) * 2016-03-25 2021-06-25 西部数据技术公司 Indirect data structure for managing file system metadata
CN109284295B (en) * 2018-10-17 2021-09-17 郑州云海信息技术有限公司 Data optimization method and device
CN112198818B (en) * 2019-07-08 2022-05-13 浙江宇视科技有限公司 Control method, device and equipment of stepping type driving structure and storage medium
CN112306825B (en) * 2019-07-31 2024-02-27 中科寒武纪科技股份有限公司 Memory operation recording method and device and computer equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1549616A (en) * 2003-05-20 2004-11-24 深圳市中兴通讯股份有限公司南京分公 Self-adaption information buffer storing method used for multi-sample
CN101286177A (en) * 2008-05-30 2008-10-15 中兴通讯股份有限公司 Method and device for allocating space to file in file allocation table
CN101567001A (en) * 2009-05-22 2009-10-28 清华大学 Method for managing metadata file layout of parallel file system
CN102024034A (en) * 2010-11-26 2011-04-20 中国科学院声学研究所 Fragment processing method for high-definition media-oriented embedded file system

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7191233B2 (en) * 2001-09-17 2007-03-13 Telecommunication Systems, Inc. System for automated, mid-session, user-directed, device-to-device session transfer system
JP4313068B2 (en) * 2003-03-28 2009-08-12 株式会社日立製作所 Cache management method for storage device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1549616A (en) * 2003-05-20 2004-11-24 深圳市中兴通讯股份有限公司南京分公 Self-adaption information buffer storing method used for multi-sample
CN101286177A (en) * 2008-05-30 2008-10-15 中兴通讯股份有限公司 Method and device for allocating space to file in file allocation table
CN101567001A (en) * 2009-05-22 2009-10-28 清华大学 Method for managing metadata file layout of parallel file system
CN102024034A (en) * 2010-11-26 2011-04-20 中国科学院声学研究所 Fragment processing method for high-definition media-oriented embedded file system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
内存数据库中空闲页面管理的方法研究;钟宝荣 等;《计算机工程与设计》;20070430;第28卷(第7期);第1523-1524页 *
基于分离日志的闪存数据库系统存储管理方法;岳丽华 等;《中国科学技术大学学报》;20100530;第40卷(第5期);第526-532页 *

Also Published As

Publication number Publication date
CN104281517A (en) 2015-01-14

Similar Documents

Publication Publication Date Title
US12265706B2 (en) Memory system with nonvolatile semiconductor memory
US11301379B2 (en) Access request processing method and apparatus, and computer device
CN110347336B (en) A key-value storage system based on NVM and SSD hybrid storage structure
US9298384B2 (en) Method and device for storing data in a flash memory using address mapping for supporting various block sizes
US8521949B2 (en) Data deleting method and apparatus
US8996799B2 (en) Content storage system with modified cache write policies
CN106708427A (en) Storage method suitable for key value pair data
CN103838853B (en) Mixed file system based on different storage media
JP6678230B2 (en) Storage device
WO2016046911A1 (en) Storage system and storage system management method
CN103858092B (en) A data migration method and device
CN105677243A (en) Data writing device and method
CN104281517B (en) Log mode based memory space management method and device
CA2978927A1 (en) Data check method and storage system
CN106445405A (en) A data access method and device for flash storage
CN104750433A (en) Cache design method based on SCST
CN104750432B (en) A kind of date storage method and device
US10180792B1 (en) Cache management in data storage systems
CN112612419A (en) Data storage structure, storage method, reading method, equipment and medium of NVM (non-volatile memory)
KR101191650B1 (en) Apparatus and method for mapping the data address in NAND flash memory
CN104834478A (en) Data writing and reading method based on heterogeneous hybrid storage device
Lee et al. An efficient index buffer management scheme for implementing a B-tree on NAND flash memory
CN103530067A (en) Data operation method and device
US20110264848A1 (en) Data recording device
US10585592B2 (en) Disk area isolation method and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant