Disk space allocation method and device, electronic equipment and storage medium

By using the binary heap data structure to optimize space allocation in hard disk space allocation, the problem of slowing down the storage system operation speed caused by differences in read and write speed of the inner and outer circle tracks and discrete space of the hard disk is solved, and a more efficient read and write speed is achieved.

CN119440406AActive Publication Date: 2025-02-14XINHUASAN INFORMATION TECH CO LTD

Patent Information

Application Number
CN202411474222.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2025-02-14
Estimated Expiration
2044-10-21

AI Technical Summary

Technical Problem

The prior art does not consider the difference in reading and writing speeds of the inner and outer ring tracks of the disk when allocating hard disk space, resulting in slow reading and writing speeds when the allocated space is close to the inner ring track, and the discrete space is due to disk rotation delay, head seek time, etc. Factors affecting this, resulting in slowing down the overall operation speed of the storage system.

Method used

Use binary heap data structure to optimize disk space allocation. By obtaining the address information of the target free space block, place the lowest address at the root node of the binary heap, and set other addresses according to the principle that the address indicated by the parent node is lower than the child node. information. During allocation, the target free space block corresponding to the address recorded by the root node is given priority, and the addresses of each node in the binary heap are updated after allocation to ensure that the free space with a low address is allocated each time.

Benefits of technology

By prioritizing the allocation of free space at low addresses, the hardware disk mechanical characteristics make the read and write speed higher, while large continuous free space reduces the impact of disk rotation delay and head seek time, and improves the overall read and write speed of the storage system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440406A_ABST
    Figure CN119440406A_ABST
Patent Text Reader

Abstract

The invention discloses a disk space distribution method and device, electronic equipment and a computer readable storage medium. The disk space distribution method comprises the steps that address information of at least one target free space block in the same disk is acquired; setting the lowest address in the obtained address information to a root node of the binary heap, and setting other obtained address information in the binary heap according to a principle that an address indicated by any father node in the binary heap is lower than an address indicated by a child node; the target free space blocks are allocated based on the binary heap, the target free space blocks corresponding to the addresses set by the root nodes are always allocated in each allocation, and the target free space blocks are allocated according to the principle that the root nodes in the binary heap indicate the lowest address and the address indicated by any father node in the binary heap is lower than the address indicated by the child nodes after allocation. And updating the address indicated by each node in the binary heap. The overall read-write speed of the storage system can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of storage, and in particular to a disk space allocation method, device, electronic device and computer-readable storage medium. Background Art

[0002] In the storage system of the related technology, the read and write speeds of the inner and outer tracks of the same hard disk are unbalanced. For example, when allocating space on the hard disk, when the allocated space is close to the inner track of the hard disk, the read and write speeds are relatively slow due to the lower track linear velocity and lower data density; when the allocated space is close to the outer track of the hard disk, the read and write speeds are relatively fast due to the higher track linear velocity and higher data density.

[0003] When allocating hard disk space, the relevant technology does not consider the address of the space on the same hard disk, that is, it does not consider whether the allocated space is close to the inner or outer tracks of the same hard disk. The probability that the allocated space is close to the inner track is higher. When the allocated space is close to the inner track, the read and write speeds are relatively slow due to the lower track line speed and lower data density of the space close to the inner track. At the same time, when the allocated space is more discrete, the read and write speeds will also slow down due to factors such as the disk's platter rotation delay, head seek time, and head stabilization time. This will eventually slow down the overall operation of the storage system. Summary of the invention

[0004] In view of the above technical problems, the present application provides a disk space allocation method, device, electronic device and computer-readable storage medium, and the technical solution is as follows:

[0005] According to a first aspect of the present application, a disk space allocation method is provided, the method comprising:

[0006] Acquire address information of at least one target free space block in the same disk, where the target free space block is greater than or equal to a space threshold;

[0007] The lowest address among the acquired address information is set at the root node of the binary heap, and according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node, the other acquired address information is set in the binary heap;

[0008] The target free space block is allocated based on the binary heap, wherein each allocation always allocates the target free space block corresponding to the address set by the root node, and after the allocation, the address indicated by each node in the binary heap is updated according to the principle that the root node in the binary heap indicates the lowest address and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

[0009] According to a second aspect of the present application, a disk space allocation device is provided, the device comprising:

[0010] An acquisition unit, used to acquire address information of at least one target free space block in the same disk, wherein the target free space block is greater than or equal to a space threshold;

[0011] A setting unit, configured to place the lowest address among the acquired address information into a root node of a binary heap, and to set other acquired address information in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node;

[0012] An allocation unit is used to allocate the target free space block based on the binary heap, wherein each allocation always allocates the target free space block corresponding to the address set by the root node, and after the allocation, the address indicated by each node in the binary heap is updated according to the principle that the root node in the binary heap indicates the lowest address and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

