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

By prioritizing the allocation of low-address free space blocks on the outer ring of the hard drive using a binary heap algorithm, the problem of uneven read and write speeds caused by the speed difference between the inner and outer rings of the hard drive is solved, thus improving the overall performance of the storage system.

CN119440406BActive Publication Date: 2025-11-07XINHUASAN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing technologies do not take into account the speed difference between inner and outer tracks when allocating hard disk space, resulting in unbalanced read and write speeds and affecting the overall performance of the storage system.

Method used

The binary heap algorithm is used to prioritize the allocation of free space blocks at low addresses. The mechanical characteristics of the hard disk are utilized to prioritize the use of the outer tracks for space allocation, thereby reducing disk rotation delay and head seek time.

Benefits of technology

It improves the overall read and write speed of the storage system by prioritizing the allocation of free space blocks at low addresses and utilizing the high track linear velocity and high data density of the outer tracks of the hard drive to reduce the impact of mechanical latency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440406B_ABST
    Figure CN119440406B_ABST
Patent Text Reader

Abstract

The application discloses a disk space allocation method and device, electronic equipment and a computer readable storage medium. The disk space allocation method comprises the following steps: acquiring address information of at least one target idle space block in a same disk; setting the lowest address in the acquired address information to a root node of a binary heap, and setting the 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 a child node; and allocating the target idle space block based on the binary heap, wherein the address corresponding to the target idle space block set by the root node is allocated each time, and the address indicated by each node in the binary heap is updated after the allocation according to the principle that 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 a child node. 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 and device, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] In a storage system of the related art, the read-write speed of the inner and outer tracks of the same hard disk is not balanced. For example, when allocating space of the hard disk, if the allocated space is close to the inner track of the hard disk, the read-write speed is relatively slow due to the low linear speed and low data density of the track; if the allocated space is close to the outer track of the hard disk, the read-write speed is relatively fast due to the high linear speed and high data density of the track.

[0003] When allocating space of the hard disk, the related art does not consider the height of the address of the space on the same hard disk, that is, does not consider whether the allocated space is close to the inner track or the outer track of the same hard disk. If the allocated space is more likely to be close to the inner track, the read-write speed is relatively slow due to the low linear speed and low data density of the track close to the inner track. At the same time, when the allocated space is relatively discrete, the read-write speed is also slowed down due to the factors such as the rotation delay of the disk, the head seek time, and the head settling time. Finally, the overall running speed of the storage system is slowed down. SUMMARY

[0004] To solve the above technical problems, the present application provides a disk space allocation method and device, an electronic device, and a computer readable storage medium, and the technical solutions are as follows:

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

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

[0007] setting the lowest address in the obtained address information to the root node of a binary heap, and setting the other obtained address information in the binary heap according to the principle that the address indicated by any parent node is lower than the address indicated by the child node;

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

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

[0010] an obtaining unit configured to obtain address information of at least one target free space block in the same disk, the target free space block being greater than or equal to a space threshold;

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

[0012] an allocating unit configured to allocate the target free space block based on the binary heap, wherein each time of allocation is always to allocate a target free space block corresponding to an address set by the root node, and after the allocation, update the address indicated by each node in the binary heap according to the principle that the root node indicates the lowest address, and an address indicated by any parent node is lower than an address indicated by a child node.

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

[0014] a processor;

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

[0016] wherein the processor is configured to implement the method according to the first aspect.

[0017] According to a fourth aspect of the present application, there is provided a computer-readable storage medium having stored thereon a computer program, the computer program being executed by a processor to implement the steps in the method according to the first aspect.

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

[0019] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the application. BRIEF DESCRIPTION OF DRAWINGS

[0020] In order to more clearly illustrate the technical schemes in the embodiments of the application or the related art, the drawings needed in the embodiment or related art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments described in the application, and other drawings can also be obtained by those skilled in the art based on these drawings.

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

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

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

