Changeset View
Changeset View
Standalone View
Standalone View
head/sys/kern/vfs_bio.c
Show First 20 Lines • Show All 1,631 Lines • ▼ Show 20 Lines | |||||
* buf_alloc: | * buf_alloc: | ||||
* | * | ||||
* Allocate an empty buffer header. | * Allocate an empty buffer header. | ||||
*/ | */ | ||||
static struct buf * | static struct buf * | ||||
buf_alloc(struct bufdomain *bd) | buf_alloc(struct bufdomain *bd) | ||||
{ | { | ||||
struct buf *bp; | struct buf *bp; | ||||
int freebufs; | int freebufs, error; | ||||
/* | /* | ||||
* We can only run out of bufs in the buf zone if the average buf | * We can only run out of bufs in the buf zone if the average buf | ||||
* is less than BKVASIZE. In this case the actual wait/block will | * is less than BKVASIZE. In this case the actual wait/block will | ||||
* come from buf_reycle() failing to flush one of these small bufs. | * come from buf_reycle() failing to flush one of these small bufs. | ||||
*/ | */ | ||||
bp = NULL; | bp = NULL; | ||||
freebufs = atomic_fetchadd_int(&bd->bd_freebuffers, -1); | freebufs = atomic_fetchadd_int(&bd->bd_freebuffers, -1); | ||||
if (freebufs > 0) | if (freebufs > 0) | ||||
bp = uma_zalloc(buf_zone, M_NOWAIT); | bp = uma_zalloc(buf_zone, M_NOWAIT); | ||||
if (bp == NULL) { | if (bp == NULL) { | ||||
atomic_add_int(&bd->bd_freebuffers, 1); | atomic_add_int(&bd->bd_freebuffers, 1); | ||||
bufspace_daemon_wakeup(bd); | bufspace_daemon_wakeup(bd); | ||||
counter_u64_add(numbufallocfails, 1); | counter_u64_add(numbufallocfails, 1); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
/* | /* | ||||
* Wake-up the bufspace daemon on transition below threshold. | * Wake-up the bufspace daemon on transition below threshold. | ||||
*/ | */ | ||||
if (freebufs == bd->bd_lofreebuffers) | if (freebufs == bd->bd_lofreebuffers) | ||||
bufspace_daemon_wakeup(bd); | bufspace_daemon_wakeup(bd); | ||||
if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL) != 0) | error = BUF_LOCK(bp, LK_EXCLUSIVE, NULL); | ||||
panic("getnewbuf_empty: Locked buf %p on free queue.", bp); | KASSERT(error == 0, ("%s: BUF_LOCK on free buf %p: %d.", __func__, bp, | ||||
error)); | |||||
(void)error; | |||||
KASSERT(bp->b_vp == NULL, | KASSERT(bp->b_vp == NULL, | ||||
("bp: %p still has vnode %p.", bp, bp->b_vp)); | ("bp: %p still has vnode %p.", bp, bp->b_vp)); | ||||
KASSERT((bp->b_flags & (B_DELWRI | B_NOREUSE)) == 0, | KASSERT((bp->b_flags & (B_DELWRI | B_NOREUSE)) == 0, | ||||
("invalid buffer %p flags %#x", bp, bp->b_flags)); | ("invalid buffer %p flags %#x", bp, bp->b_flags)); | ||||
KASSERT((bp->b_xflags & (BX_VNCLEAN|BX_VNDIRTY)) == 0, | KASSERT((bp->b_xflags & (BX_VNCLEAN|BX_VNDIRTY)) == 0, | ||||
("bp: %p still on a buffer list. xflags %X", bp, bp->b_xflags)); | ("bp: %p still on a buffer list. xflags %X", bp, bp->b_xflags)); | ||||
KASSERT(bp->b_npages == 0, | KASSERT(bp->b_npages == 0, | ||||
▲ Show 20 Lines • Show All 3,801 Lines • Show Last 20 Lines |