From owner-svn-src-head@freebsd.org Wed May 23 07:28:01 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 53F24EF2D5F; Wed, 23 May 2018 07:28:01 +0000 (UTC) (envelope-from emeric.poupon@stormshield.eu) Received: from work.stormshield.eu (gwlille.netasq.com [91.212.116.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 740AB7B88B; Wed, 23 May 2018 07:28:00 +0000 (UTC) (envelope-from emeric.poupon@stormshield.eu) Received: from work.stormshield.eu (localhost [127.0.0.1]) by work.stormshield.eu (Postfix) with ESMTPS id 7AE2B37628FB; Wed, 23 May 2018 09:27:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by work.stormshield.eu (Postfix) with ESMTP id 6D35837628EE; Wed, 23 May 2018 09:27:49 +0200 (CEST) Received: from work.stormshield.eu ([127.0.0.1]) by localhost (work.stormshield.eu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id jhLaEUSvO2Ka; Wed, 23 May 2018 09:27:49 +0200 (CEST) Received: from work.stormshield.eu (localhost [127.0.0.1]) by work.stormshield.eu (Postfix) with ESMTP id 588AA376288A; Wed, 23 May 2018 09:27:49 +0200 (CEST) Date: Wed, 23 May 2018 09:27:49 +0200 (CEST) From: Emeric POUPON To: Mateusz Guzik Cc: Fabien Thomas , svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers Message-ID: <714364035.13914889.1527060469295.JavaMail.zimbra@stormshield.eu> In-Reply-To: References: <201805221554.w4MFsPQA083334@repo.freebsd.org> Subject: Re: svn commit: r334054 - in head: sys/kern sys/netipsec tools/tools/crypto usr.bin/netstat MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Thread-Topic: svn commit: r334054 - in head: sys/kern sys/netipsec tools/tools/crypto usr.bin/netstat Thread-Index: 0B0BWMtwYN6XxTXc5DZ4pqKyNxKGBw== X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 May 2018 07:28:01 -0000 ----- Original Message ----- > From: "Mateusz Guzik" > To: "Fabien Thomas" > Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, "src-committers" > Sent: Tuesday, 22 May, 2018 18:45:32 > Subject: Re: svn commit: r334054 - in head: sys/kern sys/netipsec tools/tools/crypto usr.bin/netstat > On Tue, May 22, 2018 at 5:54 PM, Fabien Thomas wrote: > >> Author: fabient >> Date: Tue May 22 15:54:25 2018 >> New Revision: 334054 >> URL: https://svnweb.freebsd.org/changeset/base/334054 >> >> Log: >> Add a SPD cache to speed up lookups. >> >> When large SPDs are used, we face two problems: >> >> - too many CPU cycles are spent during the linear searches in the SPD >> for each packet >> - too much contention on multi socket systems, since we use a single >> shared lock. >> >> >> void >> +spdcache_init(void) >> +{ >> + int i; >> + >> + TUNABLE_INT_FETCH("net.key.spdcache.maxentries", >> + &V_key_spdcache_maxentries); >> + TUNABLE_INT_FETCH("net.key.spdcache.threshold", >> + &V_key_spdcache_threshold); >> + >> + if (V_key_spdcache_maxentries) { >> + V_key_spdcache_maxentries = MAX(V_key_spdcache_maxentries, >> + SPDCACHE_MAX_ENTRIES_PER_HASH); >> + V_spdcachehashtbl = hashinit(V_key_spdcache_maxentries / >> + SPDCACHE_MAX_ENTRIES_PER_HASH, >> + M_IPSEC_SPDCACHE, &V_spdcachehash_mask); >> + V_key_spdcache_maxentries = (V_spdcachehash_mask + 1) >> + * SPDCACHE_MAX_ENTRIES_PER_HASH; >> + >> + V_spdcache_lock = malloc(sizeof(struct mtx) * >> + (V_spdcachehash_mask + 1), >> + M_IPSEC_SPDCACHE, M_WAITOK|M_ZERO); >> + >> + for (i = 0; i < V_spdcachehash_mask + 1; ++i) >> + SPDCACHE_LOCK_INIT(i); >> + } >> +} >> + >> > > This ends up putting two locks per cacheline and sharing bucket heads > across other lines. > > Unless you got a good reason not to, you should define a struct a which has > both the lock and the list. > > An example of this can be found in kern/kern_lockf.c Fortunately the SPD lookup time is negligible compared to crypto operations time with this patch. But you are right, it should have been done your way: we will change that in the next step. Thanks for pointing this out. > > -- > Mateusz Guzik > _______________________________________________ > svn-src-all@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/svn-src-all > To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"