vfs_bio.c revision 1.85 1 1.85 gehenna /* $NetBSD: vfs_bio.c,v 1.85 2002/09/06 13:18:43 gehenna Exp $ */
2 1.31 cgd
3 1.31 cgd /*-
4 1.31 cgd * Copyright (c) 1994 Christopher G. Demetriou
5 1.31 cgd * Copyright (c) 1982, 1986, 1989, 1993
6 1.31 cgd * The Regents of the University of California. All rights reserved.
7 1.31 cgd * (c) UNIX System Laboratories, Inc.
8 1.31 cgd * All or some portions of this file are derived from material licensed
9 1.31 cgd * to the University of California by American Telephone and Telegraph
10 1.31 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 1.31 cgd * the permission of UNIX System Laboratories, Inc.
12 1.31 cgd *
13 1.31 cgd * Redistribution and use in source and binary forms, with or without
14 1.31 cgd * modification, are permitted provided that the following conditions
15 1.31 cgd * are met:
16 1.31 cgd * 1. Redistributions of source code must retain the above copyright
17 1.31 cgd * notice, this list of conditions and the following disclaimer.
18 1.31 cgd * 2. Redistributions in binary form must reproduce the above copyright
19 1.31 cgd * notice, this list of conditions and the following disclaimer in the
20 1.31 cgd * documentation and/or other materials provided with the distribution.
21 1.31 cgd * 3. All advertising materials mentioning features or use of this software
22 1.31 cgd * must display the following acknowledgement:
23 1.31 cgd * This product includes software developed by the University of
24 1.31 cgd * California, Berkeley and its contributors.
25 1.31 cgd * 4. Neither the name of the University nor the names of its contributors
26 1.31 cgd * may be used to endorse or promote products derived from this software
27 1.31 cgd * without specific prior written permission.
28 1.31 cgd *
29 1.31 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 1.31 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 1.31 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 1.31 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 1.31 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 1.31 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 1.31 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 1.31 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 1.31 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 1.31 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 1.31 cgd * SUCH DAMAGE.
40 1.31 cgd *
41 1.31 cgd * @(#)vfs_bio.c 8.6 (Berkeley) 1/11/94
42 1.31 cgd */
43 1.31 cgd
44 1.31 cgd /*
45 1.31 cgd * Some references:
46 1.31 cgd * Bach: The Design of the UNIX Operating System (Prentice Hall, 1986)
47 1.31 cgd * Leffler, et al.: The Design and Implementation of the 4.3BSD
48 1.31 cgd * UNIX Operating System (Addison Welley, 1989)
49 1.31 cgd */
50 1.77 lukem
51 1.81 matt #include "opt_softdep.h"
52 1.81 matt
53 1.77 lukem #include <sys/cdefs.h>
54 1.85 gehenna __KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.85 2002/09/06 13:18:43 gehenna Exp $");
55 1.31 cgd
56 1.31 cgd #include <sys/param.h>
57 1.31 cgd #include <sys/systm.h>
58 1.31 cgd #include <sys/proc.h>
59 1.31 cgd #include <sys/buf.h>
60 1.31 cgd #include <sys/vnode.h>
61 1.31 cgd #include <sys/mount.h>
62 1.31 cgd #include <sys/malloc.h>
63 1.31 cgd #include <sys/resourcevar.h>
64 1.35 mycroft #include <sys/conf.h>
65 1.40 christos
66 1.73 chs #include <uvm/uvm.h>
67 1.71 thorpej
68 1.59 fvdl #include <miscfs/specfs/specdev.h>
69 1.59 fvdl
70 1.31 cgd /* Macros to clear/set/test flags. */
71 1.31 cgd #define SET(t, f) (t) |= (f)
72 1.31 cgd #define CLR(t, f) (t) &= ~(f)
73 1.31 cgd #define ISSET(t, f) ((t) & (f))
74 1.31 cgd
75 1.31 cgd /*
76 1.31 cgd * Definitions for the buffer hash lists.
77 1.31 cgd */
78 1.31 cgd #define BUFHASH(dvp, lbn) \
79 1.73 chs (&bufhashtbl[(((long)(dvp) >> 8) + (int)(lbn)) & bufhash])
80 1.31 cgd LIST_HEAD(bufhashhdr, buf) *bufhashtbl, invalhash;
81 1.31 cgd u_long bufhash;
82 1.81 matt #ifndef SOFTDEP
83 1.59 fvdl struct bio_ops bioops; /* I/O operation notification */
84 1.81 matt #endif
85 1.31 cgd
86 1.31 cgd /*
87 1.31 cgd * Insq/Remq for the buffer hash lists.
88 1.31 cgd */
89 1.31 cgd #define binshash(bp, dp) LIST_INSERT_HEAD(dp, bp, b_hash)
90 1.31 cgd #define bremhash(bp) LIST_REMOVE(bp, b_hash)
91 1.31 cgd
92 1.31 cgd /*
93 1.31 cgd * Definitions for the buffer free lists.
94 1.31 cgd */
95 1.31 cgd #define BQUEUES 4 /* number of free buffer queues */
96 1.31 cgd
97 1.31 cgd #define BQ_LOCKED 0 /* super-blocks &c */
98 1.31 cgd #define BQ_LRU 1 /* lru, useful buffers */
99 1.31 cgd #define BQ_AGE 2 /* rubbish */
100 1.31 cgd #define BQ_EMPTY 3 /* buffer headers with no memory */
101 1.31 cgd
102 1.31 cgd TAILQ_HEAD(bqueues, buf) bufqueues[BQUEUES];
103 1.31 cgd int needbuffer;
104 1.31 cgd
105 1.31 cgd /*
106 1.65 thorpej * Buffer pool for I/O buffers.
107 1.65 thorpej */
108 1.65 thorpej struct pool bufpool;
109 1.65 thorpej
110 1.65 thorpej /*
111 1.31 cgd * Insq/Remq for the buffer free lists.
112 1.31 cgd */
113 1.31 cgd #define binsheadfree(bp, dp) TAILQ_INSERT_HEAD(dp, bp, b_freelist)
114 1.31 cgd #define binstailfree(bp, dp) TAILQ_INSERT_TAIL(dp, bp, b_freelist)
115 1.31 cgd
116 1.40 christos static __inline struct buf *bio_doread __P((struct vnode *, daddr_t, int,
117 1.40 christos struct ucred *, int));
118 1.40 christos int count_lock_queue __P((void));
119 1.40 christos
120 1.31 cgd void
121 1.31 cgd bremfree(bp)
122 1.31 cgd struct buf *bp;
123 1.31 cgd {
124 1.60 fvdl int s = splbio();
125 1.60 fvdl
126 1.31 cgd struct bqueues *dp = NULL;
127 1.31 cgd
128 1.31 cgd /*
129 1.31 cgd * We only calculate the head of the freelist when removing
130 1.31 cgd * the last element of the list as that is the only time that
131 1.31 cgd * it is needed (e.g. to reset the tail pointer).
132 1.31 cgd *
133 1.31 cgd * NB: This makes an assumption about how tailq's are implemented.
134 1.31 cgd */
135 1.84 matt if (TAILQ_NEXT(bp, b_freelist) == NULL) {
136 1.31 cgd for (dp = bufqueues; dp < &bufqueues[BQUEUES]; dp++)
137 1.31 cgd if (dp->tqh_last == &bp->b_freelist.tqe_next)
138 1.31 cgd break;
139 1.31 cgd if (dp == &bufqueues[BQUEUES])
140 1.31 cgd panic("bremfree: lost tail");
141 1.31 cgd }
142 1.31 cgd TAILQ_REMOVE(dp, bp, b_freelist);
143 1.60 fvdl splx(s);
144 1.31 cgd }
145 1.31 cgd
146 1.31 cgd /*
147 1.31 cgd * Initialize buffers and hash links for buffers.
148 1.31 cgd */
149 1.31 cgd void
150 1.31 cgd bufinit()
151 1.31 cgd {
152 1.66 augustss struct buf *bp;
153 1.31 cgd struct bqueues *dp;
154 1.82 thorpej u_int i, base, residual;
155 1.65 thorpej
156 1.65 thorpej /*
157 1.65 thorpej * Initialize the buffer pool. This pool is used for buffers
158 1.65 thorpej * which are strictly I/O control blocks, not buffer cache
159 1.65 thorpej * buffers.
160 1.65 thorpej */
161 1.79 thorpej pool_init(&bufpool, sizeof(struct buf), 0, 0, 0, "bufpl", NULL);
162 1.31 cgd
163 1.31 cgd for (dp = bufqueues; dp < &bufqueues[BQUEUES]; dp++)
164 1.31 cgd TAILQ_INIT(dp);
165 1.70 ad bufhashtbl = hashinit(nbuf, HASH_LIST, M_CACHE, M_WAITOK, &bufhash);
166 1.31 cgd base = bufpages / nbuf;
167 1.31 cgd residual = bufpages % nbuf;
168 1.31 cgd for (i = 0; i < nbuf; i++) {
169 1.31 cgd bp = &buf[i];
170 1.55 perry memset((char *)bp, 0, sizeof(*bp));
171 1.31 cgd bp->b_dev = NODEV;
172 1.31 cgd bp->b_vnbufs.le_next = NOLIST;
173 1.59 fvdl LIST_INIT(&bp->b_dep);
174 1.31 cgd bp->b_data = buffers + i * MAXBSIZE;
175 1.31 cgd if (i < residual)
176 1.71 thorpej bp->b_bufsize = (base + 1) * PAGE_SIZE;
177 1.31 cgd else
178 1.71 thorpej bp->b_bufsize = base * PAGE_SIZE;
179 1.31 cgd bp->b_flags = B_INVAL;
180 1.31 cgd dp = bp->b_bufsize ? &bufqueues[BQ_AGE] : &bufqueues[BQ_EMPTY];
181 1.31 cgd binsheadfree(bp, dp);
182 1.31 cgd binshash(bp, &invalhash);
183 1.31 cgd }
184 1.31 cgd }
185 1.31 cgd
186 1.40 christos static __inline struct buf *
187 1.34 mycroft bio_doread(vp, blkno, size, cred, async)
188 1.31 cgd struct vnode *vp;
189 1.31 cgd daddr_t blkno;
190 1.31 cgd int size;
191 1.31 cgd struct ucred *cred;
192 1.34 mycroft int async;
193 1.31 cgd {
194 1.66 augustss struct buf *bp;
195 1.49 cgd struct proc *p = (curproc != NULL ? curproc : &proc0); /* XXX */
196 1.31 cgd
197 1.34 mycroft bp = getblk(vp, blkno, size, 0, 0);
198 1.31 cgd
199 1.31 cgd /*
200 1.34 mycroft * If buffer does not have data valid, start a read.
201 1.31 cgd * Note that if buffer is B_INVAL, getblk() won't return it.
202 1.31 cgd * Therefore, it's valid if it's I/O has completed or been delayed.
203 1.31 cgd */
204 1.34 mycroft if (!ISSET(bp->b_flags, (B_DONE | B_DELWRI))) {
205 1.73 chs /* Start I/O for the buffer. */
206 1.34 mycroft SET(bp->b_flags, B_READ | async);
207 1.34 mycroft VOP_STRATEGY(bp);
208 1.31 cgd
209 1.34 mycroft /* Pay for the read. */
210 1.49 cgd p->p_stats->p_ru.ru_inblock++;
211 1.34 mycroft } else if (async) {
212 1.34 mycroft brelse(bp);
213 1.31 cgd }
214 1.31 cgd
215 1.34 mycroft return (bp);
216 1.34 mycroft }
217 1.34 mycroft
218 1.34 mycroft /*
219 1.34 mycroft * Read a disk block.
220 1.34 mycroft * This algorithm described in Bach (p.54).
221 1.34 mycroft */
222 1.40 christos int
223 1.34 mycroft bread(vp, blkno, size, cred, bpp)
224 1.34 mycroft struct vnode *vp;
225 1.34 mycroft daddr_t blkno;
226 1.34 mycroft int size;
227 1.34 mycroft struct ucred *cred;
228 1.34 mycroft struct buf **bpp;
229 1.34 mycroft {
230 1.66 augustss struct buf *bp;
231 1.34 mycroft
232 1.34 mycroft /* Get buffer for block. */
233 1.34 mycroft bp = *bpp = bio_doread(vp, blkno, size, cred, 0);
234 1.31 cgd
235 1.80 chs /* Wait for the read to complete, and return result. */
236 1.31 cgd return (biowait(bp));
237 1.31 cgd }
238 1.31 cgd
239 1.31 cgd /*
240 1.31 cgd * Read-ahead multiple disk blocks. The first is sync, the rest async.
241 1.31 cgd * Trivial modification to the breada algorithm presented in Bach (p.55).
242 1.31 cgd */
243 1.40 christos int
244 1.31 cgd breadn(vp, blkno, size, rablks, rasizes, nrablks, cred, bpp)
245 1.31 cgd struct vnode *vp;
246 1.31 cgd daddr_t blkno; int size;
247 1.31 cgd daddr_t rablks[]; int rasizes[];
248 1.31 cgd int nrablks;
249 1.31 cgd struct ucred *cred;
250 1.31 cgd struct buf **bpp;
251 1.31 cgd {
252 1.66 augustss struct buf *bp;
253 1.31 cgd int i;
254 1.31 cgd
255 1.34 mycroft bp = *bpp = bio_doread(vp, blkno, size, cred, 0);
256 1.31 cgd
257 1.31 cgd /*
258 1.31 cgd * For each of the read-ahead blocks, start a read, if necessary.
259 1.31 cgd */
260 1.31 cgd for (i = 0; i < nrablks; i++) {
261 1.31 cgd /* If it's in the cache, just go on to next one. */
262 1.31 cgd if (incore(vp, rablks[i]))
263 1.31 cgd continue;
264 1.31 cgd
265 1.31 cgd /* Get a buffer for the read-ahead block */
266 1.34 mycroft (void) bio_doread(vp, rablks[i], rasizes[i], cred, B_ASYNC);
267 1.31 cgd }
268 1.31 cgd
269 1.80 chs /* Otherwise, we had to start a read for it; wait until it's valid. */
270 1.31 cgd return (biowait(bp));
271 1.31 cgd }
272 1.31 cgd
273 1.31 cgd /*
274 1.31 cgd * Read with single-block read-ahead. Defined in Bach (p.55), but
275 1.31 cgd * implemented as a call to breadn().
276 1.31 cgd * XXX for compatibility with old file systems.
277 1.31 cgd */
278 1.40 christos int
279 1.31 cgd breada(vp, blkno, size, rablkno, rabsize, cred, bpp)
280 1.31 cgd struct vnode *vp;
281 1.31 cgd daddr_t blkno; int size;
282 1.31 cgd daddr_t rablkno; int rabsize;
283 1.31 cgd struct ucred *cred;
284 1.31 cgd struct buf **bpp;
285 1.31 cgd {
286 1.34 mycroft
287 1.31 cgd return (breadn(vp, blkno, size, &rablkno, &rabsize, 1, cred, bpp));
288 1.31 cgd }
289 1.31 cgd
290 1.31 cgd /*
291 1.31 cgd * Block write. Described in Bach (p.56)
292 1.31 cgd */
293 1.40 christos int
294 1.31 cgd bwrite(bp)
295 1.31 cgd struct buf *bp;
296 1.31 cgd {
297 1.44 pk int rv, sync, wasdelayed, s;
298 1.49 cgd struct proc *p = (curproc != NULL ? curproc : &proc0); /* XXX */
299 1.59 fvdl struct vnode *vp;
300 1.59 fvdl struct mount *mp;
301 1.31 cgd
302 1.76 chs vp = bp->b_vp;
303 1.76 chs if (vp != NULL) {
304 1.76 chs if (vp->v_type == VBLK)
305 1.76 chs mp = vp->v_specmountpoint;
306 1.76 chs else
307 1.76 chs mp = vp->v_mount;
308 1.76 chs } else {
309 1.76 chs mp = NULL;
310 1.76 chs }
311 1.76 chs
312 1.38 cgd /*
313 1.38 cgd * Remember buffer type, to switch on it later. If the write was
314 1.38 cgd * synchronous, but the file system was mounted with MNT_ASYNC,
315 1.38 cgd * convert it to a delayed write.
316 1.38 cgd * XXX note that this relies on delayed tape writes being converted
317 1.38 cgd * to async, not sync writes (which is safe, but ugly).
318 1.38 cgd */
319 1.31 cgd sync = !ISSET(bp->b_flags, B_ASYNC);
320 1.76 chs if (sync && mp != NULL && ISSET(mp->mnt_flag, MNT_ASYNC)) {
321 1.37 cgd bdwrite(bp);
322 1.37 cgd return (0);
323 1.37 cgd }
324 1.46 mycroft
325 1.59 fvdl /*
326 1.59 fvdl * Collect statistics on synchronous and asynchronous writes.
327 1.59 fvdl * Writes to block devices are charged to their associated
328 1.59 fvdl * filesystem (if any).
329 1.59 fvdl */
330 1.76 chs if (mp != NULL) {
331 1.76 chs if (sync)
332 1.76 chs mp->mnt_stat.f_syncwrites++;
333 1.59 fvdl else
334 1.76 chs mp->mnt_stat.f_asyncwrites++;
335 1.59 fvdl }
336 1.59 fvdl
337 1.31 cgd wasdelayed = ISSET(bp->b_flags, B_DELWRI);
338 1.31 cgd
339 1.44 pk s = splbio();
340 1.46 mycroft
341 1.60 fvdl CLR(bp->b_flags, (B_READ | B_DONE | B_ERROR | B_DELWRI));
342 1.60 fvdl
343 1.46 mycroft /*
344 1.46 mycroft * Pay for the I/O operation and make sure the buf is on the correct
345 1.46 mycroft * vnode queue.
346 1.46 mycroft */
347 1.46 mycroft if (wasdelayed)
348 1.46 mycroft reassignbuf(bp, bp->b_vp);
349 1.46 mycroft else
350 1.49 cgd p->p_stats->p_ru.ru_oublock++;
351 1.32 mycroft
352 1.31 cgd /* Initiate disk write. Make sure the appropriate party is charged. */
353 1.44 pk bp->b_vp->v_numoutput++;
354 1.44 pk splx(s);
355 1.46 mycroft
356 1.31 cgd VOP_STRATEGY(bp);
357 1.31 cgd
358 1.34 mycroft if (sync) {
359 1.46 mycroft /* If I/O was synchronous, wait for it to complete. */
360 1.31 cgd rv = biowait(bp);
361 1.31 cgd
362 1.34 mycroft /* Release the buffer. */
363 1.31 cgd brelse(bp);
364 1.34 mycroft
365 1.34 mycroft return (rv);
366 1.34 mycroft } else {
367 1.34 mycroft return (0);
368 1.31 cgd }
369 1.31 cgd }
370 1.31 cgd
371 1.31 cgd int
372 1.40 christos vn_bwrite(v)
373 1.40 christos void *v;
374 1.31 cgd {
375 1.40 christos struct vop_bwrite_args *ap = v;
376 1.34 mycroft
377 1.31 cgd return (bwrite(ap->a_bp));
378 1.31 cgd }
379 1.31 cgd
380 1.31 cgd /*
381 1.31 cgd * Delayed write.
382 1.31 cgd *
383 1.31 cgd * The buffer is marked dirty, but is not queued for I/O.
384 1.31 cgd * This routine should be used when the buffer is expected
385 1.31 cgd * to be modified again soon, typically a small write that
386 1.31 cgd * partially fills a buffer.
387 1.31 cgd *
388 1.31 cgd * NB: magnetic tapes cannot be delayed; they must be
389 1.31 cgd * written in the order that the writes are requested.
390 1.31 cgd *
391 1.31 cgd * Described in Leffler, et al. (pp. 208-213).
392 1.31 cgd */
393 1.31 cgd void
394 1.31 cgd bdwrite(bp)
395 1.31 cgd struct buf *bp;
396 1.31 cgd {
397 1.60 fvdl struct proc *p = (curproc != NULL ? curproc : &proc0); /* XXX */
398 1.85 gehenna const struct bdevsw *bdev;
399 1.45 pk int s;
400 1.31 cgd
401 1.46 mycroft /* If this is a tape block, write the block now. */
402 1.52 pk /* XXX NOTE: the memory filesystem usurpes major device */
403 1.85 gehenna /* XXX number 4095, which is a bad idea. */
404 1.85 gehenna if (bp->b_dev != NODEV && major(bp->b_dev) != 4095) {
405 1.85 gehenna bdev = bdevsw_lookup(bp->b_dev);
406 1.85 gehenna if (bdev != NULL && bdev->d_type == D_TAPE) {
407 1.85 gehenna bawrite(bp);
408 1.85 gehenna return;
409 1.85 gehenna }
410 1.46 mycroft }
411 1.46 mycroft
412 1.31 cgd /*
413 1.31 cgd * If the block hasn't been seen before:
414 1.31 cgd * (1) Mark it as having been seen,
415 1.45 pk * (2) Charge for the write,
416 1.45 pk * (3) Make sure it's on its vnode's correct block list.
417 1.31 cgd */
418 1.60 fvdl s = splbio();
419 1.60 fvdl
420 1.31 cgd if (!ISSET(bp->b_flags, B_DELWRI)) {
421 1.31 cgd SET(bp->b_flags, B_DELWRI);
422 1.49 cgd p->p_stats->p_ru.ru_oublock++;
423 1.31 cgd reassignbuf(bp, bp->b_vp);
424 1.31 cgd }
425 1.31 cgd
426 1.31 cgd /* Otherwise, the "write" is done, so mark and release the buffer. */
427 1.57 mycroft CLR(bp->b_flags, B_NEEDCOMMIT|B_DONE);
428 1.60 fvdl splx(s);
429 1.60 fvdl
430 1.31 cgd brelse(bp);
431 1.31 cgd }
432 1.31 cgd
433 1.31 cgd /*
434 1.31 cgd * Asynchronous block write; just an asynchronous bwrite().
435 1.31 cgd */
436 1.31 cgd void
437 1.31 cgd bawrite(bp)
438 1.31 cgd struct buf *bp;
439 1.31 cgd {
440 1.31 cgd
441 1.31 cgd SET(bp->b_flags, B_ASYNC);
442 1.31 cgd VOP_BWRITE(bp);
443 1.31 cgd }
444 1.31 cgd
445 1.31 cgd /*
446 1.59 fvdl * Same as first half of bdwrite, mark buffer dirty, but do not release it.
447 1.59 fvdl */
448 1.59 fvdl void
449 1.59 fvdl bdirty(bp)
450 1.59 fvdl struct buf *bp;
451 1.59 fvdl {
452 1.59 fvdl struct proc *p = (curproc != NULL ? curproc : &proc0); /* XXX */
453 1.59 fvdl int s;
454 1.59 fvdl
455 1.60 fvdl s = splbio();
456 1.61 fvdl
457 1.61 fvdl CLR(bp->b_flags, B_AGE);
458 1.60 fvdl
459 1.59 fvdl if (!ISSET(bp->b_flags, B_DELWRI)) {
460 1.59 fvdl SET(bp->b_flags, B_DELWRI);
461 1.59 fvdl p->p_stats->p_ru.ru_oublock++;
462 1.59 fvdl reassignbuf(bp, bp->b_vp);
463 1.59 fvdl }
464 1.60 fvdl
465 1.60 fvdl splx(s);
466 1.59 fvdl }
467 1.59 fvdl
468 1.59 fvdl /*
469 1.31 cgd * Release a buffer on to the free lists.
470 1.31 cgd * Described in Bach (p. 46).
471 1.31 cgd */
472 1.31 cgd void
473 1.31 cgd brelse(bp)
474 1.31 cgd struct buf *bp;
475 1.31 cgd {
476 1.31 cgd struct bqueues *bufq;
477 1.31 cgd int s;
478 1.31 cgd
479 1.73 chs KASSERT(ISSET(bp->b_flags, B_BUSY));
480 1.73 chs
481 1.31 cgd /* Wake up any processes waiting for any buffer to become free. */
482 1.31 cgd if (needbuffer) {
483 1.31 cgd needbuffer = 0;
484 1.31 cgd wakeup(&needbuffer);
485 1.31 cgd }
486 1.31 cgd
487 1.60 fvdl /* Block disk interrupts. */
488 1.60 fvdl s = splbio();
489 1.60 fvdl
490 1.31 cgd /* Wake up any proceeses waiting for _this_ buffer to become free. */
491 1.31 cgd if (ISSET(bp->b_flags, B_WANTED)) {
492 1.57 mycroft CLR(bp->b_flags, B_WANTED|B_AGE);
493 1.31 cgd wakeup(bp);
494 1.31 cgd }
495 1.31 cgd
496 1.31 cgd /*
497 1.31 cgd * Determine which queue the buffer should be on, then put it there.
498 1.31 cgd */
499 1.31 cgd
500 1.31 cgd /* If it's locked, don't report an error; try again later. */
501 1.31 cgd if (ISSET(bp->b_flags, (B_LOCKED|B_ERROR)) == (B_LOCKED|B_ERROR))
502 1.31 cgd CLR(bp->b_flags, B_ERROR);
503 1.31 cgd
504 1.31 cgd /* If it's not cacheable, or an error, mark it invalid. */
505 1.31 cgd if (ISSET(bp->b_flags, (B_NOCACHE|B_ERROR)))
506 1.31 cgd SET(bp->b_flags, B_INVAL);
507 1.31 cgd
508 1.50 mycroft if (ISSET(bp->b_flags, B_VFLUSH)) {
509 1.50 mycroft /*
510 1.50 mycroft * This is a delayed write buffer that was just flushed to
511 1.50 mycroft * disk. It is still on the LRU queue. If it's become
512 1.50 mycroft * invalid, then we need to move it to a different queue;
513 1.50 mycroft * otherwise leave it in its current position.
514 1.50 mycroft */
515 1.50 mycroft CLR(bp->b_flags, B_VFLUSH);
516 1.50 mycroft if (!ISSET(bp->b_flags, B_ERROR|B_INVAL|B_LOCKED|B_AGE))
517 1.50 mycroft goto already_queued;
518 1.50 mycroft else
519 1.50 mycroft bremfree(bp);
520 1.50 mycroft }
521 1.50 mycroft
522 1.31 cgd if ((bp->b_bufsize <= 0) || ISSET(bp->b_flags, B_INVAL)) {
523 1.31 cgd /*
524 1.31 cgd * If it's invalid or empty, dissociate it from its vnode
525 1.31 cgd * and put on the head of the appropriate queue.
526 1.31 cgd */
527 1.59 fvdl if (LIST_FIRST(&bp->b_dep) != NULL && bioops.io_deallocate)
528 1.59 fvdl (*bioops.io_deallocate)(bp);
529 1.59 fvdl CLR(bp->b_flags, B_DONE|B_DELWRI);
530 1.59 fvdl if (bp->b_vp) {
531 1.59 fvdl reassignbuf(bp, bp->b_vp);
532 1.31 cgd brelvp(bp);
533 1.59 fvdl }
534 1.31 cgd if (bp->b_bufsize <= 0)
535 1.31 cgd /* no data */
536 1.31 cgd bufq = &bufqueues[BQ_EMPTY];
537 1.31 cgd else
538 1.31 cgd /* invalid data */
539 1.31 cgd bufq = &bufqueues[BQ_AGE];
540 1.31 cgd binsheadfree(bp, bufq);
541 1.31 cgd } else {
542 1.31 cgd /*
543 1.31 cgd * It has valid data. Put it on the end of the appropriate
544 1.31 cgd * queue, so that it'll stick around for as long as possible.
545 1.67 fvdl * If buf is AGE, but has dependencies, must put it on last
546 1.67 fvdl * bufqueue to be scanned, ie LRU. This protects against the
547 1.67 fvdl * livelock where BQ_AGE only has buffers with dependencies,
548 1.67 fvdl * and we thus never get to the dependent buffers in BQ_LRU.
549 1.31 cgd */
550 1.31 cgd if (ISSET(bp->b_flags, B_LOCKED))
551 1.31 cgd /* locked in core */
552 1.31 cgd bufq = &bufqueues[BQ_LOCKED];
553 1.67 fvdl else if (!ISSET(bp->b_flags, B_AGE))
554 1.31 cgd /* valid data */
555 1.31 cgd bufq = &bufqueues[BQ_LRU];
556 1.67 fvdl else {
557 1.67 fvdl /* stale but valid data */
558 1.67 fvdl int has_deps;
559 1.67 fvdl
560 1.67 fvdl if (LIST_FIRST(&bp->b_dep) != NULL &&
561 1.67 fvdl bioops.io_countdeps)
562 1.67 fvdl has_deps = (*bioops.io_countdeps)(bp, 0);
563 1.67 fvdl else
564 1.67 fvdl has_deps = 0;
565 1.67 fvdl bufq = has_deps ? &bufqueues[BQ_LRU] :
566 1.67 fvdl &bufqueues[BQ_AGE];
567 1.67 fvdl }
568 1.31 cgd binstailfree(bp, bufq);
569 1.31 cgd }
570 1.31 cgd
571 1.50 mycroft already_queued:
572 1.31 cgd /* Unlock the buffer. */
573 1.83 hannken CLR(bp->b_flags, B_AGE|B_ASYNC|B_BUSY|B_NOCACHE);
574 1.73 chs SET(bp->b_flags, B_CACHE);
575 1.31 cgd
576 1.31 cgd /* Allow disk interrupts. */
577 1.31 cgd splx(s);
578 1.31 cgd }
579 1.31 cgd
580 1.31 cgd /*
581 1.31 cgd * Determine if a block is in the cache.
582 1.31 cgd * Just look on what would be its hash chain. If it's there, return
583 1.31 cgd * a pointer to it, unless it's marked invalid. If it's marked invalid,
584 1.31 cgd * we normally don't return the buffer, unless the caller explicitly
585 1.31 cgd * wants us to.
586 1.31 cgd */
587 1.31 cgd struct buf *
588 1.31 cgd incore(vp, blkno)
589 1.31 cgd struct vnode *vp;
590 1.31 cgd daddr_t blkno;
591 1.31 cgd {
592 1.31 cgd struct buf *bp;
593 1.31 cgd
594 1.31 cgd /* Search hash chain */
595 1.84 matt LIST_FOREACH(bp, BUFHASH(vp, blkno), b_hash) {
596 1.31 cgd if (bp->b_lblkno == blkno && bp->b_vp == vp &&
597 1.31 cgd !ISSET(bp->b_flags, B_INVAL))
598 1.31 cgd return (bp);
599 1.31 cgd }
600 1.31 cgd
601 1.73 chs return (NULL);
602 1.31 cgd }
603 1.31 cgd
604 1.31 cgd /*
605 1.31 cgd * Get a block of requested size that is associated with
606 1.31 cgd * a given vnode and block offset. If it is found in the
607 1.31 cgd * block cache, mark it as having been found, make it busy
608 1.31 cgd * and return it. Otherwise, return an empty block of the
609 1.31 cgd * correct size. It is up to the caller to insure that the
610 1.31 cgd * cached blocks be of the correct size.
611 1.31 cgd */
612 1.31 cgd struct buf *
613 1.31 cgd getblk(vp, blkno, size, slpflag, slptimeo)
614 1.66 augustss struct vnode *vp;
615 1.31 cgd daddr_t blkno;
616 1.31 cgd int size, slpflag, slptimeo;
617 1.31 cgd {
618 1.31 cgd struct buf *bp;
619 1.31 cgd int s, err;
620 1.31 cgd
621 1.39 cgd start:
622 1.73 chs bp = incore(vp, blkno);
623 1.73 chs if (bp != NULL) {
624 1.39 cgd s = splbio();
625 1.31 cgd if (ISSET(bp->b_flags, B_BUSY)) {
626 1.73 chs if (curproc == uvm.pagedaemon_proc) {
627 1.73 chs splx(s);
628 1.73 chs return NULL;
629 1.73 chs }
630 1.31 cgd SET(bp->b_flags, B_WANTED);
631 1.31 cgd err = tsleep(bp, slpflag | (PRIBIO + 1), "getblk",
632 1.73 chs slptimeo);
633 1.31 cgd splx(s);
634 1.31 cgd if (err)
635 1.31 cgd return (NULL);
636 1.31 cgd goto start;
637 1.31 cgd }
638 1.57 mycroft #ifdef DIAGNOSTIC
639 1.78 chs if (ISSET(bp->b_flags, B_DONE|B_DELWRI) &&
640 1.78 chs bp->b_bcount < size && vp->v_type != VBLK)
641 1.73 chs panic("getblk: block size invariant failed");
642 1.57 mycroft #endif
643 1.73 chs SET(bp->b_flags, B_BUSY);
644 1.73 chs bremfree(bp);
645 1.39 cgd splx(s);
646 1.73 chs } else {
647 1.31 cgd if ((bp = getnewbuf(slpflag, slptimeo)) == NULL)
648 1.31 cgd goto start;
649 1.73 chs
650 1.73 chs binshash(bp, BUFHASH(vp, blkno));
651 1.64 thorpej bp->b_blkno = bp->b_lblkno = bp->b_rawblkno = blkno;
652 1.31 cgd s = splbio();
653 1.31 cgd bgetvp(vp, bp);
654 1.31 cgd splx(s);
655 1.31 cgd }
656 1.39 cgd allocbuf(bp, size);
657 1.31 cgd return (bp);
658 1.31 cgd }
659 1.31 cgd
660 1.31 cgd /*
661 1.31 cgd * Get an empty, disassociated buffer of given size.
662 1.31 cgd */
663 1.31 cgd struct buf *
664 1.31 cgd geteblk(size)
665 1.31 cgd int size;
666 1.31 cgd {
667 1.31 cgd struct buf *bp;
668 1.31 cgd
669 1.31 cgd while ((bp = getnewbuf(0, 0)) == 0)
670 1.31 cgd ;
671 1.31 cgd SET(bp->b_flags, B_INVAL);
672 1.31 cgd binshash(bp, &invalhash);
673 1.31 cgd allocbuf(bp, size);
674 1.31 cgd return (bp);
675 1.31 cgd }
676 1.31 cgd
677 1.31 cgd /*
678 1.31 cgd * Expand or contract the actual memory allocated to a buffer.
679 1.31 cgd *
680 1.31 cgd * If the buffer shrinks, data is lost, so it's up to the
681 1.31 cgd * caller to have written it out *first*; this routine will not
682 1.31 cgd * start a write. If the buffer grows, it's the callers
683 1.31 cgd * responsibility to fill out the buffer's additional contents.
684 1.31 cgd */
685 1.40 christos void
686 1.31 cgd allocbuf(bp, size)
687 1.31 cgd struct buf *bp;
688 1.31 cgd int size;
689 1.31 cgd {
690 1.73 chs struct buf *nbp;
691 1.73 chs vsize_t desired_size;
692 1.73 chs int s;
693 1.31 cgd
694 1.69 chs desired_size = round_page((vsize_t)size);
695 1.31 cgd if (desired_size > MAXBSIZE)
696 1.31 cgd panic("allocbuf: buffer larger than MAXBSIZE requested");
697 1.31 cgd
698 1.31 cgd if (bp->b_bufsize == desired_size)
699 1.31 cgd goto out;
700 1.31 cgd
701 1.31 cgd /*
702 1.31 cgd * If the buffer is smaller than the desired size, we need to snarf
703 1.31 cgd * it from other buffers. Get buffers (via getnewbuf()), and
704 1.31 cgd * steal their pages.
705 1.31 cgd */
706 1.31 cgd while (bp->b_bufsize < desired_size) {
707 1.31 cgd int amt;
708 1.31 cgd
709 1.31 cgd /* find a buffer */
710 1.31 cgd while ((nbp = getnewbuf(0, 0)) == NULL)
711 1.31 cgd ;
712 1.73 chs
713 1.34 mycroft SET(nbp->b_flags, B_INVAL);
714 1.34 mycroft binshash(nbp, &invalhash);
715 1.31 cgd
716 1.31 cgd /* and steal its pages, up to the amount we need */
717 1.31 cgd amt = min(nbp->b_bufsize, (desired_size - bp->b_bufsize));
718 1.31 cgd pagemove((nbp->b_data + nbp->b_bufsize - amt),
719 1.40 christos bp->b_data + bp->b_bufsize, amt);
720 1.31 cgd bp->b_bufsize += amt;
721 1.31 cgd nbp->b_bufsize -= amt;
722 1.31 cgd
723 1.31 cgd /* reduce transfer count if we stole some data */
724 1.31 cgd if (nbp->b_bcount > nbp->b_bufsize)
725 1.31 cgd nbp->b_bcount = nbp->b_bufsize;
726 1.31 cgd
727 1.31 cgd #ifdef DIAGNOSTIC
728 1.31 cgd if (nbp->b_bufsize < 0)
729 1.31 cgd panic("allocbuf: negative bufsize");
730 1.31 cgd #endif
731 1.34 mycroft
732 1.31 cgd brelse(nbp);
733 1.31 cgd }
734 1.31 cgd
735 1.31 cgd /*
736 1.31 cgd * If we want a buffer smaller than the current size,
737 1.31 cgd * shrink this buffer. Grab a buf head from the EMPTY queue,
738 1.31 cgd * move a page onto it, and put it on front of the AGE queue.
739 1.31 cgd * If there are no free buffer headers, leave the buffer alone.
740 1.31 cgd */
741 1.31 cgd if (bp->b_bufsize > desired_size) {
742 1.31 cgd s = splbio();
743 1.84 matt if ((nbp = TAILQ_FIRST(&bufqueues[BQ_EMPTY])) == NULL) {
744 1.31 cgd /* No free buffer head */
745 1.31 cgd splx(s);
746 1.31 cgd goto out;
747 1.31 cgd }
748 1.31 cgd bremfree(nbp);
749 1.31 cgd SET(nbp->b_flags, B_BUSY);
750 1.31 cgd splx(s);
751 1.31 cgd
752 1.31 cgd /* move the page to it and note this change */
753 1.31 cgd pagemove(bp->b_data + desired_size,
754 1.31 cgd nbp->b_data, bp->b_bufsize - desired_size);
755 1.31 cgd nbp->b_bufsize = bp->b_bufsize - desired_size;
756 1.31 cgd bp->b_bufsize = desired_size;
757 1.31 cgd nbp->b_bcount = 0;
758 1.31 cgd SET(nbp->b_flags, B_INVAL);
759 1.31 cgd
760 1.31 cgd /* release the newly-filled buffer and leave */
761 1.31 cgd brelse(nbp);
762 1.31 cgd }
763 1.31 cgd
764 1.31 cgd out:
765 1.31 cgd bp->b_bcount = size;
766 1.31 cgd }
767 1.31 cgd
768 1.31 cgd /*
769 1.31 cgd * Find a buffer which is available for use.
770 1.31 cgd * Select something from a free list.
771 1.31 cgd * Preference is to AGE list, then LRU list.
772 1.31 cgd */
773 1.31 cgd struct buf *
774 1.31 cgd getnewbuf(slpflag, slptimeo)
775 1.31 cgd int slpflag, slptimeo;
776 1.31 cgd {
777 1.66 augustss struct buf *bp;
778 1.31 cgd int s;
779 1.31 cgd
780 1.31 cgd start:
781 1.31 cgd s = splbio();
782 1.84 matt if ((bp = TAILQ_FIRST(&bufqueues[BQ_AGE])) != NULL ||
783 1.84 matt (bp = TAILQ_FIRST(&bufqueues[BQ_LRU])) != NULL) {
784 1.31 cgd bremfree(bp);
785 1.31 cgd } else {
786 1.31 cgd /* wait for a free buffer of any kind */
787 1.31 cgd needbuffer = 1;
788 1.31 cgd tsleep(&needbuffer, slpflag|(PRIBIO+1), "getnewbuf", slptimeo);
789 1.31 cgd splx(s);
790 1.73 chs return (NULL);
791 1.31 cgd }
792 1.31 cgd
793 1.50 mycroft if (ISSET(bp->b_flags, B_VFLUSH)) {
794 1.50 mycroft /*
795 1.50 mycroft * This is a delayed write buffer being flushed to disk. Make
796 1.50 mycroft * sure it gets aged out of the queue when it's finished, and
797 1.50 mycroft * leave it off the LRU queue.
798 1.50 mycroft */
799 1.50 mycroft CLR(bp->b_flags, B_VFLUSH);
800 1.50 mycroft SET(bp->b_flags, B_AGE);
801 1.50 mycroft splx(s);
802 1.50 mycroft goto start;
803 1.50 mycroft }
804 1.50 mycroft
805 1.31 cgd /* Buffer is no longer on free lists. */
806 1.31 cgd SET(bp->b_flags, B_BUSY);
807 1.31 cgd
808 1.75 chs /*
809 1.75 chs * If buffer was a delayed write, start it and return NULL
810 1.75 chs * (since we might sleep while starting the write).
811 1.75 chs */
812 1.31 cgd if (ISSET(bp->b_flags, B_DELWRI)) {
813 1.39 cgd splx(s);
814 1.50 mycroft /*
815 1.50 mycroft * This buffer has gone through the LRU, so make sure it gets
816 1.50 mycroft * reused ASAP.
817 1.50 mycroft */
818 1.50 mycroft SET(bp->b_flags, B_AGE);
819 1.50 mycroft bawrite(bp);
820 1.75 chs return (NULL);
821 1.31 cgd }
822 1.31 cgd
823 1.31 cgd /* disassociate us from our vnode, if we had one... */
824 1.31 cgd if (bp->b_vp)
825 1.31 cgd brelvp(bp);
826 1.31 cgd splx(s);
827 1.31 cgd
828 1.59 fvdl if (LIST_FIRST(&bp->b_dep) != NULL && bioops.io_deallocate)
829 1.59 fvdl (*bioops.io_deallocate)(bp);
830 1.59 fvdl
831 1.31 cgd /* clear out various other fields */
832 1.31 cgd bp->b_flags = B_BUSY;
833 1.31 cgd bp->b_dev = NODEV;
834 1.64 thorpej bp->b_blkno = bp->b_lblkno = bp->b_rawblkno = 0;
835 1.31 cgd bp->b_iodone = 0;
836 1.31 cgd bp->b_error = 0;
837 1.31 cgd bp->b_resid = 0;
838 1.31 cgd bp->b_bcount = 0;
839 1.31 cgd
840 1.34 mycroft bremhash(bp);
841 1.31 cgd return (bp);
842 1.31 cgd }
843 1.31 cgd
844 1.31 cgd /*
845 1.31 cgd * Wait for operations on the buffer to complete.
846 1.31 cgd * When they do, extract and return the I/O's error value.
847 1.31 cgd */
848 1.31 cgd int
849 1.31 cgd biowait(bp)
850 1.31 cgd struct buf *bp;
851 1.31 cgd {
852 1.31 cgd int s;
853 1.59 fvdl
854 1.31 cgd s = splbio();
855 1.80 chs while (!ISSET(bp->b_flags, B_DONE | B_DELWRI))
856 1.31 cgd tsleep(bp, PRIBIO + 1, "biowait", 0);
857 1.31 cgd splx(s);
858 1.31 cgd
859 1.31 cgd /* check for interruption of I/O (e.g. via NFS), then errors. */
860 1.31 cgd if (ISSET(bp->b_flags, B_EINTR)) {
861 1.31 cgd CLR(bp->b_flags, B_EINTR);
862 1.31 cgd return (EINTR);
863 1.31 cgd } else if (ISSET(bp->b_flags, B_ERROR))
864 1.31 cgd return (bp->b_error ? bp->b_error : EIO);
865 1.31 cgd else
866 1.31 cgd return (0);
867 1.31 cgd }
868 1.31 cgd
869 1.31 cgd /*
870 1.31 cgd * Mark I/O complete on a buffer.
871 1.31 cgd *
872 1.31 cgd * If a callback has been requested, e.g. the pageout
873 1.31 cgd * daemon, do so. Otherwise, awaken waiting processes.
874 1.31 cgd *
875 1.31 cgd * [ Leffler, et al., says on p.247:
876 1.31 cgd * "This routine wakes up the blocked process, frees the buffer
877 1.31 cgd * for an asynchronous write, or, for a request by the pagedaemon
878 1.31 cgd * process, invokes a procedure specified in the buffer structure" ]
879 1.31 cgd *
880 1.31 cgd * In real life, the pagedaemon (or other system processes) wants
881 1.31 cgd * to do async stuff to, and doesn't want the buffer brelse()'d.
882 1.31 cgd * (for swap pager, that puts swap buffers on the free lists (!!!),
883 1.31 cgd * for the vn device, that puts malloc'd buffers on the free lists!)
884 1.31 cgd */
885 1.31 cgd void
886 1.31 cgd biodone(bp)
887 1.31 cgd struct buf *bp;
888 1.31 cgd {
889 1.60 fvdl int s = splbio();
890 1.60 fvdl
891 1.31 cgd if (ISSET(bp->b_flags, B_DONE))
892 1.31 cgd panic("biodone already");
893 1.31 cgd SET(bp->b_flags, B_DONE); /* note that it's done */
894 1.31 cgd
895 1.59 fvdl if (LIST_FIRST(&bp->b_dep) != NULL && bioops.io_complete)
896 1.59 fvdl (*bioops.io_complete)(bp);
897 1.59 fvdl
898 1.31 cgd if (!ISSET(bp->b_flags, B_READ)) /* wake up reader */
899 1.31 cgd vwakeup(bp);
900 1.31 cgd
901 1.31 cgd if (ISSET(bp->b_flags, B_CALL)) { /* if necessary, call out */
902 1.31 cgd CLR(bp->b_flags, B_CALL); /* but note callout done */
903 1.31 cgd (*bp->b_iodone)(bp);
904 1.59 fvdl } else {
905 1.59 fvdl if (ISSET(bp->b_flags, B_ASYNC)) /* if async, release */
906 1.59 fvdl brelse(bp);
907 1.59 fvdl else { /* or just wakeup the buffer */
908 1.59 fvdl CLR(bp->b_flags, B_WANTED);
909 1.59 fvdl wakeup(bp);
910 1.59 fvdl }
911 1.31 cgd }
912 1.60 fvdl
913 1.60 fvdl splx(s);
914 1.31 cgd }
915 1.31 cgd
916 1.31 cgd /*
917 1.31 cgd * Return a count of buffers on the "locked" queue.
918 1.31 cgd */
919 1.31 cgd int
920 1.31 cgd count_lock_queue()
921 1.31 cgd {
922 1.66 augustss struct buf *bp;
923 1.66 augustss int n = 0;
924 1.31 cgd
925 1.84 matt TAILQ_FOREACH(bp, &bufqueues[BQ_LOCKED], b_freelist)
926 1.31 cgd n++;
927 1.31 cgd return (n);
928 1.31 cgd }
929 1.31 cgd
930 1.36 cgd #ifdef DEBUG
931 1.31 cgd /*
932 1.31 cgd * Print out statistics on the current allocation of the buffer pool.
933 1.31 cgd * Can be enabled to print out on every ``sync'' by setting "syncprt"
934 1.31 cgd * in vfs_syscalls.c using sysctl.
935 1.31 cgd */
936 1.31 cgd void
937 1.31 cgd vfs_bufstats()
938 1.31 cgd {
939 1.31 cgd int s, i, j, count;
940 1.66 augustss struct buf *bp;
941 1.66 augustss struct bqueues *dp;
942 1.72 simonb int counts[(MAXBSIZE / PAGE_SIZE) + 1];
943 1.31 cgd static char *bname[BQUEUES] = { "LOCKED", "LRU", "AGE", "EMPTY" };
944 1.71 thorpej
945 1.31 cgd for (dp = bufqueues, i = 0; dp < &bufqueues[BQUEUES]; dp++, i++) {
946 1.31 cgd count = 0;
947 1.71 thorpej for (j = 0; j <= MAXBSIZE/PAGE_SIZE; j++)
948 1.31 cgd counts[j] = 0;
949 1.31 cgd s = splbio();
950 1.84 matt TAILQ_FOREACH(bp, dp, b_freelist) {
951 1.71 thorpej counts[bp->b_bufsize/PAGE_SIZE]++;
952 1.31 cgd count++;
953 1.31 cgd }
954 1.31 cgd splx(s);
955 1.48 christos printf("%s: total-%d", bname[i], count);
956 1.71 thorpej for (j = 0; j <= MAXBSIZE/PAGE_SIZE; j++)
957 1.31 cgd if (counts[j] != 0)
958 1.71 thorpej printf(", %d-%d", j * PAGE_SIZE, counts[j]);
959 1.48 christos printf("\n");
960 1.31 cgd }
961 1.31 cgd }
962 1.36 cgd #endif /* DEBUG */
963