[0013] According to a third aspect of the present application, an electronic device is provided, the electronic device comprising:

[0014] processor;

[0015] a memory for storing processor-executable instructions;

[0016] The processor is configured to implement the method as described in the first aspect.

[0017] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the method described in the first aspect are implemented.

[0018] The technical solution provided by the present application places the lowest address in the address information of at least one target free space block that is greater than or equal to the space threshold value in the root node of a binary heap, and sets address information other than the lowest address in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node; when allocating space, at least one target free space block is allocated based on the set binary heap, and each time the allocation is made, the target free space block corresponding to the address recorded by the root node of the binary heap is allocated first, and after the allocation, the lowest address is indicated by the root node in the binary heap, and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node. According to the principle of the address indicated by the point, the address indicated by each node in the binary heap is updated to ensure that each allocation is from the root node to the target free space block corresponding to the lowest address of all the address information currently obtained, that is, the free space with low address can be allocated first. Due to the mechanical characteristics of the hard disk, the free space with low address is close to the outer track of the disk, the track line speed is high and the data density is high, so the read and write speed is relatively high. At the same time, because the free space blocks greater than or equal to the space threshold are allocated first, large blocks of continuous free space can reduce the influence of factors such as disk rotation delay, head seek time, and head stabilization time, further improving the overall read and write speed of the storage system.

[0019] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0021] Figure 1 is a schematic diagram of a disk storage scenario in the related art;

[0022] Figure 2 It is a schematic diagram of a space allocation scenario in the related art;

[0023] Figure 3 It is a flowchart of a disk space allocation method according to an embodiment of the present application;

[0024] Figure 4 This is a schematic diagram of a disk space allocation scenario of an embodiment of the present application;

[0025] Figure 5 is a schematic diagram of a disk space allocation scenario of another embodiment of the present application;

[0026] Figure 6 is a schematic diagram of a disk space allocation scenario of another embodiment of the present application;

[0027] Figure 7 It is a structural schematic diagram of a disk space allocation device according to an embodiment of the present application;

[0028] Figure 8 It is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to enable those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be described in detail below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field should fall within the scope of protection of this application.

[0030] First, an exemplary introduction to the space allocation method in the related art is given:

[0031] In the storage system of the related art, data can be stored through a disk, for example, through a traditional hard disk (Hard Disk Drive, HDD), and the disk can manage the mapping relationship between the physical space address of the disk and the user data through a space allocator. When the disk space allocator is created for the first time, the space allocator can use the entire continuous disk space as the allocable space. When the user writes data to the object / file, the space allocator allocates a space size that meets the requirements from the allocable space, and returns the physical address range of the allocated space on the disk to the caller, so that the user data is written to this allocated disk space. The allocated space address can be saved in the metadata of the corresponding object / file. And the allocator deletes the allocated space address from the above-mentioned allocable space, and maintains the remaining allocable space after the deletion operation. However, in the storage system of the related art, the read and write speeds of the inner and outer tracks of the same hard disk are not balanced. For example, when allocating hard disk space, when the allocated space is close to the inner track of the hard disk, the read and write speeds are relatively slow due to the low track linear velocity and low data density; when the allocated space is close to the outer track of the hard disk, the read and write speeds are relatively fast due to the high track linear velocity and high data density. When allocating hard disk space, the related art does not consider the address of the space on the same hard disk, that is, it does not consider whether the allocated space is close to the inner or outer track of the same hard disk. Then the probability that the allocated space is close to the inner track is greater. When the allocated space is close to the inner track, the read and write speeds are relatively slow due to the low track linear velocity and low data density of the space close to the inner track. At the same time, when the allocated space is relatively discrete, the read and write speeds will also slow down due to factors such as the disk platter rotation delay, head seek time, and head stabilization time. This ultimately slows down the overall operation speed of the storage system.

[0032] The following is an explanation based on a specific scenario. Figure 1 In this specific scenario, take a hard disk with a space size of 512M as an example. Assume that the space usage of the hard disk is as follows Figure 1As shown, the allocated space, i.e., the occupied non-free space, is shown as 11-13M and 85M. For the unallocated space, i.e., the free space, such as the space with addresses 0-11M and 473-512M, it can be understood that the address of the space 0-11M is lower, and the address of the space 473-512M is higher, i.e., the space 0-11M is closer to the outer track of the disk, and the space 473-512M is closer to the inner track of the disk. Then, the track linear velocity of the space 0-11M is higher and the data density is higher, and the read and write speed is relatively slower, while the track linear velocity of the space 473-512M is lower and the data density is lower, and the read and write speed is relatively slower. However, in the related art, when allocating space, the address of the space on the hard disk is not considered, i.e., the allocation of lower addresses (e.g., 0-11M) or higher addresses (473-512M) is random, and the probability of allocating to the space with higher addresses is higher, resulting in lower track linear velocity and lower data density, and relatively slower read and write speeds.

