linux readv 和 writev

Unix systems have long been named readv and support writev two system calls. "Vector" versions of these read and write using an array of structures, comprising a buffer and a length value of each pointer. Readv a call is desired to turn number to each read instruction cache. Instead, writev to collect the contents of each cache together and sends them as a single write operation.

 

If your driver does not provide a way to handle vector operations, readv and writev be implemented by calling your read and write multiple times. In many cases, however, direct implementation readv and writev can get greater efficiency.

 

Prototype vector operations are:

 

ssize_t (*readv) (struct file *filp, const struct iovec *iov, unsigned long count, loff_t

*ppos);

ssize_t (*writev) (struct file *filp, const struct iovec *iov, unsigned long count, loff_t

*ppos);

 

, Where the same parameters and ppos filp with the read and write. Iovec structure, as defined in

<Linux / uio.h>, as:

 

struct iovec

{

void   user *iov_base;   kernel_size_t iov_len;

};

 

Each iovec describes a data to be transferred;.. It started in iov_base (in user space) and have iov_len bytes long count parameter tells how many iovec these structures created by the application, but the kernel copies before they call the driver to kernel space.

 

The simplest implementation of a direct vector operation cycle, but pass out of each read and write functions iovec address and length of the drive, however, effective and correct behavior is often necessary to drive smarter. For example, on a tape drive the entire contents shall writev iovec structure as a single recording on the tape.

 

Many drivers, however, do not benefit from implementing these methods themselves Accordingly, they are omitted The scull kernel using the read and write them to simulate the final result is the same.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11138704.html