From owner-svn-src-stable@freebsd.org Wed Nov 18 02:06:00 2020 Return-Path: Delivered-To: svn-src-stable@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 2FDF34757E1; Wed, 18 Nov 2020 02:06:00 +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 4CbR480xJWz4Vn1; Wed, 18 Nov 2020 02:06:00 +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 12E8C2294; Wed, 18 Nov 2020 02:06:00 +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 0AI25xn6050085; Wed, 18 Nov 2020 02:05:59 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AI25xCs050084; Wed, 18 Nov 2020 02:05:59 GMT (envelope-from mav@FreeBSD.org) Message-Id: <202011180205.0AI25xCs050084@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Wed, 18 Nov 2020 02:05:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r367780 - stable/12/sys/cam/ctl X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/cam/ctl X-SVN-Commit-Revision: 367780 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Nov 2020 02:06:00 -0000 Author: mav Date: Wed Nov 18 02:05:59 2020 New Revision: 367780 URL: https://svnweb.freebsd.org/changeset/base/367780 Log: MFC r367600: 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. Modified: stable/12/sys/cam/ctl/ctl_backend_block.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- stable/12/sys/cam/ctl/ctl_backend_block.c Wed Nov 18 01:18:45 2020 (r367779) +++ stable/12/sys/cam/ctl/ctl_backend_block.c Wed Nov 18 02:05:59 2020 (r367780) @@ -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; @@ -298,6 +301,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) { @@ -315,12 +344,12 @@ ctl_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]); } } @@ -1132,8 +1161,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; @@ -1325,8 +1353,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); @@ -1598,18 +1625,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++; @@ -1925,8 +1951,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; @@ -2771,6 +2797,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); } @@ -2797,6 +2827,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);