SG – I/O variations

Recall from the MT app file I/O with the pread, pwrite APIs section, we could use the pread(2) and pwrite(2) system calls to effectively perform file I/O in parallel via multiple threads (in a multithreaded app). Similarly, Linux provides the preadv(2) and the pwritev(2) system calls; as you can guess, they provide the functionality of the readv(2) and writev(2) with the addition of a fourth parameter offset; just as with the readv(2) and writev(2), the file offset at which SG-IO is to be performed can be specified and it will not be changed (again, perhaps useful for an MT application). The signature of the preadv(2) and pwritev(2) is shown here:

#include <sys/uio.h>
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt,
off_t offset);
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt,
off_t offset);

Recent Linux kernels (version 4.6 onward for some) also provide a further variation on the APIs: the preadv2(2) and the pwritev2(2) system calls. The difference from the previous APIs is that they take an additional fifth parameter flag allowing the developer to have more control over the behavior of the SG-I/O operations by being able to specify whether they are synchronous (via the RWF_DSYNC and the RWF_SYNC flags), high-priority (via the RWF_HIPRI flag), or non-blocking (via the RWF_NOWAIT flag). We refer the reader to the man page on preadv2(2)/ pwritev2(2) for details.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset