Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp2630260rwo; Thu, 3 Aug 2023 12:17:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlF5agu9d6BepLG5BxBsxaeukR1UyTtNX/l8JfrVZVlQBqNzQjeBY6gBhKWUtUMX5sWUZjlh X-Received: by 2002:a05:6402:1497:b0:522:2aba:bc3b with SMTP id e23-20020a056402149700b005222ababc3bmr9336966edv.28.1691090255309; Thu, 03 Aug 2023 12:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691090255; cv=none; d=google.com; s=arc-20160816; b=Lcla+y2kNjBdMTjZc8cyY6YFh0JlvG1XC577djEpra4a/eQJ1IM/6zKEJdpgB+MtLx +saboQzwqIV81SIwalvhBMp/bi4X8WMrf29Iv9TBYIZjzqtWWLRgMVf0LUbzTf+w8S+8 KGo303GcP9JTAq45kbtKvN42qXk/PGuXAd4Ll5Nudn9ufYBu2E999uylekcPEHP5TPoa NjuezU58BZ/j3sSeq0DZjIzr5i/xPax7iWfbbZ/avyRpzkzr5dASP43Gf0cEl9pbdslq nRg4RvnIXz2K8QKTeVncZFgTw+X8YVgWYvjuY4zlsPx7ZRUsEDKG0bMK/bCLpXtbJCCx qnZQ== 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=xIS//mWivAOAsi3XOjMqfz/h5GTPEmOZ/HPEr4yrQKQ=; fh=3HE1xXs4s0z3NpKSg+MkyPw1+1QpKlxno2HY1HR9bAc=; b=e8ciqWja2kj57Bw59hS5JlWtfjyeCbmYX4zm5dLxA8fy22ZYOWsOZ2iPxWb/Sw9Iqs 2Pk8CKh5mbg7Jmpn6Jf+BAld5LvjE+/pBzEUU5dF220ROYNBSAlb65q0MGMB1sBanZ5y CznJO820EFZGkC0xdlm7+5Fmhd+LplDXhGw6o+3yTrZHlTX6P6TQg8EXyMJZLCHl4DzM HzF91xifQUveHn72HGZLggh+nvRqEP2eBO5OETBKWUzdv3/0OJtKTC9fBUlFwx87Cbhu 5soixwdgGGjudDMsp/KQMWmPVohb/fufMtFepeRnO0QiCaXklfDk2cxkqOEKeuZr+l0G YZpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=McS0BZ2J; 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 j19-20020a50ed13000000b005230a2b0befsi297911eds.153.2023.08.03.12.17.09; Thu, 03 Aug 2023 12:17:35 -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=McS0BZ2J; 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 S236989AbjHCQl0 (ORCPT + 99 others); Thu, 3 Aug 2023 12:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235455AbjHCQlE (ORCPT ); Thu, 3 Aug 2023 12:41:04 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C2974200; Thu, 3 Aug 2023 09:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691080852; x=1722616852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yC3uIe0tSBLBI12LM3uJtXCP5bvqTWQRcMrArt23Bjc=; b=McS0BZ2JhbuT0UMMxHsh2CcRlkbpFd9UqtBmmSN/7iuushLeFnItRT/q Zs2BFp1iOZwyX79W0a3PMh5sYvTa/MbwJBQxJ2oPYrmLgDTlVg4A/C/oa r1GTUp7jyHC9wGqoCiYGQxkAZQ+41cfMSugHy3nQLPRlbLbvAPnJWBRMe qMm/fJetfmSsWbZI/BXfVCsEWufPtuCwGaAVtMOFD3XyN16G/jMKhYLsQ HKuP+dpfsZ7NDKxoa52OL1Qx3wkJA9mdU9O+K96f7SIMb/4qF5sxWIAbi yZvNLRTtd1xTHLm6i0UYdq22Pq1azIOSu9sUKnWODhX2vyziCYC7AKnsu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="350229273" X-IronPort-AV: E=Sophos;i="6.01,252,1684825200"; d="scan'208";a="350229273" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2023 09:40:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10791"; a="723268912" X-IronPort-AV: E=Sophos;i="6.01,252,1684825200"; d="scan'208";a="723268912" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orsmga007.jf.intel.com with ESMTP; 03 Aug 2023 09:40:48 -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 v2 6/6] net: skbuff: always try to recycle PP pages directly when in softirq Date: Thu, 3 Aug 2023 18:40:14 +0200 Message-ID: <20230803164014.993838-7-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230803164014.993838-1-aleksander.lobakin@intel.com> References: <20230803164014.993838-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 85f82a6a08dc..33fdf04d4334 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -902,8 +902,10 @@ bool napi_pp_put_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