Received: by 2002:a05:6359:1981:b0:12b:e873:ff31 with SMTP id mh1csp2434308rwb; Thu, 27 Jul 2023 08:30:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFokbYdazMujka3cHLzbx/57zMBi4CFU5s8On1jl/DzVSMsiycunJRCsVEFOCX6XC9wlKe2 X-Received: by 2002:a05:6a00:a23:b0:67a:8f2a:2cb2 with SMTP id p35-20020a056a000a2300b0067a8f2a2cb2mr6139711pfh.20.1690471831501; Thu, 27 Jul 2023 08:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690471831; cv=none; d=google.com; s=arc-20160816; b=yFXEE6ZRY3wX/z54MXM1Tkc1dsILzfw/Z+H08iyqcl22d7y+to6YYAZxwq1IeuoNAM cp5q/6qQCPlHYbAB3ezRXAurzK31ULDXsL1D52WqvmYkOehaJ3FBQYdURfSzuhXnIe4F alH0cWK4dY5BRHm7xlvn0jZzp+XNmtncjttbw3yZmHysG3ffZyG+pkH1f2O+uyXEJcan uQo6TE6LeHRa6dE92cxxK0NLhQ0e+BqExMD9lJfFILZPKjRE6AbLdHmGfBcgr3LtB38K Eo9sFKWj4ZRQp/UtWchKOGIcPPgKWRsc3aLPfVvrW284CS8pOcnzi1RVMeZLO3XA9P7i G1xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FFj0ROMS6VWyNkPnCiyySUDzg/2jHUVOn3I8XdOvcXw=; fh=3HE1xXs4s0z3NpKSg+MkyPw1+1QpKlxno2HY1HR9bAc=; b=C2f5tMGZVHYiyIDgeTD5W5CIw190ty52WthnseBv0C7xXO7dp6q656/RnowkOigxgX 1wgcZrkUWcQ4BADpLuHSbDIDPaNoUc35Yqlgi0s7HNILMZzMtwmn/LHkjb05XRTxvp5F 9O9EbFMIconi1vO8b3ZzU72dzmkNVodJrVgnGw9/whpCLOiiKBLHw1k1TGPug2roJmQG vIAvt06IGIKVCN+m0wNwJhAmP8DkHIOYEVeFC3OAHv/NUf3DWcaHW5QsNr0L5Q+rLAKn dtxS+jVdjm6C2cPSstNZwZoLuSQQexfJDILKn8BlPLMy1xCcZP/Xsv5KZEnkg+wj+Ewa 8EJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IkgpUQGN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i70-20020a638749000000b00563a0c1bf09si1375477pge.208.2023.07.27.08.30.18; Thu, 27 Jul 2023 08:30:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IkgpUQGN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234142AbjG0Oqw (ORCPT + 99 others); Thu, 27 Jul 2023 10:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234143AbjG0Oq3 (ORCPT ); Thu, 27 Jul 2023 10:46:29 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A92473AAA; Thu, 27 Jul 2023 07:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690469161; x=1722005161; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eYl99+L8eoZb9TdbyaCeQo6lRhwlNSjOXE6qobDW3K0=; b=IkgpUQGNIbKtfpljDJGk10+TiBLptw0DunKPCOtyK55fN2OgBAW8gYxh eAejiz0Qn+pA/f/3udRKxN9koAJPdaQbkAhqmPLdbMJt3s/TmXZSbgtIu GOHKwafQ11X6w1VQcvfY/7h2Iza0yEkwY/OyqxzAYtUjAHtjGE3kR1itl nBs0rbe+RYJIKim6+gGQg8LP5VHFJddzobUnjCF58eoRQR0MjE1TctsnU AlrcR8gyKvFuD7zLnuxzjq2pZVDI2WY0aa5wy9ocflw5Hr52fnSUMGdLF wxASAuNvr3TR5FqIM4P2wuiY3gfWRAGbSvb0902opVK/rHCVxVyP5mfsJ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="432139872" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="432139872" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 07:46:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="817119964" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="817119964" Received: from newjersey.igk.intel.com ([10.102.20.203]) by FMSMGA003.fm.intel.com with ESMTP; 27 Jul 2023 07:45:57 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Maciej Fijalkowski , Larysa Zaremba , Yunsheng Lin , Alexander Duyck , Jesper Dangaard Brouer , Ilias Apalodimas , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 9/9] net: skbuff: always try to recycle PP pages directly when in softirq Date: Thu, 27 Jul 2023 16:43:36 +0200 Message-ID: <20230727144336.1646454-10-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727144336.1646454-1-aleksander.lobakin@intel.com> References: <20230727144336.1646454-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 8c48eea3adf3 ("page_pool: allow caching from safely localized NAPI") allowed direct recycling of skb pages to their PP for some cases, but unfortunately missed a couple of other majors. For example, %XDP_DROP in skb mode. The netstack just calls kfree_skb(), which unconditionally passes `false` as @napi_safe. Thus, all pages go through ptr_ring and locks, although most of time we're actually inside the NAPI polling this PP is linked with, so that it would be perfectly safe to recycle pages directly. Let's address such. If @napi_safe is true, we're fine, don't change anything for this path. But if it's false, check whether we are in the softirq context. It will most likely be so and then if ->list_owner is our current CPU, we're good to use direct recycling, even though @napi_safe is false -- concurrent access is excluded. in_softirq() protection is needed mostly due to we can hit this place in the process context (not the hardirq though). For the mentioned xdp-drop-skb-mode case, the improvement I got is 3-4% in Mpps. As for page_pool stats, recycle_ring is now 0 and alloc_slow counter doesn't change most of time, which means the MM layer is not even called to allocate any new pages. Suggested-by: Jakub Kicinski # in_softirq() Signed-off-by: Alexander Lobakin --- net/core/skbuff.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index e701401092d7..5ba3948cceed 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -901,8 +901,10 @@ bool page_pool_return_skb_page(struct page *page, bool napi_safe) /* Allow direct recycle if we have reasons to believe that we are * in the same context as the consumer would run, so there's * no possible race. + * __page_pool_put_page() makes sure we're not in hardirq context + * and interrupts are enabled prior to accessing the cache. */ - if (napi_safe) { + if (napi_safe || in_softirq()) { const struct napi_struct *napi = READ_ONCE(pp->p.napi); allow_direct = napi && -- 2.41.0