summaryrefslogtreecommitdiffstats
path: root/sys/cam
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2014-05-07 06:26:34 +0000
committertrasz <trasz@FreeBSD.org>2014-05-07 06:26:34 +0000
commitdfa8f3f0a1d3923f791360de1316b13345c93065 (patch)
treedea5435c0e5ea8aab99bb90e072f6062e54609ae /sys/cam
parent2cb2c64704541dc972ea93a0297bb6f5c33880b8 (diff)
downloadFreeBSD-src-dfa8f3f0a1d3923f791360de1316b13345c93065.zip
FreeBSD-src-dfa8f3f0a1d3923f791360de1316b13345c93065.tar.gz
MFC r264020:
Remove the homegrown ctl_be_block_io allocator, replacing it with UMA. There is no performance difference. Reviewed by: mav@ Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'sys/cam')
-rw-r--r--sys/cam/ctl/ctl_backend_block.c124
1 files changed, 9 insertions, 115 deletions
diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c
index 2e0a071..8229d48 100644
--- a/sys/cam/ctl/ctl_backend_block.c
+++ b/sys/cam/ctl/ctl_backend_block.c
@@ -177,9 +177,7 @@ struct ctl_be_block_lun {
* Overall softc structure for the block backend module.
*/
struct ctl_be_block_softc {
- STAILQ_HEAD(, ctl_be_block_io) beio_free_queue;
struct mtx lock;
- int prealloc_beio;
int num_disks;
STAILQ_HEAD(, ctl_block_disk) disk_list;
int num_luns;
@@ -209,7 +207,6 @@ struct ctl_be_block_io {
uint64_t io_offset;
struct ctl_be_block_softc *softc;
struct ctl_be_block_lun *lun;
- STAILQ_ENTRY(ctl_be_block_io) links;
};
static int cbb_num_threads = 14;
@@ -221,10 +218,6 @@ SYSCTL_INT(_kern_cam_ctl_block, OID_AUTO, num_threads, CTLFLAG_RW,
static struct ctl_be_block_io *ctl_alloc_beio(struct ctl_be_block_softc *softc);
static void ctl_free_beio(struct ctl_be_block_io *beio);
-static int ctl_grow_beio(struct ctl_be_block_softc *softc, int count);
-#if 0
-static void ctl_shrink_beio(struct ctl_be_block_softc *softc);
-#endif
static void ctl_complete_beio(struct ctl_be_block_io *beio);
static int ctl_be_block_move_done(union ctl_io *io);
static void ctl_be_block_biodone(struct bio *bio);
@@ -286,68 +279,24 @@ static struct ctl_backend_driver ctl_be_block_driver =
MALLOC_DEFINE(M_CTLBLK, "ctlblk", "Memory used for CTL block backend");
CTL_BACKEND_DECLARE(cbb, ctl_be_block_driver);
+static uma_zone_t beio_zone;
+
static struct ctl_be_block_io *
ctl_alloc_beio(struct ctl_be_block_softc *softc)
{
struct ctl_be_block_io *beio;
- int count;
-
- mtx_lock(&softc->lock);
-
- beio = STAILQ_FIRST(&softc->beio_free_queue);
- if (beio != NULL) {
- STAILQ_REMOVE(&softc->beio_free_queue, beio,
- ctl_be_block_io, links);
- }
- mtx_unlock(&softc->lock);
-
- if (beio != NULL) {
- bzero(beio, sizeof(*beio));
- beio->softc = softc;
- return (beio);
- }
-
- for (;;) {
-
- count = ctl_grow_beio(softc, /*count*/ 10);
-
- /*
- * This shouldn't be possible, since ctl_grow_beio() uses a
- * blocking malloc.
- */
- if (count == 0)
- return (NULL);
-
- /*
- * Since we have to drop the lock when we're allocating beio
- * structures, it's possible someone else can come along and
- * allocate the beio's we've just allocated.
- */
- mtx_lock(&softc->lock);
- beio = STAILQ_FIRST(&softc->beio_free_queue);
- if (beio != NULL) {
- STAILQ_REMOVE(&softc->beio_free_queue, beio,
- ctl_be_block_io, links);
- }
- mtx_unlock(&softc->lock);
- if (beio != NULL) {
- bzero(beio, sizeof(*beio));
- beio->softc = softc;
- break;
- }
- }
+ beio = uma_zalloc(beio_zone, M_WAITOK | M_ZERO);
+ beio->softc = softc;
return (beio);
}
static void
ctl_free_beio(struct ctl_be_block_io *beio)
{
- struct ctl_be_block_softc *softc;
int duplicate_free;
int i;
- softc = beio->softc;
duplicate_free = 0;
for (i = 0; i < beio->num_segs; i++) {
@@ -362,47 +311,10 @@ ctl_free_beio(struct ctl_be_block_io *beio)
printf("%s: %d duplicate frees out of %d segments\n", __func__,
duplicate_free, beio->num_segs);
}
- mtx_lock(&softc->lock);
- STAILQ_INSERT_TAIL(&softc->beio_free_queue, beio, links);
- mtx_unlock(&softc->lock);
-}
-static int
-ctl_grow_beio(struct ctl_be_block_softc *softc, int count)
-{
- int i;
-
- for (i = 0; i < count; i++) {
- struct ctl_be_block_io *beio;
-
- beio = (struct ctl_be_block_io *)malloc(sizeof(*beio),
- M_CTLBLK,
- M_WAITOK | M_ZERO);
- beio->softc = softc;
- mtx_lock(&softc->lock);
- STAILQ_INSERT_TAIL(&softc->beio_free_queue, beio, links);
- mtx_unlock(&softc->lock);
- }
-
- return (i);
+ uma_zfree(beio_zone, beio);
}
-#if 0
-static void
-ctl_shrink_beio(struct ctl_be_block_softc *softc)
-{
- struct ctl_be_block_io *beio, *beio_tmp;
-
- mtx_lock(&softc->lock);
- STAILQ_FOREACH_SAFE(beio, &softc->beio_free_queue, links, beio_tmp) {
- STAILQ_REMOVE(&softc->beio_free_queue, beio,
- ctl_be_block_io, links);
- free(beio, M_CTLBLK);
- }
- mtx_unlock(&softc->lock);
-}
-#endif
-
static void
ctl_complete_beio(struct ctl_be_block_io *beio)
{
@@ -937,16 +849,7 @@ ctl_be_block_cw_dispatch(struct ctl_be_block_lun *be_lun,
softc = be_lun->softc;
beio = ctl_alloc_beio(softc);
- if (beio == NULL) {
- /*
- * This should not happen. ctl_alloc_beio() will call
- * ctl_grow_beio() with a blocking malloc as needed.
- * A malloc with M_WAITOK should not fail.
- */
- ctl_set_busy(&io->scsiio);
- ctl_done(io);
- return;
- }
+ KASSERT(beio != NULL, ("ctl_alloc_beio() failed"));
beio->io = io;
beio->softc = softc;
@@ -1017,16 +920,7 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun,
}
beio = ctl_alloc_beio(softc);
- if (beio == NULL) {
- /*
- * This should not happen. ctl_alloc_beio() will call
- * ctl_grow_beio() with a blocking malloc as needed.
- * A malloc with M_WAITOK should not fail.
- */
- ctl_set_busy(&io->scsiio);
- ctl_done(io);
- return;
- }
+ KASSERT(beio != NULL, ("ctl_alloc_beio() failed"));
beio->io = io;
beio->softc = softc;
@@ -2369,10 +2263,10 @@ ctl_be_block_init(void)
retval = 0;
mtx_init(&softc->lock, "ctlblk", NULL, MTX_DEF);
- STAILQ_INIT(&softc->beio_free_queue);
+ beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io),
+ NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
STAILQ_INIT(&softc->disk_list);
STAILQ_INIT(&softc->lun_list);
- ctl_grow_beio(softc, 200);
return (retval);
}
OpenPOWER on IntegriCloud