1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2010 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id="sd_notify">
27 <title>sd_readahead</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_readahead</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_readahead</refname>
47 <refpurpose>Control ongoing disk boot-time read-ahead operations</refpurpose>
52 <funcsynopsisinfo>#include "sd-daemon.h"</funcsynopsisinfo>
55 <funcdef>int <function>sd_readahead</function></funcdef>
56 <paramdef>const char *<parameter>action</parameter></paramdef>
62 <title>Description</title>
63 <para><function>sd_readahead()</function> may be
64 called by programs involved with early boot-up to
65 control ongoing boot-time disk read-ahead operations. It may be
66 used to terminate read-ahead operations in case an
67 uncommon disk access pattern is to be expected and
68 hence read-ahead replay or collection is unlikely to
69 have the desired speed-up effect on the current or
70 future boot-ups.</para>
72 <para>The <parameter>action</parameter> should be one
73 of the following strings:</para>
79 <listitem><para>Terminates read-ahead
80 data collection, and drops all
81 read-ahead data collected during this
82 boot-up.</para></listitem>
88 <listitem><para>Terminates read-ahead
89 data collection, but keeps all
90 read-ahead data collected during this
91 boot-up around for use during
92 subsequent boot-ups.</para></listitem>
98 <listitem><para>Terminates read-ahead
99 replay.</para></listitem>
107 <title>Return Value</title>
109 <para>On failure, these calls return a negative
110 errno-style error code. It is generally recommended to
111 ignore the return value of this call.</para>
117 <para>This function is provided by the reference
118 implementation of APIs for controlling boot-time
119 read-ahead and distributed with the systemd
120 package. The algorithm it implements is simple, and
121 can easily be reimplemented in daemons if it is
122 important to support this interface without using the
123 reference implementation.</para>
125 <para>Internally, this function creates a file in
126 <filename>/run/systemd/readahead/</filename> which is
127 then used as flag file to notify the read-ahead
130 <para>For details about the algorithm check the
131 liberally licensed reference implementation sources:
132 <ulink url="http://cgit.freedesktop.org/systemd/tree/src/sd-readahead.c"/>
134 url="http://cgit.freedesktop.org/systemd/tree/src/sd-readahead.h"/></para>
136 <para><function>sd_readahead()</function> is
137 implemented in the reference implementation's
138 <filename>sd-readahead.c</filename> and
139 <filename>sd-readahead.h</filename> files. These
140 interfaces are available as shared library, which can
141 be compiled and linked to with the
142 <literal>libsystemd-daemon</literal>
143 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
144 file. Alternatively, applications consuming this API
145 may copy the implementation into their source
146 tree. For more details about the reference
148 <citerefentry><refentrytitle>sd-readahead</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
150 <para>If the reference implementation is used as
151 drop-in files and -DDISABLE_SYSTEMD is set during
152 compilation this function will always return 0 and
153 otherwise become a NOP.</para>
157 <title>Examples</title>
160 <title>Cancelling all read-ahead operations</title>
162 <para>During boots where SELinux has to
163 relabel the file system hierarchy, it will
164 create a large amount of disk accesses that
165 are not necessary during normal boots. Hence
166 it is a good idea to disable both read-ahead replay and read-ahead collection.
169 <programlisting>sd_readahead("cancel");
170 sd_readahead("noreplay");</programlisting>
176 <title>See Also</title>
178 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
179 <citerefentry><refentrytitle>sd-readahead</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
180 <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>