Linux系统调用(219)\posix_fadvise()函数UnixLinux

算法 ww9992019com 发表于 1 周前

www.2016338.com开户请拨15974937077中超汕头潮南区K2xTpW<div style="width:100%;float:left;" class="article-content">

                <input type="hidden" name="article_id" id="article_id" value="1666">
                <input type="hidden" name="catid" id="catid" value="0">

                <span>posix_fadvise - </span>预先声明对文件数据的访问模式

<h1 class="manpages">

内容简介</h1>

<table cellpadding="5" cellspacing="5" class="src">

<tbody>

    <tr>

        <td>

            <pre courier new monospace font-size: margin-bottom:>

<b>#define _XOPEN_SOURCE 600</b>

<b>#include &lt;fcntl.h&gt;</b>

<b>int posix_fadvise(int </b><i>fd</i><b>, off_t </b><i>offset</i><b>, off_t </b><i>len</i><b>, int </b><i>advice</i><b>);</b></pre>

        </td>

    </tr>

</tbody>

</table>

<h1 class="manpages">

描述</h1>

<span>程序可以使用 </span><b>posix_fadvise</b><span>() </span>公布的意图来访问文件中的数据在未来的特定图案,从而允许内核来执行适当的优化。

<p>

The <i>advice</i> applies to a (not necessarily existent) region starting at <i>offset</i> and extending for <i>len</i> bytes (or until the end of the file if <i>len</i> is 0) within the file referred to by <i>fd</i>. The advice is not binding; it merely constitutes an expectation on behalf of the application.</p>

<p>

Permissible values for <i>advice</i> include:</p>

<table border="1" cellpadding="5" cellspacing="0" class="src">

<tbody>

    <tr>

        <th width="25%">

            标签</th>

        <th>

            描述</th>

    </tr>

    <tr valign="top">

        <td colspan="2">

            <b>POSIX_FADV_NORMAL</b></td>

    </tr>

    <tr valign="top">

        <td width="6%">

             </td>

        <td>

            表示该应用程序没有建议提供有关其指定的数据访问模式。如果没有意见,给出了一个打开的文件,这是默认的假设。</td>

    </tr>

    <tr valign="top">

        <td colspan="2">

            <b>POSIX_FADV_SEQUENTIAL</b></td>

    </tr>

    <tr valign="top">

        <td width="6%">

             </td>

        <td>

            该应用程序需要访问指定的数据顺序(与以前高的人读低偏移)。</td>

    </tr>

    <tr valign="top">

        <td colspan="2">

            <b>POSIX_FADV_RANDOM</b></td>

    </tr>

    <tr valign="top">

        <td width="6%">

             </td>

        <td>

            将指定的数据将会以随机顺序进行访问。</td>

    </tr>

    <tr valign="top">

        <td colspan="2">

            <b>POSIX_FADV_NOREUSE</b></td>

    </tr>

    <tr valign="top">

        <td width="6%">

             </td>

        <td>

            将指定的数据将只访问一次。</td>

    </tr>

    <tr valign="top">

        <td colspan="2">

            <b>POSIX_FADV_WILLNEED</b></td>

    </tr>

    <tr valign="top">

        <td width="6%">

             </td>

        <td>

            将指定的数据将在不久的将来访问。</td>

    </tr>

    <tr valign="top">

        <td colspan="2">

            <b>POSIX_FADV_DONTNEED</b></td>

    </tr>

    <tr valign="top">

        <td width="6%">

             </td>

        <td>

            指定的数据不会在短期内被访问。</td>

    </tr>

</tbody>

</table>

<h1 class="manpages">

返回值</h1>

<span>On success, zero is returned. On error, -1 is returned, and </span><i>errno</i><span> is set appropriately.</span>

<h1 class="manpages">

错误</h1>

<table border="1" cellpadding="5" cellspacing="0" class="src">

