Deleted Added
full compact
vfs_bio.c (189648) vfs_bio.c (189878)
1/*-
2 * Copyright (c) 2004 Poul-Henning Kamp
3 * Copyright (c) 1994,1997 John S. Dyson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 25 unchanged lines hidden (view full) ---

34 * Author: John S. Dyson
35 * Significant help during the development and debugging phases
36 * had been provided by David Greenman, also of the FreeBSD core team.
37 *
38 * see man buf(9) for more info.
39 */
40
41#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2004 Poul-Henning Kamp
3 * Copyright (c) 1994,1997 John S. Dyson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 25 unchanged lines hidden (view full) ---

34 * Author: John S. Dyson
35 * Significant help during the development and debugging phases
36 * had been provided by David Greenman, also of the FreeBSD core team.
37 *
38 * see man buf(9) for more info.
39 */
40
41#include <sys/cdefs.h>
42__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 189648 2009-03-10 21:27:15Z jhb $");
42__FBSDID("$FreeBSD: head/sys/kern/vfs_bio.c 189878 2009-03-16 15:39:46Z kib $");
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/bio.h>
47#include <sys/conf.h>
48#include <sys/buf.h>
49#include <sys/devicestat.h>
50#include <sys/eventhandler.h>

--- 50 unchanged lines hidden (view full) ---

101static void vfs_page_set_valid(struct buf *bp, vm_ooffset_t off,
102 vm_page_t m);
103static void vfs_clean_pages(struct buf *bp);
104static void vfs_setdirty(struct buf *bp);
105static void vfs_setdirty_locked_object(struct buf *bp);
106static void vfs_vmio_release(struct buf *bp);
107static int vfs_bio_clcheck(struct vnode *vp, int size,
108 daddr_t lblkno, daddr_t blkno);
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/bio.h>
47#include <sys/conf.h>
48#include <sys/buf.h>
49#include <sys/devicestat.h>
50#include <sys/eventhandler.h>

--- 50 unchanged lines hidden (view full) ---

101static void vfs_page_set_valid(struct buf *bp, vm_ooffset_t off,
102 vm_page_t m);
103static void vfs_clean_pages(struct buf *bp);
104static void vfs_setdirty(struct buf *bp);
105static void vfs_setdirty_locked_object(struct buf *bp);
106static void vfs_vmio_release(struct buf *bp);
107static int vfs_bio_clcheck(struct vnode *vp, int size,
108 daddr_t lblkno, daddr_t blkno);
109static int flushbufqueues(int, int);
109static int buf_do_flush(struct vnode *vp);
110static int flushbufqueues(struct vnode *, int, int);
110static void buf_daemon(void);
111static void bremfreel(struct buf *bp);
112#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
113 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
114static int sysctl_bufspace(SYSCTL_HANDLER_ARGS);
115#endif
116
117int vmiodirenable = TRUE;

--- 75 unchanged lines hidden (view full) ---

193SYSCTL_INT(_vfs, OID_AUTO, hifreebuffers, CTLFLAG_RW, &hifreebuffers, 0,
194 "XXX Complicatedly unused");
195static int getnewbufcalls;
196SYSCTL_INT(_vfs, OID_AUTO, getnewbufcalls, CTLFLAG_RW, &getnewbufcalls, 0,
197 "Number of calls to getnewbuf");
198static int getnewbufrestarts;
199SYSCTL_INT(_vfs, OID_AUTO, getnewbufrestarts, CTLFLAG_RW, &getnewbufrestarts, 0,
200 "Number of times getnewbuf has had to restart a buffer aquisition");
111static void buf_daemon(void);
112static void bremfreel(struct buf *bp);
113#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
114 defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
115static int sysctl_bufspace(SYSCTL_HANDLER_ARGS);
116#endif
117
118int vmiodirenable = TRUE;

--- 75 unchanged lines hidden (view full) ---

