I'd like to ask/verify whether an array of struct scatterlist
that were mapped with blk_rq_map_sg
are all contiguous at least in virtual address domain. Well we all know that scatterlists are primarily for DMA, where each scatter-gather (sg) array element describes a chunk of memory and those chunks are discontiguous in their physical addresses.
I'm writing a block device driver. Suppose I receive struct requests from my request_queue, and I want to do something with the I/O data that my request is holding, like memcpy
ing them to somewhere. That operation will need a virtual address and length parameter. Now all I know is that I can access the request's data via the scatterlist mapped through the helper function blk_map_rq_sg()
. Is my assumption correct, that those sg elements are contiguous in virtual, and that I can get the data address via sg_virt()
, and use that address and total length for memcpy
? Or they are discontiguous in virtual, and I have to walk through each sg array element and memcpy
to/from each sg memory chunk (in virtual) which is harder?
Functions like writev allow to submit discontiguous requests, and pages in high memory do not have a virtual address to begin with.
To access SG list contents with the CPU, use something like sg_copy_from_buffer
, which automatically maps the pages temporarily.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.