From owner-dev-commits-src-main@freebsd.org Thu Apr 1 08:20:39 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 EB1655C344D; Thu, 1 Apr 2021 08:20:39 +0000 (UTC) (envelope-from zec@fer.hr) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on060d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0c::60d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "DigiCert Cloud Services CA-1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F9x2b50LMz4vB3; Thu, 1 Apr 2021 08:20:39 +0000 (UTC) (envelope-from zec@fer.hr) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iNVR0QLjJb9kXUTkKJzhsu7mBDFLDbPLiUgzAaBNOmnpWEz45p+tExcNA9CSQ8vRp8oNUKguuztIRj9EBGq064qchCZehyML4NWcbNHIweTjrdnSvExzzyGtfluiX/U1YbdZ4+8l6f/vQSYig8GcODej0ExDf0PSTqb9a3E3qZLO8JuNIKPxOJUKC0p7JJsReQQxfvIsu156b8CvdkBoMBcXnQzVFIVAgJlK7LGQSN+ivhph1lKsOuXJzlMHkOYvHysR67CwA93/WSXTO05mo8brwpmuPTA20F94yYsHcdRnG+OpH9Iguy7CeCr+F2moeytOBOjEXFYt/gXIsnr7jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FkrIPdtncAHjN3maqzE6Cjqa2/LbfX/vOOCya4M0CAw=; b=hW6XMyJ1ze1ql3eor5EezO5NGK8rUpCtfTVfRGfgbgv0plKaTQX8Xkd5VfXy1u1SrhUBt4fb0ruvtvbScHblioUA9P89r/GRrtHxGvDH2+Kwk98BKIl8SNOmuiZsZ+FoppJwk9nKeGdvThVwxBxD4MLo9IS3LELnoT+D8N5oxdbs7viK/AIohVnNk1WUcG7dmTBlgLiq2lt+ZmZQ7hv9Sv7qcAGaDEpqd7jl9P3u3aHnbGhuY7tYyWnikE/Qv/Y6hwxt7o06bqWoNLQQ/PFM+sHPKMu8u2BiANYXKEB3OR/dPi6j60QThws+U1z+QXE9JYdt1oO41/JTPUWA80Qnng== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fer.hr; dmarc=pass action=none header.from=fer.hr; dkim=pass header.d=fer.hr; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ferhr.onmicrosoft.com; s=selector2-ferhr-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FkrIPdtncAHjN3maqzE6Cjqa2/LbfX/vOOCya4M0CAw=; b=BPfrAYbLXalyL0EElc1axmIFutjC78w32HKDTXXL+yK9irhRw+GMS7DzGslKTqxqRTtQHBuaYbQGdOC4+AVWw0aEJG+UVs5OaUiUt8PVlhgeDUegaSzXIN+ZRNu30Lm5SX91zfAcCPGHFA0+SmZxYyg7q4D9outdAMQPuHi9NCk= Received: from VE1PR08MB4783.eurprd08.prod.outlook.com (2603:10a6:802:a9::16) by VI1PR08MB3086.eurprd08.prod.outlook.com (2603:10a6:803:46::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.28; Thu, 1 Apr 2021 08:20:34 +0000 Received: from VE1PR08MB4783.eurprd08.prod.outlook.com ([fe80::2033:5b9c:c1fa:e9a1]) by VE1PR08MB4783.eurprd08.prod.outlook.com ([fe80::2033:5b9c:c1fa:e9a1%7]) with mapi id 15.20.3999.027; Thu, 1 Apr 2021 08:20:34 +0000 Date: Thu, 1 Apr 2021 10:20:35 +0200 From: Marko Zec To: Richard Scheffenegger Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 529a2a0f2765 - main - tcp: For hostcache performance, use atomics instead of counters Message-ID: <20210401102035.19636bea@x23> In-Reply-To: <202104010803.13183vQe043756@gitrepo.freebsd.org> References: <202104010803.13183vQe043756@gitrepo.freebsd.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; amd64-portbld-freebsd11.4) Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Originating-IP: [31.147.109.165] X-ClientProxiedBy: VI1PR0102CA0018.eurprd01.prod.exchangelabs.com (2603:10a6:802::31) To VE1PR08MB4783.eurprd08.prod.outlook.com (2603:10a6:802:a9::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from x23 (31.147.109.165) by VI1PR0102CA0018.eurprd01.prod.exchangelabs.com (2603:10a6:802::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3999.27 via Frontend Transport; Thu, 1 Apr 2021 08:20:34 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37cd6c79-1297-4b85-2efd-08d8f4e705ad X-MS-TrafficTypeDiagnostic: VI1PR08MB3086: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:663; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q72FpdUZEdXbox5tcr5tBhoKUT47GQi6cDGHerVYhHD1W45iqNvUM2I5KUfrgcYAfcUwtq5FOTV+dq9k31oj6xYtCU2LpzGQOLQvuPMbQcYf1LdtGJgmD/11ecI+QDD5PEsD4fIcT2/ULLJNe37EwH9kwVZboPjj2ydhsOeyj5+sHR/NFq/gkjBRmH2Tyzap4+I8sc7bGvg2IIGKU84dvb90IHzsPG3jUwlwXQWDWT+72C7uUt9GuLXCCrDKroUHmN2iNqacFRPsUv6Umi213oUDrHXGJEBgFcAaXYd51gqG/2y/p3zYWV+fBg34Kkitn9kLm877UX6hJlOSmvg4La4A0oBhS5YR+DwwCbxIBNlQLDvxHa2bC7mNBHyTl5vPlu5IBmLSSsftT6IkSDO8IIDCgoEqfsC+CVjvO5vEc2+CFobvHPz5aX2s9xEfQQKtfi1NS7X0Wtr8SM0R80Tvgc+vQ7WOHi7LTbATjiwSj/hFmUmR5jdRyCv3fq2+VGYuj+qgPbPmZ3gEApTlqDjg2nyJ9DzNGl5n2Jyt38PZx49vsrbd4mGYcp/1MrQOzeM1EF749km4y8QqsQgGYZy/9sTWfbYEXkvN4ARqRnsF3jpBARMi8U286wtY54pk2VeClcJhvAatvbGGfQ/68zDuCMm65sPUWpZpCsccg3T4uf/G4cUhCFVnhkedv0NGgGrbgVXUeGXrHo8QGAbw9pPA4ZtfztadiVtpttGGrS7Zhp0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR08MB4783.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(366004)(346002)(39830400003)(136003)(376002)(9576002)(66476007)(26005)(6916009)(316002)(33716001)(2906002)(86362001)(966005)(8676002)(5660300002)(8936002)(9686003)(786003)(4326008)(38100700001)(450100002)(83380400001)(66556008)(66946007)(16526019)(186003)(55016002)(956004)(6496006)(478600001)(52116002)(1076003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?fFGJ6MD94tOjh2gwNe0nimTTuicUsaq3Sn1+VTrE2QpUclRn+0XE3aA6Rh0U?= =?us-ascii?Q?zBcblspK1hkEIyDqYpPJoRnoL6ZkycGU4aGxLgE+52U1dwDiaR669GkZg+L0?= =?us-ascii?Q?o2jfMNPj99IFerYwtox0VXlq4CS2z1wH3YekQ3ytutrfq/fSUwCVmu+FG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xqIPyz7w96phAptXjNR+DiYZA25z?= =?us-ascii?Q?+GKTi4ertSXZzkpKPFPh7Z1yk36oQimfeql7SKFdjlMtIfW0M/WopmXfglt0?= =?us-ascii?Q?1Q7z+Z3RNEhuXCScay/VFgEcrM8JEeELx1IIBw1BpQEJvONB6y3oN1Yx5zpG?= =?us-ascii?Q?xEw85u2Isf6qkvCqh/0Rok82cT68p2DwCDMIGowH036WuFD7MSO2PDzhFt/D?= =?us-ascii?Q?Vb4T7EduvBHiSEvxPjVRA87/7lP5if2zEx6rtPn+iv6PL4y7eCEVSy2IBUvx?= =?us-ascii?Q?qG5kbDg0E+W4H497f374leQC?= X-OriginatorOrg: fer.hr X-MS-Exchange-CrossTenant-Network-Message-Id: 37cd6c79-1297-4b85-2efd-08d8f4e705ad X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4783.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2021 08:20:34.5022 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: ca71eddc-cc7b-4e5b-95bd-55b658e696be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mSrukNoHb47hKEL7xJ5BtT+tsVT+8cT7ttFZqS7NAMV2xaGQLDudgs0N9q7MwTF3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3086 X-Rspamd-Queue-Id: 4F9x2b50LMz4vB3 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] 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: Thu, 01 Apr 2021 08:20:40 -0000 On Thu, 1 Apr 2021 08:03:57 GMT Richard Scheffenegger wrote: > The branch main has been updated by rscheff: > > URL: > https://cgit.FreeBSD.org/src/commit/?id=529a2a0f2765f6c57c50a5af6be242c03bf714e3 > > commit 529a2a0f2765f6c57c50a5af6be242c03bf714e3 > Author: Richard Scheffenegger > AuthorDate: 2021-04-01 08:00:32 +0000 > Commit: Richard Scheffenegger > CommitDate: 2021-04-01 08:03:30 +0000 > > tcp: For hostcache performance, use atomics instead of counters Is that an April 1st joke, or for real, since it appears to have hit the tree? > As accessing the tcp hostcache happens frequently on some > classes of servers, it was recommended Recommended by whom? > to use atomic_add/subtract > rather than (per-CPU distributed) counters, which have to be > summed up at high cost to cache efficiency. Numbers? > > PR: 254333 > MFC after: 2 weeks > Sponsored by: NetApp, Inc. > Reviewed By: #transport, tuexen, jtl > Differential Revision: https://reviews.freebsd.org/D29522 > --- > sys/netinet/tcp_hostcache.c | 24 +++++++++++------------- > sys/netinet/tcp_hostcache.h | 2 +- > 2 files changed, 12 insertions(+), 14 deletions(-) > > diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c > index 67da97405c3f..87023cc1a760 100644 > --- a/sys/netinet/tcp_hostcache.c > +++ b/sys/netinet/tcp_hostcache.c > @@ -147,8 +147,8 @@ SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, > bucketlimit, CTLFLAG_VNET | CTLFLAG_RDTUN, > &VNET_NAME(tcp_hostcache.bucket_limit), 0, "Per-bucket hash limit for > hostcache"); > -SYSCTL_COUNTER_U64(_net_inet_tcp_hostcache, OID_AUTO, count, > CTLFLAG_VNET | CTLFLAG_RD, > - &VNET_NAME(tcp_hostcache.cache_count), > +SYSCTL_UINT(_net_inet_tcp_hostcache, OID_AUTO, count, CTLFLAG_VNET | > CTLFLAG_RD, > + &VNET_NAME(tcp_hostcache.cache_count), 0, > "Current number of entries in hostcache"); > > SYSCTL_INT(_net_inet_tcp_hostcache, OID_AUTO, expire, CTLFLAG_VNET | > CTLFLAG_RW, @@ -199,8 +199,7 @@ tcp_hc_init(void) > /* > * Initialize hostcache structures. > */ > - V_tcp_hostcache.cache_count = counter_u64_alloc(M_WAITOK); > - counter_u64_zero(V_tcp_hostcache.cache_count); > + atomic_store_int(&V_tcp_hostcache.cache_count, 0); > V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; > V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT; > V_tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE; > @@ -268,9 +267,6 @@ tcp_hc_destroy(void) > /* Purge all hc entries. */ > tcp_hc_purge_internal(1); > > - /* Release the counter */ > - counter_u64_free(V_tcp_hostcache.cache_count); > - > /* Free the uma zone and the allocated hash table. */ > uma_zdestroy(V_tcp_hostcache.zone); > > @@ -378,7 +374,7 @@ tcp_hc_insert(struct in_conninfo *inc) > * If the bucket limit is reached, reuse the least-used > element. */ > if (hc_head->hch_length >= V_tcp_hostcache.bucket_limit || > - counter_u64_fetch(V_tcp_hostcache.cache_count) >= > V_tcp_hostcache.cache_limit) { > + atomic_load_int(&V_tcp_hostcache.cache_count) >= > V_tcp_hostcache.cache_limit) { hc_entry = > TAILQ_LAST(&hc_head->hch_bucket, hc_qhead); /* > * At first we were dropping the last element, just > to @@ -395,7 +391,7 @@ tcp_hc_insert(struct in_conninfo *inc) > } > TAILQ_REMOVE(&hc_head->hch_bucket, hc_entry, rmx_q); > V_tcp_hostcache.hashbase[hash].hch_length--; > - counter_u64_add(V_tcp_hostcache.cache_count, -1); > + atomic_subtract_int(&V_tcp_hostcache.cache_count, 1); > TCPSTAT_INC(tcps_hc_bucketoverflow); > #if 0 > uma_zfree(V_tcp_hostcache.zone, hc_entry); > @@ -428,7 +424,7 @@ tcp_hc_insert(struct in_conninfo *inc) > */ > TAILQ_INSERT_HEAD(&hc_head->hch_bucket, hc_entry, rmx_q); > V_tcp_hostcache.hashbase[hash].hch_length++; > - counter_u64_add(V_tcp_hostcache.cache_count, 1); > + atomic_add_int(&V_tcp_hostcache.cache_count, 1); > TCPSTAT_INC(tcps_hc_added); > > return hc_entry; > @@ -644,7 +640,8 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) > > /* Optimize Buffer length query by sbin/sysctl */ > if (req->oldptr == NULL) { > - len = > (counter_u64_fetch(V_tcp_hostcache.cache_count) + 1) * linesize; > + len = (atomic_load_int(&V_tcp_hostcache.cache_count) > + 1) * > + linesize; > return (SYSCTL_OUT(req, NULL, len)); > } > > @@ -654,7 +651,8 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) > } > > /* Use a buffer sized for one full bucket */ > - sbuf_new_for_sysctl(&sb, NULL, V_tcp_hostcache.bucket_limit > * linesize, req); > + sbuf_new_for_sysctl(&sb, NULL, V_tcp_hostcache.bucket_limit * > + linesize, req); > > sbuf_printf(&sb, > "\nIP address MTU SSTRESH RTT RTTVAR " > @@ -716,7 +714,7 @@ tcp_hc_purge_internal(int all) > hc_entry, rmx_q); > uma_zfree(V_tcp_hostcache.zone, > hc_entry); V_tcp_hostcache.hashbase[i].hch_length--; > - > counter_u64_add(V_tcp_hostcache.cache_count, -1); > + > atomic_subtract_int(&V_tcp_hostcache.cache_count, 1); } else > hc_entry->rmx_expire -= > V_tcp_hostcache.prune; } > diff --git a/sys/netinet/tcp_hostcache.h b/sys/netinet/tcp_hostcache.h > index b5237392acc2..2f7035c0c6af 100644 > --- a/sys/netinet/tcp_hostcache.h > +++ b/sys/netinet/tcp_hostcache.h > @@ -74,7 +74,7 @@ struct tcp_hostcache { > u_int hashsize; > u_int hashmask; > u_int bucket_limit; > - counter_u64_t cache_count; > + u_int cache_count; > u_int cache_limit; > int expire; > int prune;