From patchwork Wed Feb 17 16:34:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=lWzhbruI; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=Be5Pqs4q; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkBv5mtTz9sSC for ; Thu, 18 Feb 2021 03:41:59 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 1207086E19; Wed, 17 Feb 2021 16:41:58 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f4zdCnQJwsJ3; Wed, 17 Feb 2021 16:41:47 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 197B286E0E; Wed, 17 Feb 2021 16:41:21 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F1843C1E70; Wed, 17 Feb 2021 16:41:20 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id CDA8DC1E6F for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id B3B3785B5B for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gBRdGVb9Ym0W for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 5EB2185F9B for ; Wed, 17 Feb 2021 16:41:09 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 0C00E580316; Wed, 17 Feb 2021 11:34:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 17 Feb 2021 11:34:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=bIZPkVPvZmUFE eC7GpyobSKUArsr9akGR7ntFoHc+70=; b=lWzhbruI58k1l79TyrauylxOc1czA J8W5WvYA0f4pMzX0cz2G1xJ9fCRJTYxZOvcL/bUkzYmR9ACy26f/midvtXDMVia7 OZniqf1hky+5dEgeh5jjfjzMQyWHPFmDJw6iwiC4Sh+rnuZzIdfaneQs2cTj5pW9 J696A+Z0W751b6/gu2povhj7xZi0lB02sBZNhTPegFUA2r7sDuxUfaGiD66WpYem m119CfpszCkx4HC2TH5tqMnzxmjflM965CsUxct+OJ5uDRXqWoOSggm5pEPLWM/t 3Z0CNsU8eXBCUhHpcv4eiDSI45uoO0iMIUTp5vvvjMOpiZbKbl1Iw2spg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=bIZPkVPvZmUFEeC7GpyobSKUArsr9akGR7ntFoHc+70=; b=Be5Pqs4q vMQ1GWW+b9xI2ofxbU0jvN3coHJzl9ZZOxB2+TrdpL+43uExzzDOLdEf/P6J/btZ be7oMDR6OzFDXDZrU+enpBvArCmXVNXzs7CFi0Tfvyk3TowmPcgji4qLurvW3Vmd jJGc9+TBstjy++B+YsWgT25fANtACWNXKydHAlCObYdWMFKYsM7iKxw5lJT7rvct z8MT8fI0NNwEK3M/zs24YF6pG0sNvfcSabKjadj+RKvoyzqrInoRLU0wwaYEmtsm vdSIYAQMnzmXlgk1ZnPdbjDS/iVMlBg8X5fyTRrDczPF4p8DsZlSGP/Kkyus8UhG 7dr5XQ0vjkUopQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 02886240065; Wed, 17 Feb 2021 11:34:46 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:35 +0100 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 1/9] conntrack: Use rcu-lists to store conn expirations X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Change the connection expiration lists from ovs_list to rculist. This is a pre-step towards reducing the granularity of 'ct_lock'. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein --- lib/conntrack-private.h | 76 +++++++++++++++++++++++++++-------------- lib/conntrack-tp.c | 60 +++++++++++++++++++++++++------- lib/conntrack.c | 14 ++++---- 3 files changed, 105 insertions(+), 45 deletions(-) diff --git a/lib/conntrack-private.h b/lib/conntrack-private.h index e8332bdba..4b6f9eae3 100644 --- a/lib/conntrack-private.h +++ b/lib/conntrack-private.h @@ -29,6 +29,7 @@ #include "openvswitch/list.h" #include "openvswitch/types.h" #include "packets.h" +#include "rculist.h" #include "unaligned.h" #include "dp-packet.h" @@ -86,17 +87,55 @@ struct alg_exp_node { bool nat_rpl_dst; }; +/* Timeouts: all the possible timeout states passed to update_expiration() + * are listed here. The name will be prefix by CT_TM_ and the value is in + * milliseconds */ +#define CT_TIMEOUTS \ + CT_TIMEOUT(TCP_FIRST_PACKET) \ + CT_TIMEOUT(TCP_OPENING) \ + CT_TIMEOUT(TCP_ESTABLISHED) \ + CT_TIMEOUT(TCP_CLOSING) \ + CT_TIMEOUT(TCP_FIN_WAIT) \ + CT_TIMEOUT(TCP_CLOSED) \ + CT_TIMEOUT(OTHER_FIRST) \ + CT_TIMEOUT(OTHER_MULTIPLE) \ + CT_TIMEOUT(OTHER_BIDIR) \ + CT_TIMEOUT(ICMP_FIRST) \ + CT_TIMEOUT(ICMP_REPLY) + +enum ct_timeout { +#define CT_TIMEOUT(NAME) CT_TM_##NAME, + CT_TIMEOUTS +#undef CT_TIMEOUT + N_CT_TM +}; + enum OVS_PACKED_ENUM ct_conn_type { CT_CONN_TYPE_DEFAULT, CT_CONN_TYPE_UN_NAT, }; +struct conn_expire { + /* Set once when initializing the expiration node. */ + struct conntrack *ct; + /* Timeout state of the connection. + * It follows the connection state updates. + */ + enum ct_timeout tm; + /* Insert and remove the expiration node only once per RCU syncs. + * If multiple threads update the connection, its expiration should + * be removed only once and added only once to timeout lists. + */ + atomic_flag insert_once; + atomic_flag remove_once; + struct rculist node; +}; + struct conn { /* Immutable data. */ struct conn_key key; struct conn_key rev_key; struct conn_key parent_key; /* Only used for orig_tuple support. */ - struct ovs_list exp_node; struct cmap_node cm_node; struct nat_action_info_t *nat_info; char *alg; @@ -104,6 +143,7 @@ struct conn { /* Mutable data. */ struct ovs_mutex lock; /* Guards all mutable fields. */ + struct conn_expire exp; ovs_u128 label; long long expiration; uint32_t mark; @@ -132,33 +172,10 @@ enum ct_update_res { CT_UPDATE_VALID_NEW, }; -/* Timeouts: all the possible timeout states passed to update_expiration() - * are listed here. The name will be prefix by CT_TM_ and the value is in - * milliseconds */ -#define CT_TIMEOUTS \ - CT_TIMEOUT(TCP_FIRST_PACKET) \ - CT_TIMEOUT(TCP_OPENING) \ - CT_TIMEOUT(TCP_ESTABLISHED) \ - CT_TIMEOUT(TCP_CLOSING) \ - CT_TIMEOUT(TCP_FIN_WAIT) \ - CT_TIMEOUT(TCP_CLOSED) \ - CT_TIMEOUT(OTHER_FIRST) \ - CT_TIMEOUT(OTHER_MULTIPLE) \ - CT_TIMEOUT(OTHER_BIDIR) \ - CT_TIMEOUT(ICMP_FIRST) \ - CT_TIMEOUT(ICMP_REPLY) - -enum ct_timeout { -#define CT_TIMEOUT(NAME) CT_TM_##NAME, - CT_TIMEOUTS -#undef CT_TIMEOUT - N_CT_TM -}; - struct conntrack { struct ovs_mutex ct_lock; /* Protects 2 following fields. */ struct cmap conns OVS_GUARDED; - struct ovs_list exp_lists[N_CT_TM] OVS_GUARDED; + struct rculist exp_lists[N_CT_TM] OVS_GUARDED; struct hmap zone_limits OVS_GUARDED; struct hmap timeout_policies OVS_GUARDED; uint32_t hash_basis; /* Salt for hashing a connection key. */ @@ -204,4 +221,13 @@ struct ct_l4_proto { struct ct_dpif_protoinfo *); }; +static inline void +conn_expire_remove(struct conn_expire *exp) +{ + if (!atomic_flag_test_and_set(&exp->remove_once) + && rculist_next(&exp->node)) { + rculist_remove(&exp->node); + } +} + #endif /* conntrack-private.h */ diff --git a/lib/conntrack-tp.c b/lib/conntrack-tp.c index a586d3a8d..30ba4bda8 100644 --- a/lib/conntrack-tp.c +++ b/lib/conntrack-tp.c @@ -230,6 +230,50 @@ tm_to_ct_dpif_tp(enum ct_timeout tm) return CT_DPIF_TP_ATTR_MAX; } +static void +conn_expire_init(struct conn *conn, struct conntrack *ct) +{ + struct conn_expire *exp = &conn->exp; + + if (exp->ct != NULL) { + return; + } + + exp->ct = ct; + atomic_flag_clear(&exp->insert_once); + atomic_flag_clear(&exp->remove_once); + /* The expiration is initially unscheduled, flag it as 'removed'. */ + atomic_flag_test_and_set(&exp->remove_once); +} + +static void +conn_expire_insert(struct conn *conn) +{ + struct conn_expire *exp = &conn->exp; + + ovs_mutex_lock(&exp->ct->ct_lock); + ovs_mutex_lock(&conn->lock); + + rculist_push_back(&exp->ct->exp_lists[exp->tm], &exp->node); + atomic_flag_clear(&exp->insert_once); + atomic_flag_clear(&exp->remove_once); + + ovs_mutex_unlock(&conn->lock); + ovs_mutex_unlock(&exp->ct->ct_lock); +} + +static void +conn_schedule_expiration(struct conntrack *ct, struct conn *conn, + enum ct_timeout tm, long long now, uint32_t tp_value) +{ + conn_expire_init(conn, ct); + conn->expiration = now + tp_value * 1000; + conn->exp.tm = tm; + if (!atomic_flag_test_and_set(&conn->exp.insert_once)) { + ovsrcu_postpone(conn_expire_insert, conn); + } +} + static void conn_update_expiration__(struct conntrack *ct, struct conn *conn, enum ct_timeout tm, long long now, @@ -241,9 +285,8 @@ conn_update_expiration__(struct conntrack *ct, struct conn *conn, ovs_mutex_lock(&ct->ct_lock); ovs_mutex_lock(&conn->lock); if (!conn->cleaned) { - conn->expiration = now + tp_value * 1000; - ovs_list_remove(&conn->exp_node); - ovs_list_push_back(&ct->exp_lists[tm], &conn->exp_node); + conn_expire_remove(&conn->exp); + conn_schedule_expiration(ct, conn, tm, now, tp_value); } ovs_mutex_unlock(&conn->lock); ovs_mutex_unlock(&ct->ct_lock); @@ -281,15 +324,6 @@ conn_update_expiration(struct conntrack *ct, struct conn *conn, conn_update_expiration__(ct, conn, tm, now, val); } -static void -conn_init_expiration__(struct conntrack *ct, struct conn *conn, - enum ct_timeout tm, long long now, - uint32_t tp_value) -{ - conn->expiration = now + tp_value * 1000; - ovs_list_push_back(&ct->exp_lists[tm], &conn->exp_node); -} - /* ct_lock must be held. */ void conn_init_expiration(struct conntrack *ct, struct conn *conn, @@ -309,5 +343,5 @@ conn_init_expiration(struct conntrack *ct, struct conn *conn, VLOG_DBG_RL(&rl, "Init timeout %s zone=%u with policy id=%d val=%u sec.", ct_timeout_str[tm], conn->key.zone, conn->tp_id, val); - conn_init_expiration__(ct, conn, tm, now, val); + conn_schedule_expiration(ct, conn, tm, now, val); } diff --git a/lib/conntrack.c b/lib/conntrack.c index 99198a601..ac12f9196 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -301,7 +301,7 @@ conntrack_init(void) ovs_mutex_lock(&ct->ct_lock); cmap_init(&ct->conns); for (unsigned i = 0; i < ARRAY_SIZE(ct->exp_lists); i++) { - ovs_list_init(&ct->exp_lists[i]); + rculist_init(&ct->exp_lists[i]); } hmap_init(&ct->zone_limits); ct->zone_limit_seq = 0; @@ -466,7 +466,7 @@ conn_clean(struct conntrack *ct, struct conn *conn) uint32_t hash = conn_key_hash(&conn->nat_conn->key, ct->hash_basis); cmap_remove(&ct->conns, &conn->nat_conn->cm_node, hash); } - ovs_list_remove(&conn->exp_node); + conn_expire_remove(&conn->exp); conn->cleaned = true; ovsrcu_postpone(delete_conn, conn); atomic_count_dec(&ct->n_conn); @@ -478,7 +478,7 @@ conn_clean_one(struct conntrack *ct, struct conn *conn) { conn_clean_cmn(ct, conn); if (conn->conn_type == CT_CONN_TYPE_DEFAULT) { - ovs_list_remove(&conn->exp_node); + conn_expire_remove(&conn->exp); conn->cleaned = true; atomic_count_dec(&ct->n_conn); } @@ -1075,8 +1075,8 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, * can limit DoS impact. */ nat_res_exhaustion: free(nat_conn); - ovs_list_remove(&nc->exp_node); - delete_conn_cmn(nc); + conn_expire_remove(&nc->exp); + ovsrcu_postpone(delete_conn_cmn, nc); static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 5); VLOG_WARN_RL(&rl, "Unable to NAT due to tuple space exhaustion - " "if DoS attack, use firewalling and/or zone partitioning."); @@ -1493,14 +1493,14 @@ set_label(struct dp_packet *pkt, struct conn *conn, static long long ct_sweep(struct conntrack *ct, long long now, size_t limit) { - struct conn *conn, *next; + struct conn *conn; long long min_expiration = LLONG_MAX; size_t count = 0; ovs_mutex_lock(&ct->ct_lock); for (unsigned i = 0; i < N_CT_TM; i++) { - LIST_FOR_EACH_SAFE (conn, next, exp_node, &ct->exp_lists[i]) { + RCULIST_FOR_EACH (conn, exp.node, &ct->exp_lists[i]) { ovs_mutex_lock(&conn->lock); if (now < conn->expiration || count >= limit) { min_expiration = MIN(min_expiration, conn->expiration); From patchwork Wed Feb 17 16:34:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=mNIqfLwP; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=qmzKWoFb; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkBC20dcz9sSC for ; Thu, 18 Feb 2021 03:41:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 8A7E485FC9; Wed, 17 Feb 2021 16:41:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vvzlce2K0AMU; Wed, 17 Feb 2021 16:41:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id F154585F8E; Wed, 17 Feb 2021 16:41:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DAB25C013A; Wed, 17 Feb 2021 16:41:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7A340C013A for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 6971E87220 for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TyQ0sDMHyKSa for ; Wed, 17 Feb 2021 16:41:09 +0000 (UTC) X-Greylist: delayed 00:06:21 by SQLgrey-1.7.6 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 59D318723D for ; Wed, 17 Feb 2021 16:41:09 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id 351C2580326; Wed, 17 Feb 2021 11:34:49 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Feb 2021 11:34:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=91lY0s54KdDwk zMNO/nckkbnm05isZSA7rPdBGw/kbg=; b=mNIqfLwPjYUiy7az3k9vuHKQ17Ma8 Q7IC4e0l2h7GIIG10VjXXoj2mPGgYEFZ1EcnSgci4F3crSx8UQ53eOWC8Q1bjuGb uHET1YhTPqI7i0I4Uv04l3wNivagq4EO8rTl1NygEzEmgS+JR1VQRW0j25rpfkFs rg4KBb+y3Icdw6ojQfulQGcgqDkQy5jlN6KZCqLBM9P7QWgVhX7Pf3WdkS+FOhOs RssOFk8zYPXyBcS1rTq+2vEsCNOM2Po6T5jmbtzMfeCn7QlV6J0n+0mXql/BVTsd Ir2A6kySsDIKay9flmRMsMaVpg5fJm9/HOd77K+/Y2i9QlQNS5CMMmEGw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=91lY0s54KdDwkzMNO/nckkbnm05isZSA7rPdBGw/kbg=; b=qmzKWoFb 6RpgCmXh7Rbf8ioIfh3WoZqsaNKZojHHjrQOw61s066f742IgmG1V5bYhM9QURIc D8IsfbRMbtfRGOft8AbHIv1nA4BhUXlGVrqfTEpHPqtO7JAeCdHthlvfhPEeWSMw cfSsGnKez8FLq6yaZuaeilcYZkTvXTfCbEeu/swUoVrWyr+6Vfh0yMl77Ealx+HK FzRdlPmlaSFYA9WBDBgserljga1Mf05FirK28grsyKgdVuqOz1b5r03A7T8pvHew Ne1nXlYlOB5+y0EJuLpd2nTHgS+eK08br+ouphek7AoPdfwTibhzrt65R2CCgzeA ChjbmwgaRevHcg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id D2DA0240068; Wed, 17 Feb 2021 11:34:47 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:36 +0100 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 2/9] conntrack: Use a cmap to store zone limits X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Change the data structure from hmap to cmap for zone limits. As they are shared amongst multiple conntrack users, multiple readers want to check the current zone limit state before progressing in their processing. Using a CMAP allows doing lookups without taking the global 'ct_lock', thus reducing contention. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein --- lib/conntrack-private.h | 2 +- lib/conntrack.c | 72 ++++++++++++++++++++++++++++------------- lib/conntrack.h | 2 +- lib/dpif-netdev.c | 5 +-- 4 files changed, 55 insertions(+), 26 deletions(-) diff --git a/lib/conntrack-private.h b/lib/conntrack-private.h index 4b6f9eae3..f2cbf657e 100644 --- a/lib/conntrack-private.h +++ b/lib/conntrack-private.h @@ -176,7 +176,7 @@ struct conntrack { struct ovs_mutex ct_lock; /* Protects 2 following fields. */ struct cmap conns OVS_GUARDED; struct rculist exp_lists[N_CT_TM] OVS_GUARDED; - struct hmap zone_limits OVS_GUARDED; + struct cmap zone_limits OVS_GUARDED; struct hmap timeout_policies OVS_GUARDED; uint32_t hash_basis; /* Salt for hashing a connection key. */ pthread_t clean_thread; /* Periodically cleans up connection tracker. */ diff --git a/lib/conntrack.c b/lib/conntrack.c index ac12f9196..c218200dc 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -79,7 +79,7 @@ enum ct_alg_ctl_type { }; struct zone_limit { - struct hmap_node node; + struct cmap_node node; struct conntrack_zone_limit czl; }; @@ -303,7 +303,7 @@ conntrack_init(void) for (unsigned i = 0; i < ARRAY_SIZE(ct->exp_lists); i++) { rculist_init(&ct->exp_lists[i]); } - hmap_init(&ct->zone_limits); + cmap_init(&ct->zone_limits); ct->zone_limit_seq = 0; timeout_policy_init(ct); ovs_mutex_unlock(&ct->ct_lock); @@ -339,12 +339,25 @@ zone_key_hash(int32_t zone, uint32_t basis) } static struct zone_limit * -zone_limit_lookup(struct conntrack *ct, int32_t zone) +zone_limit_lookup_protected(struct conntrack *ct, int32_t zone) OVS_REQUIRES(ct->ct_lock) { uint32_t hash = zone_key_hash(zone, ct->hash_basis); struct zone_limit *zl; - HMAP_FOR_EACH_IN_BUCKET (zl, node, hash, &ct->zone_limits) { + CMAP_FOR_EACH_WITH_HASH_PROTECTED (zl, node, hash, &ct->zone_limits) { + if (zl->czl.zone == zone) { + return zl; + } + } + return NULL; +} + +static struct zone_limit * +zone_limit_lookup(struct conntrack *ct, int32_t zone) +{ + uint32_t hash = zone_key_hash(zone, ct->hash_basis); + struct zone_limit *zl; + CMAP_FOR_EACH_WITH_HASH (zl, node, hash, &ct->zone_limits) { if (zl->czl.zone == zone) { return zl; } @@ -354,7 +367,6 @@ zone_limit_lookup(struct conntrack *ct, int32_t zone) static struct zone_limit * zone_limit_lookup_or_default(struct conntrack *ct, int32_t zone) - OVS_REQUIRES(ct->ct_lock) { struct zone_limit *zl = zone_limit_lookup(ct, zone); return zl ? zl : zone_limit_lookup(ct, DEFAULT_ZONE); @@ -363,13 +375,16 @@ zone_limit_lookup_or_default(struct conntrack *ct, int32_t zone) struct conntrack_zone_limit zone_limit_get(struct conntrack *ct, int32_t zone) { - ovs_mutex_lock(&ct->ct_lock); - struct conntrack_zone_limit czl = {DEFAULT_ZONE, 0, 0, 0}; + struct conntrack_zone_limit czl = { + .zone = DEFAULT_ZONE, + .limit = 0, + .count = ATOMIC_COUNT_INIT(0), + .zone_limit_seq = 0, + }; struct zone_limit *zl = zone_limit_lookup_or_default(ct, zone); if (zl) { czl = zl->czl; } - ovs_mutex_unlock(&ct->ct_lock); return czl; } @@ -377,13 +392,19 @@ static int zone_limit_create(struct conntrack *ct, int32_t zone, uint32_t limit) OVS_REQUIRES(ct->ct_lock) { + struct zone_limit *zl = zone_limit_lookup_protected(ct, zone); + + if (zl) { + return 0; + } + if (zone >= DEFAULT_ZONE && zone <= MAX_ZONE) { - struct zone_limit *zl = xzalloc(sizeof *zl); + zl = xzalloc(sizeof *zl); zl->czl.limit = limit; zl->czl.zone = zone; zl->czl.zone_limit_seq = ct->zone_limit_seq++; uint32_t hash = zone_key_hash(zone, ct->hash_basis); - hmap_insert(&ct->zone_limits, &zl->node, hash); + cmap_insert(&ct->zone_limits, &zl->node, hash); return 0; } else { return EINVAL; @@ -394,13 +415,14 @@ int zone_limit_update(struct conntrack *ct, int32_t zone, uint32_t limit) { int err = 0; - ovs_mutex_lock(&ct->ct_lock); struct zone_limit *zl = zone_limit_lookup(ct, zone); if (zl) { zl->czl.limit = limit; VLOG_INFO("Changed zone limit of %u for zone %d", limit, zone); } else { + ovs_mutex_lock(&ct->ct_lock); err = zone_limit_create(ct, zone, limit); + ovs_mutex_unlock(&ct->ct_lock); if (!err) { VLOG_INFO("Created zone limit of %u for zone %d", limit, zone); } else { @@ -408,7 +430,6 @@ zone_limit_update(struct conntrack *ct, int32_t zone, uint32_t limit) zone); } } - ovs_mutex_unlock(&ct->ct_lock); return err; } @@ -416,23 +437,25 @@ static void zone_limit_clean(struct conntrack *ct, struct zone_limit *zl) OVS_REQUIRES(ct->ct_lock) { - hmap_remove(&ct->zone_limits, &zl->node); - free(zl); + uint32_t hash = zone_key_hash(zl->czl.zone, ct->hash_basis); + cmap_remove(&ct->zone_limits, &zl->node, hash); + ovsrcu_postpone(free, zl); } int zone_limit_delete(struct conntrack *ct, uint16_t zone) { ovs_mutex_lock(&ct->ct_lock); - struct zone_limit *zl = zone_limit_lookup(ct, zone); + struct zone_limit *zl = zone_limit_lookup_protected(ct, zone); if (zl) { zone_limit_clean(ct, zl); + ovs_mutex_unlock(&ct->ct_lock); VLOG_INFO("Deleted zone limit for zone %d", zone); } else { + ovs_mutex_unlock(&ct->ct_lock); VLOG_INFO("Attempted delete of non-existent zone limit: zone %d", zone); } - ovs_mutex_unlock(&ct->ct_lock); return 0; } @@ -449,7 +472,7 @@ conn_clean_cmn(struct conntrack *ct, struct conn *conn) struct zone_limit *zl = zone_limit_lookup(ct, conn->admit_zone); if (zl && zl->czl.zone_limit_seq == conn->zone_limit_seq) { - zl->czl.count--; + atomic_count_dec(&zl->czl.count); } } @@ -503,10 +526,13 @@ conntrack_destroy(struct conntrack *ct) cmap_destroy(&ct->conns); struct zone_limit *zl; - HMAP_FOR_EACH_POP (zl, node, &ct->zone_limits) { - free(zl); + CMAP_FOR_EACH (zl, node, &ct->zone_limits) { + uint32_t hash = zone_key_hash(zl->czl.zone, ct->hash_basis); + + cmap_remove(&ct->zone_limits, &zl->node, hash); + ovsrcu_postpone(free, zl); } - hmap_destroy(&ct->zone_limits); + cmap_destroy(&ct->zone_limits); struct timeout_policy *tp; HMAP_FOR_EACH_POP (tp, node, &ct->timeout_policies) { @@ -988,7 +1014,7 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, if (commit) { struct zone_limit *zl = zone_limit_lookup_or_default(ct, ctx->key.zone); - if (zl && zl->czl.count >= zl->czl.limit) { + if (zl && atomic_count_get(&zl->czl.count) >= zl->czl.limit) { return nc; } @@ -1057,10 +1083,12 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, cmap_insert(&ct->conns, &nc->cm_node, ctx->hash); atomic_count_inc(&ct->n_conn); ctx->conn = nc; /* For completeness. */ + + zl = zone_limit_lookup_or_default(ct, ctx->key.zone); if (zl) { nc->admit_zone = zl->czl.zone; nc->zone_limit_seq = zl->czl.zone_limit_seq; - zl->czl.count++; + atomic_count_inc(&zl->czl.count); } else { nc->admit_zone = INVALID_ZONE; } diff --git a/lib/conntrack.h b/lib/conntrack.h index 9553b188a..58b181834 100644 --- a/lib/conntrack.h +++ b/lib/conntrack.h @@ -108,7 +108,7 @@ struct conntrack_dump { struct conntrack_zone_limit { int32_t zone; uint32_t limit; - uint32_t count; + atomic_count count; uint32_t zone_limit_seq; /* Used to disambiguate zone limit counts. */ }; diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4381c618f..9d9767b2c 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8193,7 +8193,8 @@ dpif_netdev_ct_get_limits(struct dpif *dpif OVS_UNUSED, czl = zone_limit_get(dp->conntrack, zone_limit->zone); if (czl.zone == zone_limit->zone || czl.zone == DEFAULT_ZONE) { ct_dpif_push_zone_limit(zone_limits_reply, zone_limit->zone, - czl.limit, czl.count); + czl.limit, + atomic_count_get(&czl.count)); } else { return EINVAL; } @@ -8203,7 +8204,7 @@ dpif_netdev_ct_get_limits(struct dpif *dpif OVS_UNUSED, czl = zone_limit_get(dp->conntrack, z); if (czl.zone == z) { ct_dpif_push_zone_limit(zone_limits_reply, z, czl.limit, - czl.count); + atomic_count_get(&czl.count)); } } } From patchwork Wed Feb 17 16:34:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=v+ax+a4f; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=VCQFUnWG; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkB40lptz9sSC for ; Thu, 18 Feb 2021 03:41:16 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 9B2CD86CAB; Wed, 17 Feb 2021 16:41:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 938u8bOEMTzx; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id BC32A86AB1; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A77C2C1DA9; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3A377C013A for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 268F287248 for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g3h8DwI8+USK for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 0781287220 for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 8D833580340; Wed, 17 Feb 2021 11:34:49 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 17 Feb 2021 11:34:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=UvGnotpRSDssd n8yhb637C+8D/+WOfMrJ65XtWdjgUg=; b=v+ax+a4fdEQK4jDzf0bKjtT2IJR4p bNeTnD/7bE8Tcr3kSCUm9rkgMSaq/oZ3BzUkPFYqvUNvUpp7vt2XEaQN9POXuGoz D9hK1WPIDXIHygcMOzyyaapJOaKU1OPZ055uMDWIR70kOy+0nF1127RbEZ4OWxhm fsMduRHtCn7rPp4SG1XgooJIPtwYgP3TVKMoo7SY7GZW3mJP6+jAmuFioX/CzbSC v2dAH89Tmrl/mQRAqPU1awcP6zcuC8vXG7CP6bwcR7JWvUGlIxczvQDcsVl1TobQ yJ6njkyhscDEfMcxTVdzN64huIQtYk2CRH/pd5DuiE8AYhunGu6Xs4fkw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=UvGnotpRSDssdn8yhb637C+8D/+WOfMrJ65XtWdjgUg=; b=VCQFUnWG 7VFcllsY6+RJhDADativjYzjvCyNZWcf9U67LopMg0ZOh6hO39ygJsoYvVIQ2l4n qTTje9MWY2wYNjaBgVFdHBKVfVIw+i/NzdYT/twbHvlfxXGPva+CkAzyiFvrSQHM iBvv5lgNIO7K7yyXbWtTvRk3viN2+0f4+NnRg5K11695x+z/wrSzsNyQ1S7VI8Pm Uzkfe1Swwi3FP4OQp62PggORV2n2p9vub/7mBFiw/7+XPjpqP37ym6NVpV1xKg2d nK9cCQUTGZndJj+zWbhvxfJi7EowqTpJ6+vpV+8014rZPVOOBAJqzPlX3tcfRCsa 9Ab0azCNP2xpPw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgepudenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id AC009240065; Wed, 17 Feb 2021 11:34:48 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:37 +0100 Message-Id: X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 3/9] conntrack: Init hash basis first at creation X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The 'hash_basis' field is used sometimes during sub-systems init routine. It will be 0 by default before randomization. Sub-systems would then init some nodes with incorrect hash values. The timeout policies module is affected, making the default policy being referenced using an incorrect hash value. Fixes: 2078901a4c14 ("userspace: Add conntrack timeout policy support.") Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein Acked-by: William Tu --- lib/conntrack.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index c218200dc..8062dcd6b 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -291,6 +291,11 @@ conntrack_init(void) static struct ovsthread_once setup_l4_once = OVSTHREAD_ONCE_INITIALIZER; struct conntrack *ct = xzalloc(sizeof *ct); + /* This value can be used during init (e.g. timeout_policy_init()), + * set it first to ensure it is available. + */ + ct->hash_basis = random_uint32(); + ovs_rwlock_init(&ct->resources_lock); ovs_rwlock_wrlock(&ct->resources_lock); hmap_init(&ct->alg_expectations); @@ -308,7 +313,6 @@ conntrack_init(void) timeout_policy_init(ct); ovs_mutex_unlock(&ct->ct_lock); - ct->hash_basis = random_uint32(); atomic_count_init(&ct->n_conn, 0); atomic_init(&ct->n_conn_limit, DEFAULT_N_CONN_LIMIT); atomic_init(&ct->tcp_seq_chk, true); From patchwork Wed Feb 17 16:34:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=AgGC6O85; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=Vg0F+DnU; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkBK39cmz9sSC for ; Thu, 18 Feb 2021 03:41:29 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C7F2886E77; Wed, 17 Feb 2021 16:41:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UqxKsmevREIQ; Wed, 17 Feb 2021 16:41:15 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id F268A86CF6; Wed, 17 Feb 2021 16:41:14 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DA966C1E70; Wed, 17 Feb 2021 16:41:14 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3FA02C0893 for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 3C4BE87220 for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D5q2BOp+M1cE for ; Wed, 17 Feb 2021 16:41:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 5EB888723F for ; Wed, 17 Feb 2021 16:41:09 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id 9C973580341; Wed, 17 Feb 2021 11:34:50 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Feb 2021 11:34:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=9K8sFrTQTdp51 h8VO4MTIqNqbUBM2cYSA36edrKyLqs=; b=AgGC6O85MTVN/bDQ1TjiCpfKf/5Rb Pix/gXG6QJwrIvzsBb60NX86HeAnbLBr3htT87ugr2/OmagAZbGu1o/jvoukzkLO HpCJXJT2MHf1TiNL/KmsCyVM/xsf/Nrga+ELAixFxr++0T1ClU7Y7iV2yye0fVIL 4NROI2ZzoFpHywK02NT5aV41k9KbrULRixqzPcCDW7eOrcA+CfFBni/DuGb9sb2H xq81qdtrsAqnbZeU+8oo5FUf+Zo7nNQnkLByFDyv1bdCNJqfCkrYI1f74hfKdsPj yVYJvqaJH8fwFR8+Re94c0PfrWKl5ag1ly90C3OAXg5EONrLW5qzWdlzQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=9K8sFrTQTdp51h8VO4MTIqNqbUBM2cYSA36edrKyLqs=; b=Vg0F+DnU fhCRjRZBYcq8RjaJjy1qgb6mpw2ESuzGERUhartADXG054PoPeLiEAHFuYz4cDFM XzYHUkFCEouDaobcygSd0gj173PwLiQG1/nJ1SBeYfLx5S6bxhcyz7UYsa9sLLGh PRDOliCBVYLs4U6s/wrZxj/V5Qh2XM8AGkwCXojFjRXl8pPc9TngtB0fpcKAQuC3 38St5P0DBx0qPrSlUdXRgpw225gjWOKGs0Cp8BjohmQNs5q71W2RjOEKIc7RqTIk hM3YYKArnc5ZkiVrC6vN+3tglJZv9S4tI2nJnRciNhlnwAKMx6JtuPWhyny4Nkqt 3cXMrEf4Q4M+VA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 89B67240067; Wed, 17 Feb 2021 11:34:49 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:38 +0100 Message-Id: <925ea2f1d48fccebe46952092562d585083009b0.1613557616.git.grive@u256.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 4/9] conntrack-tp: Use a cmap to store timeout policies X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Multiple lookups are done to stored timeout policies, each time blocking the global 'ct_lock'. This is usually not necessary and it should be acceptable to get policy updates slightly delayed (by one RCU sync at most). Using a CMAP reduces multiple lock taking and releasing in the connection insertion path. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein Acked-by: William Tu --- lib/conntrack-private.h | 2 +- lib/conntrack-tp.c | 54 +++++++++++++++++++++++------------------ lib/conntrack.c | 9 ++++--- lib/conntrack.h | 2 +- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/conntrack-private.h b/lib/conntrack-private.h index f2cbf657e..7eb555092 100644 --- a/lib/conntrack-private.h +++ b/lib/conntrack-private.h @@ -177,7 +177,7 @@ struct conntrack { struct cmap conns OVS_GUARDED; struct rculist exp_lists[N_CT_TM] OVS_GUARDED; struct cmap zone_limits OVS_GUARDED; - struct hmap timeout_policies OVS_GUARDED; + struct cmap timeout_policies OVS_GUARDED; uint32_t hash_basis; /* Salt for hashing a connection key. */ pthread_t clean_thread; /* Periodically cleans up connection tracker. */ struct latch clean_thread_exit; /* To destroy the 'clean_thread'. */ diff --git a/lib/conntrack-tp.c b/lib/conntrack-tp.c index 30ba4bda8..a376857ec 100644 --- a/lib/conntrack-tp.c +++ b/lib/conntrack-tp.c @@ -47,14 +47,15 @@ static unsigned int ct_dpif_netdev_tp_def[] = { }; static struct timeout_policy * -timeout_policy_lookup(struct conntrack *ct, int32_t tp_id) +timeout_policy_lookup_protected(struct conntrack *ct, int32_t tp_id) OVS_REQUIRES(ct->ct_lock) { struct timeout_policy *tp; uint32_t hash; hash = hash_int(tp_id, ct->hash_basis); - HMAP_FOR_EACH_IN_BUCKET (tp, node, hash, &ct->timeout_policies) { + CMAP_FOR_EACH_WITH_HASH_PROTECTED (tp, node, hash, + &ct->timeout_policies) { if (tp->policy.id == tp_id) { return tp; } @@ -62,20 +63,25 @@ timeout_policy_lookup(struct conntrack *ct, int32_t tp_id) return NULL; } -struct timeout_policy * -timeout_policy_get(struct conntrack *ct, int32_t tp_id) +static struct timeout_policy * +timeout_policy_lookup(struct conntrack *ct, int32_t tp_id) { struct timeout_policy *tp; + uint32_t hash; - ovs_mutex_lock(&ct->ct_lock); - tp = timeout_policy_lookup(ct, tp_id); - if (!tp) { - ovs_mutex_unlock(&ct->ct_lock); - return NULL; + hash = hash_int(tp_id, ct->hash_basis); + CMAP_FOR_EACH_WITH_HASH (tp, node, hash, &ct->timeout_policies) { + if (tp->policy.id == tp_id) { + return tp; + } } + return NULL; +} - ovs_mutex_unlock(&ct->ct_lock); - return tp; +struct timeout_policy * +timeout_policy_get(struct conntrack *ct, int32_t tp_id) +{ + return timeout_policy_lookup(ct, tp_id); } static void @@ -125,27 +131,30 @@ timeout_policy_create(struct conntrack *ct, init_default_tp(tp, tp_id); update_existing_tp(tp, new_tp); hash = hash_int(tp_id, ct->hash_basis); - hmap_insert(&ct->timeout_policies, &tp->node, hash); + cmap_insert(&ct->timeout_policies, &tp->node, hash); } static void timeout_policy_clean(struct conntrack *ct, struct timeout_policy *tp) OVS_REQUIRES(ct->ct_lock) { - hmap_remove(&ct->timeout_policies, &tp->node); - free(tp); + uint32_t hash = hash_int(tp->policy.id, ct->hash_basis); + cmap_remove(&ct->timeout_policies, &tp->node, hash); + ovsrcu_postpone(free, tp); } static int -timeout_policy_delete__(struct conntrack *ct, uint32_t tp_id) +timeout_policy_delete__(struct conntrack *ct, uint32_t tp_id, + bool warn_on_error) OVS_REQUIRES(ct->ct_lock) { + struct timeout_policy *tp; int err = 0; - struct timeout_policy *tp = timeout_policy_lookup(ct, tp_id); + tp = timeout_policy_lookup_protected(ct, tp_id); if (tp) { timeout_policy_clean(ct, tp); - } else { + } else if (warn_on_error) { VLOG_WARN_RL(&rl, "Failed to delete a non-existent timeout " "policy: id=%d", tp_id); err = ENOENT; @@ -159,7 +168,7 @@ timeout_policy_delete(struct conntrack *ct, uint32_t tp_id) int err; ovs_mutex_lock(&ct->ct_lock); - err = timeout_policy_delete__(ct, tp_id); + err = timeout_policy_delete__(ct, tp_id, true); ovs_mutex_unlock(&ct->ct_lock); return err; } @@ -170,7 +179,7 @@ timeout_policy_init(struct conntrack *ct) { struct timeout_policy tp; - hmap_init(&ct->timeout_policies); + cmap_init(&ct->timeout_policies); /* Create default timeout policy. */ memset(&tp, 0, sizeof tp); @@ -182,14 +191,11 @@ int timeout_policy_update(struct conntrack *ct, struct timeout_policy *new_tp) { - int err = 0; uint32_t tp_id = new_tp->policy.id; + int err = 0; ovs_mutex_lock(&ct->ct_lock); - struct timeout_policy *tp = timeout_policy_lookup(ct, tp_id); - if (tp) { - err = timeout_policy_delete__(ct, tp_id); - } + timeout_policy_delete__(ct, tp_id, false); timeout_policy_create(ct, new_tp); ovs_mutex_unlock(&ct->ct_lock); return err; diff --git a/lib/conntrack.c b/lib/conntrack.c index 8062dcd6b..06b18f9fa 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -539,10 +539,13 @@ conntrack_destroy(struct conntrack *ct) cmap_destroy(&ct->zone_limits); struct timeout_policy *tp; - HMAP_FOR_EACH_POP (tp, node, &ct->timeout_policies) { - free(tp); + CMAP_FOR_EACH (tp, node, &ct->timeout_policies) { + uint32_t hash = hash_int(tp->policy.id, ct->hash_basis); + + cmap_remove(&ct->timeout_policies, &tp->node, hash); + ovsrcu_postpone(free, tp); } - hmap_destroy(&ct->timeout_policies); + cmap_destroy(&ct->timeout_policies); ovs_mutex_unlock(&ct->ct_lock); ovs_mutex_destroy(&ct->ct_lock); diff --git a/lib/conntrack.h b/lib/conntrack.h index 58b181834..b064abc9f 100644 --- a/lib/conntrack.h +++ b/lib/conntrack.h @@ -113,7 +113,7 @@ struct conntrack_zone_limit { }; struct timeout_policy { - struct hmap_node node; + struct cmap_node node; struct ct_dpif_timeout_policy policy; }; From patchwork Wed Feb 17 16:34:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=t16hdqbB; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=B/tXwqB2; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkC46vg1z9sSC for ; Thu, 18 Feb 2021 03:42:08 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5FC7B86F8F; Wed, 17 Feb 2021 16:42:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1ni5KyJ078Xk; Wed, 17 Feb 2021 16:41:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 5751C86E2D; Wed, 17 Feb 2021 16:41:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 266B1C1DA9; Wed, 17 Feb 2021 16:41:22 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7389DC1DA9 for ; Wed, 17 Feb 2021 16:41:14 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5F63A6F479 for ; Wed, 17 Feb 2021 16:41:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4prWsmYDpO00 for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: by smtp3.osuosl.org (Postfix, from userid 1001) id F24996F5DB; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4CD046F479 for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 77EB3580344; Wed, 17 Feb 2021 11:34:51 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 17 Feb 2021 11:34:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=qbHgIXjh0DMcJ pNeH8TdLy/5JQqA1KqwI4unY/lbOXc=; b=t16hdqbB1SegsCOoI0ptJNKliS/L7 SSaQXzmeDJQxbZfufb5dtRI2W33gxnfXuHkmTLtBoDe1tF9uqN3LYOqSm/Pgqzcm tHga01duQ6ffn7AO6IoauFNHjc0ZFHDX+3CIUY3S5s4ErS8PaBdcrOhpP7SJ8iIt LHwKYU18WzbtnSp8cEt57zi1H12Y9KdvoeXWlDExZztqCu/gb9mkQDAjq+J/Tpow 5tkFRRoH//eHMJwEnK1fYNK1woFpd77scdjHvjCwNvH6YBb04OKOR6y5HPC6aNaa yvIVa+va2s7PP6TCRrqPndnjBB+5FPrlP3rR66ZXER5zptTwW9StTaS8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=qbHgIXjh0DMcJpNeH8TdLy/5JQqA1KqwI4unY/lbOXc=; b=B/tXwqB2 QpyKo4EPT2lBnUT8LjU4UJfgiLRB+hxm54v7dnkFVBNg9TtVPcawWa2C774XEe9E 1hsWYCh+TDUnL6E96qh7MUvDZkJ/guXcNi0V2B+np1HYAB+qjZ9zx51Bi9z7WF2B vnflbbn4mPd6brg8LvTJsCwLpV+3MXHr2B/khMxHL3eS0n/NlkjJtiKzIOyfqW9q DAy43XuYcxpwuM7tPvuSynKiRQWVljEKJnSGhu2stVE8zQhAFyoUQH+Y+PUqNfsw 8g82/tytOgK3zsp/E5Z3K4IlC7JPUSlwPN1m0BWEtbN4FLcR4enerZvtWiSz7vxA NxJW9FI4+XyMwA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgepudenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 63FE424005B; Wed, 17 Feb 2021 11:34:50 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:39 +0100 Message-Id: <8da1b23f2a7bb2b8e216b845ecb022795f9ac7c4.1613557616.git.grive@u256.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 5/9] conntrack: Inverse conn and ct lock precedence X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The lock priority order is for the global 'ct_lock' to be taken first and then 'conn->lock'. This is an issue, as multiple operations on connections are thus blocked between threads contending on the global 'ct_lock'. This was previously necessary due to how the expiration lists, timeout policies and zone limits were managed. They are now using RCU-friendly structures that allow concurrent readers. The mutual exclusion now only needs to happen during writes. This allows reducing the 'ct_lock' precedence, and to only take it when writing the relevant structures. This will reduce contention on 'ct_lock', which impairs scalability when the connection tracker is used by many threads. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein --- lib/conntrack-private.h | 16 +++++++++--- lib/conntrack-tp.c | 29 ++++++--------------- lib/conntrack.c | 58 +++++++++++++++++++++++++---------------- 3 files changed, 57 insertions(+), 46 deletions(-) diff --git a/lib/conntrack-private.h b/lib/conntrack-private.h index 7eb555092..e8ffb5bf9 100644 --- a/lib/conntrack-private.h +++ b/lib/conntrack-private.h @@ -140,6 +140,9 @@ struct conn { struct nat_action_info_t *nat_info; char *alg; struct conn *nat_conn; /* The NAT 'conn' context, if there is one. */ + atomic_flag reclaimed; /* False during the lifetime of the connection, + * True as soon as a thread has started freeing + * its memory. */ /* Mutable data. */ struct ovs_mutex lock; /* Guards all mutable fields. */ @@ -200,8 +203,8 @@ struct conntrack { }; /* Lock acquisition order: - * 1. 'ct_lock' - * 2. 'conn->lock' + * 1. 'conn->lock' + * 2. 'ct_lock' * 3. 'resources_lock' */ @@ -222,11 +225,18 @@ struct ct_l4_proto { }; static inline void -conn_expire_remove(struct conn_expire *exp) +conn_expire_remove(struct conn_expire *exp, bool need_ct_lock) + OVS_NO_THREAD_SAFETY_ANALYSIS { if (!atomic_flag_test_and_set(&exp->remove_once) && rculist_next(&exp->node)) { + if (need_ct_lock) { + ovs_mutex_lock(&exp->ct->ct_lock); + } rculist_remove(&exp->node); + if (need_ct_lock) { + ovs_mutex_unlock(&exp->ct->ct_lock); + } } } diff --git a/lib/conntrack-tp.c b/lib/conntrack-tp.c index a376857ec..01ffa30df 100644 --- a/lib/conntrack-tp.c +++ b/lib/conntrack-tp.c @@ -238,6 +238,7 @@ tm_to_ct_dpif_tp(enum ct_timeout tm) static void conn_expire_init(struct conn *conn, struct conntrack *ct) + OVS_REQUIRES(conn->lock) { struct conn_expire *exp = &conn->exp; @@ -257,20 +258,22 @@ conn_expire_insert(struct conn *conn) { struct conn_expire *exp = &conn->exp; - ovs_mutex_lock(&exp->ct->ct_lock); ovs_mutex_lock(&conn->lock); + ovs_mutex_lock(&exp->ct->ct_lock); rculist_push_back(&exp->ct->exp_lists[exp->tm], &exp->node); + ovs_mutex_unlock(&exp->ct->ct_lock); + atomic_flag_clear(&exp->insert_once); atomic_flag_clear(&exp->remove_once); ovs_mutex_unlock(&conn->lock); - ovs_mutex_unlock(&exp->ct->ct_lock); } static void conn_schedule_expiration(struct conntrack *ct, struct conn *conn, enum ct_timeout tm, long long now, uint32_t tp_value) + OVS_REQUIRES(conn->lock) { conn_expire_init(conn, ct); conn->expiration = now + tp_value * 1000; @@ -285,19 +288,12 @@ conn_update_expiration__(struct conntrack *ct, struct conn *conn, enum ct_timeout tm, long long now, uint32_t tp_value) OVS_REQUIRES(conn->lock) + OVS_EXCLUDED(ct->ct_lock) { - ovs_mutex_unlock(&conn->lock); - - ovs_mutex_lock(&ct->ct_lock); - ovs_mutex_lock(&conn->lock); if (!conn->cleaned) { - conn_expire_remove(&conn->exp); + conn_expire_remove(&conn->exp, true); conn_schedule_expiration(ct, conn, tm, now, tp_value); } - ovs_mutex_unlock(&conn->lock); - ovs_mutex_unlock(&ct->ct_lock); - - ovs_mutex_lock(&conn->lock); } /* The conn entry lock must be held on entry and exit. */ @@ -309,20 +305,12 @@ conn_update_expiration(struct conntrack *ct, struct conn *conn, struct timeout_policy *tp; uint32_t val; - ovs_mutex_unlock(&conn->lock); - - ovs_mutex_lock(&ct->ct_lock); - ovs_mutex_lock(&conn->lock); tp = timeout_policy_lookup(ct, conn->tp_id); if (tp) { val = tp->policy.attrs[tm_to_ct_dpif_tp(tm)]; } else { val = ct_dpif_netdev_tp_def[tm_to_ct_dpif_tp(tm)]; } - ovs_mutex_unlock(&conn->lock); - ovs_mutex_unlock(&ct->ct_lock); - - ovs_mutex_lock(&conn->lock); VLOG_DBG_RL(&rl, "Update timeout %s zone=%u with policy id=%d " "val=%u sec.", ct_timeout_str[tm], conn->key.zone, conn->tp_id, val); @@ -330,11 +318,10 @@ conn_update_expiration(struct conntrack *ct, struct conn *conn, conn_update_expiration__(ct, conn, tm, now, val); } -/* ct_lock must be held. */ void conn_init_expiration(struct conntrack *ct, struct conn *conn, enum ct_timeout tm, long long now) - OVS_REQUIRES(ct->ct_lock) + OVS_REQUIRES(conn->lock) { struct timeout_policy *tp; uint32_t val; diff --git a/lib/conntrack.c b/lib/conntrack.c index 06b18f9fa..5aad64994 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -465,7 +465,7 @@ zone_limit_delete(struct conntrack *ct, uint16_t zone) static void conn_clean_cmn(struct conntrack *ct, struct conn *conn) - OVS_REQUIRES(ct->ct_lock) + OVS_REQUIRES(conn->lock, ct->ct_lock) { if (conn->alg) { expectation_clean(ct, &conn->key); @@ -484,32 +484,52 @@ conn_clean_cmn(struct conntrack *ct, struct conn *conn) * removes the associated nat 'conn' from the lookup datastructures. */ static void conn_clean(struct conntrack *ct, struct conn *conn) - OVS_REQUIRES(ct->ct_lock) + OVS_EXCLUDED(conn->lock, ct->ct_lock) { ovs_assert(conn->conn_type == CT_CONN_TYPE_DEFAULT); + if (atomic_flag_test_and_set(&conn->reclaimed)) { + return; + } + + ovs_mutex_lock(&conn->lock); + ovs_mutex_lock(&ct->ct_lock); + conn_clean_cmn(ct, conn); if (conn->nat_conn) { uint32_t hash = conn_key_hash(&conn->nat_conn->key, ct->hash_basis); cmap_remove(&ct->conns, &conn->nat_conn->cm_node, hash); } - conn_expire_remove(&conn->exp); + conn_expire_remove(&conn->exp, false); conn->cleaned = true; ovsrcu_postpone(delete_conn, conn); atomic_count_dec(&ct->n_conn); + + ovs_mutex_unlock(&ct->ct_lock); + ovs_mutex_unlock(&conn->lock); } static void conn_clean_one(struct conntrack *ct, struct conn *conn) - OVS_REQUIRES(ct->ct_lock) + OVS_EXCLUDED(conn->lock, ct->ct_lock) { + if (atomic_flag_test_and_set(&conn->reclaimed)) { + return; + } + + ovs_mutex_lock(&conn->lock); + ovs_mutex_lock(&ct->ct_lock); + conn_clean_cmn(ct, conn); if (conn->conn_type == CT_CONN_TYPE_DEFAULT) { - conn_expire_remove(&conn->exp); + conn_expire_remove(&conn->exp, false); conn->cleaned = true; atomic_count_dec(&ct->n_conn); } ovsrcu_postpone(delete_conn_one, conn); + + ovs_mutex_unlock(&ct->ct_lock); + ovs_mutex_unlock(&conn->lock); } /* Destroys the connection tracker 'ct' and frees all the allocated memory. @@ -523,10 +543,12 @@ conntrack_destroy(struct conntrack *ct) pthread_join(ct->clean_thread, NULL); latch_destroy(&ct->clean_thread_exit); - ovs_mutex_lock(&ct->ct_lock); CMAP_FOR_EACH (conn, cm_node, &ct->conns) { conn_clean_one(ct, conn); } + + ovs_mutex_lock(&ct->ct_lock); + cmap_destroy(&ct->conns); struct zone_limit *zl; @@ -1002,7 +1024,6 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, const struct nat_action_info_t *nat_action_info, const char *helper, const struct alg_exp_node *alg_exp, enum ct_alg_ctl_type ct_alg_ctl, uint32_t tp_id) - OVS_REQUIRES(ct->ct_lock) { struct conn *nc = NULL; struct conn *nat_conn = NULL; @@ -1076,18 +1097,24 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, nat_packet(pkt, nc, ctx->icmp_related); memcpy(&nat_conn->key, &nc->rev_key, sizeof nat_conn->key); memcpy(&nat_conn->rev_key, &nc->key, sizeof nat_conn->rev_key); + ovs_mutex_init_adaptive(&nat_conn->lock); nat_conn->conn_type = CT_CONN_TYPE_UN_NAT; nat_conn->nat_info = NULL; nat_conn->alg = NULL; nat_conn->nat_conn = NULL; uint32_t nat_hash = conn_key_hash(&nat_conn->key, ct->hash_basis); + ovs_mutex_lock(&ct->ct_lock); cmap_insert(&ct->conns, &nat_conn->cm_node, nat_hash); + ovs_mutex_unlock(&ct->ct_lock); } nc->nat_conn = nat_conn; ovs_mutex_init_adaptive(&nc->lock); nc->conn_type = CT_CONN_TYPE_DEFAULT; + atomic_flag_clear(&nc->reclaimed); + ovs_mutex_lock(&ct->ct_lock); cmap_insert(&ct->conns, &nc->cm_node, ctx->hash); + ovs_mutex_unlock(&ct->ct_lock); atomic_count_inc(&ct->n_conn); ctx->conn = nc; /* For completeness. */ @@ -1110,7 +1137,7 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, * can limit DoS impact. */ nat_res_exhaustion: free(nat_conn); - conn_expire_remove(&nc->exp); + conn_expire_remove(&nc->exp, false); ovsrcu_postpone(delete_conn_cmn, nc); static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 5); VLOG_WARN_RL(&rl, "Unable to NAT due to tuple space exhaustion - " @@ -1150,11 +1177,9 @@ conn_update_state(struct conntrack *ct, struct dp_packet *pkt, pkt->md.ct_state = CS_INVALID; break; case CT_UPDATE_NEW: - ovs_mutex_lock(&ct->ct_lock); if (conn_lookup(ct, &conn->key, now, NULL, NULL)) { conn_clean(ct, conn); } - ovs_mutex_unlock(&ct->ct_lock); create_new_conn = true; break; case CT_UPDATE_VALID_NEW: @@ -1336,11 +1361,9 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, /* Delete found entry if in wrong direction. 'force' implies commit. */ if (OVS_UNLIKELY(force && ctx->reply && conn)) { - ovs_mutex_lock(&ct->ct_lock); if (conn_lookup(ct, &conn->key, now, NULL, NULL)) { conn_clean(ct, conn); } - ovs_mutex_unlock(&ct->ct_lock); conn = NULL; } @@ -1404,12 +1427,10 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, } ovs_rwlock_unlock(&ct->resources_lock); - ovs_mutex_lock(&ct->ct_lock); if (!conn_lookup(ct, &ctx->key, now, NULL, NULL)) { conn = conn_not_found(ct, pkt, ctx, commit, now, nat_action_info, helper, alg_exp, ct_alg_ctl, tp_id); } - ovs_mutex_unlock(&ct->ct_lock); } write_ct_md(pkt, zone, conn, &ctx->key, alg_exp); @@ -1532,8 +1553,6 @@ ct_sweep(struct conntrack *ct, long long now, size_t limit) long long min_expiration = LLONG_MAX; size_t count = 0; - ovs_mutex_lock(&ct->ct_lock); - for (unsigned i = 0; i < N_CT_TM; i++) { RCULIST_FOR_EACH (conn, exp.node, &ct->exp_lists[i]) { ovs_mutex_lock(&conn->lock); @@ -1557,7 +1576,6 @@ ct_sweep(struct conntrack *ct, long long now, size_t limit) out: VLOG_DBG("conntrack cleanup %"PRIuSIZE" entries in %lld msec", count, time_msec() - now); - ovs_mutex_unlock(&ct->ct_lock); return min_expiration; } @@ -2606,13 +2624,11 @@ conntrack_flush(struct conntrack *ct, const uint16_t *zone) { struct conn *conn; - ovs_mutex_lock(&ct->ct_lock); CMAP_FOR_EACH (conn, cm_node, &ct->conns) { if (!zone || *zone == conn->key.zone) { conn_clean_one(ct, conn); } } - ovs_mutex_unlock(&ct->ct_lock); return 0; } @@ -2627,9 +2643,8 @@ conntrack_flush_tuple(struct conntrack *ct, const struct ct_dpif_tuple *tuple, memset(&key, 0, sizeof(key)); tuple_to_conn_key(tuple, zone, &key); - ovs_mutex_lock(&ct->ct_lock); - conn_lookup(ct, &key, time_msec(), &conn, NULL); + conn_lookup(ct, &key, time_msec(), &conn, NULL); if (conn && conn->conn_type == CT_CONN_TYPE_DEFAULT) { conn_clean(ct, conn); } else { @@ -2637,7 +2652,6 @@ conntrack_flush_tuple(struct conntrack *ct, const struct ct_dpif_tuple *tuple, error = ENOENT; } - ovs_mutex_unlock(&ct->ct_lock); return error; } From patchwork Wed Feb 17 16:34:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=ClpuwGxn; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=msvXGhAn; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkBK64zcz9sVF for ; Thu, 18 Feb 2021 03:41:29 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 5EF71872C8; Wed, 17 Feb 2021 16:41:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xaOq05ddBID9; Wed, 17 Feb 2021 16:41:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 93FD8872CC; Wed, 17 Feb 2021 16:41:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6B12DC1E74; Wed, 17 Feb 2021 16:41:23 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 09843C1E6F for ; Wed, 17 Feb 2021 16:41:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E567E6F5C6 for ; Wed, 17 Feb 2021 16:41:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S5M870A3hDjY for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) Received: by smtp3.osuosl.org (Postfix, from userid 1001) id C29EA6F52B; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4D2E26F60A for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 0899E580346; Wed, 17 Feb 2021 11:34:52 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 17 Feb 2021 11:34:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=trAAoBQ+Q0snr RO5hLaQTtHIf6aJB8ts+36RrLPFR5A=; b=ClpuwGxnAtGjR/Ldfx9RfJh9DM76f PykJ8G//vTdYySH2jbsrGlHVE/WpTH4hQHFwT1+6y9R4t4uc9r0Jcz+CgNzMS9+y nLJrvvzahSuqddHT7pZAn2pUKTVu7dYOV6WS/lg+lWJ5QrIHwNNmt3dTmLQDqSTm 8c5dg6oVV2QW4dnQrKQCTCvKaiSwqJ/qM5v0Dymuo3wDEN2ikwerzCdYMMPlzOIA lSfwCCFeEKaA+uBGqL0oQaEfkrNM4wIrYvWtVBsllESZesbwLw4sXVpQrlBi8fEk tIPUDC255zgsppdA5uL8cBqSb4PZoUSiDD5PkkDjqXzenNus8eloJB5kg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=trAAoBQ+Q0snrRO5hLaQTtHIf6aJB8ts+36RrLPFR5A=; b=msvXGhAn P0T/Nq6RlXgffLn9Bl0n64pAz5TjKpb/VMrHoHmF3hX1Viu4nuWJw2iVBH6xp+4M zXzypi44W1ogwWowCPju7i/6b5LW3I9jDS5dq4DrGr0cz3NnQ2fdFgyeMzrYK2V6 R7LlkVpsEvMWtIcTvHGLgLPhNMNG7z9J2Q+ywDzKt8C9QRr8d7CoUCETbGLkV322 nXRvl0JzHV8dzxYkbWIa9BgEZm/agB4GTsVSpCasnOZySW8uch4pF6oC7OMsU6om cqErjmRBZ9qETm0pd3e1vRJmj/Hs9oEJSbK92UbZtD2Kik2wY5IwBVdZxdCQST4Q G8vXAAnRRuHBkQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgepudenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 3D7B8240067; Wed, 17 Feb 2021 11:34:51 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:40 +0100 Message-Id: <397eadf064f25300cc1833f159ce77205c7d9efe.1613557616.git.grive@u256.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 6/9] conntrack: Do not schedule zero ms timers X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When ct_sweep() is far behind on its work, the 'next_wake' returned can be before the moment it started. When it happens, the thread schedules a zero ms timer that is logged as an error. Instead, mark the thread for immediate wake in the next poll_block(). Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein --- lib/conntrack.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/conntrack.c b/lib/conntrack.c index 5aad64994..71f79a790 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -1628,6 +1628,8 @@ clean_thread_main(void *f_) next_wake = conntrack_clean(ct, now); if (next_wake < now) { + poll_immediate_wake(); + } else if (next_wake < now + CT_CLEAN_MIN_INTERVAL) { poll_timer_wait_until(now + CT_CLEAN_MIN_INTERVAL); } else { poll_timer_wait_until(MAX(next_wake, now + CT_CLEAN_INTERVAL)); From patchwork Wed Feb 17 16:34:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=cYOe4KQ9; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=bv8SHz8V; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkB8210hz9sSC for ; Thu, 18 Feb 2021 03:41:20 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 981918728C; Wed, 17 Feb 2021 16:41:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cgR5SNbbj9pp; Wed, 17 Feb 2021 16:41:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 2E3B887287; Wed, 17 Feb 2021 16:41:16 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 02083C1E70; Wed, 17 Feb 2021 16:41:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id ECD49C013A for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id DBBC287220 for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pVllti7WAk98 for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 078788722D for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id 05576580354; Wed, 17 Feb 2021 11:34:53 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Feb 2021 11:34:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=JBKCdBiltWddo 7iR/30y2wnOBV1Aou8mgeBDRm3M6bI=; b=cYOe4KQ9fRfRloi/C7+WCAHEFCKOU PRA1aO5nabIPjYz1ZzLLKEgUfKUoBMZV8BTUHxnrsrqvcDLqfycx7P/yL1QwqGEr iGpwap8qwMJIqELHfkUevzSszI5kM55gXWuuWgBbuK8vy3kz01Ks5hu1at27FPY6 X36S1Y/KJqpsCCLPbAlHjirPFwpvgPgLSTF+RcV4LN4KXXKXZPc7UORTIogDOBHK bYJZdyydR2u9umBRLJXPCrVnTizc/xs2FC5ev2D5pHkPKBMuvIhIgL3IxU9uhTY+ 62dhEA/WsoPMOi5isDrKHA02UcZTrU8rEfUEqm1rJkXDiHH4wVMN2X6Fw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=JBKCdBiltWddo7iR/30y2wnOBV1Aou8mgeBDRm3M6bI=; b=bv8SHz8V 3cS9EkvO6w5GSZEtujQ3CVUFnxXhyLpa0t0IFJ+fwWWhtwdNbHVpWT552eKAtLAY /tsWbyEcH6gfvi+SyqEN+Bh783W4JvJFsordCb4I3pCEFxGO7Z3b8ZLvh/ks1tjL 6P09eCV11o/hDjwGKzvfMXumfFvkxTjJ92Pat4TkheEkQjoP3iVPakwWQjmXpQAd SOE9zgR1PlLTVYoNfHUTIPPJQtNV1PS4ahbo9SCCBqNllLHQatsBs9etEFp0F/S0 8khhtJO/oxT8r7HjdqOUV4TmrNSG2BralyEDtzWue/QmRS4xXncv9ZhFaVsk12eC FVd01IRJq/XzSA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id 160EF240067; Wed, 17 Feb 2021 11:34:51 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:41 +0100 Message-Id: <3871314632b1a1b09b3d83dad1f73122ee1377ef.1613557616.git.grive@u256.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 7/9] conntrack: Do not rate limit ct-sweep X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The current rate limit is set to allow other threads to update the connections when applicable. This was valid when taking the 'ct_lock' was needed with a global critical section. Now that the size of the critical section for 'ct_lock' is reduced, it is not necessary to rate limit calls to ct_sweep() anymore. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein --- lib/conntrack.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 71f79a790..1b21b79bd 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -1602,20 +1602,12 @@ conntrack_clean(struct conntrack *ct, long long now) * there is an actual connection that expires, or because a new connection * might be created with the minimum timeout). * - * The logic below has two goals: - * - * - We want to reduce the number of wakeups and batch connection cleanup - * when the load is not very high. CT_CLEAN_INTERVAL ensures that if we - * are coping with the current cleanup tasks, then we wait at least - * 5 seconds to do further cleanup. - * - * - We don't want to keep the map locked too long, as we might prevent - * traffic from flowing. CT_CLEAN_MIN_INTERVAL ensures that if cleanup is - * behind, there is at least some 200ms blocks of time when the map will be - * left alone, so the datapath can operate unhindered. + * We want to reduce the number of wakeups and batch connection cleanup + * when the load is not very high. CT_CLEAN_INTERVAL ensures that if we + * are coping with the current cleanup tasks, then we wait at least + * 5 seconds to do further cleanup. */ #define CT_CLEAN_INTERVAL 5000 /* 5 seconds */ -#define CT_CLEAN_MIN_INTERVAL 200 /* 0.2 seconds */ static void * clean_thread_main(void *f_) @@ -1627,12 +1619,10 @@ clean_thread_main(void *f_) long long now = time_msec(); next_wake = conntrack_clean(ct, now); - if (next_wake < now) { - poll_immediate_wake(); - } else if (next_wake < now + CT_CLEAN_MIN_INTERVAL) { - poll_timer_wait_until(now + CT_CLEAN_MIN_INTERVAL); + if (next_wake > now) { + poll_timer_wait_until(MIN(next_wake, now + CT_CLEAN_INTERVAL)); } else { - poll_timer_wait_until(MAX(next_wake, now + CT_CLEAN_INTERVAL)); + poll_immediate_wake(); } latch_wait(&ct->clean_thread_exit); poll_block(); From patchwork Wed Feb 17 16:34:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441288 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=l6wh6gQ7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=uInqIt7F; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkBR543Jz9sSC for ; Thu, 18 Feb 2021 03:41:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3E15486CAC; Wed, 17 Feb 2021 16:41:34 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q0D4OY3obbQR; Wed, 17 Feb 2021 16:41:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 2415E86DB3; Wed, 17 Feb 2021 16:41:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 16B31C1E6F; Wed, 17 Feb 2021 16:41:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3A825C013A for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 36FF487220 for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5F8b+kdnFmFH for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 0871D87239 for ; Wed, 17 Feb 2021 16:41:10 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id A75B4580359; Wed, 17 Feb 2021 11:34:53 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Feb 2021 11:34:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=yy1co82+mvulp qoZGEQP0Dgi0TlxruCYSZUnrnKQiO0=; b=l6wh6gQ7Zl0J2ok1Yv4MLSjuOt3XU +6A9+0m8E9I/9vIUPPjWolWC/dLJF8ppyks1K3Pcsm1YrFgWsDQwt3OcHsINZ7dx ZRNYUbQQIfyWzzMsgE7MdE/lGKxnaxYNykHbwlWjzKtfUkSw9Ew2z/uW7iQ66wfD W0vtVKU8Yns3INyC35Bwd6VHcFKdoUKgBVJijY+y/OuYWhghkQKVPGVTV1e6mp4/ NNVt3oXp9uwAlKLgk02iZS81dZsnrrG+XisLpw1oSPNQpaWMh2a4v/lDq7o+JWKF IeBPz8Q8HB7qlbjdt5jHCi/9Tktu2kSC6uVNCU0Pe2yxkxlBZSPacJ/7Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=yy1co82+mvulpqoZGEQP0Dgi0TlxruCYSZUnrnKQiO0=; b=uInqIt7F D3AbrU4ZE2U+lCGhWZEG8BAf0g+4LEsBmuqgp+XxxbLHwUxBxADUFTx4fSfSqJGL RY1nC+mlcAYmUsr7vbOFhd3GZj4YYZ0J+Xw3yn4IxSWfbbCklEc0HLvH5+3Renz3 MfUsB6pHPuNmaAvCW6nA0R0P09fy0UErrqpEGTc6lg/6GPeMJxknJVYsvy6JfQfG DHr+54ELYXlIB/m4VLyW2bAqpHj+xqNxpfkkyz2dqs4W1QEyX2vIOSC31rMS6oPE pa7GUi0K8EKqdT2o0zVvdmzkd1IDoPnVkr19sh7PVYh5SJXgUoAA41XjNyRWnNsp t8+t+04IcrQbbA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgepfeenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id E3021240065; Wed, 17 Feb 2021 11:34:52 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:42 +0100 Message-Id: <9940347db5b3f2107001b5c0f89630bcfb9c3898.1613557616.git.grive@u256.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 8/9] conntrack: Do not log empty ct-sweep X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Do not add noise to the DBG log for empty sweeps. Only log time taken when some connections were cleaned. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein Acked-by: William Tu --- lib/conntrack.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 1b21b79bd..e042683aa 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -1574,8 +1574,10 @@ ct_sweep(struct conntrack *ct, long long now, size_t limit) } out: - VLOG_DBG("conntrack cleanup %"PRIuSIZE" entries in %lld msec", count, - time_msec() - now); + if (count > 0) { + VLOG_DBG("conntrack cleanup %"PRIuSIZE" entries in %lld msec", count, + time_msec() - now); + } return min_expiration; } From patchwork Wed Feb 17 16:34:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaetan Rivet X-Patchwork-Id: 1441287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=u256.net header.i=@u256.net header.a=rsa-sha256 header.s=fm1 header.b=KNG4zGUx; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm2 header.b=L+DWeMOb; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgkBP2ZMKz9sSC for ; Thu, 18 Feb 2021 03:41:33 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8D44E86EA1; Wed, 17 Feb 2021 16:41:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UZoZ5wojYfqv; Wed, 17 Feb 2021 16:41:25 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 528CA86D72; Wed, 17 Feb 2021 16:41:17 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 32D96C1E6F; Wed, 17 Feb 2021 16:41:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 16D8DC0893 for ; Wed, 17 Feb 2021 16:41:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id EF5CB6F47D for ; Wed, 17 Feb 2021 16:41:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LKtsQ9T2QXA8 for ; Wed, 17 Feb 2021 16:41:11 +0000 (UTC) Received: by smtp3.osuosl.org (Postfix, from userid 1001) id E1ECA6F5E0; Wed, 17 Feb 2021 16:41:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com [66.111.4.230]) by smtp3.osuosl.org (Postfix) with ESMTPS id 990BA6F52B for ; Wed, 17 Feb 2021 16:41:09 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailnew.nyi.internal (Postfix) with ESMTP id B8B5458036C; Wed, 17 Feb 2021 11:34:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Feb 2021 11:34:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u256.net; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=yu1xVdPdKGzja hDmvT+2FmUN1U2iZMxoC5ExU4er38s=; b=KNG4zGUxocsIzcuJe/Ciedlyu46YK UOVkTMA2i7XY1FDF+da7doB0w1W6wqoiZkwlhAo9WHmnbvdMwKuPOY6nnfKLzbN1 s2Q9Ea1FM7pz9j3yWsrjlqDrWk/0dV5UJJuSGOpoj6Abweh2sZ9RGSA5IK1zcM7S oWsQeKt3FQFZzTyS6U5gs0SrYjvA6AflLFwD6P0qbz7aLVz0gmV8kl5j2iRAHeai PHmn2gNAnBsFOfjhrIcMcqGyUffPX84FdzJrPgCaHl1K2m30a3pm1d/NtoMI4YoG BQabAY7c6c/4PfoDORCdOlph+8hTPO+CD0pH5Kkb3XQFASwqIBCcVD2uQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=yu1xVdPdKGzjahDmvT+2FmUN1U2iZMxoC5ExU4er38s=; b=L+DWeMOb pyenbGZ6UotAeCRAR9kYr3WP2kA4Ohvnj7Ard43yT8xFRNkqszdQSN9l+2YScgx0 aXRNGsCwiC735i7+L3k67M4DUJfCkVN7NhmhwPm5xHEa3/3gzL5tDe+/gek0zmYz nksqwgKjIPUdcfoGYGeYmiyLb4z7l18yHxBP4WebdiB8saK1mlajnaVlTgwstU1F vTvr2/lTw+8NQP7FoIvhDqbKRosBxp1lBaCAX3jgktRtU4DJRkFrjMjpUfmQj2KE WNSkHgP+7YNL09cnPP3o7VdqF4yIuWxdm4gKLaHKCuWeRy0bWfS9ORQPGLn5TK+K lMoL+TlacPZU2Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrjedvgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepifgrvghtrghn ucftihhvvghtuceoghhrihhvvgesuhdvheeirdhnvghtqeenucggtffrrghtthgvrhhnpe ehgfevffekteehteefieefvdehleefjeefheevudetjefhkeeutdekieeuvdetheenucfk phepkeeirddvheegrddvgeefrddugeeinecuvehluhhsthgvrhfuihiivgepfeenucfrrg hrrghmpehmrghilhhfrhhomhepghhrihhvvgesuhdvheeirdhnvght X-ME-Proxy: Received: from inocybe.home (lfbn-poi-1-930-146.w86-254.abo.wanadoo.fr [86.254.243.146]) by mail.messagingengine.com (Postfix) with ESMTPA id BCBBE240065; Wed, 17 Feb 2021 11:34:53 -0500 (EST) From: Gaetan Rivet To: dev@openvswitch.org Date: Wed, 17 Feb 2021 17:34:43 +0100 Message-Id: <97e250478cde86a1bb27cfc3131fd45b5d6de2ca.1613557616.git.grive@u256.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: MIME-Version: 1.0 Cc: Eli Britstein , ameerm@nvidia.com, majd@nvidia.com Subject: [ovs-dev] [PATCH v1 9/9] conntrack: Use an atomic conn expiration value X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" A lock is taken during conn_lookup() to check whether a connection is expired before returning it. This lock can have some contention. Even though this lock ensures a consistent sequence of writes, it does not imply a specific order. A ct_clean thread taking the lock first could read a value that would be updated immediately after by a PMD waiting on the same lock, just as well as the opposite order. As such, the expiration time can be stale anytime it is read. In this context, using an atomic will ensure the same write consistency while keeping the same (lack of) guarantee for reads. Reading the atomic will however be less costly than taking and releasing the lock. Signed-off-by: Gaetan Rivet Reviewed-by: Eli Britstein Acked-by: William Tu --- lib/conntrack-private.h | 2 +- lib/conntrack-tp.c | 2 +- lib/conntrack.c | 25 +++++++++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/conntrack-private.h b/lib/conntrack-private.h index e8ffb5bf9..7f3f8714a 100644 --- a/lib/conntrack-private.h +++ b/lib/conntrack-private.h @@ -148,7 +148,7 @@ struct conn { struct ovs_mutex lock; /* Guards all mutable fields. */ struct conn_expire exp; ovs_u128 label; - long long expiration; + atomic_llong expiration; uint32_t mark; int seq_skew; diff --git a/lib/conntrack-tp.c b/lib/conntrack-tp.c index 01ffa30df..a4ea19c1b 100644 --- a/lib/conntrack-tp.c +++ b/lib/conntrack-tp.c @@ -276,7 +276,7 @@ conn_schedule_expiration(struct conntrack *ct, struct conn *conn, OVS_REQUIRES(conn->lock) { conn_expire_init(conn, ct); - conn->expiration = now + tp_value * 1000; + atomic_store_relaxed(&conn->expiration, now + tp_value * 1000); conn->exp.tm = tm; if (!atomic_flag_test_and_set(&conn->exp.insert_once)) { ovsrcu_postpone(conn_expire_insert, conn); diff --git a/lib/conntrack.c b/lib/conntrack.c index e042683aa..193d550cb 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -99,6 +99,7 @@ static enum ct_update_res conn_update(struct conntrack *ct, struct conn *conn, struct dp_packet *pkt, struct conn_lookup_ctx *ctx, long long now); +static long long int conn_expiration(const struct conn *); static bool conn_expired(struct conn *, long long now); static void set_mark(struct dp_packet *, struct conn *, uint32_t val, uint32_t mask); @@ -1555,10 +1556,8 @@ ct_sweep(struct conntrack *ct, long long now, size_t limit) for (unsigned i = 0; i < N_CT_TM; i++) { RCULIST_FOR_EACH (conn, exp.node, &ct->exp_lists[i]) { - ovs_mutex_lock(&conn->lock); - if (now < conn->expiration || count >= limit) { - min_expiration = MIN(min_expiration, conn->expiration); - ovs_mutex_unlock(&conn->lock); + if (!conn_expired(conn, now) || count >= limit) { + min_expiration = MIN(min_expiration, conn_expiration(conn)); if (count >= limit) { /* Do not check other lists. */ COVERAGE_INC(conntrack_long_cleanup); @@ -1566,7 +1565,6 @@ ct_sweep(struct conntrack *ct, long long now, size_t limit) } break; } else { - ovs_mutex_unlock(&conn->lock); conn_clean(ct, conn); } count++; @@ -2395,14 +2393,21 @@ conn_update(struct conntrack *ct, struct conn *conn, struct dp_packet *pkt, return update_res; } +static long long int +conn_expiration(const struct conn *conn) +{ + long long int expiration; + + atomic_read_relaxed(&CONST_CAST(struct conn *, conn)->expiration, + &expiration); + return expiration; +} + static bool conn_expired(struct conn *conn, long long now) { if (conn->conn_type == CT_CONN_TYPE_DEFAULT) { - ovs_mutex_lock(&conn->lock); - bool expired = now >= conn->expiration ? true : false; - ovs_mutex_unlock(&conn->lock); - return expired; + return now >= conn_expiration(conn); } return false; } @@ -2545,7 +2550,7 @@ conn_to_ct_dpif_entry(const struct conn *conn, struct ct_dpif_entry *entry, entry->mark = conn->mark; memcpy(&entry->labels, &conn->label, sizeof entry->labels); - long long expiration = conn->expiration - now; + long long expiration = conn_expiration(conn) - now; struct ct_l4_proto *class = l4_protos[conn->key.nw_proto]; if (class->conn_get_protoinfo) {