[0033] It is worth noting that the above introduction to the disk space allocation scenario is only an exemplary display. In actual application, other allocation scenarios are not excluded and are not specifically limited to this.

[0034] The following is an exemplary description of two specific space allocators in the related art:

[0035] See also Figure 2 , taking the Bitmap allocator as an example, the BitMap allocator organizes the data structure in a tree-like manner, which is divided into three layers: L0, L1, and L2. Each layer contains a complete disk space mapping, and the granularity of the basic unit of bit operation (slot) and the allocation unit (children) of the slot are different in each layer, which can speed up the search. Figure 2 As shown, the steps for the BitMap allocator to allocate space can be as follows:

[0036] (1) Loop through L2 to find the slots and children locations where space can be allocated.

[0037] (2) Based on the slots and children positions of L2, loop to find the slots and children positions in L1 that can allocate space.

[0038] (3) Based on the slots and children positions of L1, loop to find the slots and children positions in L0 that can allocate space.

[0039] (4) Save the results of the space allocation in steps (1)-(3) and set the flag bit of the corresponding position allocation in each layer.

[0040] Taking the self-balancing binary search tree (Avl-tree) allocator as another example, the AVL tree used by the Avl-tree allocator is a balanced binary tree, that is, if it is a non-empty tree, the height difference between the left and right subtrees does not exceed 1. Two AVL trees are defined in the Avl-tree allocator: one is an AVL tree sorted by starting position (offset) (that is, the nodes are sorted according to their starting positions in the storage space), hereinafter referred to as Tree1, and the other is an AVL tree sorted by space size (length) (that is, the nodes are sorted according to the size of the storage space they occupy), hereinafter referred to as Tree2.

[0041] When allocating space, the Avl-tree allocator first decides which tree to start searching from based on the length (the size of the space requested by the user) and the size of the last node in Tree2 (the largest continuous interval, that is, the current largest continuous available space). If one of the following three conditions is met, it is allocated from Tree2; otherwise, it is allocated from Tree1:

[0042] (1) The largest contiguous block in Tree2 (i.e., the size of the space of the last node) is smaller than the space requested by the user.

[0043] (2) The remaining free space in Tree2 is less than the preset ratio.

[0044] (3) The largest continuous block in Tree2 is smaller than the preset value.

[0045] For the BitMap allocator, since the process of allocating space is a linear search process, the BitMap allocator always searches for allocatable units one by one in order, and finally pieces them together into the large block of space required by the user. This will cause multiple read and write operations at different locations on the disk to allocate the required space, which will increase the disk seek time and delay, thereby affecting the overall read and write speed. As for the Avl-tree allocator, although it can avoid the problem of the BitMap allocator linearly searching for free blocks and optimize the search performance. However, it still cannot solve the problem of high fragmentation of the allocated space, and the allocated space does not give priority to the low address space of the hard disk, nor can it maintain the storage system at a high read and write level.

[0046] In view of the above problems existing in the related art, the present application provides a disk space allocation method that can improve the reading and writing speed. Figure 3 As shown, the method comprises the following steps:

[0047] S301. Obtain address information of at least one target free space block in the same disk.

[0048] The target free space block is greater than or equal to the space threshold.

[0049] S302: placing the lowest address in the acquired address information at the root node of the binary heap, and setting other acquired address information in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

[0050] S303: Allocate the target free space block based on the binary heap.

[0051] Among them, each allocation always allocates the target free space block corresponding to the address recorded by the root node, and after the allocation, the addresses indicated by each node in the binary heap are updated according to the principle that the root node in the binary heap indicates the lowest address and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

[0052] The technical solution provided by the embodiment of the present application places the lowest address in the address information of at least one target free space block that is greater than or equal to the space threshold value in the root node of the binary heap, and sets address information other than the lowest address in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node; when allocating space, allocate at least one target free space block based on the set binary heap, and each time the allocation is made, the target free space block corresponding to the address recorded by the root node of the binary heap is allocated first, and after the allocation, the lowest address is indicated by the root node in the binary heap, and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node. According to the principle of the address indicated by the node, the address indicated by each node in the binary heap is updated to ensure that each allocation is from the root node to the target free space block corresponding to the lowest address of all the address information currently obtained, that is, the free space with low address can be allocated first. Due to the mechanical characteristics of the hard disk, the free space with low address is close to the outer track of the disk, the track line speed is high and the data density is high, so the read and write speed is relatively high. At the same time, because the free space blocks greater than or equal to the space threshold are allocated first, large blocks of continuous free space can reduce the influence of factors such as disk rotation delay, head seek time, and head stabilization time, further improving the overall read and write speed of the storage system.

