From owner-dev-commits-src-main@freebsd.org Mon Jun 28 08:15:34 2021 Return-Path: Delivered-To: dev-commits-src-main@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 2D7DA651F23; Mon, 28 Jun 2021 08:15:34 +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 4GD0m60pGmz4bdk; Mon, 28 Jun 2021 08:15:34 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 044A621EB4; Mon, 28 Jun 2021 08:15:34 +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 15S8FXd7014454; Mon, 28 Jun 2021 08:15:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15S8FXVK014453; Mon, 28 Jun 2021 08:15:33 GMT (envelope-from git) Date: Mon, 28 Jun 2021 08:15:33 GMT Message-Id: <202106280815.15S8FXVK014453@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: e0893890eb60 - main - ipsec: globalize lft zone and zero out buffers at allocation time MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e0893890eb6080e92f7e7fd9da319536bb5fe64e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2021 08:15:34 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=e0893890eb6080e92f7e7fd9da319536bb5fe64e commit e0893890eb6080e92f7e7fd9da319536bb5fe64e Author: Mateusz Guzik AuthorDate: 2021-06-24 11:19:09 +0000 Commit: Mateusz Guzik CommitDate: 2021-06-28 08:14:26 +0000 ipsec: globalize lft zone and zero out buffers at allocation time Creation of a zone is expensive and there is no need to have one for every vnet. Moreover, this wastes memory as these separate zones cannot use the same per-cpu caches. Finally, this is a step towards replacing the custom zone with pcpu-16. Two counter_u64_zero calls induce back-to-back IPIs to zero everything out. Instead, pass the M_ZERO flag to let uma just iterate all buffers. The counter(9) API abstraction is already violated by not using counter_u64_alloc. Reviewed by: ae Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D30916 --- sys/netipsec/key.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 86dc9ea41024..4ca65979d5b2 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -534,8 +534,7 @@ MALLOC_DEFINE(M_IPSEC_SAQ, "ipsec-saq", "ipsec sa acquire"); MALLOC_DEFINE(M_IPSEC_SAR, "ipsec-reg", "ipsec sa acquire"); MALLOC_DEFINE(M_IPSEC_SPDCACHE, "ipsec-spdcache", "ipsec SPD cache"); -VNET_DEFINE_STATIC(uma_zone_t, key_lft_zone); -#define V_key_lft_zone VNET(key_lft_zone) +static uma_zone_t __read_mostly ipsec_key_lft_zone; /* * set parameters into secpolicyindex buffer. @@ -2939,13 +2938,11 @@ key_newsav(const struct sadb_msghdr *mhp, struct secasindex *saidx, goto done; } mtx_init(sav->lock, "ipsec association", NULL, MTX_DEF); - sav->lft_c = uma_zalloc_pcpu(V_key_lft_zone, M_NOWAIT); + sav->lft_c = uma_zalloc_pcpu(ipsec_key_lft_zone, M_NOWAIT | M_ZERO); if (sav->lft_c == NULL) { *errp = ENOBUFS; goto done; } - counter_u64_zero(sav->lft_c_allocations); - counter_u64_zero(sav->lft_c_bytes); sav->spi = spi; sav->seq = mhp->msg->sadb_msg_seq; @@ -3031,7 +3028,7 @@ done: free(sav->lock, M_IPSEC_MISC); } if (sav->lft_c != NULL) - uma_zfree_pcpu(V_key_lft_zone, sav->lft_c); + uma_zfree_pcpu(ipsec_key_lft_zone, sav->lft_c); free(sav, M_IPSEC_SA), sav = NULL; } if (sah != NULL) @@ -3109,7 +3106,7 @@ key_delsav(struct secasvar *sav) if ((sav->flags & SADB_X_EXT_F_CLONED) == 0) { mtx_destroy(sav->lock); free(sav->lock, M_IPSEC_MISC); - uma_zfree_pcpu(V_key_lft_zone, sav->lft_c); + uma_zfree_pcpu(ipsec_key_lft_zone, sav->lft_c); } free(sav, M_IPSEC_SA); } @@ -8269,10 +8266,6 @@ key_init(void) TAILQ_INIT(&V_sptree_ifnet[i]); } - V_key_lft_zone = uma_zcreate("IPsec SA lft_c", - sizeof(uint64_t) * 2, NULL, NULL, NULL, NULL, - UMA_ALIGN_PTR, UMA_ZONE_PCPU); - TAILQ_INIT(&V_sahtree); V_sphashtbl = hashinit(SPHASH_NHASH, M_IPSEC_SP, &V_sphash_mask); V_savhashtbl = hashinit(SAVHASH_NHASH, M_IPSEC_SA, &V_savhash_mask); @@ -8294,6 +8287,10 @@ key_init(void) if (!IS_DEFAULT_VNET(curvnet)) return; + ipsec_key_lft_zone = uma_zcreate("IPsec SA lft_c", + sizeof(uint64_t) * 2, NULL, NULL, NULL, NULL, + UMA_ALIGN_PTR, UMA_ZONE_PCPU); + SPTREE_LOCK_INIT(); REGTREE_LOCK_INIT(); SAHTREE_LOCK_INIT(); @@ -8409,10 +8406,12 @@ key_destroy(void) SPACQ_UNLOCK(); hashdestroy(V_acqaddrhashtbl, M_IPSEC_SAQ, V_acqaddrhash_mask); hashdestroy(V_acqseqhashtbl, M_IPSEC_SAQ, V_acqseqhash_mask); - uma_zdestroy(V_key_lft_zone); if (!IS_DEFAULT_VNET(curvnet)) return; + + uma_zdestroy(ipsec_key_lft_zone); + #ifndef IPSEC_DEBUG2 callout_drain(&key_timer); #endif