From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A116DA0544; Fri, 30 Dec 2022 05:25:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 507D540DD8; Fri, 30 Dec 2022 05:25:33 +0100 (CET) Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by mails.dpdk.org (Postfix) with ESMTP id D0C344067B; Fri, 30 Dec 2022 05:25:31 +0100 (CET) Received: by mail-pj1-f47.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso24848325pjt.0; Thu, 29 Dec 2022 20:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mJLr5YV7tS4c2FAmTXMr6Q6B67kX969+8vHMOMXqn3g=; b=BbIvq6pYpIEvv6b0TXZYXWnOi7p5kZxnKgjSOMxwJFtz74MApl3GJTeQMM9wiNJOMa gkUbDIhGT6wtRNQl0sbtgRFCMFQl1PhescfFlTnBlut9VEVq7WMi0lYOr6OuQ2djs3jJ 73s2C2HjWiuxemHtFIJg10LhjVYxYkSy4/MSrdB8NpLMqs0gUYYOAGufBqTWCuBtM/7S FubPeOBZi0Cpc/A9eQTqoXPjlGjOdQdm8DJOrunR3U0bLugMPriLu14U3YBexibni4ij DWGV7hVJnL/DzD/3lhJ9uBymxvxKCEBbPdSI56OHDRqBKwQIOQ0R05SZCUJK0h00rDD7 fxaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mJLr5YV7tS4c2FAmTXMr6Q6B67kX969+8vHMOMXqn3g=; b=W+q6u7m2S6rLPOaXcPsqqGdBp1w5NYDBzUmgZi3j+ahU9GENMZed+I2ZZyKNz7KSY3 VzUc24QDbOiLeGkCFi9loO//LNo8VfXB205Kz8PDwRRqsZN1K7VFtY8MyqiS8xcFruJ5 dP3X3dlELiIWIJfdWk65/Di/cK1oSiQJXWrRkVbqVkNDICbUzR/ItHCYp9KX3LuwjZ8Q GAlWQeE5LanT9YFaG/PHDV+e70Qts3CWM6qWnsD0GTRQ3TrJlHRC8rK5OJvO/+W2mfds X8T8rLFz/ES7Zz1oTLvzJYmnFD706g2+2FYAlbRrxs6zz4HRMKILpsnFva9wpIbSoRO4 uG1g== X-Gm-Message-State: AFqh2kpO+3xSMpqCh+zteFpVJkETBcwz1mzqslR7ykyYaXm8yNyQxIPx m6EVyKQ7RJR45RAib/lFyX440qv4TyzYfA== X-Google-Smtp-Source: AMrXdXsyLr9of1Okm6d1EQF7my6ktoxHT6MskcTgXFlVVVoXCdWhoAXuC6tNqUbLBI+2dDejCK7ZcQ== X-Received: by 2002:a05:6a20:4a05:b0:a4:cb40:cf2e with SMTP id fr5-20020a056a204a0500b000a4cb40cf2emr32213804pzb.47.1672374330631; Thu, 29 Dec 2022 20:25:30 -0800 (PST) Received: from localhost.localdomain ([143.92.127.230]) by smtp.gmail.com with ESMTPSA id c2-20020a63d502000000b0046ff3634a78sm11881728pgg.71.2022.12.29.20.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 20:25:30 -0800 (PST) From: Yangchao Zhou To: dev@dpdk.org Cc: stephen@networkplumber.org, ferruh.yigit@amd.com, stable@dpdk.org Subject: [PATCH v3] kni: fix possible alloc_q starvation when mbufs are exhausted Date: Fri, 30 Dec 2022 12:23:38 +0800 Message-Id: <20221230042338.1670768-1-zhouyates@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221109060434.2012064-1-zhouyates@gmail.com> References: <20221109060434.2012064-1-zhouyates@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In some scenarios, mbufs returned by rte_kni_rx_burst are not freed immediately. So kni_allocate_mbufs may be failed, but we don't know. Even worse, when alloc_q is completely exhausted, kni_net_tx in rte_kni.ko will drop all tx packets. kni_allocate_mbufs is never called again, even if the mbufs are eventually freed. In this patch, we try to allocate mbufs for alloc_q when it is empty. According to historical experience, the performance bottleneck of KNI is offen the usleep_range of kni thread in rte_kni.ko. The check of kni_fifo_count is trivial and the cost should be acceptable. Fixes: 3e12a98fe397 ("kni: optimize Rx burst") Cc: stable@dpdk.org Signed-off-by: Yangchao Zhou --- lib/kni/rte_kni.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c index 8ab6c47153..bfa6a001ff 100644 --- a/lib/kni/rte_kni.c +++ b/lib/kni/rte_kni.c @@ -634,8 +634,8 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num) { unsigned int ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num); - /* If buffers removed, allocate mbufs and then put them into alloc_q */ - if (ret) + /* If buffers removed or alloc_q is empty, allocate mbufs and then put them into alloc_q */ + if (ret || (kni_fifo_count(kni->alloc_q) == 0)) kni_allocate_mbufs(kni); return ret; -- 2.25.1