Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Apr 2014 21:13:05 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r264020 - head/sys/cam/ctl
Message-ID:  <201404012113.s31LD54C086337@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Tue Apr  1 21:13:05 2014
New Revision: 264020
URL: http://svnweb.freebsd.org/changeset/base/264020

Log:
  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

Modified:
  head/sys/cam/ctl/ctl_backend_block.c

Modified: head/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- head/sys/cam/ctl/ctl_backend_block.c	Tue Apr  1 18:46:56 2014	(r264019)
+++ head/sys/cam/ctl/ctl_backend_block.c	Tue Apr  1 21:13:05 2014	(r264020)
@@ -173,9 +173,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;
@@ -205,7 +203,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;
@@ -217,10 +214,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);
@@ -282,68 +275,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++) {
@@ -358,47 +307,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)
 {
@@ -933,16 +845,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;
@@ -1013,16 +916,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;
@@ -2342,10 +2236,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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404012113.s31LD54C086337>