[0053] As an example, the above-mentioned disk can be an HDD hard disk. The disk space allocation method of the present application can be applied to any storage system that stores data through an HDD hard disk, such as a distributed hybrid flash storage system that uses an HDD hard disk to store data, or other storage systems that use an HDD hard disk to store data, without specific limitation.

[0054] The address information of at least one target free space block in the same disk can be obtained in a variety of ways. As an example, the information of each free space block in the same disk can be recorded in the first data structure respectively, wherein the information of each free space block can include address information and size information, and the address information of at least one target free space block can be obtained from the first data structure; as another example, when obtaining, the size of the free space block can be judged by the size information included in the free space block, so as to determine whether the free space block is the target free space block. It is worth noting that the above introduction to the method of obtaining address information is only an exemplary display. In practical applications, other methods of obtaining are not excluded, and no specific limitation is made to this. As another example, the address information of at least one target free space block in the same disk can be obtained dynamically and continuously, for example, the address information of the target free space block can be obtained dynamically and in real time, or the address information of the target free space block can be obtained according to a preset frequency, and no specific limitation is made to this.

[0055] It can be understood that recording the information of each free space block in the same disk in the first data structure, that is, the first data structure records the free space in blocks, means that all the current free space in the disk (that is, the total amount of free space) is divided into several blocks of free space according to spatial continuity, that is, the address of the space in each free space block is continuous, and the sum of the free space sizes of each block is equal to the total free space size of the disk. For example: Figure 1 Taking the usage of a hard disk with a total space size of 512M as an example, for the unallocated space, that is, the free space, the free space of 0-11M is continuous, which can be recorded as a free space block in the first data structure. For another example, the two free spaces of 84-85M and 87-91M are also continuous, respectively, and these two free spaces can also be recorded in the first data structure respectively.

[0056] The address information included in each free space block can be implemented in many ways. As an example, the address information included in each free space block can be the starting address information of the free space block. As another example, the address information included in each free space block can be the ending address information of the free space block. Therefore, the specific implementation of the address information is not limited. For example: Figure 1 For example, when the starting address information is used as the address information of any free space block, for Figure 1 The address information of the free space block 0-11M can be "0", and the address information of the two free space blocks 84-85M and 87-91M are "84" and "87" respectively.

[0057] The information of each free space block in the same disk can be recorded in the first data structure in a variety of ways. As an example, the first data structure can be a B+ tree (B+tree), and the information of each free space block in the same disk can be recorded in each leaf node of the B+ tree. As a tree data structure, B+tree is characterized by the insertion of elements from bottom to top. In B+tree, all data records can be stored in leaf nodes, that is, each leaf node can record the information of the free space block, including the address information and size information of the free space block, and the nodes other than the leaf nodes only store the key value and the pointer to the child node. Therefore, when a new data record is inserted, the record can be placed in the leaf node. The leaf nodes of B+tree form an ordered linked list, which enables data to be stored and accessed in the order of key values, and data access is more efficient. It is worth noting that the above introduction to the method of recording the free space blocks in the first data structure is only an exemplary display. In practical applications, other recording methods are not excluded, and no specific limitation is made to this.

[0058] See also Figure 1 , Figure 4 The following is an example of how to record free space in B+tree blocks: Figure 1 Take the usage of a hard disk with a total space of 512M as an example. Figure 4 As shown in the B+ tree structure, the leaf nodes of the B+ tree record the information of the entire free space of the same disk, including the address information (off) and size information (len) of the free space blocks. Any node in the B+ tree except the leaf nodes only stores the key value (address index) and the pointer to the child node of the node. The address information of each free space block recorded in the B+ tree can be the starting address information of each free space block. For example, the leaf node corresponding to the free space block 0 (off: 0; len: 11) records the starting address information "0" and size information "11" of the free space block 0-11M. For another example, the leaf node corresponding to the free space block 346 (off: 346; len: 3) records the starting address information "346" and size information "3" of the free space block 346-348M. It can be understood that multiple free space blocks can be merged into the same leaf node or recorded independently on different leaf nodes. For example, free space block 14 and free space block 84 can be recorded on the same leaf node, free space block 206 and free space block 228 can also be recorded on the same leaf node, while free space block 341 is recorded independently on a leaf node.

