Avoid few memory accesses in g_disk_done().

This commit is contained in:
Alexander Motin 2019-12-31 03:43:13 +00:00
parent 29001a810a
commit 4aa1289a38

View File

@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
struct g_disk_softc {
struct disk *dp;
struct devstat *d_devstat;
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
char led[64];
@ -231,15 +232,13 @@ g_disk_done(struct bio *bp)
struct g_disk_softc *sc;
/* See "notes" for why we need a mutex here */
/* XXX: will witness accept a mix of Giant/unGiant drivers here ? */
sc = bp->bio_caller1;
bp2 = bp->bio_parent;
sc = bp2->bio_to->private;
bp->bio_completed = bp->bio_length - bp->bio_resid;
binuptime(&now);
mtx_lock(&sc->done_mtx);
if (bp2->bio_error == 0)
bp2->bio_error = bp->bio_error;
bp2->bio_completed += bp->bio_completed;
bp2->bio_completed += bp->bio_length - bp->bio_resid;
switch (bp->bio_cmd) {
case BIO_ZONE:
@ -249,7 +248,7 @@ g_disk_done(struct bio *bp)
case BIO_WRITE:
case BIO_DELETE:
case BIO_FLUSH:
devstat_end_transaction_bio_bt(sc->dp->d_devstat, bp, &now);
devstat_end_transaction_bio_bt(sc->d_devstat, bp, &now);
break;
default:
break;
@ -469,6 +468,7 @@ g_disk_start(struct bio *bp)
bp->bio_error = ENOMEM;
}
bp2->bio_done = g_disk_done;
bp2->bio_caller1 = sc;
bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize;
bp2->bio_bcount = bp2->bio_length;
bp2->bio_disk = dp;
@ -555,6 +555,7 @@ g_disk_start(struct bio *bp)
return;
}
bp2->bio_done = g_disk_done;
bp2->bio_caller1 = sc;
bp2->bio_disk = dp;
devstat_start_transaction_bio(dp->d_devstat, bp2);
dp->d_strategy(bp2);
@ -706,6 +707,7 @@ g_disk_create(void *arg, int flag)
sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO);
mtx_init(&sc->done_mtx, "g_disk_done", NULL, MTX_DEF);
sc->dp = dp;
sc->d_devstat = dp->d_devstat;
gp = g_new_geomf(&g_disk_class, "%s%d", dp->d_name, dp->d_unit);
gp->softc = sc;
LIST_FOREACH(dap, &dp->d_aliases, da_next) {