From 73e769cd28fbea0dd374e8a7fbd8a9ca75fb7e18 Mon Sep 17 00:00:00 2001 From: mav Date: Wed, 16 Oct 2013 09:56:40 +0000 Subject: [PATCH] MFprojects/camlock r256370: - Take BIO lock in biodone() only when there is no completion callback set and so we should wake up thread waiting in biowait(). - Remove msleep() timeout from biowait(). It was added 11 years ago, when there was no locks used, and it should not be needed any more. --- sys/kern/vfs_bio.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 362de37e8aa6..3812813ac1d7 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -3559,9 +3559,6 @@ biodone(struct bio *bp) vm_offset_t start, end; int transient; - mtxp = mtx_pool_find(mtxpool_sleep, bp); - mtx_lock(mtxp); - bp->bio_flags |= BIO_DONE; if ((bp->bio_flags & BIO_TRANSIENT_MAPPING) != 0) { start = trunc_page((vm_offset_t)bp->bio_data); end = round_page((vm_offset_t)bp->bio_data + bp->bio_length); @@ -3571,11 +3568,16 @@ biodone(struct bio *bp) start = end = 0; } done = bp->bio_done; - if (done == NULL) + if (done == NULL) { + mtxp = mtx_pool_find(mtxpool_sleep, bp); + mtx_lock(mtxp); + bp->bio_flags |= BIO_DONE; wakeup(bp); - mtx_unlock(mtxp); - if (done != NULL) + mtx_unlock(mtxp); + } else { + bp->bio_flags |= BIO_DONE; done(bp); + } if (transient) { pmap_qremove(start, OFF_TO_IDX(end - start)); vmem_free(transient_arena, start, end - start); @@ -3585,9 +3587,6 @@ biodone(struct bio *bp) /* * Wait for a BIO to finish. - * - * XXX: resort to a timeout for now. The optimal locking (if any) for this - * case is not yet clear. */ int biowait(struct bio *bp, const char *wchan) @@ -3597,7 +3596,7 @@ biowait(struct bio *bp, const char *wchan) mtxp = mtx_pool_find(mtxpool_sleep, bp); mtx_lock(mtxp); while ((bp->bio_flags & BIO_DONE) == 0) - msleep(bp, mtxp, PRIBIO, wchan, hz / 10); + msleep(bp, mtxp, PRIBIO, wchan, 0); mtx_unlock(mtxp); if (bp->bio_error != 0) return (bp->bio_error);