Deleted Added
full compact
subr_disk.c (103675) subr_disk.c (103683)
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
1/*
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * $FreeBSD: head/sys/kern/subr_disk.c 103675 2002-09-20 12:52:03Z phk $
9 * $FreeBSD: head/sys/kern/subr_disk.c 103683 2002-09-20 14:14:37Z phk $
10 *
11 */
12
13#include "opt_geom.h"
14
15#include <sys/param.h>
16#include <sys/systm.h>
17#include <sys/stdint.h>

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

464 sn += blkdone;
465 printf("fsbn %jd of ", (intmax_t)sn);
466 }
467 printf("%jd-%jd", (intmax_t)bp->bio_blkno,
468 (intmax_t)(bp->bio_blkno + (bp->bio_bcount - 1) / DEV_BSIZE));
469 if (nl)
470 printf("\n");
471}
10 *
11 */
12
13#include "opt_geom.h"
14
15#include <sys/param.h>
16#include <sys/systm.h>
17#include <sys/stdint.h>

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

464 sn += blkdone;
465 printf("fsbn %jd of ", (intmax_t)sn);
466 }
467 printf("%jd-%jd", (intmax_t)bp->bio_blkno,
468 (intmax_t)(bp->bio_blkno + (bp->bio_bcount - 1) / DEV_BSIZE));
469 if (nl)
470 printf("\n");
471}
472
473#ifdef notquite
474/*
475 * Mutex to use when delaying niced I/O bound processes in bioq_disksort().
476 */
477static struct mtx dksort_mtx;
478static void
479dksort_init(void)
480{
481
482 mtx_init(&dksort_mtx, "dksort", NULL, MTX_DEF);
483}
484SYSINIT(dksort, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dksort_init, NULL)
485#endif
486
487/*
488 * Seek sort for disks.
489 *
490 * The buf_queue keep two queues, sorted in ascending block order. The first
491 * queue holds those requests which are positioned after the current block
492 * (in the first request); the second, which starts at queue->switch_point,
493 * holds requests which came in after their block number was passed. Thus
494 * we implement a one way scan, retracting after reaching the end of the drive
495 * to the first request on the second queue, at which time it becomes the
496 * first queue.
497 *
498 * A one-way scan is natural because of the way UNIX read-ahead blocks are
499 * allocated.
500 */
501
502void
503bioq_disksort(bioq, bp)
504 struct bio_queue_head *bioq;
505 struct bio *bp;
506{
507 struct bio *bq;
508 struct bio *bn;
509 struct bio *be;
510
511#ifdef notquite
512 struct thread *td = curthread;
513
514 if (td && td->td_ksegrp->kg_nice > 0) {
515 TAILQ_FOREACH(bn, &bioq->queue, bio_queue)
516 if (BIOTOBUF(bp)->b_vp != BIOTOBUF(bn)->b_vp)
517 break;
518 if (bn != NULL) {
519 mtx_lock(&dksort_mtx);
520 msleep(&dksort_mtx, &dksort_mtx,
521 PPAUSE | PCATCH | PDROP, "ioslow",
522 td->td_ksegrp->kg_nice);
523 }
524 }
525#endif
526 if (!atomic_cmpset_int(&bioq->busy, 0, 1))
527 panic("Recursing in bioq_disksort()");
528 be = TAILQ_LAST(&bioq->queue, bio_queue);
529 /*
530 * If the queue is empty or we are an
531 * ordered transaction, then it's easy.
532 */
533 if ((bq = bioq_first(bioq)) == NULL) {
534 bioq_insert_tail(bioq, bp);
535 bioq->busy = 0;
536 return;
537 } else if (bioq->insert_point != NULL) {
538
539 /*
540 * A certain portion of the list is
541 * "locked" to preserve ordering, so
542 * we can only insert after the insert
543 * point.
544 */
545 bq = bioq->insert_point;
546 } else {
547
548 /*
549 * If we lie before the last removed (currently active)
550 * request, and are not inserting ourselves into the
551 * "locked" portion of the list, then we must add ourselves
552 * to the second request list.
553 */
554 if (bp->bio_pblkno < bioq->last_pblkno) {
555
556 bq = bioq->switch_point;
557 /*
558 * If we are starting a new secondary list,
559 * then it's easy.
560 */
561 if (bq == NULL) {
562 bioq->switch_point = bp;
563 bioq_insert_tail(bioq, bp);
564 bioq->busy = 0;
565 return;
566 }
567 /*
568 * If we lie ahead of the current switch point,
569 * insert us before the switch point and move
570 * the switch point.
571 */
572 if (bp->bio_pblkno < bq->bio_pblkno) {
573 bioq->switch_point = bp;
574 TAILQ_INSERT_BEFORE(bq, bp, bio_queue);
575 bioq->busy = 0;
576 return;
577 }
578 } else {
579 if (bioq->switch_point != NULL)
580 be = TAILQ_PREV(bioq->switch_point,
581 bio_queue, bio_queue);
582 /*
583 * If we lie between last_pblkno and bq,
584 * insert before bq.
585 */
586 if (bp->bio_pblkno < bq->bio_pblkno) {
587 TAILQ_INSERT_BEFORE(bq, bp, bio_queue);
588 bioq->busy = 0;
589 return;
590 }
591 }
592 }
593
594 /*
595 * Request is at/after our current position in the list.
596 * Optimize for sequential I/O by seeing if we go at the tail.
597 */
598 if (bp->bio_pblkno > be->bio_pblkno) {
599 TAILQ_INSERT_AFTER(&bioq->queue, be, bp, bio_queue);
600 bioq->busy = 0;
601 return;
602 }
603
604 /* Otherwise, insertion sort */
605 while ((bn = TAILQ_NEXT(bq, bio_queue)) != NULL) {
606
607 /*
608 * We want to go after the current request if it is the end
609 * of the first request list, or if the next request is a
610 * larger cylinder than our request.
611 */
612 if (bn == bioq->switch_point
613 || bp->bio_pblkno < bn->bio_pblkno)
614 break;
615 bq = bn;
616 }
617 TAILQ_INSERT_AFTER(&bioq->queue, bq, bp, bio_queue);
618 bioq->busy = 0;
619}
620
621