[0059] As an example, the address information of the free space blocks whose size is greater than or equal to the space threshold value, i.e., the address information of the target free space blocks, can be extracted from the free space blocks recorded in the first data structure. Multiple target free space blocks correspond to multiple pieces of address information. The lowest address of the extracted multiple pieces of address information can be placed in the root node of the binary heap, and other acquired address information can be set in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node. When allocating space, each target free space block indicated by the address set in the binary heap is allocated first, ensuring that large and continuous space is allocated first. At the same time, each allocation always allocates the target free space block corresponding to the address set by the root node of the binary heap (i.e., the top of the binary heap), and after the allocation, according to the principle that the root node in the binary heap indicates the lowest address, and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node, the address indicated by each node in the binary heap is updated. For example, for the root node, each time the target free space block corresponding to the lowest address currently set is allocated, the lowest address set by the root node is updated, that is, updated to the lowest address among the addresses currently set by other nodes, and the target free space block corresponding to the lowest address after the root node is updated is still allocated in the next allocation. As another example, the specific process of the update is to move the address higher than the lowest address allocated from the root node but lower than other addresses to the top of the binary heap as the new lowest address. In this way, each allocation allocates the target free space block with the lowest address among all the remaining target free space blocks from the top of the binary heap, that is, further ensures that the target free space block with a low address can be allocated preferentially. It can ensure that the target free space block with a low address can be allocated preferentially.

[0060] See also Figure 1 , Figure 4 , the following is an exemplary introduction to the way of setting the address information of the target free space block of the binary heap:

[0061] Still Figure 1 Take the usage of a hard disk with a total space of 512M as an example. Figure 4In the binary heap structure shown, assuming that the above space threshold is 10M, each node of the binary heap records the address information of the target free space block whose size is greater than or equal to 10M. The address information of each target free space block recorded in the binary heap may be the starting address information of each target free space block. For example, the size of the target free space block 0 (off: 0; len: 11) is greater than 10M, and its corresponding node in the binary heap records the starting address information "0" of the target free space block 0 (off: 0; len: 11). At the top of the binary heap, the free space block with the lowest address among all the remaining target free space blocks is always recorded, such as the starting address information "0" of the target free space block 0 (off: 0; len: 11). The target free space block with the lowest address among all the remaining target free space blocks is recorded at the top of the binary heap. The address recorded by any parent node in the binary heap is lower than the address recorded by the child node of the parent node. For example, the address of the target free space block 0 (off: 0; len: 11) recorded by the top node is lower than the addresses of the target free space blocks 14 (off: 14; len: 70) and 93 (off: 93; len: 112) recorded on its child node, and the address of the target free space block 14 (off: 14; len: 70) is lower than the addresses of the target free space blocks 473 (off: 473; len: 40) and 206 (off: 206; len: 19) recorded by the child node of the node where it is located.

[0062] See also Figure 1 , Figure 4 , Figure 5 , Figure 6 , the following is an exemplary introduction to the method of allocating the target free space block from the binary heap:

[0063] Allocate from the top of the binary heap, still with Figure 1 Take the 512M hard disk as an example. Figure 4 The target free space block 0 (off: 0; len: 11) recorded at the top of the binary heap is allocated to the storage system. This target free space block has the lowest address among all target free space blocks, that is, the space closest to the outer track of the disk, and has a faster read and write speed. After the target free space block 0 (off: 0; len: 11) is allocated, the space usage of the hard disk is updated as follows: Figure 5 As shown in the figure, it can be seen that 0-11M in the hard disk is updated from unallocated to allocated. Figure 6As shown, after the target free space block 0 (off: 0; len: 11) is allocated, the information recorded in the binary heap and the B+ tree is updated, such as deleting the information of the target free space block in the binary heap and the B+ tree, and the top of the binary heap automatically updates the target free space block 14 (off: 14; len: 70) with the smallest address among all the remaining target free space blocks after this allocation. If space needs to be allocated again in the future, the target free space block 14 (off: 14; len: 70) will continue to be allocated from the top of the binary heap. This free space block is also the space closest to the outer track of the disk among all the remaining target free space blocks, and has a faster reading and writing speed.

[0064] When the target free space blocks recorded in the first data structure and greater than or equal to the space threshold are extracted by the binary heap, the free space blocks recorded in the first data structure and less than the space threshold, i.e., the candidate free space blocks, can also be extracted, and the total free space of the same disk recorded in the first data structure is equal to the sum of the sizes of all target free space blocks and all candidate free space blocks. As an example, information of at least one candidate free space block can be obtained from the first data structure, and the obtained information can be recorded in the second data structure in the order from earliest to latest when the free space blocks are released. The information of the candidate free space block can include address information and size information; as another example, when obtaining, the size of the free space block can be determined by the size information included in the free space block, so as to determine whether the free space block is a candidate free space block. If the target free space blocks recorded in the binary heap are allocated, the at least one candidate free space block can be allocated in sequence in the order from earliest to latest when the space is released based on the second data structure.