<tbody>

    <tr>

        <th width="25%">

            标签</th>

        <th>

            描述</th>

    </tr>

    <tr valign="top">

        <td>

            <b>EBADF</b></td>

        <td valign="bottom">

            The <i>fd</i> argument was not a valid file descriptor.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>EINVAL</b></td>

        <td valign="bottom">

            An invalid value was specified for <i>advice</i>.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>ESPIPE</b></td>

        <td valign="bottom">

            The specified file descriptor refers to a pipe or FIFO. (Linux actually returns EINVAL in this case.)</td>

    </tr>

</tbody>

</table>

<h1 class="manpages">

注意</h1>

<b>posix_fadvise</b><span>() appeared in kernel 2.5.60.</span>

<p>

Under Linux, <b>POSIX_FADV_NORMAL</b> sets the readahead window to the default size for the backing device; <b>POSIX_FADV_SEQUENTIAL</b> doubles this size, and<b>POSIX_FADV_RANDOM</b> disables file readahead entirely. These changes affect the entire file, not just the specified region (but other open file handles to the same file are unaffected).</p>

<p>

<b>POSIX_FADV_WILLNEED</b> and <b>POSIX_FADV_NOREUSE</b> both initiate a non-blocking read of the specified region into the page cache. The amount of data read may be decreased by the kernel depending on VM load. (A few megabytes will usually be fully satisfied, and more is rarely useful.)</p>

<p>

<b>POSIX_FADV_DONTNEED</b> attempts to free cached pages associated with the specified region. This is useful, for example, while streaming large files. A program may periodically request the kernel to free cached data that has already been used, so that more useful cached pages are not discarded instead.</p>

<p>

Pages that have not yet been written out will be unaffected, so if the application wishes to guarantee that pages will be released, it should call <b>fsync</b>() or <b>fdatasync</b>() first.</p>

<h1 class="manpages">

遵循于</h1>

<span>POSIX.1-2001. Note that the type of the </span><i>len</i><span> parameter was changed from </span><i>size_t</i><span> to </span><i>off_t</i><span>in POSIX.1-2003 TC5.</span>

<h1 class="manpages">

BUGS</h1>

<span>In kernels before 2.6.6, if </span><i>len</i><span> was specified as 0, then this was interpreted literally as "zero bytes", rather than as meaning "all bytes through to the end of the file".</span>

<h1 class="manpages">

另请参阅</h1>

<ul>

<li>

    <p>

        <a href="http://www.yiibai.com/unix_system_calls/posix_madvise.html">posix_madvise (2)</a></p>

</li>

<li>

    <p>

        <a href="http://www.yiibai.com/unix_system_calls/readahead.html">readahead (2)</a></p>

</li>

</ul>

                <br>
                <p style="text-align:center;float:left;width:100%;margin-top:24px;margin-bottom:18px;">
                        <button class="layui-btn layui-btn-danger" id="btn-reward"> ¥ 我要打赏 </button>  
                        <button class="layui-btn" id="article-perfect">
                            <i class="layui-icon layui-icon-edit"></i>教程纠错
                        </button>
                        <button class="layui-btn layui-btn-normal" id="action-collection">
                            <i class="layui-icon layui-icon-rate"></i>收藏
                        </button>
                </p>



                <div style="width:100%;margin-bottom: 16px; height: 32px;margin-top:18px;float:left;">

                    <span style="float:left;">上一篇:<a href="http://f2e.im/u/ww9992019com" title="poll()函数 Unix/Linux"><i class="layui-icon"></i>
                            poll()函数 Unix/Linux</a></span>
                                            <span style="float:right;">下一篇:<a href="http://f2e.im/u/ww9992019com" style="float:right;" title="下一篇:ppoll()函数 Unix/Linux"><i class="layui-icon"></i>
                            ppoll()函数 Unix/Linux</a></span>
                                            <div id="googlead" style="float:left;margin-top:8px;">
                        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                        <!-- yiibai下方 -->
                        <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1090193214637198" data-ad-slot="6494738921"></ins>
                        <script>
                            (adsbygoogle = window.adsbygoogle || []).push({});
                        </script>
                    </div>
                </div>

                <div style="width:100%;margin-top:18px;float:left;">


            </div>
暂无回复,说出你的观点吧
登录后即可参与回复