194SYSCTL_INT(_vfs, OID_AUTO, hifreebuffers, CTLFLAG_RW, &hifreebuffers, 0,
195 "XXX Complicatedly unused");
196static int getnewbufcalls;
197SYSCTL_INT(_vfs, OID_AUTO, getnewbufcalls, CTLFLAG_RW, &getnewbufcalls, 0,
198 "Number of calls to getnewbuf");
199static int getnewbufrestarts;
200SYSCTL_INT(_vfs, OID_AUTO, getnewbufrestarts, CTLFLAG_RW, &getnewbufrestarts, 0,
201 "Number of times getnewbuf has had to restart a buffer aquisition");
202static int flushbufqtarget = 100;
203SYSCTL_INT(_vfs, OID_AUTO, flushbufqtarget, CTLFLAG_RW, &flushbufqtarget, 0,
204 "Amount of work to do in flushbufqueues when helping bufdaemon");
201
202/*
203 * Wakeup point for bufdaemon, as well as indicator of whether it is already
204 * active. Set to 1 when the bufdaemon is already "on" the queue, 0 when it
205 * is idling.
206 */
207static int bd_request;
208

--- 44 unchanged lines hidden (view full) ---

253#define BUFFER_QUEUES 6 /* number of free buffer queues */
254
255#define QUEUE_NONE 0 /* on no queue */
256#define QUEUE_CLEAN 1 /* non-B_DELWRI buffers */
257#define QUEUE_DIRTY 2 /* B_DELWRI buffers */
258#define QUEUE_DIRTY_GIANT 3 /* B_DELWRI buffers that need giant */
259#define QUEUE_EMPTYKVA 4 /* empty buffer headers w/KVA assignment */
260#define QUEUE_EMPTY 5 /* empty buffer headers */
205
206/*
207 * Wakeup point for bufdaemon, as well as indicator of whether it is already
208 * active. Set to 1 when the bufdaemon is already "on" the queue, 0 when it
209 * is idling.
210 */
211static int bd_request;
212

--- 44 unchanged lines hidden (view full) ---

