Wed Nov 11 09:15:42 2009 UTC ()
Add a small comment on buffer cache locking, fix mark letter b_objlock.


(rmind)
diff -r1.220 -r1.221 src/sys/kern/vfs_bio.c
diff -r1.114 -r1.115 src/sys/sys/buf.h

cvs diff -r1.220 -r1.221 src/sys/kern/vfs_bio.c (expand / switch to unified diff)

--- src/sys/kern/vfs_bio.c 2009/11/11 07:22:33 1.220
+++ src/sys/kern/vfs_bio.c 2009/11/11 09:15:42 1.221
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_bio.c,v 1.220 2009/11/11 07:22:33 rmind Exp $ */ 1/* $NetBSD: vfs_bio.c,v 1.221 2009/11/11 09:15:42 rmind Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran, and by Wasabi Systems, Inc. 8 * by Andrew Doran, and by Wasabi Systems, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -90,34 +90,50 @@ @@ -90,34 +90,50 @@
90 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 90 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * SUCH DAMAGE. 97 * SUCH DAMAGE.
98 * 98 *
99 * @(#)vfs_bio.c 8.6 (Berkeley) 1/11/94 99 * @(#)vfs_bio.c 8.6 (Berkeley) 1/11/94
100 */ 100 */
101 101
102/* 102/*
 103 * The buffer cache subsystem.
 104 *
103 * Some references: 105 * Some references:
104 * Bach: The Design of the UNIX Operating System (Prentice Hall, 1986) 106 * Bach: The Design of the UNIX Operating System (Prentice Hall, 1986)
105 * Leffler, et al.: The Design and Implementation of the 4.3BSD 107 * Leffler, et al.: The Design and Implementation of the 4.3BSD
106 * UNIX Operating System (Addison Welley, 1989) 108 * UNIX Operating System (Addison Welley, 1989)
 109 *
 110 * Locking
 111 *
 112 * There are three locks:
 113 * - bufcache_lock: protects global buffer cache state.
 114 * - BC_BUSY: a long term per-buffer lock.
 115 * - buf_t::b_objlock: lock on completion (biowait vs biodone).
 116 *
 117 * For buffers associated with vnodes (a most common case) b_objlock points
 118 * to the vnode_t::v_interlock. Otherwise, it points to generic buffer_lock.
 119 *
 120 * Lock order:
 121 * bufcache_lock ->
 122 * buf_t::b_objlock
107 */ 123 */
108 124
109#include <sys/cdefs.h> 125#include <sys/cdefs.h>
110__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.220 2009/11/11 07:22:33 rmind Exp $"); 126__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.221 2009/11/11 09:15:42 rmind Exp $");
111 127
112#include "fs_ffs.h" 128#include "fs_ffs.h"
113#include "opt_bufcache.h" 129#include "opt_bufcache.h"
114 130
115#include <sys/param.h> 131#include <sys/param.h>
116#include <sys/systm.h> 132#include <sys/systm.h>
117#include <sys/kernel.h> 133#include <sys/kernel.h>
118#include <sys/proc.h> 134#include <sys/proc.h>
119#include <sys/buf.h> 135#include <sys/buf.h>
120#include <sys/vnode.h> 136#include <sys/vnode.h>
121#include <sys/mount.h> 137#include <sys/mount.h>
122#include <sys/resourcevar.h> 138#include <sys/resourcevar.h>
123#include <sys/sysctl.h> 139#include <sys/sysctl.h>

cvs diff -r1.114 -r1.115 src/sys/sys/buf.h (expand / switch to unified diff)

--- src/sys/sys/buf.h 2009/11/11 07:22:34 1.114
+++ src/sys/sys/buf.h 2009/11/11 09:15:42 1.115
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: buf.h,v 1.114 2009/11/11 07:22:34 rmind Exp $ */ 1/* $NetBSD: buf.h,v 1.115 2009/11/11 09:15:42 rmind Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran. 9 * NASA Ames Research Center, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -85,27 +85,27 @@ struct kauth_cred; @@ -85,27 +85,27 @@ struct kauth_cred;
85#define NOLIST ((struct buf *)0x87654321) 85#define NOLIST ((struct buf *)0x87654321)
86 86
87extern kmutex_t bufcache_lock; 87extern kmutex_t bufcache_lock;
88extern kmutex_t buffer_lock; 88extern kmutex_t buffer_lock;
89 89
90/* 90/*
91 * The buffer header describes an I/O operation in the kernel. 91 * The buffer header describes an I/O operation in the kernel.
92 * 92 *
93 * Field markings and the corresponding locks: 93 * Field markings and the corresponding locks:
94 * 94 *
95 * b thread of execution that holds BC_BUSY, does not correspond 95 * b thread of execution that holds BC_BUSY, does not correspond
96 * directly to any particular LWP 96 * directly to any particular LWP
97 * c bufcache_lock 97 * c bufcache_lock
98 * l b_objlock 98 * o b_objlock
99 * 99 *
100 * For buffers associated with a vnode, b_objlock points to vp->v_interlock. 100 * For buffers associated with a vnode, b_objlock points to vp->v_interlock.
101 * If not associated with a vnode, it points to the generic buffer_lock. 101 * If not associated with a vnode, it points to the generic buffer_lock.
102 */ 102 */
103struct buf { 103struct buf {
104 union { 104 union {
105 TAILQ_ENTRY(buf) u_actq; 105 TAILQ_ENTRY(buf) u_actq;
106#if defined(_KERNEL) /* u_work is smaller than u_actq. XXX */ 106#if defined(_KERNEL) /* u_work is smaller than u_actq. XXX */
107 struct work u_work; 107 struct work u_work;
108#endif /* defined(_KERNEL) */ 108#endif /* defined(_KERNEL) */
109 } b_u; /* b: device driver queue */ 109 } b_u; /* b: device driver queue */
110#define b_actq b_u.u_actq 110#define b_actq b_u.u_actq
111#define b_work b_u.u_work 111#define b_work b_u.u_work