diff options
author | alfred <alfred@FreeBSD.org> | 2001-04-13 10:23:32 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2001-04-13 10:23:32 +0000 |
commit | bbee48d66dece6822697c554a8c8f5be89d29b43 (patch) | |
tree | 1098b4e6f9de21424bb3b5c7cf8752ce51bc14e7 /sys/vm/vm_pager.c | |
parent | bcfbf5a27d260a49d59056fbbaa0937bfacbda85 (diff) | |
download | FreeBSD-src-bbee48d66dece6822697c554a8c8f5be89d29b43.zip FreeBSD-src-bbee48d66dece6822697c554a8c8f5be89d29b43.tar.gz |
protect pbufs and associated counts with a mutex
Diffstat (limited to 'sys/vm/vm_pager.c')
-rw-r--r-- | sys/vm/vm_pager.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sys/vm/vm_pager.c b/sys/vm/vm_pager.c index 648b340..f8cea1b 100644 --- a/sys/vm/vm_pager.c +++ b/sys/vm/vm_pager.c @@ -193,6 +193,7 @@ int pager_map_size = PAGER_MAP_SIZE; vm_map_t pager_map; static int bswneeded; static vm_offset_t swapbkva; /* swap buffers kva */ +struct mtx pbuf_mtx; void vm_pager_init() @@ -213,6 +214,7 @@ vm_pager_bufferinit() struct buf *bp; int i; + mtx_init(&pbuf_mtx, "pbuf mutex", MTX_DEF); bp = swbuf; /* * Now set up swap and physical I/O buffer headers. @@ -379,11 +381,12 @@ getpbuf(pfreecnt) struct buf *bp; s = splvm(); + mtx_lock(&pbuf_mtx); for (;;) { if (pfreecnt) { while (*pfreecnt == 0) { - tsleep(pfreecnt, PVM, "wswbuf0", 0); + msleep(pfreecnt, &pbuf_mtx, PVM, "wswbuf0", 0); } } @@ -392,12 +395,13 @@ getpbuf(pfreecnt) break; bswneeded = 1; - tsleep(&bswneeded, PVM, "wswbuf1", 0); + msleep(&bswneeded, &pbuf_mtx, PVM, "wswbuf1", 0); /* loop in case someone else grabbed one */ } TAILQ_REMOVE(&bswlist, bp, b_freelist); if (pfreecnt) --*pfreecnt; + mtx_unlock(&pbuf_mtx); splx(s); initpbuf(bp); @@ -418,7 +422,9 @@ trypbuf(pfreecnt) struct buf *bp; s = splvm(); + mtx_lock(&pbuf_mtx); if (*pfreecnt == 0 || (bp = TAILQ_FIRST(&bswlist)) == NULL) { + mtx_unlock(&pbuf_mtx); splx(s); return NULL; } @@ -426,6 +432,7 @@ trypbuf(pfreecnt) --*pfreecnt; + mtx_unlock(&pbuf_mtx); splx(s); initpbuf(bp); @@ -447,6 +454,7 @@ relpbuf(bp, pfreecnt) int s; s = splvm(); + mtx_lock(&pbuf_mtx); if (bp->b_rcred != NOCRED) { crfree(bp->b_rcred); @@ -472,5 +480,6 @@ relpbuf(bp, pfreecnt) if (++*pfreecnt == 1) wakeup(pfreecnt); } + mtx_unlock(&pbuf_mtx); splx(s); } |