1 .\" $NetBSD: buffercache.9,v 1.23 2008/05/16 09:21:59 hannken Exp $
3 .\" Copyright (c)2003 YAMAMOTO Takashi,
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" following copyright notices are from sys/kern/vfs_bio.c.
29 .\" they are here because i took some comments from it. yamt@NetBSD.org
33 .\" * Copyright (c) 1982, 1986, 1989, 1993
34 .\" * The Regents of the University of California. All rights reserved.
35 .\" * (c) UNIX System Laboratories, Inc.
36 .\" * All or some portions of this file are derived from material licensed
37 .\" * to the University of California by American Telephone and Telegraph
38 .\" * Co. or Unix System Laboratories, Inc. and are reproduced herein with
39 .\" * the permission of UNIX System Laboratories, Inc.
41 .\" * Redistribution and use in source and binary forms, with or without
42 .\" * modification, are permitted provided that the following conditions
44 .\" * 1. Redistributions of source code must retain the above copyright
45 .\" * notice, this list of conditions and the following disclaimer.
46 .\" * 2. Redistributions in binary form must reproduce the above copyright
47 .\" * notice, this list of conditions and the following disclaimer in the
48 .\" * documentation and/or other materials provided with the distribution.
49 .\" * 3. Neither the name of the University nor the names of its contributors
50 .\" * may be used to endorse or promote products derived from this software
51 .\" * without specific prior written permission.
53 .\" * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 .\" * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 .\" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 .\" * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 .\" * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 .\" * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 .\" * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 .\" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 .\" * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 .\" * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 .\" * @(#)vfs_bio.c 8.6 (Berkeley) 1/11/94
69 .\" * Copyright (c) 1994 Christopher G. Demetriou
71 .\" * Redistribution and use in source and binary forms, with or without
72 .\" * modification, are permitted provided that the following conditions
74 .\" * 1. Redistributions of source code must retain the above copyright
75 .\" * notice, this list of conditions and the following disclaimer.
76 .\" * 2. Redistributions in binary form must reproduce the above copyright
77 .\" * notice, this list of conditions and the following disclaimer in the
78 .\" * documentation and/or other materials provided with the distribution.
79 .\" * 3. All advertising materials mentioning features or use of this software
80 .\" * must display the following acknowledgement:
81 .\" * This product includes software developed by the University of
82 .\" * California, Berkeley and its contributors.
83 .\" * 4. Neither the name of the University nor the names of its contributors
84 .\" * may be used to endorse or promote products derived from this software
85 .\" * without specific prior written permission.
87 .\" * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
88 .\" * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 .\" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90 .\" * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
91 .\" * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 .\" * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93 .\" * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 .\" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 .\" * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 .\" * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 .\" * @(#)vfs_bio.c 8.6 (Berkeley) 1/11/94
103 .\" ------------------------------------------------------------
104 .Dd November 11, 2009
121 .Nd buffer cache interfaces
122 .\" ------------------------------------------------------------
126 .Fn bread "struct vnode *vp" "daddr_t blkno" "int size" \
127 "struct kauth_cred *cred" "int flags" "buf_t **bpp"
129 .Fn breadn "struct vnode *vp" "daddr_t blkno" "int size" \
130 "daddr_t rablks[]" "int rasizes[]" "int nrablks" \
131 "struct kauth_cred *cred" "int flags" "buf_t **bpp"
133 .Fn bwrite "buf_t *bp"
135 .Fn bawrite "buf_t *bp"
137 .Fn bdwrite "buf_t *bp"
139 .Fn getblk "struct vnode *vp" "daddr_t blkno" "int size" \
140 "int slpflag" "int slptimeo"
142 .Fn geteblk "int size"
144 .Fn incore "struct vnode *vp" "daddr_t blkno"
146 .Fn allocbuf "buf_t *bp" "int size" "int preserve"
148 .Fn brelse "buf_t *bp" "int set"
150 .Fn biodone "buf_t *bp"
152 .Fn biowait "buf_t *bp"
153 .\" ------------------------------------------------------------
157 interface is used by each filesystems to improve I/O performance using
158 in-core caches of filesystem blocks.
160 The kernel memory used to cache a block is called a buffer and
164 In addition to describing a cached block, a
166 structure is also used to describe an I/O request as a part of
167 the disk driver interface.
168 .\" XXX buf_t, B_ flags, MP locks, etc
169 .\" ------------------------------------------------------------
171 .Bl -tag -width compact
172 .It Fn bread "vp" "blkno" "size" "cred" "flags" "bpp"
173 Read a block corresponding to
177 The buffer is returned via
181 are specifically the units used by the
186 For device special files,
194 must be multiples of the underlying device's block size.
197 is in units chosen by the file system containing
200 If the buffer is not found (i.e. the block is not cached in memory),
202 allocates a buffer with enough pages for
204 and reads the specified disk block into it using
208 The buffer returned by
214 After manipulation of the buffer returned from
216 the caller should unbusy it so that another thread can get it.
217 If the buffer contents are modified and should be written back to disk,
218 it should be unbusied using one of variants of
220 Otherwise, it should be unbusied using
222 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223 .It Fn breadn "vp" "blkno" "size" "rablks" "rasizes" "nrablks" "cred" "flags" \
229 will start read-ahead of blocks specified by
233 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234 .It Fn breada "vp" "blkno" "size" "rablkno" "rabsize" "cred" "flags" "bpp"
237 with single block read-ahead.
238 This function is for compatibility with old filesystem code and
239 shouldn't be used by new ones.
240 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
243 Start I/O for write using
250 waits for the I/O to complete.
251 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
253 Write a block asynchronously.
262 for most filesystems.
263 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
270 It only marks the buffer as dirty
273 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
274 .It Fn getblk "vp" "blkno" "size" "slpflag" "slptimeo"
275 Get a block of requested size
277 that is associated with a given vnode and block
282 If it is found in the block cache, make it busy and return it.
283 Otherwise, return an empty block of the correct size.
284 It is up to the caller to ensure that the cached blocks
285 are of the correct size.
293 are used as arguments for
295 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
296 .It Fn geteblk "size"
297 Allocate an empty, disassociated block of a given size
299 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
300 .It Fn incore "vp" "blkno"
301 Determine if a block associated to a given vnode and block offset
303 If it is there, return a pointer to it.
306 doesn't busy the buffer unlike
308 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
309 .It Fn allocbuf "bp" "size" "preserve"
310 Expand or contract the actual memory allocated to a buffer.
313 is zero, the entire data in the buffer will be lost.
314 Otherwise, if the buffer shrinks, the truncated part of the data
315 is lost, so it is up to the caller to have written
318 if needed; this routine will not start a write.
319 If the buffer grows, it is the callers responsibility to fill out
320 the buffer's additional contents.
321 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
322 .It Fn brelse "bp" "set"
323 Unbusy a buffer and release it to the free lists.
324 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
326 Mark I/O complete on a buffer.
327 If a callback has been requested by
330 Otherwise, wakeup waiters.
331 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
333 Wait for operations on the buffer to complete.
334 When they do, extract and return the I/O's error value.
336 .\" ------------------------------------------------------------
338 This section describes places within the
340 source tree where actual code implementing the buffer cache subsystem
342 All pathnames are relative to
345 The buffer cache subsystem is implemented within the file
346 .Pa sys/kern/vfs_bio.c .
352 .%B "The Design of the UNIX Operating System"
357 .%A Marshall Kirk McKusick
359 .%A Michael J. Karels
360 .%A John S. Quarterman
361 .%B "The Design and Implementation of the 4.4BSD Operating System"
365 .\" ------------------------------------------------------------
367 In the current implementation,
370 don't use a specified credential.
376 do not really belong to
378 they shouldn't be documented here.