1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Zero-Copy Interface</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Linux Kernel Crypto API"><link rel="up" href="User.html" title="Chapter&#160;4.&#160;User Space Interface"><link rel="prev" href="ch04s07.html" title="Random Number Generator API"><link rel="next" href="ch04s09.html" title="Setsockopt Interface"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Zero-Copy Interface</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch04s07.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;4.&#160;User Space Interface</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch04s09.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp1097382972"></a>Zero-Copy Interface</h2></div></div></div><p>
2     In addition to the send/write/read/recv system call familty, the AF_ALG
3     interface can be accessed with the zero-copy interface of splice/vmsplice.
4     As the name indicates, the kernel tries to avoid a copy operation into
5     kernel space.
6    </p><p>
7     The zero-copy operation requires data to be aligned at the page boundary.
8     Non-aligned data can be used as well, but may require more operations of
9     the kernel which would defeat the speed gains obtained from the zero-copy
10     interface.
11    </p><p>
12     The system-interent limit for the size of one zero-copy operation is
13     16 pages. If more data is to be sent to AF_ALG, user space must slice
14     the input into segments with a maximum size of 16 pages.
15    </p><p>
16     Zero-copy can be used with the following code example (a complete working
17     example is provided with libkcapi):
18    </p><pre class="programlisting">
19int pipes[2];
20
21pipe(pipes);
22/* input data in iov */
23vmsplice(pipes[1], iov, iovlen, SPLICE_F_GIFT);
24/* opfd is the file descriptor returned from accept() system call */
25splice(pipes[0], NULL, opfd, NULL, ret, 0);
26read(opfd, out, outlen);
27    </pre></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch04s07.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="User.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch04s09.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Random Number Generator API&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Setsockopt Interface</td></tr></table></div></body></html>
28