From nobody Mon Jun 20 17:00:32 2022 X-Original-To: dev-commits-src-all@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 CCA628774FF; Mon, 20 Jun 2022 17:00:32 +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 4LRbW444wyz3DDm; Mon, 20 Jun 2022 17:00:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655744432; 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=5NmGo8L4WnMRVClbPTBS+f/xnhdzLw+/Ieh55I9edqA=; b=Kvf4mSwQX8LTSeW4XPI/WUBr7uJVMTukOjULP/bl6Db8x2un0z63sA3GCfpfT0PZhCip6J GqwABKw0DNQtYH5lR5lBZHKT8xd1C5H21AL/36oPD99LbGaUi9DisvDiiszfs0wqgpkLB+ 7AXrFA6oCap3JFbncYL6lKU0kuj53fhiq9wQtwvvo6rlmI7BZeQTVzlPNNusJ7PHd+qimX tqGXT3QhwAdHnYDHXzdxR2+JJSSW8ZemzNwtwYLPQDwrxEVSRAALjuZOOdeHtGPJod3ost 0BD8pJzScAPDv30OHjlncQjhgt3C7tPR1s4YFe46nXM/WpCGQcd4yGS7mPHteA== 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 56D4121133; Mon, 20 Jun 2022 17:00:32 +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 25KH0WmN049825; Mon, 20 Jun 2022 17:00:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25KH0W54049824; Mon, 20 Jun 2022 17:00:32 GMT (envelope-from git) Date: Mon, 20 Jun 2022 17:00:32 GMT Message-Id: <202206201700.25KH0W54049824@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 9553bc89dbc3 - main - aio: Improve UMA usage List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 9553bc89dbc38a861a750ddc605cec0381788c5d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655744432; 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=5NmGo8L4WnMRVClbPTBS+f/xnhdzLw+/Ieh55I9edqA=; b=ZCL9TUE6nUo0Yl6n6JKiw4zWFfq83LEEhaCNsgni0FqjHcYWDZiWfauHHMvvZJi6KexTXp SYGUip70I2XVsUZWAv+LX6u0vrzpTHYQE7shpAQnQyJYfdTV6XhIm4mIgdOcLurrr9zr+S +q6vNxc19ud3oairT1I+9KbGGtGJkqisoJVbu9APrB1J6RZCtv3oem8FcfK8wqxIavsSot DHdPduwwVJpILZw1zgzyetnltlAHeykO+Gsav4Tc+EET4x+JCelyI0pYk7lJOY0NwaW9vw DBNwd8VkQy9DJu1vlF0TBJNwyr+dQc1YamXopfW4d1NbLDQj53wxwTasIJBE4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655744432; a=rsa-sha256; cv=none; b=ImzgqngORtDUVI28Lgc6bKE9IvP2T5zE4iW3+/d2vscbyyFiAAP77bbX4ku3uivc4ivzCV zVRadiJzhCgi3lit4ingcZ8+e2SO08uK/cNnjlymppFWMPeENnt8D3KAsEDe93YqmR6PWx Tq5dRrTmRlDvmXwW76kdDFJWFdog3k+Jk6DroY5CMq0Kn/PbrJ2FBiAZ9shtVrYagWOqQI kdlc5vfNeJJuHTfGFXiHTu131S80Utc9h9KJto2VWn5Ih+sIIx+Z6zFr/KKJHIK7JzeYEv WyTHL3j+/walMjQCdUvzO6I8XU96FAYfMgAC0QFd1q+AdYx7MUzC6Pwf8NWIAw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9553bc89dbc38a861a750ddc605cec0381788c5d commit 9553bc89dbc38a861a750ddc605cec0381788c5d Author: Mark Johnston AuthorDate: 2022-06-20 16:17:11 +0000 Commit: Mark Johnston CommitDate: 2022-06-20 16:48:13 +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 MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35493 --- 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 ffb18f636cb1..c9489ee5b4ad 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); @@ -1091,7 +1088,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; @@ -1157,7 +1154,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); @@ -2034,11 +2031,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); } @@ -2957,7 +2954,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])); @@ -2967,7 +2964,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); }