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 34053A0093; Wed, 9 Nov 2022 07:05:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 226B7400D7; Wed, 9 Nov 2022 07:05:05 +0100 (CET) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mails.dpdk.org (Postfix) with ESMTP id 24DBD400D4; Wed, 9 Nov 2022 07:05:04 +0100 (CET) Received: by mail-pg1-f177.google.com with SMTP id s196so15358875pgs.3; Tue, 08 Nov 2022 22:05:04 -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=CVf9/OA9SxKpZsn3Gc3sBJXAzRtHLRI1DxoDCfxXjTE=; b=HwYsWsGE9pN8XwAs6qLgcesmcQHs/QTycf+I6Zk8EAwasMVYG65cdH6PAAkeaNJJGJ drzKswxliMTz91o/Q/W/G3RgJOs58BakSo2RNgPfkKkIGHmmCZqJ1nca8TSaH/j+o+xY 60Ps8QEsN0Gvn0JST9+EaOlHmNU4UySK/eNhezBGlesidUKX9aS/ESN4XM6OYAgEHMZh /N5zF2inEp1FK+WnCBLlilKNj20eGj391ldUmOfEvbnuqRA6NQIOG72T6TvpBuP6j/EU sU8g23oc+zZtay488O98U/wKaPcjLA4xJuHbUiimLwQzeJVmFROFDxk/yA4lCxY8JbnP 1JdA== 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=CVf9/OA9SxKpZsn3Gc3sBJXAzRtHLRI1DxoDCfxXjTE=; b=HV0CrZQTlCCSwVxAAbkSwrgOKV8//GiVLzu9Y1b7+j45aksRXkSbi+c+vJCBGYfZ4N gtUERrjWd63Fe20yhiK/xUpGeODBiW0B69seV6/W9jA10BWtqR5OvbU7RCk3L+EWbhDY fEzHOqhS2pWrNnxGaebW1oB92KXo438fBlRNQ6uQaumb7lqFsDmOY+TaytI7SkNxMHUe zSrszvK8hPXQ4jhRT4L+egOwYKxcgpTqkrVVpfx8im271IHoORNbMC6Cpov1VOHdGbzo UZzJTBpcTjsR6IUU9IOu+0HR4J3plvQrFSBORRyfAPUlbRNBFuJW2S4iWKcUtOhwVc82 uFbg== X-Gm-Message-State: ACrzQf0hhOA67zqvz4lyUSLh/peKgi39jZPvXNfmGi8oZgkEfH/sN5YR o14GbXOa5/nK4AnCzWDzFxL2gPP791wE/Q== X-Google-Smtp-Source: AMsMyM7HwapeQ7KeNIfdc8c9NcvJiUb8MGVMPlnSEhsHNU4sj0rUHtCd52TeSGQPfenVBCzHDEvcFw== X-Received: by 2002:a63:fe54:0:b0:470:f04:5ca5 with SMTP id x20-20020a63fe54000000b004700f045ca5mr954615pgj.323.1667973902901; Tue, 08 Nov 2022 22:05:02 -0800 (PST) Received: from localhost.localdomain ([143.92.127.236]) by smtp.gmail.com with ESMTPSA id d10-20020a621d0a000000b00562664d5027sm7382828pfd.61.2022.11.08.22.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 22:05:02 -0800 (PST) From: Yangchao Zhou To: dev@dpdk.org Cc: Hemant@freescale.com, stable@dpdk.org Subject: [PATCH v2] kni: fix possible alloc_q starvation when mbufs are exhausted Date: Wed, 9 Nov 2022 14:04:34 +0800 Message-Id: <20221109060434.2012064-1-zhouyates@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221109051339.1998037-1-zhouyates@gmail.com> References: <20221109051339.1998037-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 always try to allocate mbufs for alloc_q. Don't worry about alloc_q being allocated too many mbufs, in fact, the old logic will gradually fill up alloc_q. Also, the cost of more calls to kni_allocate_mbufs should be acceptable. Fixes: 3e12a98fe397 ("kni: optimize Rx burst") Cc: Hemant@freescale.com Cc: stable@dpdk.org Signed-off-by: Yangchao Zhou --- lib/kni/rte_kni.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c index 8ab6c47153..ea9a507de3 100644 --- a/lib/kni/rte_kni.c +++ b/lib/kni/rte_kni.c @@ -634,9 +634,11 @@ 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) - kni_allocate_mbufs(kni); + /* + * Always try to allocate mbufs for alloc_q to avoid starvation when + * kni->pktmbuf_pool is exhausted. + */ + kni_allocate_mbufs(kni); return ret; } -- 2.25.1