From nobody Wed Jul 20 14:02:13 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Lny7T4qmZz4X5yp; Wed, 20 Jul 2022 14:02:13 +0000 (UTC) (envelope-from git@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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Lny7T3HTkz3bdh; Wed, 20 Jul 2022 14:02:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658325733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k0MHVfUdyBspaRX8rcrWzAgDFOTdQN6FJm4g0DAXZ5U=; b=L1aJ70bd1q+nOs3Vibm6s0CFYLo93gIS6Qv6nUOSqGhI3SKpGZsz3qJ3w6/dazf5rKoq8e 43QK7PLxWFpKwk9Vc5Ig1TvM+yvQhSI7UZeq5Bz6RmLcRLFeJyaKRb64UazBag/lhjCYGn 0qu9f63GvVIiCMwsI34jJ+D0KS8ttSaNWnqiuqROYPLdptRH06YZzMo3te4+wrGXyVN+3Z BAljmIsBrUwoj4fQgo9J3z4oNAhLH4Fm8DvFipFT+feBUnPO6vl/wSXy65dRo7vWrPKc2n 1asP9H64SMYcTmjOpOKI3ZnfXCZwqWFcC5qZ8q8WqFnD6eVEenQQtfE4T8PXlw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Lny7T21txz11JT; Wed, 20 Jul 2022 14:02:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26KE2DIO010036; Wed, 20 Jul 2022 14:02:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26KE2Dp5010035; Wed, 20 Jul 2022 14:02:13 GMT (envelope-from git) Date: Wed, 20 Jul 2022 14:02:13 GMT Message-Id: <202207201402.26KE2Dp5010035@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: d57ddc1d2804 - stable/13 - aio: Improve UMA usage List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d57ddc1d2804654c4bc6015d9f17704912ac2153 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658325733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k0MHVfUdyBspaRX8rcrWzAgDFOTdQN6FJm4g0DAXZ5U=; b=hZBUXqQ9TgqaEuxXjJ0KgND4RbBQNCUo6r+KICzA2C9mvx4L1Oj1tU+tO/6bphVRM+hIss xtclzMVOkn6XQe0ABL7FhccEkdLr3zg7hd/NM2h6lERyfpHxEQ7jirr3/xXDiJiSE0Bk+G KsRP6IVmpN6sZSsRNjd5FKQZ/ZJtvDHUaaXj0UuiudNsQcCoeWQ0U4bx5ZNWagW1LYBSlk ITCBOlMF2NC6RJ0yoGodroGiEtfg69uiPIFXvvsOTUmrd5iTquXJ4L6iTPtB5nGo0kbUQR bvHITHggRr1PSt9hyxWUDxStkcWNCOD1iDvkgIZsMsDdgq5WBV1lN9BUi8NdOg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658325733; a=rsa-sha256; cv=none; b=jIrFay21hbl+ddhXwUqqVC5WS6/z2eWekp/IQBd0wXHkt8sMaGI9PBUT/AeBg5Ot6/ymI6 S549Xcgmo/pqWzbraGmzfuRU9a19JYw2N8X+g2B/f2on4xR98ZH0shH+Ks73+0R97kbg7G /qE+qOxlZrD1TT1WJkM7M/B5XoyS1Qf2YNtqjjZwOXyc61GeuzW2FRUmWk0wwo2PiuGEAr i+/3fvoS5xQ0L+oAXCqtU0cyMmdNktuIBVuXQqh5Tloztj2ZKVzu7wgyRgAJqKe/B9np3h Asvn8n7ZtlDBhtVwwqzh6W8SlEpXQBVHipYezhXauKlE+qiwVuKKe+v/NsJ29w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d57ddc1d2804654c4bc6015d9f17704912ac2153 commit d57ddc1d2804654c4bc6015d9f17704912ac2153 Author: Mark Johnston AuthorDate: 2022-06-20 16:17:11 +0000 Commit: Mark Johnston CommitDate: 2022-07-20 13:53:48 +0000 aio: Improve UMA usage - Remove the AIO proc zone. This zone gets one allocation per AIO daemon process, which isn't enough to warrant a dedicated zone. Plus, unlike other AIO structures, aiops are small (32 bytes with LP64), so UMA doesn't provide better space efficiency than malloc(9). Change one of the malloc types in vfs_aio.c to make it more general. - Don't set the NOFREE flag on the other AIO zones. This flag means that memory allocated to the AIO subsystem is never freed back to the VM, so it's always preferable to avoid using it when possible. NOFREE was set without explanation when AIO was converted to use UMA 20 years ago, but it does not appear to be required; all of the structures allocated from UMA (per-process kaioinfo, kaiocb, and aioliojob) keep track of references and get freed only when none exist. Plus, these structures will contain dangling pointer after they're freed (e.g., the "cred", "fd_file" and "uiop" fields of struct kaiocb), so use-after-frees are dangerous even when the structures themselves are type-stable. Reviewed by: asomers Sponsored by: The FreeBSD Foundation (cherry picked from commit 9553bc89dbc38a861a750ddc605cec0381788c5d) --- sys/kern/vfs_aio.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 32a31ec80cfb..90c49d4818b3 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -104,7 +104,7 @@ FEATURE(aio, "Asynchronous I/O"); SYSCTL_DECL(_p1003_1b); static MALLOC_DEFINE(M_LIO, "lio", "listio aio control block list"); -static MALLOC_DEFINE(M_AIOS, "aios", "aio_suspend aio control block list"); +static MALLOC_DEFINE(M_AIO, "aio", "structures for asynchronous I/O"); static SYSCTL_NODE(_vfs, OID_AUTO, aio, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "Async IO management"); @@ -339,11 +339,10 @@ static int filt_lio(struct knote *kn, long hint); /* * Zones for: * kaio Per process async io info - * aiop async io process data * aiocb async io jobs * aiolio list io jobs */ -static uma_zone_t kaio_zone, aiop_zone, aiocb_zone, aiolio_zone; +static uma_zone_t kaio_zone, aiocb_zone, aiolio_zone; /* kqueue filters for aio */ static struct filterops aio_filtops = { @@ -412,13 +411,11 @@ aio_onceonly(void) TAILQ_INIT(&aio_jobs); aiod_unr = new_unrhdr(1, INT_MAX, NULL); kaio_zone = uma_zcreate("AIO", sizeof(struct kaioinfo), NULL, NULL, - NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); - aiop_zone = uma_zcreate("AIOP", sizeof(struct aioproc), NULL, - NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); + NULL, NULL, UMA_ALIGN_PTR, 0); aiocb_zone = uma_zcreate("AIOCB", sizeof(struct kaiocb), NULL, NULL, - NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); + NULL, NULL, UMA_ALIGN_PTR, 0); aiolio_zone = uma_zcreate("AIOLIO", sizeof(struct aioliojob), NULL, - NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); + NULL, NULL, NULL, UMA_ALIGN_PTR, 0); aiod_lifetime = AIOD_LIFETIME_DEFAULT; jobrefid = 1; p31b_setcfg(CTL_P1003_1B_ASYNCHRONOUS_IO, _POSIX_ASYNCHRONOUS_IO); @@ -1093,7 +1090,7 @@ aio_daemon(void *_id) * Allocate and ready the aio control info. There is one aiop structure * per daemon. */ - aiop = uma_zalloc(aiop_zone, M_WAITOK); + aiop = malloc(sizeof(*aiop), M_AIO, M_WAITOK); aiop->aioproc = p; aiop->aioprocflags = 0; @@ -1159,7 +1156,7 @@ aio_daemon(void *_id) TAILQ_REMOVE(&aio_freeproc, aiop, list); num_aio_procs--; mtx_unlock(&aio_job_mtx); - uma_zfree(aiop_zone, aiop); + free(aiop, M_AIO); free_unr(aiod_unr, id); vmspace_free(myvm); @@ -2032,11 +2029,11 @@ sys_aio_suspend(struct thread *td, struct aio_suspend_args *uap) } else tsp = NULL; - ujoblist = malloc(uap->nent * sizeof(ujoblist[0]), M_AIOS, M_WAITOK); + ujoblist = malloc(uap->nent * sizeof(ujoblist[0]), M_AIO, M_WAITOK); error = copyin(uap->aiocbp, ujoblist, uap->nent * sizeof(ujoblist[0])); if (error == 0) error = kern_aio_suspend(td, uap->nent, ujoblist, tsp); - free(ujoblist, M_AIOS); + free(ujoblist, M_AIO); return (error); } @@ -2954,7 +2951,7 @@ freebsd32_aio_suspend(struct thread *td, struct freebsd32_aio_suspend_args *uap) } else tsp = NULL; - ujoblist = malloc(uap->nent * sizeof(ujoblist[0]), M_AIOS, M_WAITOK); + ujoblist = malloc(uap->nent * sizeof(ujoblist[0]), M_AIO, M_WAITOK); ujoblist32 = (uint32_t *)ujoblist; error = copyin(uap->aiocbp, ujoblist32, uap->nent * sizeof(ujoblist32[0])); @@ -2964,7 +2961,7 @@ freebsd32_aio_suspend(struct thread *td, struct freebsd32_aio_suspend_args *uap) error = kern_aio_suspend(td, uap->nent, ujoblist, tsp); } - free(ujoblist, M_AIOS); + free(ujoblist, M_AIO); return (error); }