posix_fadviseのヘルプ・マニュアル
日本語 英語
posix_fadvise --help
man posix_fadvise
POSIX_FADVISE(2) Linux Programmer’s Manual POSIX_FADVISE(2)
名前
posix_fadvise - ファイルデータのアクセスパターンをあらかじめ宣言する
書式
#define _XOPEN_SOURCE 600
#include
int posix_fadvise(int fd, off_t offset, off_t len, int advice);
説明
プ ログラムは、将来特定のパターンでファイルデータにアクセスする意思を伝
えるために posix_fadvise() を使うことができる。これにより、カーネルが適
切な最適化を実行することが可能になる。
advice は fd が参照しているファイルの offset から始まる len バイトの範
囲内 (len が 0 の場合はファイルの終りまで) の (必ずしも存在しない) 領域
に 適用される。アドバイスは義務づけではない。アドバイスは単にアプリケー
ションのために可能性を構成するだけである。
advice に許される値には、以下のものが含まれる:
POSIX_FADV_NORMAL
指定されたデータのアクセスパターンを指示するアドバイスをアプリケ
ーションが何も持っていないことを示す。オープンされたファイルにア
ドバイスが指定されない場合、これがデフォルトで仮定される。
POSIX_FADV_SEQUENTIAL
アプリケーションは指定されたデータがシーケンシャルに (大きなオフ
セットの前に小さなオフセットのデータを読むように) アクセスされる
ことを期待する。
POSIX_FADV_RANDOM
指定されたデータがランダムな順番でアクセスされる。
POSIX_FADV_NOREUSE
指定されたデータは 1 度しかアクセスされない。
POSIX_FADV_WILLNEED
指定されたデータは近い将来アクセスされる。
POSIX_FADV_DONTNEED
指定されたデータは近い将来アクセスされない。
返り値
成功した場合は 0 が返される。失敗した場合はエラー番号が返される。
エラー
EBADF fd 引き数が有効なファイルディスクリプタでない。
EINVAL 無効な値が advice に指定された。
ESPIPE 指定されたファイルディスクリプタがパイプまたは FIFO を参照してい
る (この場合、Linux は実際には EINVAL を返す)。
バージョン
posix_fadvise() は カ ーネル 2.5.60 で登場した。 glibc でのサポートは
glibc バージョン 2.2 以降で行われている。
準拠
POSIX.1-2001. len 引き数の型が POSIX.1-2003 TC1 において size_t か ら
off_t に変更された点に注意すること。
注意
Linux では、POSIX_FADV_NORMAL はバッキングデバイスのデフォルトサイズに
先読み (readahead) ウインドウを設定する。 POSIX_FADV_SEQUENTIAL はこ の
サ イズを 2 倍し、 POSIX_FADV_RANDOM は先読みを全く無効にする。これらの
変更はファイル全体に影響し、指定された領域のみに影響するわけではない (
しかし同じファイルに対する他のオープンファイルハンドルは影響を受けない)
。
POSIX_FADV_WILLNEED は、ページキャッシュに指定領域のブロックされない 読
み 込みを開始する。読み込まれるデータの総量は、仮想メモリの負荷に依って
カーネルが減らすかもしれない (数メガバイトであれば通常は全く十分であ り
、それより多くてもめったに役に立たない)。
2.6.18 より前のカーネルでは、POSIX_FADV_NOREUSE は POSIX_FADV_WILLNEED
と同じ意味であった。これは多分バグであった。カーネル 2.6.18 以降では 、
このフラグは何も行わない。
POSIX_FADV_DONTNEED は指定された領域に関連付けられたキャッシュページを
解放しようとする。例えば、これは大きなファイルをストリーミングすると き
に 役立つ。プログラムは、使用済みのキャッシュされたデータを解放するよう
に、定期的にカーネルに要求するかもしれない。そうすることにより、さら に
有効なキャッシュされたページが、代わりに破棄されることはない。
ま だ書き出されていないページは影響を受けないので、そのページの解放が保
証されることをアプリケーションが望んでいるなら、最初に fsync(2) また は
fdatasync(2) を呼ぶべきである。
バグ
2.6.6 より前のカーネルでは、 len に 0 が指定された場合、「ファイルの終
りまでの全てのバイト」という意味ではなく、文字通り「0 バイト」として 解
釈されていた。
関連項目
readahead(2), posix_fallocate(3), posix_madvise(3), fea-
ture_test_macros(7)
Linux 2003-02-14 POSIX_FADVISE(2)
POSIX_FADVISE(2) Linux Programmer’s Manual POSIX_FADVISE(2)
NAME
posix_fadvise - predeclare an access pattern for file data
SYNOPSIS
#define _XOPEN_SOURCE 600
#include
int posix_fadvise(int fd, off_t offset, off_t len, int advice);
DESCRIPTION
Programs can use posix_fadvise() to announce an intention to access
file data in a specific pattern in the future, thus allowing the kernel
to perform appropriate optimizations.
The advice applies to a (not necessarily existent) region starting at
offset and extending for len bytes (or until the end of the file if len
is 0) within the file referred to by fd. The advice is not binding; it
merely constitutes an expectation on behalf of the application.
Permissible values for advice include:
POSIX_FADV_NORMAL
Indicates that the application has no advice to give about its
access pattern for the specified data. If no advice is given
for an open file, this is the default assumption.
POSIX_FADV_SEQUENTIAL
The application expects to access the specified data sequen-
tially (with lower offsets read before higher ones).
POSIX_FADV_RANDOM
The specified data will be accessed in random order.
POSIX_FADV_NOREUSE
The specified data will be accessed only once.
POSIX_FADV_WILLNEED
The specified data will be accessed in the near future.
POSIX_FADV_DONTNEED
The specified data will not be accessed in the near future.
RETURN VALUE
On success, zero is returned. On error, an error number is returned.
ERRORS
EBADF The fd argument was not a valid file descriptor.
EINVAL An invalid value was specified for advice.
ESPIPE The specified file descriptor refers to a pipe or FIFO. (Linux
actually returns EINVAL in this case.)
VERSIONS
posix_fadvise() appeared in kernel 2.5.60. Glibc support has been pro-
vided since version 2.2.
CONFORMING TO
POSIX.1-2001. Note that the type of the len argument was changed from
size_t to off_t in POSIX.1-2003 TC1.
NOTES
Under Linux, POSIX_FADV_NORMAL sets the readahead window to the default
size for the backing device; POSIX_FADV_SEQUENTIAL doubles this size,
and POSIX_FADV_RANDOM 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).
POSIX_FADV_WILLNEED initiates 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 virtual memory load. (A few megabytes will
usually be fully satisfied, and more is rarely useful.)
In kernels before 2.6.18, POSIX_FADV_NOREUSE had the same semantics as
POSIX_FADV_WILLNEED. This was probably a bug; since kernel 2.6.18,
this flag is a no-op.
POSIX_FADV_DONTNEED 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.
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 fsync(2) or fdatasync(2) first.
BUGS
In kernels before 2.6.6, if len 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".
SEE ALSO
readahead(2), posix_fallocate(3), posix_madvise(3), fea-
ture_test_macros(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2003-02-14 POSIX_FADVISE(2)