svn commit: r265657 - stable/9/sys/cam/ctl
Alexander Motin
mav at FreeBSD.org
Thu May 8 08:25:28 UTC 2014
Author: mav
Date: Thu May 8 08:25:27 2014
New Revision: 265657
URL: http://svnweb.freebsd.org/changeset/base/265657
Log:
MFC r264020 (by trasz):
Remove the homegrown ctl_be_block_io allocator, replacing it with UMA.
There is no performance difference.
Modified:
stable/9/sys/cam/ctl/ctl_backend_block.c
Directory Properties:
stable/9/ (props changed)
stable/9/sys/ (props changed)
Modified: stable/9/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- stable/9/sys/cam/ctl/ctl_backend_block.c Thu May 8 08:24:08 2014 (r265656)
+++ stable/9/sys/cam/ctl/ctl_backend_block.c Thu May 8 08:25:27 2014 (r265657)
@@ -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
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_
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 *be
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)
{
@@ -943,16 +855,7 @@ ctl_be_block_cw_dispatch(struct ctl_be_b
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;
@@ -1023,16 +926,7 @@ ctl_be_block_dispatch(struct ctl_be_bloc
}
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;
@@ -2373,10 +2267,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);
}
More information about the svn-src-stable-9
mailing list