[0024] Figure 4 is a schematic diagram of a disk space allocation scene according to an embodiment of the application;

[0025] Figure 5 is a schematic diagram of a disk space allocation scene according to another embodiment of the application;

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

[0027] Figure 7 is a schematic diagram of a structure of a disk space allocation apparatus of an embodiment of the present application;

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

[0029] In order for 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 with reference to 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 the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art shall belong to the scope of protection of the present application.

[0030] First, the space allocation manner in the related art is exemplarily introduced:

[0031] In a storage system of the related art, data can be stored by a disk, for example, by a traditional hard disk drive (HDD), and the disk can manage a mapping relationship between a physical space address of the disk and user data by a space allocator. When the space allocator is created for the first time, the space allocator can take a whole continuous disk space as allocatable space. When a user writes data to an object / file, the space allocator allocates a space of a size satisfying a requirement from the allocatable space, and returns a physical address range of the allocated space on the disk to a caller, so that the user data is written to the allocated disk space. The allocated space address can be saved in metadata of the corresponding object / file. And the allocator deletes the allocated space address from the allocatable space, and maintains the remaining allocatable space after the deletion. However, in the storage system of the related art, the read / write speed of the inner and outer tracks of the same hard disk is unbalanced. For example, when the space of the hard disk is allocated, if the allocated space is close to the inner track of the hard disk, the read / write speed is relatively slow due to the low linear speed and low data density of the track. If the allocated space is close to the outer track of the hard disk, the read / write speed is relatively fast due to the high linear speed and high data density of the track. When the space of the hard disk is allocated, the related art does not consider the height of the address of the space on the same hard disk, that is, does not consider whether the allocated space is close to the inner track or the outer track of the same hard disk. Therefore, the probability that the allocated space is close to the inner track is relatively high. When the allocated space is close to the inner track, the read / write speed is relatively slow due to the low linear speed and low data density of the track close to the inner track. At the same time, when the allocated space is relatively discrete, the read / write speed can also be slowed down due to the factors such as the rotation delay of the disk, the head seek time, and the head settling time. Finally, the overall running speed of the storage system is slowed down.

[0032] The following will be described in combination with a specific scenario. Please refer to Figure 1 In the specific scenario, a hard disk with a space size of 512M is taken as an example. It is assumed 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, 85M. For the unallocated space, i.e. the free space, such as the space with addresses of 0-11M and 473-512M, it can be understood that the space with addresses of 0-11M has a lower address and the space with addresses of 473-512M has a higher address, i.e. the space with addresses of 0-11M is closer to the outer track of the disk and the space with addresses of 473-512M is closer to the inner track of the disk, so the track linear speed of the space with addresses of 0-11M is higher and the data density is higher, and the read-write speed is relatively slower, while the track linear speed of the space with addresses of 473-512M is lower and the data density is lower, and the read-write speed is relatively slower. However, in the related art, when allocating space, the high and low addresses of the space on the hard disk are not considered, i.e. the allocation of lower addresses (such as 0-11M) or higher addresses (473-512M) is random, so the probability of allocating space to higher addresses is higher, resulting in lower track linear speed and lower data density, and relatively slower read-write speed.

[0033] It should be noted that the above introduction of the disk space allocation scenario is only exemplary, and other allocation scenarios can exist in actual applications, which are not limited.

[0034] The following exemplary describes two specific space allocators in the related art:

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

[0036] (1) Loop to find the slot and children position that can allocate space from L2.

[0037] (2) Loop to find the slot and children position that can allocate space in L1 based on the slot and children position of L2.

[0038] (3) Loop to find the slot and children position that can allocate space in L0 based on the slot and children position of L1.

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