[0065] As an example, information of free space blocks whose size is smaller than the above space threshold can be extracted from each free space block recorded in the first data structure. The information may include address information and size information of the free space block, i.e., information of the candidate free space block. Multiple candidate free space blocks correspond to multiple pieces of information. The extracted multiple pieces of information can be recorded in the second data structure in the order of the time when the space is released from the earliest to the latest. When allocating space, each target free space block is allocated first. When each target free space block is allocated, each candidate free space block is allocated.

[0066] There are many ways to record the information of at least one candidate free space block in the second data structure. As an example, the second data structure can be a least recently used (Least Recently Used, LRU) linked list, and each free space block in the candidate free space block can be recorded in each data item in the LRU linked list in the order from earliest to latest when the space is released; wherein, the free space block in the candidate free space block whose space is released earliest is recorded in the head of the LRU linked list, and the free space block in the candidate free space block whose space is released latest (i.e., most recently released) is recorded in the tail of the LRU linked list. It is understandable that if the target free space block recorded in the binary heap is allocated, then the candidate free space blocks can be allocated in order from the earliest to the latest time when the space is released based on the LRU linked list, that is, each allocation is made from the free space block recorded in the link list header of the LRU linked list. After the free space block recorded in the link list header is allocated, the link list header automatically updates the record to the free space block recorded by the next data item of the link list header, that is, the free space block that is later than the time when the space of the allocated free space block in the previous link list header is released, but the time when the space is released is the earliest free space block among all the remaining candidate free space blocks. If space needs to be allocated again later, continue to allocate the free space block from the link list header. Since the recently released space will have a greater impact on the disk wear if it is allocated again immediately, in order to reduce the wear, the LRU linked list is used to allocate each candidate free space block in the order from the earliest to the latest time when the space is released. Each allocation is made from the free space block recorded in the header of the LRU linked list (that is, the free space block that was released earliest), which can ensure that the recently released space will not be allocated again immediately, thereby reducing the disk wear.

[0067] See also Figure 1 , Figure 4 , Figure 6 , the following is an exemplary introduction to the way in which the LRU linked list records the information of the candidate free space blocks:

[0068] Still Figure 1 Take the usage of a hard disk with a total space of 512M as an example. Figure 4 , Figure 6The LRU linked list structure shown in the figure assumes that the above-mentioned space threshold is 10M, and each data item of the LRU linked list records the information of the candidate free space blocks whose size is less than 10M, and the information includes address information (off) and size information (len). The address information of each candidate free space block recorded in the LRU linked list can be the starting address information of each candidate free space block. For example, the size of the candidate free space block 351 (off: 351; len: 4) is less than 10M, and its corresponding data item in the LRU linked list records the starting address information of the candidate free space block as "351". The head of the LRU linked list always records the free space block whose space is released earliest among all the remaining candidate free space blocks (hereinafter referred to as the "earliest free space block"), and the tail of the LRU linked list always records the free space block whose space is released latest among all the remaining candidate free space blocks (hereinafter referred to as the "latest free space block"), and the data items between the head and the tail of the linked list record the free space blocks except the earliest free space block and the latest free space block in the order of the time when the space is released from the earliest to the latest, such as Figure 4 As shown, the alternative free space block 351 (off: 351; len: 4) recorded at the head of the LRU linked list has its space released the earliest, that is, the moment when it changes from the "allocated" state to the "unallocated" state is the earliest, so it is recorded at the head of the linked list, and the alternative free space block 341 (off: 341; len: 3) is the earliest to be released except for the alternative free space block 351 (off: 351; len: 4), then the alternative free space block 341 is recorded in the next data item of the alternative free space block 351, and so on. The tail of the linked list records the alternative free space block 84 (off: 84; len: 2) whose space is released the latest. If the target free space block recorded in the binary heap has been allocated, the candidate free space blocks can be allocated in order from the earliest to the latest time when the space is released based on the LRU linked list, that is, each allocation is made from the free space block recorded in the head of the LRU linked list. For example, in this allocation, the candidate free space block 351 (off: 351; len: 4) currently at the head of the linked list is allocated. After the free space block is allocated, the linked list head automatically updates the record to the free space block recorded by the next data item of the linked list head, that is, the candidate free space block 341 (off: 341; len: 3). If space needs to be allocated again later, the candidate free space block 341 (off: 341; len: 3) will continue to be allocated from the head of the linked list. Each time a candidate free space block is allocated from the head of the linked list, the information of the candidate free space block can be deleted from the LRU linked list and the B+ tree.

