From patchwork Tue Mar 5 13:46:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng Li X-Patchwork-Id: 1908278 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tpxxm6HfJz23cw for ; Wed, 6 Mar 2024 00:59:08 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 535EB60E3A; Tue, 5 Mar 2024 13:59:06 +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 Zw5iRoLeZJ4e; Tue, 5 Mar 2024 13:59:04 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 62E3E60E2B Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 62E3E60E2B; Tue, 5 Mar 2024 13:59:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5271EC0077; Tue, 5 Mar 2024 13:59:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3A40AC0037 for ; Tue, 5 Mar 2024 13:59:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 23256415E7 for ; Tue, 5 Mar 2024 13:59:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BFwcBylC2fY1 for ; Tue, 5 Mar 2024 13:59:02 +0000 (UTC) X-Greylist: delayed 702 seconds by postgrey-1.37 at util1.osuosl.org; Tue, 05 Mar 2024 13:59:00 UTC DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 3432041602 Authentication-Results: smtp4.osuosl.org; dmarc=none (p=none dis=none) header.from=chinatelecom.cn DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 3432041602 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=182.42.158.78; helo=chinatelecom.cn; envelope-from=lic121@chinatelecom.cn; receiver= Received: from chinatelecom.cn (smtpnm6-04.21cn.com [182.42.158.78]) by smtp4.osuosl.org (Postfix) with ESMTP id 3432041602 for ; Tue, 5 Mar 2024 13:59:00 +0000 (UTC) HMM_SOURCE_IP: 192.168.137.232:6294.1410184662 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-118.114.58.94 (unknown [192.168.137.232]) by chinatelecom.cn (HERMES) with SMTP id B90A09BF2E; Tue, 5 Mar 2024 21:47:05 +0800 (CST) X-189-SAVE-TO-SEND: +lic121@chinatelecom.cn Received: from ([118.114.58.94]) by gateway-ssl-dep-77bc75f6c8-dplxv with ESMTP id 7c89ba6ac914456ba8954a3a8b209a79 for dev@openvswitch.org; Tue, 05 Mar 2024 21:47:10 CST X-Transaction-ID: 7c89ba6ac914456ba8954a3a8b209a79 X-Real-From: lic121@chinatelecom.cn X-Receive-IP: 118.114.58.94 X-MEDUSA-Status: 0 From: Cheng Li To: dev@openvswitch.org, grive@u256.net, pvalerio@redhat.com Date: Tue, 5 Mar 2024 13:46:55 +0000 Message-Id: <20240305134655.641196-1-lic121@chinatelecom.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH] conntrack: Do clean instead of forece expire. 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" Force expire a connection and then create new connection of the same tuple(cmap hash). This makes ct->conns cmap operation expensive( within ct->ct_lock). This patch cover the scenario by doing the clean immediately instead of setting expire. Also this patch fix ct_clean debug log. Signed-off-by: Cheng Li --- lib/conntrack.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 8a7056bac..6e137daa6 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -461,12 +461,6 @@ conn_clean(struct conntrack *ct, struct conn *conn) atomic_count_dec(&ct->n_conn); } -static void -conn_force_expire(struct conn *conn) -{ - atomic_store_relaxed(&conn->expiration, 0); -} - /* Destroys the connection tracker 'ct' and frees all the allocated memory. * The caller of this function must already have shut down packet input * and PMD threads (which would have been quiesced). */ @@ -1030,7 +1024,10 @@ conn_update_state(struct conntrack *ct, struct dp_packet *pkt, case CT_UPDATE_NEW: if (conn_lookup(ct, &conn->key_node[CT_DIR_FWD].key, now, NULL, NULL)) { - conn_force_expire(conn); + /* Instead of setting conn->expiration and let ct_clean thread + * clean the conn, doing the clean now to avoid duplicate hash + * in ct->conns for performance reason. */ + conn_clean(ct, conn); } create_new_conn = true; break; @@ -1242,7 +1239,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, if (OVS_UNLIKELY(force && ctx->reply && conn)) { if (conn_lookup(ct, &conn->key_node[CT_DIR_FWD].key, now, NULL, NULL)) { - conn_force_expire(conn); + conn_clean(ct, conn); } conn = NULL; } @@ -1429,7 +1426,8 @@ conntrack_get_sweep_interval(struct conntrack *ct) } static size_t -ct_sweep(struct conntrack *ct, struct rculist *list, long long now) +ct_sweep(struct conntrack *ct, struct rculist *list, long long now, + size_t *cleaned_count) OVS_NO_THREAD_SAFETY_ANALYSIS { struct conn *conn; @@ -1438,6 +1436,7 @@ ct_sweep(struct conntrack *ct, struct rculist *list, long long now) RCULIST_FOR_EACH (conn, node, list) { if (conn_expired(conn, now)) { conn_clean(ct, conn); + (*cleaned_count) ++; } count++; @@ -1454,7 +1453,7 @@ conntrack_clean(struct conntrack *ct, long long now) { long long next_wakeup = now + conntrack_get_sweep_interval(ct); unsigned int n_conn_limit, i; - size_t clean_end, count = 0; + size_t clean_end, count = 0, cleaned_count = 0; atomic_read_relaxed(&ct->n_conn_limit, &n_conn_limit); clean_end = n_conn_limit / 64; @@ -1465,13 +1464,13 @@ conntrack_clean(struct conntrack *ct, long long now) break; } - count += ct_sweep(ct, &ct->exp_lists[i], now); + count += ct_sweep(ct, &ct->exp_lists[i], now, &cleaned_count); } ct->next_sweep = (i < N_EXP_LISTS) ? i : 0; - VLOG_DBG("conntrack cleanup %"PRIuSIZE" entries in %lld msec", count, - time_msec() - now); + VLOG_DBG("conntrack cleanup %"PRIuSIZE"/%"PRIuSIZE" entries in %lld msec", + cleaned_count, count, time_msec() - now); return next_wakeup; }