[0040] Taking an 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 is not more than 1. Two AVL trees are defined in the Avl-tree allocator: one is an AVL tree sorted according to the 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 according to the space size (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 determines which tree to start searching from according to the length (the size of the space requested by the user) and the size of the last node in Tree2 (the largest contiguous interval, that is, the currently largest contiguous 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 maximum contiguous block in Tree2 (that is, the size of the last node) is smaller than the space requested by the user.

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

[0044] (3) The maximum contiguous block in Tree2 is less than a preset value.

[0045] For the BitMap allocator, because the process of allocating space is a linear search process, the BitMap allocator always searches for individual allocable units in order, eventually piecing together the large block of space required by the user, which will cause multiple read and write operations at different locations on the disk to allocate the required space, which will increase the seek time and delay of the disk, thereby affecting the overall read and write speed. For the Avl-tree allocator, although it can avoid the problem of linear search for free blocks in the BitMap allocator and optimize the search performance, it still cannot solve the problem of high fragmentation of the allocated space, and the allocated space does not preferentially use 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, which can improve the read and write speed. As shown in Figure 3 The method comprises the following steps:

[0047] S301, obtaining 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 a space threshold.

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

[0050] S303, allocating the target free space block based on the binary heap.

[0051] In the method, each time of allocation is to allocate the target free space block corresponding to the address recorded by the root node, and after the allocation, the addresses indicated by the nodes in the binary heap are updated according to the principle that the root node indicates the lowest address and an address indicated by any parent node is lower than an address indicated by a child node in the binary heap.

[0052] The technical scheme provided by the embodiments of the present application places the lowest address in the address information of at least one target free space block greater than or equal to a space threshold in a root node of a binary heap, and sets the address information other than the lowest address in the binary heap according to a principle that an address indicated by any parent node is lower than an address indicated by a child node in the binary heap; when allocating space, at least one target free space block is allocated based on the set binary heap, each time of allocation is to preferentially allocate the target free space block corresponding to the address recorded by the root node of the binary heap, and after the allocation, the addresses indicated by the nodes in the binary heap are updated according to the principle that the root node indicates the lowest address and an address indicated by any parent node is lower than an address indicated by a child node in the binary heap, so that each time of allocation is from the root node to allocate the target free space block corresponding to the lowest address in all the currently acquired address information, that is, the free space with a low address can be preferentially allocated, due to the mechanical characteristics of the hard disk, the free space with a low address is close to the outer track of the disk, the track line speed is high and the data density is high, so that the read-write speed is relatively high, and meanwhile, because the free space block greater than or equal to the space threshold is preferentially allocated, the large and continuous free space can reduce the influence of factors such as disk rotation delay, head seek time, head stabilization time, and further improve the overall read-write speed of the storage system.

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

[0054] The address information of the at least one target free space block in the same disk can be acquired in various manners. As an example, information of each free space block in the same disk can be recorded in a first data structure respectively, wherein the information of each free space block can include address information and size information, and the address information of the at least one target free space block can be acquired from the first data structure. As another example, when acquiring, whether a free space block is a target free space block can be determined by judging the size of the free space block according to the size information included by the free space block. It should be noted that the above description of the manner of acquiring address information is only exemplary, and other acquisition manners can exist in actual application, and the specific implementation is not limited. As another example, the address information of the at least one target free space block in the same disk can be acquired dynamically and continuously, for example, the address information of the target free space block is acquired dynamically and in real time, or the address information of the target free space block is acquired according to a preset frequency, and the specific implementation is not limited.

[0055] It can be understood that recording 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 blocks, means that all current free spaces in the disk (that is, the total free spaces) are divided into a plurality of block free spaces according to spatial continuity, that is, the addresses of the spaces in each block free space are continuous, and the sum of the sizes of the block free spaces is equal to the total size of the current free spaces in the disk. For example, taking a hard disk with a total space size of 512M as an example, for unallocated spaces, that is, free spaces, 0-11M of the free spaces are continuous, which can be recorded in the first data structure as a block free space, and for example, 84-85M and 87-91M of the free spaces are also continuous, which can also be recorded in the first data structure as two block free spaces respectively. Figure 1

[0056] The address information included by each free space block can have various specific implementations. As an example, the address information included by each free space block can be start address information of the free space block. As another example, the address information included by each free space block can be end address information of the free space block. Therefore, the specific implementation of the address information is not limited. For example, still taking the hard disk with a total space size of 512M as an example, when the start address information is taken as the address information of any free space block, for the 0-11M block free space, the address information can be “0”, and for the 84-85M and 87-91M block free spaces, the address information corresponds to “84” and “87” respectively. Figure 1 Figure 1

[0057] ​​​The information of each free space block in the same disk can be recorded in the first data structure in various manners. As an example, the first data structure can be a 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. The B+ tree is a tree data structure, and the feature thereof is that elements are inserted from bottom to top. In the B+ tree, all data records can be stored in leaf nodes, i.e., each leaf node can record the information of a free space block, including address information and size information of the free space block, and nodes other than the leaf nodes only store key values and pointers to child nodes. Therefore, when a new data record is inserted, the record can be placed in a leaf node. The leaf nodes of the B+ tree form an ordered linked list, which enables data to be stored and accessed in a key value order, and data access is efficient. It should be noted that the above description of the manner of recording the free space blocks in the first data structure is only exemplary, and other recording manners can also be used in actual applications, which are not limited in this regard.

[0058] Please refer to Figure 1 , Figure 4 , and the following exemplary description of the manner of recording the free space blocks in the B+ tree. Still taking the use of the hard disk with a total space size of 512M in Figure 1 as an example, the B+ tree structure is shown in Figure 4 . The leaf nodes of the B+ tree record the information of all free spaces of the same disk, including address information (off) and size information (len) of the free space blocks. Any node other than the leaf nodes of the B+ tree only stores key values (address index) and pointers to child nodes of the node. The address information of each free space block recorded in the B+ tree can be the start 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 start address information "0" and the size information "11" of the free space blocks 0-11M. For another example, the leaf node corresponding to the free space block 346 (off: 346; len: 3) records the start address information "346" and the size information "3" of the free space blocks 346-348M. It can be understood that multiple free space blocks can be combined in the same leaf node or recorded independently in different leaf nodes. For example, the free space block 14 and the free space block 84 can be recorded in the same leaf node, the free space block 206 and the free space block 228 can also be recorded in the same leaf node, and the free space block 341 is recorded independently in a leaf node.

[0059] As an example, address information for free space blocks whose size is greater than or equal to a space threshold can be extracted from the free space blocks recorded in the first data structure. This is the address information of the target free space blocks. Multiple target free space blocks correspond to multiple address information entries. The lowest extracted address can be placed at the root node of a binary heap. Following the principle that the address indicated by any parent node in the binary heap is lower than the address indicated by any child node, other obtained address information is set in the binary heap. During space allocation, priority is given to allocating the target free space blocks indicated by the addresses set in the binary heap, ensuring that large and contiguous blocks of space are allocated preferentially. Simultaneously, each allocation always allocates the target free space block corresponding to the address set by the root node (i.e., the top of the binary heap). After allocation, the addresses indicated by each node in the binary heap are updated according to the principle that the lowest address indicated by the root node and the address indicated by any parent node in the binary heap is lower than the address indicated by its child node. For example, for the root node, after each allocation of the target free space block corresponding to its currently set lowest address, the root node's lowest address is updated to the lowest address set by all other nodes. In the next allocation, the target free space block corresponding to the updated lowest address of the root node is still allocated. As another example, the specific update process is to move addresses higher than the lowest address already 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 remaining target free space blocks from the top of the binary heap, further ensuring that target free space blocks with low addresses are allocated preferentially. This ensures that target free space blocks with low addresses are allocated preferentially.

[0060] Please see Figure 1 , Figure 4 The following is an example of how to set the address information of the target free space block in a binary heap:

[0061] Still with Figure 1 Taking the usage of a hard drive with a total space of 512MB as an example, for instance... Figure 4The binary heap structure shown assumes a space threshold of 10M. Each node in the binary heap records the address information of target free space blocks with a size greater than or equal to 10M. The address information of each target free space block recorded in the binary heap can be the starting address information of each target free space block. For example, if the size of target free space block 0 (off: 0; len: 11) is greater than 10M, the node corresponding to it in the binary heap records the starting address information "0" of 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 remaining target free space blocks is always recorded, such as the starting address information "0" of target free space block 0 (off: 0; len: 11). If the address of the lowest target free space block among all remaining targets is the target free space block, then it 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 nodes of that 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 by its child nodes. 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 nodes of its node.

[0062] Please see Figure 1 , Figure 4 , Figure 5 , Figure 6 The following is an example of how to allocate a target free space block from a binary heap:

[0063] Distribution is made from the top of the binary heap, still using... Figure 1 Taking a 512MB hard drive 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, meaning it is closest to the outer track of the disk, resulting in faster read and write speeds. After allocating target free space block 0 (off: 0; len: 11), the disk space usage is updated as follows: Figure 5 As shown, the 0-11M space on the hard drive has been updated from an unallocated state to an allocated state. Simultaneously, as... 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, i.e. the information of the target free space block 0 is deleted in the binary heap and the B+ tree, and the top of the binary heap is automatically updated to record the target free space block 14 (off: 14; len: 70) with the smallest address among all the target free space blocks remaining after the allocation. If the space needs to be allocated again subsequently, the target free space block 14 (off: 14; len: 70) is allocated from the top of the binary heap, which is also the space closest to the outer track of the disk among all the target free space blocks remaining after the allocation, and thus has a faster read-write speed.

[0064] While the target free space blocks greater than or equal to the space threshold recorded in the first data structure are extracted by the binary heap, the free space blocks smaller than the space threshold recorded in the first data structure, i.e. the alternative free space blocks, can also be extracted, and the total free space of the same disk recorded in the first data structure, i.e. the sum of the sizes of all the target free space blocks and all the alternative free space blocks. As an example, the information of at least one of the alternative free space blocks can be obtained from the first data structure, and the obtained information is recorded in the second data structure in the order from the time when the free space blocks are released to the time when the free space blocks are released, and the information of the alternative free space blocks 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 an alternative free space block. If the target free space blocks recorded in the binary heap are allocated, the at least one alternative free space block can be allocated in sequence based on the second data structure in the order from the time when the space is released to the time when the space is released.

[0065] As an example, the information of the free space blocks with a size smaller than the space threshold recorded in the first data structure can be extracted, which can include the address information and the size information of the free space blocks, i.e. the information of the alternative free space blocks, and a plurality of alternative free space blocks correspond to a plurality of information, and the extracted plurality of information can be recorded in the second data structure in the order from the time when the space is released to the time when the space is released. When allocating the space, the target free space blocks are preferentially allocated, and the alternative free space blocks are allocated after the target free space blocks are allocated.

[0066] There are various ways to record the information of the at least one alternative free space block in the second data structure. As an example, the second data structure can be a Least Recently Used (LRU) linked list, and each of the alternative free space blocks can be recorded in a data item in the LRU linked list in order of time of space release from early to late. The alternative free space block in which the space is released earliest is recorded at the head of the LRU linked list, and the alternative free space block in which the space is released latest (i.e., the space is released most recently) is recorded at the tail of the LRU linked list. It can be understood that if the target free space block recorded in the binary heap is allocated, the LRU linked list can be used to allocate each of the alternative free space blocks in order of time of space release from early to late, i.e., each time the free space block recorded at the head of the LRU linked list is allocated, and after the free space block recorded at the head of the LRU linked list is allocated, the head of the LRU linked list is automatically updated to record the free space block recorded in the next data item of the head of the LRU linked list, i.e., the free space block in which the space is released later than the free space block allocated from the previous head of the LRU linked list, but in which the space is released earliest among all the alternative free space blocks currently remaining. If the space needs to be allocated again, the free space block recorded at the head of the LRU linked list is allocated. Since the space is released most recently, if the space is immediately allocated again, the wear degree of the disk is relatively large. In order to reduce the wear degree, the LRU linked list is used to allocate each of the alternative free space blocks in order of time of space release from early to late, and each time the free space block recorded at the head of the LRU linked list (i.e., the free space block in which the space is released earliest) is allocated, which can ensure that the space released most recently is not immediately allocated again, thereby reducing the wear degree of the disk.

[0067] Please refer to Figure 1 、 Figure 4 、 Figure 6 The following exemplary introduces the way in which the LRU linked list records the information of the alternative free space blocks:

[0068] Still taking the use of the hard disk with a total space size of 512M in Figure 1 as an example, as shown in Figure 4 、 Figure 6The LRU chain table structure shown, assuming the space threshold is 10M, each data item of the LRU chain table records information of the candidate free space block with size less than 10M, including address information (off) and size information (len), the address information of each candidate free space block recorded in the LRU chain table can be the start 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 the start address information of the candidate free space block recorded in the corresponding data item in the LRU chain table is "351". In the chain table head of the LRU chain table, the earliest free space block (hereinafter referred to as "the earliest free space block") among all the currently remaining candidate free space blocks is always recorded, and in the chain table tail of the LRU chain table, the latest free space block (hereinafter referred to as "the latest free space block") among all the currently remaining candidate free space blocks is always recorded, and each data item between the chain table head and the chain table tail records the free space blocks other than the earliest free space block and the latest free space block in the order from early to late according to the time when the space is released, for example Figure 4 As shown, the candidate free space block 351 (off: 351; len: 4) recorded in the chain table head of the LRU chain table is the earliest released, that is, the time when it changes from the "allocated" state to the "unallocated" state is the earliest, so it is recorded in the chain table head, and the candidate free space block 341 (off: 341; len: 3) is the earliest released except the candidate free space block 351 (off: 351; len: 4), so the candidate free space block 341 is recorded in the next data item of the candidate free space block 351. By analogy, the chain table tail records the candidate free space block 84 (off: 84; len: 2) which is the latest released. If the target free space block recorded in the binary heap is allocated, the candidate free space block can be allocated in order from early to late according to the time when the space is released based on the LRU chain table, that is, each time the free space block recorded in the chain table head of the LRU chain table is allocated, for example, in this allocation, the candidate free space block 351 (off: 351; len: 4) currently in the chain table head is allocated, after the allocation of the free space block, the chain table head is automatically updated to record the free space block recorded in the next data item of the chain table head, that is, the candidate free space block 341 (off: 341; len: 3), if subsequent space needs to be allocated again, the candidate free space block 341 (off: 341; len: 3) is continued to be allocated from the chain table head. Each time the candidate free space block is allocated from the chain table head, the information of the candidate free space block can be deleted in the LRU chain table and the B+ tree.

[0069] In view of the allocated space in the disk being released, i.e., becoming unallocated free space, to address the 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 address-adjacent free space block recorded in the first data structure, the information of the released space block and the address-adjacent free space block is aggregated to be inserted into the first data structure as the 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. As another example, if the released space block cannot be aggregated with the address-adjacent free space block recorded in the first data structure, based on the position of the information of the address-adjacent free space block 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 address-adjacent free space block recorded in the first data structure can be judged based on whether the address-adjacent free space block and the released space block are continuous, e.g., continuous in address, for example, as follows: Figure 1 、 Figure 4As shown, taking the idle space block 0 (off: 0; len: 11) as an example, the end address of the idle space block is 10M, and the space of 11-13M is in the allocated state, i.e., not idle. If the space block with the address of 12M is released at this time, the released space block is not contiguous to the idle space block (idle space block 0 or idle space block 14) adjacent in address, i.e., not contiguous in address, and thus the released space block cannot be aggregated with the idle space block adjacent in address. If the space block with the address of 11M is released, the released space block is contiguous to the idle space block (idle space block 0) adjacent in address, and thus the two can be aggregated into a new idle space block: idle space block 0 (off: 0; len: 12). It can be understood that if the released space block can be aggregated with the idle space block adjacent in address recorded in the first data structure, the information of the idle space block adjacent in address can be deleted from the binary heap or the second data structure, for example, if the information of the idle space block adjacent in address is recorded in the binary heap, the information of the idle space block adjacent in address is deleted from the binary heap; and if the information of the idle space block adjacent in address is recorded in the LRU linked list, the information of the idle space block adjacent in address is deleted from the LRU linked list. For example, if the space block with the address of 11M is released, the released space block can be aggregated with the idle space block 0 adjacent in address into a new idle space block: at this time, the address information of the idle space block 0 recorded in the binary heap can be deleted first, and then the address information of the new idle space block is inserted into the binary heap again.

[0071] It can be understood that when the second data structure is the LRU linked list, whether the information of the new idle space block is inserted or only the information of the released space block is inserted, since the space corresponding to the inserted information is the most recently released space, i.e., the latest released space, the information of the new idle space block or only the information of the released space is inserted into the tail of the LRU linked list.

[0072] Corresponding to the method embodiment, the embodiment of the application further provides a disk space allocation device, as shown in Figure 7 The device can include:

[0073] The acquisition unit 701 is configured to acquire address information of at least one target idle space block in the same disk, the target idle space block being greater than or equal to a space threshold value;

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

[0075] The allocation unit 703 is configured to allocate the target free space block based on the binary heap, wherein each time of allocation is to allocate the target free space block corresponding to the address of 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 indicates the lowest address in the binary heap, and the address indicated by any parent node is lower than the address indicated by the child node.

[0076] As an example, the apparatus further comprises a recording unit configured to record information of each free space block in the same disk in a first data structure respectively, wherein the information of each free space block comprises address information and size information; and the obtaining unit 701 is specifically configured 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 further configured to obtain 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 obtained information in a second data structure in the order from early to late of the time when the free space block is released, the information of the candidate free space block comprising address information and size information; and if the target free space block in the binary heap is allocated completely, the at least one candidate free space block is sequentially allocated in the order from early to late of the time when the free space block is released based on the second data structure.

[0078] As an example, the first data structure is a B+ tree, and the recording unit is specifically configured to record the information of each free space block in the disk in a leaf node of the B+ tree.

[0079] As an example, the second data structure is an LRU linked list; and the recording unit is specifically configured to record each free space block in the at least one candidate free space block in each data item in the LRU linked list in the order from early to late of the time 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 LRU linked list, and the latest released free space block is recorded at the tail of the LRU linked list.

[0080] As an example, the recording unit is further configured to, when detecting that a space block allocated in the disk is released, if the released space block can be aggregated with the address-adjacent free space block recorded in the first data structure, aggregate the information of the released space block and the address-adjacent free space block as the information of a new free space block and 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, insert the address information of the new free space block into the binary heap; and if the new free space block is less than the space threshold, insert the information of the new free space block into the second data structure.

[0081] As an example, the recording unit is further configured to, when detecting that a space block allocated in the disk is released, if the released space block can be aggregated with the address-adjacent free space block recorded in the first data structure, aggregate the information of the released space block and the address-adjacent free space block as the information of a new free space block and 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, insert the address information of the new free space block into the binary heap; and if the new free space block is less than the space threshold, insert the information of the new free space block into the second data structure.

[0082] The present application also provides an electronic device, as shown in the accompanying drawings, which comprises a processor 801 and 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. Figure 8 The present application also provides an electronic device, as shown in the accompanying drawings, which comprises a processor 801 and 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 having a computer program stored thereon, wherein the computer program is executed by a processor to implement the disk space allocation method described in any of the above embodiments.

[0084] The above is merely specific embodiments of the present application, and it should be noted that, for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should also be considered as falling within the scope of protection of the present application.

Claims

1. A method of disk space allocation, characterized by, The method comprises: obtaining address information of at least one target free space block in the same disk, the target free space block being greater than or equal to a space threshold; setting the lowest address in the obtained address information to a root node of a binary heap, and setting other obtained address information in the binary heap according to a principle that an address indicated by any parent node in the binary heap is lower than an address indicated by a child node; allocating the target free space block based on the binary heap, wherein each allocation is always of a target free space block corresponding to the address set by the root node, and after the allocation, the address indicated by the root node is the lowest address in the binary heap, and the address indicated by any parent node in the binary heap is lower than the address indicated by a child node.

2. The method of claim 1, wherein, The method further comprises: recording information of each free space block in the same disk in a first data structure respectively, wherein the information of each free space block comprises address information and size information; the obtaining of the address information of the at least one target free space block in the same disk comprises: obtaining the address information of the at least one target free space block from the first data structure.

3. The method of claim 2, wherein, The method further comprises: obtaining information of at least one alternative free space block from the first data structure, the alternative free space block being smaller than the space threshold, and recording the obtained information in a second data structure in an order from early to late in terms of a time when the free space block is released, the information of the alternative free space block comprising address information and size information; if the allocation of the target free space block in the binary heap is completed, allocating the at least one alternative free space block in an order from early to late in terms of a time when the free space block is released based on the second data structure.

4. The method of claim 2, wherein, The first data structure is a B+ tree, and the recording of the information of each free space block in the same disk in the first data structure comprises: recording the information of each free space block in the disk in a leaf node of the B+ tree.

5. The method of claim 3, wherein, The second data structure is an LRU linked list, and the recording of the obtained information in the second data structure in an order from early to late in terms of a time when the free space block is released comprises: recording each free space block in the at least one alternative free space block in each data item in the LRU linked list in an order from early to late in terms of a time when the free space block is released, wherein the earliest released free space block in the at least one alternative free space block is recorded at a head of the LRU linked list, and the latest released free space block is recorded at a tail of the LRU linked list.

6. The method of claim 3, wherein, The method further comprises: when detecting that 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, aggregating the information of the released space block and the free space block adjacent to the address to be information of a new free space block and inserting the information into the first data structure; if the new free space block is greater than or equal to the space threshold, inserting address information of the new free space block into the binary heap. If the new free space block is smaller than the space threshold, information of the new free space block is inserted into the second data structure.

7. The method of claim 6, wherein, 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, information of the released space block is inserted 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, address information of the released space block is inserted into the binary heap; If the released space block is smaller than the space threshold, information of the released space block is inserted into the second data structure.

8. A disk space allocation apparatus characterized by comprising: Comprise: An acquisition unit configured to acquire address information of at least one target free space block in a same disk, the target free space block being greater than or equal to a space threshold; A setting unit configured to set the lowest address in the acquired address information to a root node of a binary heap, and set other obtained address information in the binary heap according to a principle that an address indicated by any parent node is lower than an address indicated by a child node; An allocation unit configured to allocate the target free space block based on the binary heap, wherein each time of allocation is to allocate a target free space block corresponding to an address set by the root node, and after the allocation, update addresses indicated by each node in the binary heap according to the principle that the root node indicates the lowest address, and an address indicated by any parent node is lower than an address indicated by a child node.

9. An electronic device, comprising: Comprise: A processor; A memory for storing processor-executable instructions; The processor is configured to implement the method in any one of claims 1 to 7.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by the processor, implements the steps in the method in any one of claims 1 to 7. The computer program, when executed by the processor, implements the steps in the method in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Memory space management method and device

    CN107229429A

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

    CN115562584A