From owner-svn-src-all@freebsd.org Wed Nov 11 21:59:40 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 51010467680; Wed, 11 Nov 2020 21:59:40 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CWdth1rJbz3rR5; Wed, 11 Nov 2020 21:59:40 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 320A41B929; Wed, 11 Nov 2020 21:59:40 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0ABLxeKY043626; Wed, 11 Nov 2020 21:59:40 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0ABLxeYV043625; Wed, 11 Nov 2020 21:59:40 GMT (envelope-from mav@FreeBSD.org) Message-Id: <202011112159.0ABLxeYV043625@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Wed, 11 Nov 2020 21:59:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367600 - head/sys/cam/ctl X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: head/sys/cam/ctl X-SVN-Commit-Revision: 367600 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Nov 2020 21:59:40 -0000 Author: mav Date: Wed Nov 11 21:59:39 2020 New Revision: 367600 URL: https://svnweb.freebsd.org/changeset/base/367600 Log: Make CTL nicer to increased MAXPHYS. Before this CTL always allocated MAXPHYS-sized buffers, even for 4KB I/O, that is even more overkill for MAXPHYS of 1MB. This change limits maximum allocation to 512KB if MAXPHYS is bigger, plus if one is above 128KB, adds new 128KB UMA zone for smaller I/Os. The patch factors out alloc/free, so later we could make it use more zones or malloc() if we'd like. MFC after: 1 week Sponsored by: iXsystems, Inc. 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 Wed Nov 11 21:27:16 2020 (r367599) +++ head/sys/cam/ctl/ctl_backend_block.c Wed Nov 11 21:59:39 2020 (r367600) @@ -102,7 +102,7 @@ __FBSDID("$FreeBSD$"); */ #define CTLBLK_HALF_IO_SIZE (512 * 1024) #define CTLBLK_MAX_IO_SIZE (CTLBLK_HALF_IO_SIZE * 2) -#define CTLBLK_MAX_SEG MAXPHYS +#define CTLBLK_MAX_SEG MIN(CTLBLK_HALF_IO_SIZE, MAXPHYS) #define CTLBLK_HALF_SEGS MAX(CTLBLK_HALF_IO_SIZE / CTLBLK_MAX_SEG, 1) #define CTLBLK_MAX_SEGS (CTLBLK_HALF_SEGS * 2) @@ -190,6 +190,9 @@ struct ctl_be_block_softc { SLIST_HEAD(, ctl_be_block_lun) lun_list; uma_zone_t beio_zone; uma_zone_t buf_zone; +#if (CTLBLK_MAX_SEG > 131072) + uma_zone_t buf128_zone; +#endif }; static struct ctl_be_block_softc backend_block_softc; @@ -299,6 +302,32 @@ static struct ctl_backend_driver ctl_be_block_driver = MALLOC_DEFINE(M_CTLBLK, "ctlblock", "Memory used for CTL block backend"); CTL_BACKEND_DECLARE(cbb, ctl_be_block_driver); +static void +ctl_alloc_seg(struct ctl_be_block_softc *softc, struct ctl_sg_entry *sg, + size_t len) +{ + +#if (CTLBLK_MAX_SEG > 131072) + if (len <= 131072) + sg->addr = uma_zalloc(softc->buf128_zone, M_WAITOK); + else +#endif + sg->addr = uma_zalloc(softc->buf_zone, M_WAITOK); + sg->len = len; +} + +static void +ctl_free_seg(struct ctl_be_block_softc *softc, struct ctl_sg_entry *sg) +{ + +#if (CTLBLK_MAX_SEG > 131072) + if (sg->len <= 131072) + uma_zfree(softc->buf128_zone, sg->addr); + else +#endif + uma_zfree(softc->buf_zone, sg->addr); +} + static struct ctl_be_block_io * ctl_alloc_beio(struct ctl_be_block_softc *softc) { @@ -317,12 +346,12 @@ ctl_real_free_beio(struct ctl_be_block_io *beio) int i; for (i = 0; i < beio->num_segs; i++) { - uma_zfree(softc->buf_zone, beio->sg_segs[i].addr); + ctl_free_seg(softc, &beio->sg_segs[i]); /* For compare we had two equal S/G lists. */ if (beio->two_sglists) { - uma_zfree(softc->buf_zone, - beio->sg_segs[i + CTLBLK_HALF_SEGS].addr); + ctl_free_seg(softc, + &beio->sg_segs[i + CTLBLK_HALF_SEGS]); } } @@ -1140,8 +1169,7 @@ ctl_be_block_dispatch_dev(struct ctl_be_block_lun *be_ /* * We have to limit our I/O size to the maximum supported by the - * backend device. Hopefully it is MAXPHYS. If the driver doesn't - * set it properly, use DFLTPHYS. + * backend device. */ if (csw) { max_iosize = dev->si_iosize_max; @@ -1330,8 +1358,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lun *b seglen -= seglen % cbe_lun->blocksize; } else seglen -= seglen % cbe_lun->blocksize; - beio->sg_segs[i].len = seglen; - beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK); + ctl_alloc_seg(softc, &beio->sg_segs[i], seglen); DPRINTF("segment %d addr %p len %zd\n", i, beio->sg_segs[i].addr, beio->sg_segs[i].len); @@ -1603,18 +1630,17 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, /* * Setup the S/G entry for this chunk. */ - beio->sg_segs[i].len = min(CTLBLK_MAX_SEG, len_left); - beio->sg_segs[i].addr = uma_zalloc(softc->buf_zone, M_WAITOK); + ctl_alloc_seg(softc, &beio->sg_segs[i], + min(CTLBLK_MAX_SEG, len_left)); DPRINTF("segment %d addr %p len %zd\n", i, beio->sg_segs[i].addr, beio->sg_segs[i].len); /* Set up second segment for compare operation. */ if (beio->two_sglists) { - beio->sg_segs[i + CTLBLK_HALF_SEGS].len = - beio->sg_segs[i].len; - beio->sg_segs[i + CTLBLK_HALF_SEGS].addr = - uma_zalloc(softc->buf_zone, M_WAITOK); + ctl_alloc_seg(softc, + &beio->sg_segs[i + CTLBLK_HALF_SEGS], + beio->sg_segs[i].len); } beio->num_segs++; @@ -1932,8 +1958,8 @@ ctl_be_block_open_dev(struct ctl_be_block_lun *be_lun, maxio = dev->si_iosize_max; if (maxio <= 0) maxio = DFLTPHYS; - if (maxio > CTLBLK_MAX_IO_SIZE) - maxio = CTLBLK_MAX_IO_SIZE; + if (maxio > CTLBLK_MAX_SEG) + maxio = CTLBLK_MAX_SEG; } be_lun->lun_flush = ctl_be_block_flush_dev; be_lun->getattr = ctl_be_block_getattr_dev; @@ -2778,6 +2804,10 @@ ctl_be_block_init(void) NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); softc->buf_zone = uma_zcreate("ctlblock", CTLBLK_MAX_SEG, NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); +#if (CTLBLK_MAX_SEG > 131072) + softc->buf128_zone = uma_zcreate("ctlblock128", 131072, + NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); +#endif SLIST_INIT(&softc->lun_list); return (0); } @@ -2803,6 +2833,9 @@ ctl_be_block_shutdown(void) } mtx_unlock(&softc->lock); uma_zdestroy(softc->buf_zone); +#if (CTLBLK_MAX_SEG > 131072) + uma_zdestroy(softc->buf128_zone); +#endif uma_zdestroy(softc->beio_zone); mtx_destroy(&softc->lock); sx_destroy(&softc->modify_lock);