257#define BUFFER_QUEUES 6 /* number of free buffer queues */
258
259#define QUEUE_NONE 0 /* on no queue */
260#define QUEUE_CLEAN 1 /* non-B_DELWRI buffers */
261#define QUEUE_DIRTY 2 /* B_DELWRI buffers */
262#define QUEUE_DIRTY_GIANT 3 /* B_DELWRI buffers that need giant */
263#define QUEUE_EMPTYKVA 4 /* empty buffer headers w/KVA assignment */
264#define QUEUE_EMPTY 5 /* empty buffer headers */
265#define QUEUE_SENTINEL 1024 /* not an queue index, but mark for sentinel */
261
262/* Queues for free buffers with various properties */
263static TAILQ_HEAD(bqueues, buf) bufqueues[BUFFER_QUEUES] = { { 0 } };
264
265/* Lock for the bufqueues */
266static struct mtx bqlock;
267
268/*

--- 1436 unchanged lines hidden (view full) ---

1705 * If we have to flush dirty buffers ( but we try to avoid this )
1706 *
1707 * To avoid VFS layer recursion we do not flush dirty buffers ourselves.
1708 * Instead we ask the buf daemon to do it for us. We attempt to
1709 * avoid piecemeal wakeups of the pageout daemon.
1710 */
1711
1712static struct buf *
266
267/* Queues for free buffers with various properties */
268static TAILQ_HEAD(bqueues, buf) bufqueues[BUFFER_QUEUES] = { { 0 } };
269
270/* Lock for the bufqueues */
271static struct mtx bqlock;
272
273/*

--- 1436 unchanged lines hidden (view full) ---

1710 * If we have to flush dirty buffers ( but we try to avoid this )
1711 *
1712 * To avoid VFS layer recursion we do not flush dirty buffers ourselves.
1713 * Instead we ask the buf daemon to do it for us. We attempt to
1714 * avoid piecemeal wakeups of the pageout daemon.
1715 */
1716
1717static struct buf *
1713getnewbuf(int slpflag, int slptimeo, int size, int maxsize)
1718getnewbuf(struct vnode *vp, int slpflag, int slptimeo, int size, int maxsize,
1719 int gbflags)
1714{
1720{
1721 struct thread *td;
1715 struct buf *bp;
1716 struct buf *nbp;
1717 int defrag = 0;
1718 int nqindex;
1719 static int flushingbufs;
1720
1722 struct buf *bp;
1723 struct buf *nbp;
1724 int defrag = 0;
1725 int nqindex;
1726 static int flushingbufs;
1727
1728 td = curthread;
1721 /*
1722 * We can't afford to block since we might be holding a vnode lock,
1723 * which may prevent system daemons from running. We deal with
1724 * low-memory situations by proactively returning memory and running
1725 * async I/O rather then sync I/O.
1726 */
1729 /*
1730 * We can't afford to block since we might be holding a vnode lock,
1731 * which may prevent system daemons from running. We deal with
1732 * low-memory situations by proactively returning memory and running
1733 * async I/O rather then sync I/O.
1734 */
1727
1728 atomic_add_int(&getnewbufcalls, 1);
1729 atomic_subtract_int(&getnewbufrestarts, 1);
1730restart:
1731 atomic_add_int(&getnewbufrestarts, 1);
1732
1733 /*
1734 * Setup for scan. If we do not have enough free buffers,
1735 * we setup a degenerate case that immediately fails. Note

--- 215 unchanged lines hidden (view full) ---

1951 /*
1952 * If we exhausted our list, sleep as appropriate. We may have to
1953 * wakeup various daemons and write out some dirty buffers.
1954 *
1955 * Generally we are sleeping due to insufficient buffer space.
1956 */
1957
1958 if (bp == NULL) {
1735 atomic_add_int(&getnewbufcalls, 1);
1736 atomic_subtract_int(&getnewbufrestarts, 1);
1737restart:
1738 atomic_add_int(&getnewbufrestarts, 1);
1739
1740 /*
1741 * Setup for scan. If we do not have enough free buffers,
1742 * we setup a degenerate case that immediately fails. Note

--- 215 unchanged lines hidden (view full) ---

1958 /*
1959 * If we exhausted our list, sleep as appropriate. We may have to
1960 * wakeup various daemons and write out some dirty buffers.
1961 *
1962 * Generally we are sleeping due to insufficient buffer space.
1963 */
1964
1965 if (bp == NULL) {
1959 int flags;
1966 int flags, norunbuf;
1960 char *waitmsg;
1967 char *waitmsg;
1968 int fl;
1961
1962 if (defrag) {
1963 flags = VFS_BIO_NEED_BUFSPACE;
1964 waitmsg = "nbufkv";
1965 } else if (bufspace >= hibufspace) {
1966 waitmsg = "nbufbs";
1967 flags = VFS_BIO_NEED_BUFSPACE;
1968 } else {
1969 waitmsg = "newbuf";
1970 flags = VFS_BIO_NEED_ANY;
1971 }
1972 mtx_lock(&nblock);
1973 needsbuffer |= flags;
1974 mtx_unlock(&nblock);
1975 mtx_unlock(&bqlock);
1976
1977 bd_speedup(); /* heeeelp */
1969
1970 if (defrag) {
1971 flags = VFS_BIO_NEED_BUFSPACE;
1972 waitmsg = "nbufkv";
1973 } else if (bufspace >= hibufspace) {
1974 waitmsg = "nbufbs";
1975 flags = VFS_BIO_NEED_BUFSPACE;
1976 } else {
1977 waitmsg = "newbuf";
1978 flags = VFS_BIO_NEED_ANY;
1979 }
1980 mtx_lock(&nblock);
1981 needsbuffer |= flags;
1982 mtx_unlock(&nblock);
1983 mtx_unlock(&bqlock);
1984
1985 bd_speedup(); /* heeeelp */
1986 if (gbflags & GB_NOWAIT_BD)
1987 return (NULL);
1978
1979 mtx_lock(&nblock);
1980 while (needsbuffer & flags) {
1988
1989 mtx_lock(&nblock);
1990 while (needsbuffer & flags) {
1991 if (vp != NULL && (td->td_pflags & TDP_BUFNEED) == 0) {
1992 mtx_unlock(&nblock);
1993 /*
1994 * getblk() is called with a vnode
1995 * locked, and some majority of the
1996 * dirty buffers may as well belong to
1997 * the vnode. Flushing the buffers
1998 * there would make a progress that
1999 * cannot be achieved by the
2000 * buf_daemon, that cannot lock the
2001 * vnode.
2002 */
2003 norunbuf = ~(TDP_BUFNEED | TDP_NORUNNINGBUF) |
2004 (td->td_pflags & TDP_NORUNNINGBUF);
2005 /* play bufdaemon */
2006 td->td_pflags |= TDP_BUFNEED | TDP_NORUNNINGBUF;
2007 fl = buf_do_flush(vp);
2008 td->td_pflags &= norunbuf;
2009 mtx_lock(&nblock);
2010 if (fl != 0)
2011 continue;
2012 if ((needsbuffer & flags) == 0)
2013 break;
2014 }
1981 if (msleep(&needsbuffer, &nblock,
1982 (PRIBIO + 4) | slpflag, waitmsg, slptimeo)) {
1983 mtx_unlock(&nblock);
1984 return (NULL);
1985 }
1986 }
1987 mtx_unlock(&nblock);
1988 } else {

--- 52 unchanged lines hidden (view full) ---

2041
2042static struct kproc_desc buf_kp = {
2043 "bufdaemon",
2044 buf_daemon,
2045 &bufdaemonproc
2046};
2047SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start, &buf_kp);
2048
2015 if (msleep(&needsbuffer, &nblock,
2016 (PRIBIO + 4) | slpflag, waitmsg, slptimeo)) {
2017 mtx_unlock(&nblock);
2018 return (NULL);
2019 }
2020 }
2021 mtx_unlock(&nblock);
2022 } else {

--- 52 unchanged lines hidden (view full) ---

2075
2076static struct kproc_desc buf_kp = {
2077 "bufdaemon",
2078 buf_daemon,
2079 &bufdaemonproc
2080};
2081SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start, &buf_kp);
2082
2083static int
2084buf_do_flush(struct vnode *vp)
2085{
2086 int flushed;
2087
2088 flushed = flushbufqueues(vp, QUEUE_DIRTY, 0);
2089 /* The list empty check here is slightly racy */
2090 if (!TAILQ_EMPTY(&bufqueues[QUEUE_DIRTY_GIANT])) {
2091 mtx_lock(&Giant);
2092 flushed += flushbufqueues(vp, QUEUE_DIRTY_GIANT, 0);
2093 mtx_unlock(&Giant);
2094 }
2095 if (flushed == 0) {
2096 /*
2097 * Could not find any buffers without rollback
2098 * dependencies, so just write the first one
2099 * in the hopes of eventually making progress.
2100 */
2101 flushbufqueues(vp, QUEUE_DIRTY, 1);
2102 if (!TAILQ_EMPTY(
2103 &bufqueues[QUEUE_DIRTY_GIANT])) {
2104 mtx_lock(&Giant);
2105 flushbufqueues(vp, QUEUE_DIRTY_GIANT, 1);
2106 mtx_unlock(&Giant);
2107 }
2108 }
2109 return (flushed);
2110}
2111
2049static void
2050buf_daemon()
2051{
2052
2053 /*
2054 * This process needs to be suspended prior to shutdown sync.
2055 */
2056 EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, bufdaemonproc,
2057 SHUTDOWN_PRI_LAST);
2058
2059 /*
2060 * This process is allowed to take the buffer cache to the limit
2061 */
2112static void
2113buf_daemon()
2114{
2115
2116 /*
2117 * This process needs to be suspended prior to shutdown sync.
2118 */
2119 EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, bufdaemonproc,
2120 SHUTDOWN_PRI_LAST);
2121
2122 /*
2123 * This process is allowed to take the buffer cache to the limit
2124 */
2062 curthread->td_pflags |= TDP_NORUNNINGBUF;
2125 curthread->td_pflags |= TDP_NORUNNINGBUF | TDP_BUFNEED;
2063 mtx_lock(&bdlock);
2064 for (;;) {
2065 bd_request = 0;
2066 mtx_unlock(&bdlock);
2067
2068 kproc_suspend_check(bufdaemonproc);
2069
2070 /*
2071 * Do the flush. Limit the amount of in-transit I/O we
2072 * allow to build up, otherwise we would completely saturate
2073 * the I/O system. Wakeup any waiting processes before we
2074 * normally would so they can run in parallel with our drain.
2075 */
2076 while (numdirtybuffers > lodirtybuffers) {
2126 mtx_lock(&bdlock);
2127 for (;;) {
2128 bd_request = 0;
2129 mtx_unlock(&bdlock);
2130
2131 kproc_suspend_check(bufdaemonproc);
2132
2133 /*
2134 * Do the flush. Limit the amount of in-transit I/O we
2135 * allow to build up, otherwise we would completely saturate
2136 * the I/O system. Wakeup any waiting processes before we
2137 * normally would so they can run in parallel with our drain.
2138 */
2139 while (numdirtybuffers > lodirtybuffers) {
2077 int flushed;
2078
2079 flushed = flushbufqueues(QUEUE_DIRTY, 0);
2080 /* The list empty check here is slightly racy */
2081 if (!TAILQ_EMPTY(&bufqueues[QUEUE_DIRTY_GIANT])) {
2082 mtx_lock(&Giant);
2083 flushed += flushbufqueues(QUEUE_DIRTY_GIANT, 0);
2084 mtx_unlock(&Giant);
2085 }
2086 if (flushed == 0) {
2087 /*
2088 * Could not find any buffers without rollback
2089 * dependencies, so just write the first one
2090 * in the hopes of eventually making progress.
2091 */
2092 flushbufqueues(QUEUE_DIRTY, 1);
2093 if (!TAILQ_EMPTY(
2094 &bufqueues[QUEUE_DIRTY_GIANT])) {
2095 mtx_lock(&Giant);
2096 flushbufqueues(QUEUE_DIRTY_GIANT, 1);
2097 mtx_unlock(&Giant);
2098 }
2140 if (buf_do_flush(NULL) == 0)
2099 break;
2141 break;
2100 }
2101 uio_yield();
2102 }
2103
2104 /*
2105 * Only clear bd_request if we have reached our low water
2106 * mark. The buf_daemon normally waits 1 second and
2107 * then incrementally flushes any dirty buffers that have
2108 * built up, within reason.

--- 29 unchanged lines hidden (view full) ---

2138 * free up B_INVAL buffers instead of write them, which NFS is
2139 * particularly sensitive to.
2140 */
2141static int flushwithdeps = 0;
2142SYSCTL_INT(_vfs, OID_AUTO, flushwithdeps, CTLFLAG_RW, &flushwithdeps,
2143 0, "Number of buffers flushed with dependecies that require rollbacks");
2144
2145static int
2142 uio_yield();
2143 }
2144
2145 /*
2146 * Only clear bd_request if we have reached our low water
2147 * mark. The buf_daemon normally waits 1 second and
2148 * then incrementally flushes any dirty buffers that have
2149 * built up, within reason.

--- 29 unchanged lines hidden (view full) ---

2179 * free up B_INVAL buffers instead of write them, which NFS is
2180 * particularly sensitive to.
2181 */
2182static int flushwithdeps = 0;
2183SYSCTL_INT(_vfs, OID_AUTO, flushwithdeps, CTLFLAG_RW, &flushwithdeps,
2184 0, "Number of buffers flushed with dependecies that require rollbacks");
2185
2186static int
2146flushbufqueues(int queue, int flushdeps)
2187flushbufqueues(struct vnode *lvp, int queue, int flushdeps)
2147{
2148 struct buf sentinel;
2149 struct vnode *vp;
2150 struct mount *mp;
2151 struct buf *bp;
2152 int hasdeps;
2153 int flushed;
2154 int target;
2155
2188{
2189 struct buf sentinel;
2190 struct vnode *vp;
2191 struct mount *mp;
2192 struct buf *bp;
2193 int hasdeps;
2194 int flushed;
2195 int target;
2196
2156 target = numdirtybuffers - lodirtybuffers;
2157 if (flushdeps && target > 2)
2158 target /= 2;
2197 if (lvp == NULL) {
2198 target = numdirtybuffers - lodirtybuffers;
2199 if (flushdeps && target > 2)
2200 target /= 2;
2201 } else
2202 target = flushbufqtarget;
2159 flushed = 0;
2160 bp = NULL;
2203 flushed = 0;
2204 bp = NULL;
2205 sentinel.b_qindex = QUEUE_SENTINEL;
2161 mtx_lock(&bqlock);
2206 mtx_lock(&bqlock);
2162 TAILQ_INSERT_TAIL(&bufqueues[queue], &sentinel, b_freelist);
2207 TAILQ_INSERT_HEAD(&bufqueues[queue], &sentinel, b_freelist);
2163 while (flushed != target) {
2208 while (flushed != target) {
2164 bp = TAILQ_FIRST(&bufqueues[queue]);
2165 if (bp == &sentinel)
2209 bp = TAILQ_NEXT(&sentinel, b_freelist);
2210 if (bp != NULL) {
2211 TAILQ_REMOVE(&bufqueues[queue], &sentinel, b_freelist);
2212 TAILQ_INSERT_AFTER(&bufqueues[queue], bp, &sentinel,
2213 b_freelist);
2214 } else
2166 break;
2215 break;
2167 TAILQ_REMOVE(&bufqueues[queue], bp, b_freelist);
2168 TAILQ_INSERT_TAIL(&bufqueues[queue], bp, b_freelist);
2169
2216 /*
2217 * Skip sentinels inserted by other invocations of the
2218 * flushbufqueues(), taking care to not reorder them.
2219 */
2220 if (bp->b_qindex == QUEUE_SENTINEL)
2221 continue;
2222 /*
2223 * Only flush the buffers that belong to the
2224 * vnode locked by the curthread.
2225 */
2226 if (lvp != NULL && bp->b_vp != lvp)
2227 continue;
2170 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL) != 0)
2171 continue;
2172 if (bp->b_pin_count > 0) {
2173 BUF_UNLOCK(bp);
2174 continue;
2175 }
2176 BO_LOCK(bp->b_bufobj);
2177 if ((bp->b_vflags & BV_BKGRDINPROG) != 0 ||

--- 31 unchanged lines hidden (view full) ---

2209 * of vnode followed by buf lock. This is ok because
2210 * the NOWAIT will prevent deadlock.
2211 */
2212 vp = bp->b_vp;
2213 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
2214 BUF_UNLOCK(bp);
2215 continue;
2216 }
2228 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL) != 0)
2229 continue;
2230 if (bp->b_pin_count > 0) {
2231 BUF_UNLOCK(bp);
2232 continue;
2233 }
2234 BO_LOCK(bp->b_bufobj);
2235 if ((bp->b_vflags & BV_BKGRDINPROG) != 0 ||

--- 31 unchanged lines hidden (view full) ---

2267 * of vnode followed by buf lock. This is ok because
2268 * the NOWAIT will prevent deadlock.
2269 */
2270 vp = bp->b_vp;
2271 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
2272 BUF_UNLOCK(bp);
2273 continue;
2274 }
2217 if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) == 0) {
2275 if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT | LK_CANRECURSE) == 0) {
2218 mtx_unlock(&bqlock);
2219 CTR3(KTR_BUF, "flushbufqueue(%p) vp %p flags %X",
2220 bp, bp->b_vp, bp->b_flags);
2276 mtx_unlock(&bqlock);
2277 CTR3(KTR_BUF, "flushbufqueue(%p) vp %p flags %X",
2278 bp, bp->b_vp, bp->b_flags);
2221 vfs_bio_awrite(bp);
2279 if (curproc == bufdaemonproc)
2280 vfs_bio_awrite(bp);
2281 else {
2282 bremfree(bp);
2283 bwrite(bp);
2284 }
2222 vn_finished_write(mp);
2223 VOP_UNLOCK(vp, 0);
2224 flushwithdeps += hasdeps;
2225 flushed++;
2285 vn_finished_write(mp);
2286 VOP_UNLOCK(vp, 0);
2287 flushwithdeps += hasdeps;
2288 flushed++;
2226 waitrunningbufspace();
2289
2290 /*
2291 * Sleeping on runningbufspace while holding
2292 * vnode lock leads to deadlock.
2293 */
2294 if (curproc == bufdaemonproc)
2295 waitrunningbufspace();
2227 numdirtywakeup((lodirtybuffers + hidirtybuffers) / 2);
2228 mtx_lock(&bqlock);
2229 continue;
2230 }
2231 vn_finished_write(mp);
2232 BUF_UNLOCK(bp);
2233 }
2234 TAILQ_REMOVE(&bufqueues[queue], &sentinel, b_freelist);

