From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58254C61D97 for ; Fri, 24 Nov 2023 07:35:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E73B08D0062; Fri, 24 Nov 2023 02:35:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E24518D0002; Fri, 24 Nov 2023 02:35:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC5998D0062; Fri, 24 Nov 2023 02:35:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B7BEE8D0002 for ; Fri, 24 Nov 2023 02:35:34 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9950C1CBBF6 for ; Fri, 24 Nov 2023 07:35:34 +0000 (UTC) X-FDA: 81492037788.20.C3A0288 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf29.hostedemail.com (Postfix) with ESMTP id DC2FE120019 for ; Fri, 24 Nov 2023 07:35:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LuzcQcc0; spf=pass (imf29.hostedemail.com: domain of liangchen.linux@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=liangchen.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700811332; a=rsa-sha256; cv=none; b=EjDZVQY526zgsMkTeRVrarW6+bv/mGx+cjMgJteFWqsZ3WV+uAjJ88ijKLQvq/FStAHTgj iRQGFG44LKLqmjc1owDUwNFfy7tTbjDn4KaTzntA/qL0EpKnfVZoEuTzvdZo4/V48q5cKT nyzLDDgyqnhWKbFLXlyWKTijBS2PQeM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=LuzcQcc0; spf=pass (imf29.hostedemail.com: domain of liangchen.linux@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=liangchen.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700811332; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1+7Fm45mXPbJos9JDi9Ng8q2lxxttPsawkbzBvsMyCY=; b=ar3RTqVFaV/ASzBm8qvKQouPCO29JtSaZAK5ynnGkvi11E9E7ukQJA5ZITfTqDQ/zUDsy0 2CE9FKXpUCt9GemfHI8mc9BvJ3EzFrkfU1DuSXjPe8pEBtLp+1BkWaFAXPpLPGPZLlseUT aGqyGKZ37K6VN4pImyh3WxDqOb/hpmk= Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-5c230c79c0bso1081349a12.1 for ; Thu, 23 Nov 2023 23:35:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700811332; x=1701416132; darn=kvack.org; 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=1+7Fm45mXPbJos9JDi9Ng8q2lxxttPsawkbzBvsMyCY=; b=LuzcQcc0DUX3gfFr+QGBiloKL1zkp+J9Fs+4rxOMRCoUBXYjJbh7cc/IN2MCQq8HFl /XEKwCgyQSh7WOLGLvud3ZWKRzQpwsuEEGbTwMUHgP1A0CFA6kscEoznRSALCKHSBh6t 5Tx28xhnmSEFeFbjDQjEbRwVP6PD3w7yYEBR35/r8ySFUqqBCWGoichy/EESS4BLjxt+ t/pmlFc6jIWPfbDobQpuBorp8H6CtKkvUwlvoeBZly2kAe6Km0NfLrNeJ8Uqu4AuJkm/ i35AB0daJXeh5XnnfBfapvFUkQrUA/TRLtfPyryoekVuSGVRW7fr7u+L0uAkGyn0ZQMp DpKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700811332; x=1701416132; 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=1+7Fm45mXPbJos9JDi9Ng8q2lxxttPsawkbzBvsMyCY=; b=ALLQTwkGY0lP7Uvn4k070Z86pwFbMx+rR+KgIkjIlYOwonUA4NhW7/IvG6eIqZPbjA buNrCzQ4qcjg5NKL8/KB3PQPfoXb4pAI1nNrCBHDf8uOHZP5fATNxnayq/Csdr5UjdBe XJiA3rGURXgHoZwInpxx1wxFX4hDbE9zQ0bezHrKRY35oK4ZCduxwweseaJxy1BcnBXl zxvuY5W513SxOetQOVBwIs4/3tpN7md5gW4BdSi7JXoHWroLq237kRofDi0rNBsCgKP0 niqSHAQGLYt/y2V6xl6oloDXvm6O7M8PZ6vo0igC9oBnD8XXKOgjTcYG97ND5A4ewSMq 038g== X-Gm-Message-State: AOJu0YzAcDGicbrjcUdcc2iIZxX/PRWMo1bsLXO1EQcZw9D3FTFUEe+l lK0SRXew4Bt0cP5MIhASEQQ= X-Google-Smtp-Source: AGHT+IEY5zFaHsjjsH+W05ik6A5APVeYSGIO3q3AFeGd/v8kdg+F0wdCUU5FPt/FldayEbptAC3s9w== X-Received: by 2002:a05:6a20:4388:b0:18b:30d1:8140 with SMTP id i8-20020a056a20438800b0018b30d18140mr2442174pzl.6.1700811331713; Thu, 23 Nov 2023 23:35:31 -0800 (PST) Received: from localhost.localdomain ([89.187.161.180]) by smtp.gmail.com with ESMTPSA id t15-20020a170902e84f00b001b9d7c8f44dsm2499329plg.182.2023.11.23.23.35.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 23:35:30 -0800 (PST) From: Liang Chen To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, hawk@kernel.org, ilias.apalodimas@linaro.org, linyunsheng@huawei.com Cc: netdev@vger.kernel.org, linux-mm@kvack.org, liangchen.linux@gmail.com Subject: [PATCH net-next v3 3/3] skbuff: Optimization of SKB coalescing for page pool Date: Fri, 24 Nov 2023 15:34:39 +0800 Message-Id: <20231124073439.52626-4-liangchen.linux@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231124073439.52626-1-liangchen.linux@gmail.com> References: <20231124073439.52626-1-liangchen.linux@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: DC2FE120019 X-Stat-Signature: cdkygpyoakp6h43bkcmjhw5ocmrmhykf X-Rspam-User: X-HE-Tag: 1700811332-962048 X-HE-Meta: U2FsdGVkX18RSi/hqNWJL/xVpwezi5SkIiD5ItnXnxWNrVJUOD0f6zlNZJ7ZQR/uXT1t0YGQxEOZ2tgGzE/jOwxhrqGXSBGNISLilZgL31neIYjuf0gZhOQ9lavC5lWqoDHuFPAZgifgu3Dx6PQ1zkx9dyOXmbVO5BSY7sFGRw5Ka2Be1kVPC9XlTpthwvcz1ThjtgJ/jtiXu/ucDjW/UWWd63yUoN9EwbTDwLxHAjIiD22eqITDDhHkhSlVWiT62XKgFq5WD01pmANhqf/B7x/OSa50j1mn46LxVcklsMaTqiFS3N1gzBJNfG2aii23PQd46EpyBvQSkSt+KgYTmY9jBwUzbMA1+v7P/9UL59VJF/ZiiaiaVqmPuY1pLrzTbKLS+X7KBfw4HoxN30YeRf/+r6/1H3HG/ZZzO7gwIyipBzqvSv+y1Cro/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eXSbw9IP4xPAG0CBM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In order to address the issues encountered with commit 1effe8ca4e34 ("skbuff: fix coalescing for page_pool fragment recycling"), the combination of the following condition was excluded from skb coalescing: from->pp_recycle = 1 from->cloned = 1 to->pp_recycle = 1 However, with page pool environments, the aforementioned combination can be quite common(ex. NetworkMananger may lead to the additional packet_type being registered, thus the cloning). In scenarios with a higher number of small packets, it can significantly affect the success rate of coalescing. For example, considering packets of 256 bytes size, our comparison of coalescing success rate is as follows: Without page pool: 70% With page pool: 13% Consequently, this has an impact on performance: Without page pool: 2.57 Gbits/sec With page pool: 2.26 Gbits/sec Therefore, it seems worthwhile to optimize this scenario and enable coalescing of this particular combination. To achieve this, we need to ensure the correct increment of the "from" SKB page's page pool reference count (pp_ref_count). Following this optimization, the success rate of coalescing measured in our environment has improved as follows: With page pool: 60% This success rate is approaching the rate achieved without using page pool, and the performance has also been improved: With page pool: 2.52 Gbits/sec Below is the performance comparison for small packets before and after this optimization. We observe no impact to packets larger than 4K. packet size before after improved (bytes) (Gbits/sec) (Gbits/sec) 128 1.19 1.27 7.13% 256 2.26 2.52 11.75% 512 4.13 4.81 16.50% 1024 6.17 6.73 9.05% 2048 14.54 15.47 6.45% 4096 25.44 27.87 9.52% Signed-off-by: Liang Chen --- include/net/page_pool/helpers.h | 22 ++++++++++++++++++++++ net/core/skbuff.c | 23 +++++++++++------------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index 700f435292e7..6b3c0d4d47f5 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -402,4 +402,26 @@ static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid) page_pool_update_nid(pool, new_nid); } +static inline bool page_pool_is_pp_page(struct page *page) +{ + return (page->pp_magic & ~0x3UL) == PP_SIGNATURE; +} + +/** + * page_pool_get_frag_ref() - Increase fragment reference count of a page + * @page: page of the fragment on which to increase a reference + * + * Increase fragment reference count (pp_ref_count) on a page, but if it is + * not a page pool page, fallback to increase a reference(_refcount) on a + * normal page. + */ +static inline void page_pool_get_frag_ref(struct page *page) +{ + struct page *head_page = compound_head(page); + + if (likely(page_pool_is_pp_page(head_page))) + atomic_long_inc(&head_page->pp_ref_count); + else + get_page(head_page); +} #endif /* _NET_PAGE_POOL_HELPERS_H */ diff --git a/net/core/skbuff.c b/net/core/skbuff.c index b157efea5dea..54e6945ead56 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5764,17 +5764,12 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, return false; /* In general, avoid mixing page_pool and non-page_pool allocated - * pages within the same SKB. Additionally avoid dealing with clones - * with page_pool pages, in case the SKB is using page_pool fragment - * references (page_pool_alloc_frag()). Since we only take full page - * references for cloned SKBs at the moment that would result in - * inconsistent reference counts. - * In theory we could take full references if @from is cloned and - * !@to->pp_recycle but its tricky (due to potential race with - * the clone disappearing) and rare, so not worth dealing with. + * pages within the same SKB. In theory we could take full + * references if @from is cloned and !@to->pp_recycle but its + * tricky (due to potential race with the clone disappearing) and + * rare, so not worth dealing with. */ - if (to->pp_recycle != from->pp_recycle || - (from->pp_recycle && skb_cloned(from))) + if (to->pp_recycle != from->pp_recycle) return false; if (len <= skb_tailroom(to)) { @@ -5831,8 +5826,12 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from, /* if the skb is not cloned this does nothing * since we set nr_frags to 0. */ - for (i = 0; i < from_shinfo->nr_frags; i++) - __skb_frag_ref(&from_shinfo->frags[i]); + if (from->pp_recycle) + for (i = 0; i < from_shinfo->nr_frags; i++) + page_pool_get_frag_ref(skb_frag_page(&from_shinfo->frags[i])); + else + for (i = 0; i < from_shinfo->nr_frags; i++) + __skb_frag_ref(&from_shinfo->frags[i]); to->truesize += delta; to->len += len; -- 2.31.1