[0069] Considering that the allocated space in the disk will be released, that is, it will become unallocated free space, for this problem, as an example, when it is detected that the allocated space in the same disk is about to be released, if the released space block can be aggregated with the free space block adjacent to the address recorded in the first data structure, the information of the free space block to be released and the free space block adjacent to the address are aggregated to insert the information of the new free space block into the first data structure; if the new free space block is greater than or equal to the space threshold, the address information of the new free space block is inserted into the binary heap; if the new free space block is less than the space threshold, the information of the new free space block is inserted into the second data structure. As another example, if the released space block cannot be aggregated with the free space block adjacent to the address recorded in the first data structure, based on the position of the information of the free space block adjacent to the address of the released space block, the information of the released space block is inserted into the first data structure; if the released space block is greater than or equal to the space threshold, the address information of the released space block is inserted into the binary heap; if the released space block is less than the space threshold, the information of the released space block is inserted into the second data structure.

[0070] As an example, whether the released space block can be aggregated with the free space block adjacent to the address recorded in the first data structure may be determined by whether the free space block adjacent to the address of the released space block and the released space block are continuous, such as continuous in address. For example, Figure 1 , Figure 4As shown, taking free space block 0 (off: 0; len: 11) as an example, the end address of the free space block is 10M, and the space from 11 to 13M is in an allocated state, i.e., a non-free state. If the space block with address 12M is released at this time, the released space block is discontinuous with the free space block adjacent to the address (free space block 0 or free space block 14). If the address is discontinuous, the released space block cannot be aggregated with the free space block adjacent to the address. If the space block with address 11M is released, it is continuous with the free space block adjacent to the address (free space block 0), and the two can be aggregated into a new free space block: free space block 0 (off: 0; len: 12). It can be understood that if the released space block can be aggregated with the free space block adjacent to the address recorded in the first data structure, the information of the free space block adjacent to the address can be deleted in the binary heap or the second data structure. For example, if the information of the free space block adjacent to the address is recorded in the binary heap, the information of the free space block adjacent to the address is deleted in the binary heap; and if the information of the free space block adjacent to the address is recorded in the LRU linked list, the information of the free space block adjacent to the address is deleted in the LRU linked list. For example: if the space block with an address of 11M is released, it can be aggregated with the free space block 0 adjacent to the address into a new free space block: at this time, the address information of the free space block 0 recorded in the binary heap can be deleted first, and then the address information of the new free space block can be reinserted into the binary heap.

[0071] It can be understood that when the second data structure is an LRU linked list, no matter whether the information of a new free space block is inserted or only the information of a released space block is inserted, since the space corresponding to the inserted information is the most recent, that is, the space released latest, no matter whether the information of a new free space block is inserted or only the information of a released space is inserted, it is inserted into the end of the LRU linked list.

[0072] Corresponding to the above method embodiment, the present application embodiment also provides a disk space allocation device, see Figure 7 As shown, the device may include:

[0073] An acquisition unit 701 is used to acquire address information of at least one target free space block in the same disk, where the target free space block is greater than or equal to a space threshold;

[0074] A setting unit 702 is used to place the lowest address in the acquired address information at the root node of the binary heap, and set other acquired address information in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node;

[0075] The allocation unit 703 is used to allocate the target free space block based on the binary heap, wherein each allocation always allocates the target free space block corresponding to the address set by the root node, and after the allocation, the address indicated by each node in the binary heap is updated according to the principle that the root node in the binary heap indicates the lowest address and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

[0076] As an example, the device also includes a recording unit, which is used to record the information of each free space block in the same disk in a first data structure, wherein the information of each free space block includes address information and size information; the acquisition unit 701 is specifically used to obtain the address information of the at least one target free space block from the first data structure.

[0077] As an example, the recording unit 701 is also used to obtain information of at least one alternative free space block from the first data structure, where the alternative free space block is smaller than the space threshold, and record the obtained information in the second data structure in order from early to late when the free space block is released, and the information of the alternative free space block includes address information and size information; if the target free space block in the binary heap is allocated, then based on the second data structure, the at least one alternative free space block is allocated in sequence from early to late when the space is released.

[0078] As an example, the first data structure is a B-plus tree, and the recording unit is specifically used to record the information of each free space block in the disk in the leaf nodes of the B-plus tree respectively.

[0079] As an example, the second data structure is an LRU linked list; the recording unit is specifically used to record each free space block in the at least one candidate free space block in the respective data items in the LRU linked list in the order from early to late when the free space block is released; wherein, the earliest released free space block in the at least one candidate free space block is recorded at the head of the linked list of the LRU linked list, and the latest released free space block is recorded at the tail of the linked list of the LRU linked list.

[0080] As an example, the recording unit is also used to detect that when an allocated space block in the disk is released, if the released space block can be aggregated with a free space block adjacent to the address recorded in the first data structure, the information of the released space block and the free space block adjacent to the address are aggregated to be inserted into the first data structure as information of a new free space block; if the new free space block is greater than or equal to the space threshold, the address information of the new free space block is inserted into the binary heap; if the new free space block is less than the space threshold, the information of the new free space block is inserted into the second data structure.

