summaryrefslogtreecommitdiffstats
path: root/sys/vm
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2015-09-16 04:38:07 +0000
committerimp <imp@FreeBSD.org>2015-09-16 04:38:07 +0000
commit617221c5399ac65c352ca5a9b09c99fac9fa41f8 (patch)
treea863b6c9230ae1452ee9651435c29e6808b90410 /sys/vm
parent6b2dbe45194d69ff67dc5072e7ba1f4685adcafe (diff)
downloadFreeBSD-src-617221c5399ac65c352ca5a9b09c99fac9fa41f8.zip
FreeBSD-src-617221c5399ac65c352ca5a9b09c99fac9fa41f8.tar.gz
MFC 281310, 287567:
r287567 | imp | 2015-09-08 11:47:56 -0600 (Tue, 08 Sep 2015) | 16 lines Mark the swap pager as direct dispatch compatible. r281310 | mav | 2015-04-09 07:09:05 -0600 (Thu, 09 Apr 2015) | 4 lines Remove sleeps from geom_up thread on device destruction.
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/swap_pager.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index c09dbc2..4deebd9 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -2354,8 +2354,8 @@ swapoff_one(struct swdevt *sp, struct ucred *cred)
swap_pager_swapoff(sp);
sp->sw_close(curthread, sp);
- sp->sw_id = NULL;
mtx_lock(&sw_dev_mtx);
+ sp->sw_id = NULL;
TAILQ_REMOVE(&swtailq, sp, sw_list);
nswapdev--;
if (nswapdev == 0) {
@@ -2541,13 +2541,39 @@ swapgeom_close_ev(void *arg, int flags)
g_destroy_consumer(cp);
}
+/*
+ * Add a reference to the g_consumer for an inflight transaction.
+ */
+static void
+swapgeom_acquire(struct g_consumer *cp)
+{
+
+ mtx_assert(&sw_dev_mtx, MA_OWNED);
+ cp->index++;
+}
+
+/*
+ * Remove a reference from the g_consumer. Post a close event if
+ * all referneces go away.
+ */
+static void
+swapgeom_release(struct g_consumer *cp, struct swdevt *sp)
+{
+
+ mtx_assert(&sw_dev_mtx, MA_OWNED);
+ cp->index--;
+ if (cp->index == 0) {
+ if (g_post_event(swapgeom_close_ev, cp, M_NOWAIT, NULL) == 0)
+ sp->sw_id = NULL;
+ }
+}
+
static void
swapgeom_done(struct bio *bp2)
{
struct swdevt *sp;
struct buf *bp;
struct g_consumer *cp;
- int destroy;
bp = bp2->bio_caller2;
cp = bp2->bio_from;
@@ -2557,16 +2583,11 @@ swapgeom_done(struct bio *bp2)
bp->b_resid = bp->b_bcount - bp2->bio_completed;
bp->b_error = bp2->bio_error;
bufdone(bp);
+ sp = bp2->bio_caller1;
mtx_lock(&sw_dev_mtx);
- destroy = ((--cp->index) == 0 && cp->private);
- if (destroy) {
- sp = bp2->bio_caller1;
- sp->sw_id = NULL;
- }
+ swapgeom_release(cp, sp);
mtx_unlock(&sw_dev_mtx);
g_destroy_bio(bp2);
- if (destroy)
- g_waitfor_event(swapgeom_close_ev, cp, M_WAITOK, NULL);
}
static void
@@ -2584,13 +2605,16 @@ swapgeom_strategy(struct buf *bp, struct swdevt *sp)
bufdone(bp);
return;
}
- cp->index++;
+ swapgeom_acquire(cp);
mtx_unlock(&sw_dev_mtx);
if (bp->b_iocmd == BIO_WRITE)
bio = g_new_bio();
else
bio = g_alloc_bio();
if (bio == NULL) {
+ mtx_lock(&sw_dev_mtx);
+ swapgeom_release(cp, sp);
+ mtx_unlock(&sw_dev_mtx);
bp->b_error = ENOMEM;
bp->b_ioflags |= BIO_ERROR;
bufdone(bp);
@@ -2630,7 +2654,12 @@ swapgeom_orphan(struct g_consumer *cp)
break;
}
}
- cp->private = (void *)(uintptr_t)1;
+ /*
+ * Drop reference we were created with. Do directly since we're in a
+ * special context where we don't have to queue the call to
+ * swapgeom_close_ev().
+ */
+ cp->index--;
destroy = ((sp != NULL) && (cp->index == 0));
if (destroy)
sp->sw_id = NULL;
@@ -2691,8 +2720,8 @@ swapongeom_ev(void *arg, int flags)
if (gp == NULL)
gp = g_new_geomf(&g_swap_class, "swap");
cp = g_new_consumer(gp);
- cp->index = 0; /* Number of active I/Os. */
- cp->private = NULL; /* Orphanization flag */
+ cp->index = 1; /* Number of active I/Os, plus one for being active. */
+ cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
g_attach(cp, pp);
/*
* XXX: Everytime you think you can improve the margin for
OpenPOWER on IntegriCloud