diff options
-rw-r--r-- | share/man/man9/buffercache.9 | 41 | ||||
-rw-r--r-- | sys/kern/vfs_bio.c | 11 |
2 files changed, 49 insertions, 3 deletions
diff --git a/share/man/man9/buffercache.9 b/share/man/man9/buffercache.9 index 84df0c06513..30c615cd129 100644 --- a/share/man/man9/buffercache.9 +++ b/share/man/man9/buffercache.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: buffercache.9,v 1.11 2017/02/28 19:36:14 natano Exp $ +.\" $OpenBSD: buffercache.9,v 1.12 2017/08/22 00:18:56 sf Exp $ .\" $NetBSD: buffercache.9,v 1.13 2004/06/25 15:31:37 wiz Exp $ .\" .\" Copyright (c)2003 YAMAMOTO Takashi, @@ -102,12 +102,13 @@ .\" .\" .\" ------------------------------------------------------------ -.Dd $Mdocdate: February 28 2017 $ +.Dd $Mdocdate: August 22 2017 $ .Dt BUFFERCACHE 9 .Os .Sh NAME .Nm buffercache , .Nm bread , +.Nm bread_cluster , .Nm breadn , .Nm bwrite , .Nm bawrite , @@ -126,6 +127,9 @@ .Fn bread "struct vnode *vp" "daddr_t blkno" "int size" \ "struct buf **bpp" .Ft int +.Fn bread_cluster "struct vnode *vp" "daddr_t blkno" "int size" \ +"struct buf **bpp" +.Ft int .Fn breadn "struct vnode *vp" "daddr_t blkno" "int size" \ "daddr_t rablks[]" "int rasizes[]" "int nrablks" \ "struct buf **bpp" @@ -163,6 +167,11 @@ In addition to describing a cached block, a .Em buf structure is also used to describe an I/O request as a part of the disk driver interface. +.Pp +The block size used for logical block numbers depends on the type of the +given vnode. +For file vnodes, this is f_iosize of the underlying filesystem. +For block device vnodes, this will usually be DEV_BSIZE. .\" XXX struct buf, B_ flags, MP locks, etc. .\" XXX free list, hash queue, etc. .\" ------------------------------------------------------------ @@ -184,6 +193,10 @@ to allocate a buffer with enough pages for .Fa size and reads the specified disk block into it. .Pp +.Fn bread +always returns a buffer, even if it returns an error due to an I/O +error. +.Pp The buffer returned by .Fn bread is marked as busy. @@ -222,6 +235,30 @@ and The read-ahead blocks aren't returned, but are available in cache for future accesses. .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +.It Xo +.Fo bread_cluster +.Fa "vp" +.Fa "blkno" +.Fa "size" +.Fa "bpp" +.Fc +.Xc +Read a block of size +.Fa "size" +corresponding to +.Fa vp +and +.Fa blkno , +with readahead. +If neither the first block nor a part of the next MAXBSIZE bytes is already +in the buffer cache, +.Fn bread_cluster +will perform a read-ahead of MAXBSIZE bytes in a single I/O operation. +This is currently more efficient than +.Fn breadn . +The read-ahead data isn't returned, but is available in cache for +future access. +.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .It Fn bwrite "bp" Write a block. Start I/O for write using diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 88adfeff237..217455c1f3f 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.183 2017/07/12 11:13:22 mikeb Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.184 2017/08/22 00:18:56 sf Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /* @@ -568,6 +568,12 @@ bread_cluster_callback(struct buf *bp) } } +/* + * Read-ahead multiple disk blocks, but make sure only one (big) I/O + * request is sent to the disk. + * XXX This should probably be dropped and breadn should instead be optimized + * XXX to do fewer I/O requests. + */ int bread_cluster(struct vnode *vp, daddr_t blkno, int size, struct buf **rbpp) { @@ -1023,6 +1029,9 @@ geteblk(size_t size) /* * Allocate a buffer. + * If vp is given, put it into the buffer cache for that vnode. + * If size != 0, allocate memory and call buf_map(). + * If there is already a buffer for the given vnode/blkno, return NULL. */ struct buf * buf_get(struct vnode *vp, daddr_t blkno, size_t size) |