读NVMe之Directives与Stream

Posted by Yina Lv on 2019-02-10

对NVMe支持的多流SSD进行整理,虽然在NVMe1.3c中关于这方面的篇幅不长,但还是可以清楚的了解从上层软件到下层设备是如何进行信息交换的

Directives


可以看到在NVMe1.3c的第九章中,讲述了这部分内容。Directives是host和NVM subsystem/controller之间信息交换的机制,实现了SSD设备和上层软件之间的信息交互,而stream只是directives的一个部分,在1.3c中也只实现了stream

对Directive的支持是可选的,在 Identify Controller data structure中的Optional Admin Command Support (OACS) 字段中表示。
过程如下:
1.上层软件向SSD发送identify command
2.SSD 接收到后回复identify data structure,描述了该设备支持的相关特性。
3.对于支持directive的ssd设备,用户必须显式调用directive send command执行enable stream操作,以开启multi-stream特性
4.在write command的directive type 字段设置streams(01h),同时directive specific字段设置为对应的stream id,那么就可以将相应的写入数据映射到对应stream id描述的stream中了

如果控制器支持directives,那么controller应该在OACS可选字段中显示;支持directive receive command(controller到host)和directive send command(host到controller);支持identify directive(type 00h)。

下面这段话是1.3c spec中的,描述了上述过程

Support for a specific directive type is indicated using the Return Parameters operation of the Identify Directive. A specific directive may be enabled or disabled using the Enable operation of the Identify Directive. Before using a specific directive, the host should determine if that directive is supported and should enable that directive using the Identify Directive

Directive Specific field 和 Directive Operation field 取决于特定的指令类型(directive send还是directive receive还是I/O command)

上述情况是支持directive的,那么对于不支持directive或者支持directive但没有被启用的情况,所有的带有该指令类型的directive send command和directive receive command都将在命令中设置无效字段而中止。

identify(directive type 00h)

确定控制器是否支持特定类型的指令。directive receive返回的参数中描述了指令是否支持并是否启用;directive send中描述了需要将那个类型的指令启用或者不启用。

stream(directive type 01h)

Streams Directive 使得主机通过标识stream id向控制器传递数据,确保在一个write command中的数据是一组相关的数据,这样控制器存储数据的时候将会存放到相关的位置上。
控制器在返回的参数中会提供相关的配置信息( Stream Write Size, Stream Granularity Size, and stream resources at the NVM subsystem and namespace levels)
数据在写入到时候按照SWS对齐的方式,而SGS是每个stream分配单元大小。SGS是SWS的倍数。

传统的不支持 multi-stream 的 SSD FTL 通常只维护一个 log structure,它只会根据操作系统提交的 IO 请求的先后顺序,将这些 IO 请求依次存储到可用的存储空间中

而支持 multi-stream 的 SSD FTL 则会维护多个 log structure,其中为每个 stream 维护一个单独的 log structure,FTL 以 Stream Granularity Size (SGS) 为单位分配存储空间,即 FTL 一开始会为每个 stream 预先分配 SGS 大小的存储块,之后该 stream 的数据都会存储到这一预分配的 SGS 大小的存储块中。当这一存储块的空间用尽时,FTL 则再次分配一个 SGS 大小的存储块。stream 的 log structure 会维护该 stream 分配的所有存储块,而正是所有的这些 SGS 大小的存储块构成了一个 stream。

推荐阅读:
multi-stream SSD 介绍



支付宝打赏 微信打赏

good luck!