Linux块设备驱动程序请求排序 - RaW?

时间:2016-04-15 17:23:54

标签: c linux block-device

我正在编写一个Linux块设备驱动程序,它通过注册blk_init_queue()的函数接收请求。

我的硬件设备重新排序请求,因此为了避免写后读写冲突,需要在发出write(lba x)之前等待read(lba x)完成。

我的问题:Linux阻止层是否跟踪RaW冲突,它会发出read(lba x),直到收到请求完成(通过__blk_end_request_all(req r))为止在write(lba x)之前,还是我必须在我的驱动程序中执行此操作?

1 个答案:

答案 0 :(得分:0)

According to the article below, Linux block device drivers are now free to reorder requests arbitrarily, the filesystem layer is responsible for avoiding hazards and implementing barriers. https://lwn.net/Articles/400541/

The only exception are REQ_FLUSH and REQ_FUA requests for devices that implement write-back caches. In the case these flags are set certain ordering requirements need to be enforced by the blk device driver. https://www.kernel.org/doc/Documentation/block/writeback_cache_control.txt

In particular, the following ordering requirements exist:

  • No write data, REQ_FLUSH - doesn't have any ordering constraint other than the inherent FLUSH requirement (previously completed WRITEs should be on the media on FLUSH completion).

  • Write data, REQ_FLUSH - FLUSH must be completed before write data is issued. ie. write data must not be written to the media before all previous writes are on the media.

  • Write data, REQ_FUA - Write should be completed before FLUSH is issued - ie. the write data should be on platter along with previously completed writes on bio completion.

  • Write data, REQ_FLUSH | REQ_FUA - Write data must not be written to the media before all previous writes are on the media && the write data must be on the media on bio completion. This is usually sequenced as FLUSH write FLUSH.

[from the linux-fsdevel mailinglist: http://www.spinics.net/lists/linux-fsdevel/msg45616.html]