重要的寄存器
Offset 14h: CC – Controller Configuration
Memory Page Size (MPS): This field indicates the host memory page size. The memory page size is (2 ^ (12 + MPS)). Thus, the minimum host memory page size is 4 KiB and the maximum host memory page size is 128 MiB。
重要的数据结构
nvme 中的metadata
关于PRP
每个PRP 的结构如下,就是一个64bit 的地址(包含偏移)
描述了PRP entry 及其和下一个PRP entry page 之间的链接方式:
A physical region page list (PRP List) is a set of PRP entries in a single page of contiguous memory. A PRP List describes additional PRP entries that could not be described within the command itself. Any PRP entries described within the command are not duplicated in a PRP List. If the amount of data to transfer requires multiple PRP List memory pages, then the last PRP entry before the end of the memory page shall be a pointer to the next PRP List, indicating the next segment of the PRP List. Figure 109 shows the layout of a PRP List where each PRP entry identifies memory pages that are physically contiguous. Figure 109 shows the layout of a PRP List where each PRP entry identifies a different memory page (i.e., the memory pages are not physically contiguous).
SGL 重要数据结构
entry 摆放方式
entry 分类
下表列出了主要的几种sgl descriptor的类型:
其实每个主类型里还有子类型,这里就不具体列举了。
entry 的结构
每个entry 都是16 bytes, 下面介绍几种最主要的entry.
SGL Data Block Descripotr
顾名思义,用来描述内存中需要和NVME交互的数据的起始地址和长度:
(通过它,可以把LBA上相邻的数据,通过DMA合并一起读写)
SGL bit bucket Descpritor
用来描述内存中不需要和NVME交互的数据的起始地址和长度,碰到从不连续的LBA读的时候需要用到。
通过它,可以调过NVME 设备上业务不需要访问的数据区域,告诉DMA这里需要新启一个DMA传输。
SGL Segment Descripotr
用来链接下一个但非最后一个SGL descriptor. 一般在碰到要从不连续的内存地址做IO需要用到。
SGL Last Segment Descriptor:
用来链接最后一个SGL descriptor,告诉DMA 这是最后一个传输了。
示例
下面一个示意图,用到了上面列出的四种描述符,是一个SGL用法非常好的例子:
Command Format – Admin and NVM Command Set 定义了每个NVME submit queue entry 格式
指定执行什么NVME命令操作
Command Dword 0 : 指定命令类型、 使用PRP 还是SGL 来传输数据
指定在哪个name space 上执行
Namespace Identifier (NSID):
元数据指针:Metadata Pointer (MPTR):
Metadata Pointer (MPTR): This field is valid only if the command has metadata that is not interleaved with the logical block data, as specified in the Format NVM command. This is a reserved field in NVMe over Fabrics implementations.
如果CDW0.PSDT 为0, 这个字段表示使用PRP 来描述是PRP (Physical Region pointer);
否则,表示数据走SCL机制;
(Metadata Pointer 到底做什么用?和后面的 Date buffer 字段相比,功能上有和联系和区别?)
数据指针:Data Pointer (DPTR):
- 如果使用PRP: 表示PRP Entry2
如果数据不跨memory page, 保留无用; 如果数据跨越memory page, 就表示第二个physical region memroy page; -
如果使用SGL:表示SGL1: 指向第一个SGL segment
问题: PRP (Physical memory range pointer)是SPDK处理的最小内存单元。