Multi-Namespace distribution management method applied to NVMe SSD
By using dynamically sized allocation units, free lists, and red-black tree management, the problem of gaps in NVMe SSD multi-namespace space management is solved, improving space utilization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-04-10
AI Technical Summary
The existing multi-namespace space management method for NVMe SSDs results in low physical space utilization and voiding issues.
It adopts a dynamically variable allocation unit, manages free and allocated space through a free linked list and a red-black tree, and dynamically allocates namespaces to avoid space waste.
It effectively avoids physical space gaps, improves storage space utilization, and achieves intelligent management.
Smart Images

Figure CN121832834A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of solid-state storage, specifically a method for multi-namespace allocation and management applied to NVMe SSDs. Background Technology
[0002] NVMe SSDs are solid-state drives that conform to the Non-Volatile Memoryexpress (NVMe) host controller interface specification. An SSD consists of a controller and memory. Current NVMe SSDs often support multiple namespaces, which divide the SSD's physical space into multiple logical namespaces. Each logical namespace corresponds to a portion of the physical space, and the physical space addresses of each namespace do not overlap. The addresses of the logical space all start from 0.
[0003] Currently available technologies mostly manage the logical addresses of namespaces using fixed block allocation. This method typically divides the entire SSD space into N blocks. When a namespace is created, M (M <= N) blocks are requested, regardless of whether the namespace size is an integer multiple of the block size. Therefore, this method can lead to gaps in the physical space of the SSD during use, reducing space utilization. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention applies to a multi-namespace space allocation management method for NVMe SSDs. By using dynamically variable-sized allocation units, it avoids space waste caused by SSD physical space gaps and improves space utilization.
[0005] To solve the aforementioned technical problem, the technical solution adopted by this invention is: a multi-namespace space allocation and management method applied to NVMe SSDs, comprising the following steps: S01. Define a data structure for managing free space and allocated space. Use a free linked list to manage free space. The free linked list includes multiple free block nodes. Each free block node represents the starting LBA and length of a contiguous LBA space that is not occupied by the Namespace. Use the red-black tree of the Namespace and allocated block nodes to manage the allocated LBA range within each Namespace. Each allocated block node represents the starting LBA and length of the LBA space occupied by each Namespace. S02. Create a Namespace by searching for free blocks in the free list. The search method prioritizes finding the best matching free block, which is the free block closest to requested_size in the range [requested_size, LEN]. requested_size is the size of the Namespace to be created, and LEN is the length of the logical address space of the entire SSD. If no best matching free block is found, continue searching to see if the space after merging adjacent free blocks is greater than or equal to requested_size. If not, continue merging adjacent free blocks, and so on, until a combination of free blocks that meets the conditions is found or the free list has been traversed. S03. After finding the best matching free block or a combination of free blocks that meet the conditions, remove target_node->size from the free list, calculate the remaining space after allocation: remaining_size = target_node->size - requested_size. If remaining_size > 0, insert the remaining space back into the free list as a new free block; target_node->size is the size of the best matching free block or the combination of free blocks that meet the conditions. S04. After the Namespace is created, target_node->start_lba and requested_size are filled into the allocated block nodes, and the allocated block nodes are inserted into the red-black tree of the Namespace. The red-black tree is organized according to the starting address; target_node->start_lba is the starting LBA of the best matching free block or the combination of free blocks that meet the conditions. S05. When a namespace is deleted, the deleted LBA range is written to a node, and the node is inserted between adjacent nodes according to the actual address. If the starting address and length of adjacent nodes are consecutive, the adjacent nodes are merged into one.
[0006] Furthermore, during SSD initialization, the head pointer of the free list points to a node with a starting LBA address of 0 and a length equal to the total number of LBAs in the SSD.
[0007] Further, step S02 searches for the best-matching free block by traversing the head pointer of the free list. If a best-matching free block is found, its node number and size are recorded. If no best-matching free block is found, the merge scan process begins. The head pointer of the free list is traversed again, and adjacent free blocks are checked. If the addresses of the current node and the next node are contiguous, their combined size is calculated. If the combined size is greater than or equal to requested_size, the merged space meets the requirement. If two adjacent merges still do not meet the requirement of being greater than or equal to requested_size, multiple free blocks are merged until a combination of free blocks that meets the condition is found or the free list has been traversed completely. If the addresses of the current node and the next node are not contiguous, the current node is removed from the free list and inserted into the red-black tree of the Namespace. The requested_size of the Namespace is then modified to requested_size – the length of the current node.
[0008] Furthermore, a maximum number of nodes to merge is set. If the maximum number of nodes to merge is reached but the value is still greater than or equal to requested_size, the process exits and returns a failure message.
[0009] Furthermore, the starting LBA of the new free block formed by the remaining space is target_node->start_lba+requested_size, and its length is remaining_size.
[0010] Furthermore, step S05 specifically includes: S51. Traverse the red-black tree of the deleted namespace and obtain all allocated intervals; S52. For each allocated block node in the red-black tree, create a new free block node according to its starting LBA and size, and insert the new free block node into the free list in address order. During insertion, a check and merge is performed to check whether the addresses of the new node are consecutive with the addresses of the preceding and following nodes in the free list. If they are, the nodes are merged. S53. Clean up, release all nodes in the red-black tree of the Namespace, and destroy the Namespace data structure.
[0011] Furthermore, the merging process involves adjusting the size of the predecessor or successor node and then releasing the merged node.
[0012] The beneficial effects of this invention are as follows: This invention avoids space waste caused by physical space gaps in SSDs by using dynamically sized allocation units, thereby improving space utilization. This invention can dynamically and intelligently manage multiple namespaces of NVMe SSDs, effectively avoiding physical space gaps and significantly improving storage space utilization efficiency. Attached Figure Description
[0013] Figure 1 This represents the intention of a chain representing the entire free space of the SSD; Figure 2 Intended meaning for the free chain after the namespace is created; Figure 3 A schematic diagram of the allocated block nodes corresponding to the Namespace red-black tree; Figure 4 This is a flowchart of the method described in Example 1. Detailed Implementation
[0014] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0015] Example 1 This embodiment discloses a multi-namespace space allocation and management method for NVMe SSDs, avoiding the problem of empty physical space in SSDs and improving space utilization. To solve the problem of empty physical space, the technical solution adopted in this invention is: a multi-namespace space allocation and management method for NVMe SSDs, where Namespace refers to the logical space divided within the NVMe protocol host, LBA refers to the logical block address, requested_size is the size of the created Namespace, target_node->size is the size of the best matching free block or a combination of free blocks that meets the conditions, target_node->start_lba is the starting LBA of the best matching free block or a combination of free blocks that meets the conditions, and remaining_size is the remaining space size after allocation.
[0016] like Figure 4 As shown, the method includes the following steps: I. Data Structure Design: Define data structures for managing free and allocated space. Define free block nodes (free_node_t) and free lists (Free_List). This structure is used to manage all contiguous LBA space not occupied by any namespace. Figure 1As shown, during SSD initialization, g_free_list_head points to a node with start_lba=0 and size=the total number of LBAs in the SSD.
[0017] Define the allocated block nodes (used_node_t) and the red-black tree (Used_Tree) of the namespace. This structure is used to manage the allocated LBA ranges within each namespace. The red-black tree provides efficient lookup, insertion, and deletion operations by key (starting LBA).
[0018] II. Namespace Creation and Space Allocation (namespace_create): Step 1: Initial scan (best fit) Traverse the free list g_free_list_head, searching for a free block whose size is greater than or equal to requested_size and is closest to it. Record the node number best_fit_node and its size best_fit_size of this candidate block.
[0019] Step 2: Post-merge scan (to resolve holes). If no suitable block is found in the initial scan (i.e., best_fit_node is empty), then the merge scan process begins: Iterate through g_free_list_head again, this time checking adjacent free blocks. Since the linked list is sorted by LBA address, adjacent nodes are likely to be physically contiguous.
[0020] If the addresses of the current node `curr` and the next node `curr->next` are found to be contiguous (i.e., `curr->start_lba + curr->size == curr->next->start_lba`), then the combined size `combined_size` is calculated. If the addresses of the current node `curr` and the next node `curr->next` are not found to be contiguous, then the current node is removed from the free list, inserted into the red-black tree of this namespace, and the namespace's `requested_size` is modified to `requested_size - current node length`.
[0021] If combined_size >= requested_size, then the merged space meets the requirements. Record the current node curr as the starting point of the merged block.
[0022] If merging two adjacent nodes isn't enough, you can continue trying to merge three, four, and so on, until you find a combination that meets the conditions or traverse the entire linked list. To control complexity, you can set a maximum number of nodes to merge. If the maximum number of nodes to merge is reached but the result is still not greater than or equal to requested_size, exit and return a failure message.
[0023] Step 3: Allocate space: If a suitable free block (or merge block) target_node is found through step 1 or step 2.
[0024] Remove target_node from g_free_list.
[0025] Calculate the remaining space after allocation: The remaining size remaining_size=target_node->size-requested_size.
[0026] If remaining_size > 0, the remaining space needs to be inserted back into the linked list as a new free block, such as... Figure 2 As shown: The start_lba of the new free block is calculated as target_node->start_lba + requested_size.
[0027] The size of the new free block is equal to the remaining size.
[0028] Insert the new node into g_free_list in address order. Release the original target_node data structure.
[0029] Step 4: Update Namespace: Create a new used_node_t, such as Figure 3 As shown, its start_lba is target_node->start_lba, and its size is requested_size.
[0030] Insert this node into the red-black tree used_tree_root corresponding to this namespace.
[0031] III. Namespace Deletion and Space Release (namespace_delete): This function is responsible for releasing space and merging it back into the global free pool, which is crucial for maintaining space continuity.
[0032] Step 1: Traverse the red-black tree. Inorder traversal of the red-black tree used_tree_root of this namespace to obtain all allocated ranges.
[0033] Step 2: Release each interval. For each used_node_t in the red-black tree: A new free_node_t is created based on its start_lba and size.
[0034] Insert this new free node into the global free list g_free_list in address order. Merge is checked immediately during insertion. Check if the new node is contiguous with the address of the previous node in the linked list; if so, merge them.
[0035] Check if the new node is contiguous with the address of the next node in the linked list; if so, merge them.
[0036] The merge operation involves adjusting the size of the predecessor or successor node and then releasing the merged new node (or successor node).
[0037] Step 3: Cleaning Release all nodes in the red-black tree of the Namespace and destroy the Namespace data structure itself.
[0038] Through the above specific implementation, the present invention can dynamically and intelligently manage the multiple namespaces of NVMe SSDs, effectively avoid physical space gaps, and significantly improve the utilization efficiency of storage space.
[0039] The above description is merely the basic principle and preferred embodiment of the present invention. Improvements and substitutions made by those skilled in the art based on the present invention are within the scope of protection of the present invention.
Claims
1. A multi-namespace space allocation and management method applied to NVMe SSDs, characterized by: Includes the following steps: S01. Define a data structure for managing free space and allocated space. Use a free linked list to manage free space. The free linked list includes multiple free block nodes. Each free block node represents the starting LBA and length of a contiguous LBA space that is not occupied by the Namespace. Use the red-black tree of the Namespace and allocated block nodes to manage the allocated LBA range within each Namespace. Each allocated block node represents the starting LBA and length of the LBA space occupied by each Namespace. S02. Create a Namespace by searching for free blocks in the free list. The search method prioritizes finding the best matching free block, which is the free block closest to requested_size in the range [requested_size, LEN]. requested_size is the size of the Namespace to be created, and LEN is the length of the logical address space of the entire SSD. If no best matching free block is found, continue searching to see if the space after merging adjacent free blocks is greater than or equal to requested_size. If not, continue merging adjacent free blocks, and so on, until a combination of free blocks that meets the conditions is found or the free list has been traversed. S03. After finding the best matching free block or a combination of free blocks that meet the conditions, remove target_node->size from the free list, calculate the remaining space size after allocation: remaining_size = target_node->size - requested_size. If remaining_size > 0, insert the remaining space back into the free list as a new free block; target_node->size is the size of the best matching free block or the combination of free blocks that meet the conditions. S04. After the Namespace is created, target_node->start_lba and requested_size are filled into the allocated block nodes, and the allocated block nodes are inserted into the red-black tree of the Namespace. The red-black tree is organized according to the starting address; target_node->start_lba is the starting LBA of the best matching free block or the combination of free blocks that meet the conditions. S05. When a namespace is deleted, the deleted LBA range is written to a node, and the node is inserted between adjacent nodes according to the actual address. If the starting address and length of adjacent nodes are consecutive, the adjacent nodes are merged into one.
2. The multi-namespace space allocation and management method for NVMe SSDs according to claim 1, characterized in that: During SSD initialization, the head pointer of the free list points to a node with a starting LBA address of 0 and a length equal to the total number of LBAs in the SSD.
3. The multi-namespace space allocation and management method for NVMe SSDs according to claim 1, characterized in that: Step S02 searches for the best matching free block by traversing the head pointer of the free list. If the best matching free block is found, its node number and size are recorded. If the best matching free block is not found, the merge scan process is entered. The head pointer of the free list is traversed again, and adjacent free blocks are checked. If the addresses of the current node and the next node are consecutive, the total size after merging them is calculated. If the total size after merging is greater than or equal to requested_size, the merged space meets the requirements. If two adjacent merges still do not meet the requirement of being greater than or equal to requested_size, multiple free blocks are merged until a combination of free blocks that meets the conditions is found or the free list is traversed.
4. The multi-namespace space allocation and management method for NVMe SSDs according to claim 3, characterized in that: Set a maximum number of nodes to merge. If the maximum number of nodes to merge is reached but the value is still greater than or equal to requested_size, exit and return a failure to create the node.
5. The multi-namespace space allocation and management method for NVMe SSDs according to claim 1, characterized in that: The starting LBA of the new free block formed by the remaining space is target_node->start_lba+requested_size, and the length is remaining_size.
6. The multi-namespace space allocation and management method for NVMe SSDs according to claim 1, characterized in that: Step S05 is as follows: S51. Traverse the red-black tree of the deleted namespace and obtain all allocated intervals; S52. For each allocated block node in the red-black tree, create a new free block node according to its starting LBA and size, and insert the new free block node into the free list in address order. During insertion, a check and merge is performed to check whether the addresses of the new node are consecutive with the addresses of the preceding and following nodes in the free list. If they are, the nodes are merged. S53. Clean up, release all nodes in the red-black tree of the Namespace, and destroy the Namespace data structure.
7. The multi-namespace space allocation and management method for NVMe SSDs according to claim 6, characterized in that: The merging process involves adjusting the size of the predecessor or successor node and then releasing the merged node.