[0081] As an example, the recording unit is also used to insert the information of the released space block into the first data structure based on the position of the information of the free space block adjacent to the address of the released space block if the released space block cannot be aggregated with the free space block adjacent to the address recorded in the first data structure; if the released space block is greater than or equal to the space threshold, insert the address information of the released space block into the binary heap; if the released space block is less than the space threshold, insert the information of the released space block into the second data structure.

[0082] The present application also provides an electronic device, such as Figure 8 As shown, the electronic device includes: a processor 801; a memory 802 for storing processor executable instructions; wherein the processor 801 is configured to implement the disk space allocation method described in any of the above embodiments.

[0083] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the disk space allocation method described in any of the above embodiments is implemented.

[0084] The above is only a specific implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A disk space allocation method, characterized in that: include: Acquire address information of at least one target free space block in the same disk, where the target free space block is greater than or equal to a space threshold; The lowest address among the acquired address information is set at the root node of the binary heap, and according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node, the other acquired address information is set in the binary heap; The target free space block is allocated based on the binary heap, wherein each allocation always allocates the target free space block corresponding to the address set by the root node, and after the allocation, the address indicated by each node in the binary heap is updated according to the principle that the root node in the binary heap indicates the lowest address and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

2. The method according to claim 1, characterized in that The method further comprises: Recording the information of each free space block in the same disk in a first data structure respectively, wherein the information of each free space block includes address information and size information; The step of obtaining address information of at least one target free space block in the same disk includes: The address information of the at least one target free space block is obtained from the first data structure.

3. The method according to claim 2, characterized in that The method further comprises: Acquire information of at least one candidate free space block from the first data structure, the candidate free space block being smaller than the space threshold, and record the acquired information in a second data structure in order from earliest to latest when the free space block is released, the information of the candidate free space block including address information and size information; If the target free space block in the binary heap is allocated, then based on the second data structure, the at least one candidate free space block is allocated in order from the earliest to the latest time when the space is released.

4. The method according to claim 2, characterized in that: The first data structure is a B-plus tree, and the information of each free space block in the same disk is recorded in the first data structure respectively, including: The information of each free space block in the disk is recorded in the leaf nodes of the B-plus tree respectively.

5. The method according to claim 3, characterized in that: The second data structure is an LRU linked list; the acquired information is recorded in the second data structure in the order of the time when the free space blocks are released from the earliest to the latest, including: The free space blocks in the at least one candidate free space block are recorded in the data items of the LRU linked list in the order from the earliest to the latest when the free space blocks are released; wherein the free space block released earliest in the at least one candidate free space block is recorded in the head of the linked list of the LRU linked list, and the free space block released latest is recorded in the tail of the linked list of the LRU linked list.

6. The method according to claim 3, characterized in that The method further comprises: When it is detected that the allocated space block in the disk is released, if the released space block can be aggregated with the free space block with an address adjacent to that recorded in the first data structure, the information of the released space block and the free space block with an address adjacent to that recorded in the first data structure are aggregated to insert the information of the new free space block into the first data structure; If the new free space block is greater than or equal to the space threshold, inserting the address information of the new free space block into the binary heap; If the new free space block is smaller than the space threshold, the information of the new free space block is inserted into the second data structure.

7. The method according to claim 6, characterized in that The method further comprises: If the released space block cannot be aggregated with the free space block adjacent to the address recorded in the first data structure, inserting the information of the released space block into the first data structure based on the position of the information of the free space block adjacent to the address of the released space block; If the released space block is greater than or equal to the space threshold, inserting the address information of the released space block into the binary heap; If the released space block is smaller than the space threshold, the information of the released space block is inserted into the second data structure.

8. A disk space allocation device, characterized in that: include: An acquisition unit, used to acquire address information of at least one target free space block in the same disk, wherein the target free space block is greater than or equal to a space threshold; A setting unit, configured to place the lowest address among the acquired address information into a root node of a binary heap, and to set other acquired address information in the binary heap according to the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by the child node; An allocation unit is used to allocate the target free space block based on the binary heap, wherein each allocation always allocates the target free space block corresponding to the address set by the root node, and after the allocation, the address indicated by each node in the binary heap is updated according to the principle that the root node in the binary heap indicates the lowest address and the address indicated by any parent node in the binary heap is lower than the address indicated by the child node.

9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to implement the method according to any one of claims 1 to 7.

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

Citation Information

Patent Citations

  • Memory space management method and device

    CN107229429A

  • Disk space distribution method and device of storage system and medium

    CN115562584A

  • Disk device

    JP2000331463A

  • Magnetic disk management method, apparatus and electronic device

    US20210191616A1

  • Gang blocks

    US7437528B1

Cited By

  • File system space management method and system

    CN121614096A

  • A file system space management method and system

    CN121614096B