--- 365 unchanged lines hidden (view full) ---

2600 if (flags & GB_NOCREAT)
2601 return NULL;
2602 bsize = bo->bo_bsize;
2603 offset = blkno * bsize;
2604 vmio = vp->v_object != NULL;
2605 maxsize = vmio ? size + (offset & PAGE_MASK) : size;
2606 maxsize = imax(maxsize, bsize);
2607
2296 numdirtywakeup((lodirtybuffers + hidirtybuffers) / 2);
2297 mtx_lock(&bqlock);
2298 continue;
2299 }
2300 vn_finished_write(mp);
2301 BUF_UNLOCK(bp);
2302 }
2303 TAILQ_REMOVE(&bufqueues[queue], &sentinel, b_freelist);

--- 365 unchanged lines hidden (view full) ---

2669 if (flags & GB_NOCREAT)
2670 return NULL;
2671 bsize = bo->bo_bsize;
2672 offset = blkno * bsize;
2673 vmio = vp->v_object != NULL;
2674 maxsize = vmio ? size + (offset & PAGE_MASK) : size;
2675 maxsize = imax(maxsize, bsize);
2676
2608 bp = getnewbuf(slpflag, slptimeo, size, maxsize);
2677 bp = getnewbuf(vp, slpflag, slptimeo, size, maxsize, flags);
2609 if (bp == NULL) {
2610 if (slpflag || slptimeo)
2611 return NULL;
2612 goto loop;
2613 }
2614
2615 /*
2616 * This code is used to make sure that a buffer is not

--- 58 unchanged lines hidden (view full) ---

2675 return (bp);
2676}
2677
2678/*
2679 * Get an empty, disassociated buffer of given size. The buffer is initially
2680 * set to B_INVAL.
2681 */
2682struct buf *
2678 if (bp == NULL) {
2679 if (slpflag || slptimeo)
2680 return NULL;
2681 goto loop;
2682 }
2683
2684 /*
2685 * This code is used to make sure that a buffer is not

--- 58 unchanged lines hidden (view full) ---

2744 return (bp);
2745}
2746
2747/*
2748 * Get an empty, disassociated buffer of given size. The buffer is initially
2749 * set to B_INVAL.
2750 */
2751struct buf *
2683geteblk(int size)
2752geteblk(int size, int flags)
2684{
2685 struct buf *bp;
2686 int maxsize;
2687
2688 maxsize = (size + BKVAMASK) & ~BKVAMASK;
2753{
2754 struct buf *bp;
2755 int maxsize;
2756
2757 maxsize = (size + BKVAMASK) & ~BKVAMASK;
2689 while ((bp = getnewbuf(0, 0, size, maxsize)) == 0)
2690 continue;
2758 while ((bp = getnewbuf(NULL, 0, 0, size, maxsize, flags)) == NULL) {
2759 if ((flags & GB_NOWAIT_BD) &&
2760 (curthread->td_pflags & TDP_BUFNEED) != 0)
2761 return (NULL);
2762 }
2691 allocbuf(bp, size);
2692 bp->b_flags |= B_INVAL; /* b_dep cleared by getnewbuf() */
2693 BUF_ASSERT_HELD(bp);
2694 return (bp);
2695}
2696
2697
2698/*

--- 1301 unchanged lines hidden ---
2763 allocbuf(bp, size);
2764 bp->b_flags |= B_INVAL; /* b_dep cleared by getnewbuf() */
2765 BUF_ASSERT_HELD(bp);
2766 return (bp);
2767}
2768
2769
2770/*

--- 1301 unchanged lines hidden ---