Fast Scatter-Gather I/O

Some applications may need to read or write data to multiple buffers, which are separated in memory. Although this can be done easily enough with multiple calls to read and write, it is inefficient because there is overhead associated with each kernel call.

Instead, many platforms provide special high-speed primitives to perform these scatter-gather operations in a single kernel call. The GNU C library will provide an emulation on any system that lacks these primitives, so they are not a portability threat. They are defined in sys/uio.h.

These functions are controlled with arrays of iovec structures, which describe the location and size of each buffer.

— Data Type: struct iovec

The iovec structure describes a buffer. It contains two fields:

void *iov_base
Contains the address of a buffer.
size_t iov_len
Contains the length of the buffer.

— Function: ssize_t readv ( int filedes, const struct iovec *vector, int count)

The readv function reads data from filedes and scatters it into the buffers described in vector, which is taken to be count structures long. As each buffer is filled, data is sent to the next.

Note that readv is not guaranteed to fill all the buffers. It may stop at any point, for the same reasons read would.

The return value is a count of bytes (not buffers) read, 0 indicating end-of-file, or -1 indicating an error. The possible errors are the same as in read.

— Function: ssize_t writev ( int filedes, const struct iovec *vector, int count)

The writev function gathers data from the buffers described in vector, which is taken to be count structures long, and writes them to filedes. As each buffer is written, it moves on to the next.

Like readv, writev may stop midstream under the same conditions write would.

The return value is a count of bytes written, or -1 indicating an error. The possible errors are the same as in write.

Note that if the buffers are small (under about 1kB), high-level streams may be easier to use than these functions. However, readv and writev are more efficient when the individual buffers themselves (as opposed to the total output), are large. In that case, a high-level stream would not be able to cache the data effectively.

阅读(692) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
Unable to handle kernel paging request at virtual address fffffdfb pgd = 9893b828 [fffffdfb] *pgd=2fef9841, *pte=00000000, *ppte=00000000 Internal error: Oops - BUG: 27 [#3] PREEMPT SMP ARM Modules linked in: cdmadriver(O) zynqdatspace(O) zynqregspace(O) zynqirqspace(O) uio_pdrv_genirq CPU: 1 PID: 555 Comm: cdmatest Tainted: G D O 5.15.36-xilinx-v2022.2 #1 Hardware name: Xilinx Zynq Platform PC is at dmaIoCtrl+0x44/0x25c [cdmadriver] LR is at vfs_ioctl+0x20/0x38 pc : [<bf01c120>] lr : [<c01fff78>] psr: a00b0013 sp : c1ecfee0 ip : 00000001 fp : aefe6008 r10: 00000036 r9 : c1bc0180 r8 : 00000003 r7 : 00004101 r6 : be98bbe0 r5 : be98bbe0 r4 : c18dd100 r3 : fffffdfb r2 : 00000018 r1 : 00000000 r0 : c1ecfee8 Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none Control: 18c5387d Table: 01c0404a DAC: 00000051 Register r0 information: non-slab/vmalloc memory Register r1 information: NULL pointer Register r2 information: non-paged memory Register r3 information: non-paged memory Register r4 information: slab kmalloc-192 start c18dd0c0 pointer offset 64 size 192 Register r5 information: non-paged memory Register r6 information: non-paged memory Register r7 information: non-paged memory Register r8 information: non-paged memory Register r9 information: slab filp start c1bc0180 pointer offset 0 Register r10 information: non-paged memory Register r11 information: non-paged memory Register r12 information: non-paged memory Process cdmatest (pid: 555, stack limit = 0xf648a677) Stack: (0xc1ecfee0 to 0xc1ed0000) fee0: ffffffd8 0000001f c1baf9c0 0000001f c1ecff78 00022190 c1ece000 00000004 ff00: aefe6008 be10b395 0000001f c1e543a8 c1bc0180 be98bbe0 00004101 c01fff78 ff20: c1e543a8 c02008d8 00000000 00000000 c1baf9c0 00000000 00000000 00000000 ff40: 00000000 00000000 00000000 40040000 00000000 00000000 00000000 be10b395 ff60: c1baf9c0 00022190 c1baf9c0 00000000 c1baf9c0 00000000 00000000 be10b395 ff80: aefe6008 00000003 80000000 00000000 00000036 c01002a4 c1ece000 00000036 ffa0: aefe6008 c0100060 00000003 80000000 00000003 00004101 be98bbe0 00000000 ffc0: 00000003 80000000 00000000 00000036 00000000 00000000 00010cb0 aefe6008 ffe0: b6e8e971 be98bbcc 00010940 b6e8e978 800b0030 00000003 00000000 00000000 [<bf01c120>] (dmaIoCtrl [cdmadriver]) from [<c01fff78>] (vfs_ioctl+0x20/0x38) [<c01fff78>] (vfs_ioctl) from [<c02008d8>] (sys_ioctl+0xc0/0x918) [<c02008d8>] (sys_ioctl) from [<c0100060>] (ret_fast_syscall+0x0/0x48) Exception stack(0xc1ecffa8 to 0xc1ecfff0) ffa0: 00000003 80000000 00000003 00004101 be98bbe0 00000000 ffc0: 00000003 80000000 00000000 00000036 00000000 00000000 00010cb0 aefe6008 ffe0: b6e8e971 be98bbcc 00010940 b6e8e978 Code: e3a01000 e28d0008 e3a02018 e5943014 (e5936000) ---[ end trace 492e80f2fa491ffe ]--- dma_release! Segmentation fault
06-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值