From nobody Fri Aug 18 04:09:17 2023 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 4RRpKV2Qk6z4qcH2; Fri, 18 Aug 2023 04:09:18 +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 4RRpKV0rGxz3fXh; Fri, 18 Aug 2023 04:09:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692331758; 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=/VDkYP6f+/zIe0CsBSTP3+QXhB5nqLl24SYD7m+3vN8=; b=Kkmr1Dg89cCOmjr02i2Cd+Mtija7/nr4tDXKJumO/L272IqZWi65o3lE0GhxjZW/Y8J/NL kSbJuW8OHXaaGV7pgqgSoPiZINrjW69EjWC9adwpXyMcE7hXFlLDGQ025xeSJp4IsEDr3d 0WGvtrDvoZnD4vpzKPTr4ao5IrjWrl+X/bR5/ShEqgbv70B63z7GsrpK9LcNeqrKFuTEKv S7PcTBC5pwSJ4cMmZaCUtSQFsS7+4SHWhSUkQyyLRPK0XImSKHmLC4C4NRIu8dFtyJEhF9 2L2JdiRYnuwOZvwAWACxrAkr6r0YEazy8BiO08DJNDXHyFynzTGHdYKgbdkKWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692331758; 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=/VDkYP6f+/zIe0CsBSTP3+QXhB5nqLl24SYD7m+3vN8=; b=ZSEv+cqI4B239R7hG4pmAZXqs539MKhHbZPXbjtYvHSMf29a6dTMqo3JgQizk+8UCkY1Hz SLoYDwqyJQJ+pcDV35WnQ26ivwJVoNSzq2sUqIhveGO9w8lRBlu4/Iobu+F2UKuypyt4r7 7t2eZv1OuBeeP2Su2/75wt2uChzilxYVPup1hVhQCSlpEHo8fr2DYLz15mf5O2nXYqX8Z8 N7hXJgv1XfrruVA9TpFX4CAy9RBc5s6FsBS10fFwQ0wgoBTkKPegpkZSDypinuJfX8jbud nEXsH1oJe7ZRgWvsJ5dt1MkPi1OpLP7CJt5yZ1mE4i3D7Kp1V3e9/uY41b+Xgg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692331758; a=rsa-sha256; cv=none; b=Dgkm1OYyBB2UCVexYN9TmMK+5WhAdx7xq/lGkmofwa2uIer/nIn8YSPwSEYQbQpyUVbd6t MLfAgfuZE4LOTiV2ef7/YLKrHmQCAdmbzIzfgAWvWtB8O3T6ApVqQTi4HxitU+nDT+WmuG RtsMH4hlILldW057oghzytR2cGWrGeKQVQ0NTVuUFpNoBPkHHmHzQqpREFyCKK2GA+YzpL THryZUa9VIOUVf8oI4UM2i+215mZjkQIzOQIsjNvQqNm5T5Dw1bgDfn/7O3ER11e+fnpWK Eg8UEyFCcvzJh5F2YZngJuUyrDF5xU4RuEUIl0ntO/f5WVQ/wR5tID33CvKZzA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RRpKT6r09z11mb; Fri, 18 Aug 2023 04:09:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37I49HvJ099628; Fri, 18 Aug 2023 04:09:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37I49Hv2099625; Fri, 18 Aug 2023 04:09:17 GMT (envelope-from git) Date: Fri, 18 Aug 2023 04:09:17 GMT Message-Id: <202308180409.37I49Hv2099625@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: a76629cb0381 - main - kern: osd: stop downsizing arrays when the last slot deregisters 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a76629cb0381ee1ccd9b233259ca8130a53b6583 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=a76629cb0381ee1ccd9b233259ca8130a53b6583 commit a76629cb0381ee1ccd9b233259ca8130a53b6583 Author: Kyle Evans AuthorDate: 2023-08-18 04:05:55 +0000 Commit: Kyle Evans CommitDate: 2023-08-18 04:06:12 +0000 kern: osd: stop downsizing arrays when the last slot deregisters It was noted in D41404 that these reallocations aren't actually guaranteed to succeed, despite assertions to the contrary. We're talking relatively small allocations, so just free up the individual slot to be reused later as needed. Note that this doesn't track the last active slot as of this moment, but this could be done later if we find it's worth the complexity for what little that would allow to be optimized (osd_call, slightly). While we're here, fix the debug message that indicates which slot we just allocated when we find an unused one; the slot # is actually one higher than the index. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D41409 --- sys/kern/kern_osd.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/sys/kern/kern_osd.c b/sys/kern/kern_osd.c index 1b623d822cee..1f93f7021201 100644 --- a/sys/kern/kern_osd.c +++ b/sys/kern/kern_osd.c @@ -112,7 +112,7 @@ osd_register(u_int type, osd_destructor_t destructor, osd_method_t *methods) for (i = 0; i < osdm[type].osd_ntslots; i++) { if (osdm[type].osd_destructors[i] == NULL) { OSD_DEBUG("Unused slot found (type=%u, slot=%u).", - type, i); + type, i + 1); break; } } @@ -166,32 +166,18 @@ osd_deregister(u_int type, u_int slot) LIST_FOREACH_SAFE(osd, &osdm[type].osd_list, osd_next, tosd) do_osd_del(type, osd, slot, 1); mtx_unlock(&osdm[type].osd_list_lock); + /* - * Set destructor to NULL to free the slot. + * Set destructor to NULL to free the slot. We don't bother actually + * freeing any memory here because we'll gracefully reuse any freed + * slots, and reallocating the arrays as a smaller chunk of memory isn't + * actually guaranteed to succeed. As such, we'll err on the side of + * caution and just leave it be since these are generally modestly sized + * allocations. */ osdm[type].osd_destructors[slot - 1] = NULL; - if (slot == osdm[type].osd_ntslots) { - osdm[type].osd_ntslots--; - osdm[type].osd_destructors = realloc(osdm[type].osd_destructors, - sizeof(osd_destructor_t) * osdm[type].osd_ntslots, M_OSD, - M_NOWAIT | M_ZERO); - if (osdm[type].osd_nmethods != 0) - osdm[type].osd_methods = realloc(osdm[type].osd_methods, - sizeof(osd_method_t) * osdm[type].osd_ntslots * - osdm[type].osd_nmethods, M_OSD, M_NOWAIT | M_ZERO); - /* - * We always reallocate to smaller size, so we assume it will - * always succeed. - */ - KASSERT(osdm[type].osd_destructors != NULL && - (osdm[type].osd_nmethods == 0 || - osdm[type].osd_methods != NULL), ("realloc() failed")); - OSD_DEBUG("Deregistration of the last slot (type=%u, slot=%u).", - type, slot); - } else { - OSD_DEBUG("Slot deregistration (type=%u, slot=%u).", - type, slot); - } + OSD_DEBUG("Slot deregistration (type=%u, slot=%u).", type, slot); + rm_wunlock(&osdm[type].osd_object_lock); sx_xunlock(&osdm[type].osd_module_lock); }