Message ID | 20230214104316.2254814-1-ilias.apalodimas@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2894233wrn; Tue, 14 Feb 2023 02:47:37 -0800 (PST) X-Google-Smtp-Source: AK7set9HD4GW1c9iyMV2lWoeEk00o1oSjL0heHJNfRee2tJ35XSUqJiJAPcFEc30rd/lA7spqxcr X-Received: by 2002:a17:902:f251:b0:19a:853e:92eb with SMTP id j17-20020a170902f25100b0019a853e92ebmr1551070plc.12.1676371657673; Tue, 14 Feb 2023 02:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676371657; cv=none; d=google.com; s=arc-20160816; b=KpXtE/XNTHRxJtl251xJqKx2yitwdNn74flqdRtILMKAoYIC88+25g1HVAxOVrml1y n9Owdtq+KQbP8eAn6Vt8nxDye7h/zVLf94Nkn/qzXwwOpY3h77heTR5DX+TgYyi0Kllo G2JNbbguGEZMpNn0c/IZJlQqln2GmZCLti7Tgy5duuKtBjdMIXGPyF7gVmc6v6vqnE0+ xV82+LrkiKmVpMnYgZc3eUfjgZmI2wmqBXaRpphna/wg88keFgGEY+ICousQLc5Vyzv0 tzHO27GzjriezxMNFTys+Ap3IzYPMktviyijbYBYgRKDJsWFlwovqx+aGZZd9RFknoOA qKQQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=XqS5XS9K0gVFKIqlVQ1fvlwwhKgBIsbsx/lxGSO4I14=; b=BFXijqggAsyTRuOV4le4XP+kWgwsQ2sllS+//RU8FjvPko9XwQ04j4gcyruuOy4uRz yax2wQ3oWD2l+prSeaQGVqR9SNIlDz0O/jn/JzPVOhLO9xBG5OYzkBfAuEnRmH9R+SYO KoKErFLCBS+zgUJvtGNpnL/LHbJKvS5cAF8oQloFor9nHUBV/+JwQ/uNQ6R+h0jv60Tw K3mUutBON9lQ9CZEQ5oimQ6Fnda887sFWOBrsh1HpC9uUFOcKmkxAw5/GgU5lGZcoikZ VEpqUZMMxzs7kwTLVe/+ihOwAf5jXi/FrHXvttVqEYvjFlrP1oLu9iNi7hTWfdMOJvvT jlrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wZeIsjeB; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a1709028f8500b001949482830esi13619859plo.414.2023.02.14.02.47.25; Tue, 14 Feb 2023 02:47:37 -0800 (PST) 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=@linaro.org header.s=google header.b=wZeIsjeB; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbjBNKpS (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Tue, 14 Feb 2023 05:45:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232035AbjBNKoq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 14 Feb 2023 05:44:46 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3CBF86AE for <linux-kernel@vger.kernel.org>; Tue, 14 Feb 2023 02:44:00 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id lf10so7091435ejc.5 for <linux-kernel@vger.kernel.org>; Tue, 14 Feb 2023 02:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XqS5XS9K0gVFKIqlVQ1fvlwwhKgBIsbsx/lxGSO4I14=; b=wZeIsjeB/Zo2j6NDzZYavDee4rG/0MNaS+S9sQ5sz3es7byC3q3/CGB+7Y2zZNlEnv 3I3hrZE4drN47D0K2TnrLZhUkaECrKnxG7yK0Kvjpa0JoO15OzjdO1xwQhppm3YOmAtQ 2sAAHoYigNpPXi/RMobt5MUC+KGbVXLsc+4+S4gaVelGK4667CRCzpOUad1lUj7ZFi1W OM8pE0LqrTgGDWrOHR25XJOjciu1A+IMC/oSWbV8Y/0lqPGgM0iuXOTTp84+YKR838E/ GMyBKknGwtIWn03f4zVmPg3Ad3ZZzBwbcwtOAfrxFSq4Hkt/c6G9wB5fvw/9sQW5bmHh 3HMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XqS5XS9K0gVFKIqlVQ1fvlwwhKgBIsbsx/lxGSO4I14=; b=dwMrMjg/s7TdyRSFW2fq18JobTWl+KUK+5e1nQIg+3pviEe0iBVKyljLK78Nbb4Jsq o5Xu+hEO23WBlUhYOIg25HTe3EeJEqHmCU4Tj61sWsVedx3Xi6B23onrg8ZYgPI40CJn 1NOyE7awy0ufJynMSU9qbHBd916lFJsGRFcBfDrGedwEphCbxGXbWQHrWAy3xb9BIXXd Apjio+r3QZifrnbuGE9ezQlMjm0ZLUhl+yWiPoOPJ0HV9gdQU76YDg4CyAYb3J8dvpMY rnpkopkSooNaL+OcopawTvi50ZucTkRkXHX1imo11FR68wWZ9yIN8dAaK02LvYtlLHIs 495Q== X-Gm-Message-State: AO0yUKUYMnPceBr7G68gkOSs+oUsotaKbGZBr9qnl3HxOpboIRKyMkVN ii2wRdXfJGYnXB8/vW8LtWtb/g== X-Received: by 2002:a17:906:f913:b0:87b:d60a:fcbb with SMTP id lc19-20020a170906f91300b0087bd60afcbbmr2135967ejb.47.1676371414259; Tue, 14 Feb 2023 02:43:34 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:af84:8794:2f3f:88f1]) by smtp.gmail.com with ESMTPSA id a15-20020a1709063e8f00b0084cb4d37b8csm8184654ejj.141.2023.02.14.02.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 02:43:33 -0800 (PST) From: Ilias Apalodimas <ilias.apalodimas@linaro.org> To: netdev@vger.kernel.org Cc: alexander.duyck@gmail.com, Ilias Apalodimas <ilias.apalodimas@linaro.org>, Jesper Dangaard Brouer <hawk@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-kernel@vger.kernel.org Subject: [PATCH v2] page_pool: add a comment explaining the fragment counter usage Date: Tue, 14 Feb 2023 12:43:16 +0200 Message-Id: <20230214104316.2254814-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757803087002247335?= X-GMAIL-MSGID: =?utf-8?q?1757803087002247335?= |
Series |
[v2] page_pool: add a comment explaining the fragment counter usage
|
|
Commit Message
Ilias Apalodimas
Feb. 14, 2023, 10:43 a.m. UTC
When reading the page_pool code the first impression is that keeping
two separate counters, one being the page refcnt and the other being
fragment pp_frag_count, is counter-intuitive.
However without that fragment counter we don't know when to reliably
destroy or sync the outstanding DMA mappings. So let's add a comment
explaining this part.
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
Changes since v1:
- Update the comment withe the correct description for pp_frag_count
include/net/page_pool.h | 10 ++++++++++
1 file changed, 10 insertions(+)
--
2.38.1
Comments
On Tue, 2023-02-14 at 12:43 +0200, Ilias Apalodimas wrote: > When reading the page_pool code the first impression is that keeping > two separate counters, one being the page refcnt and the other being > fragment pp_frag_count, is counter-intuitive. > > However without that fragment counter we don't know when to reliably > destroy or sync the outstanding DMA mappings. So let's add a comment > explaining this part. > > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> > --- > Changes since v1: > - Update the comment withe the correct description for pp_frag_count > include/net/page_pool.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/include/net/page_pool.h b/include/net/page_pool.h > index 34bf531ffc8d..277e215cfb58 100644 > --- a/include/net/page_pool.h > +++ b/include/net/page_pool.h > @@ -277,6 +277,16 @@ void page_pool_put_defragged_page(struct page_pool *pool, struct page *page, > unsigned int dma_sync_size, > bool allow_direct); > > +/* pp_frag_count represents the number of writers who can update the page > + * either by updating skb->data or via DMA mappings for the device. > + * We can't rely on the page refcnt, as we don't know who might be > + * holding page references and we can't reliably destroy or sync DMA mappings > + * of the fragments. > + * > + * When pp_frag_count reaches 0 we can either recycle the page, if the page > + * refcnt is 1, or return it back to the memory allocator and destroy any > + * mappings we have. > + */ I would get rid of the comma between "page" and "if" in the second paragraph. It breaks things up and makes it a bit harder to read. What we want to emphasize is that there are two possible paths. The extra comma makes it almost appear as if there are 3 options. Otherwise it looks good to me. Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
diff --git a/include/net/page_pool.h b/include/net/page_pool.h index 34bf531ffc8d..277e215cfb58 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -277,6 +277,16 @@ void page_pool_put_defragged_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct); +/* pp_frag_count represents the number of writers who can update the page + * either by updating skb->data or via DMA mappings for the device. + * We can't rely on the page refcnt, as we don't know who might be + * holding page references and we can't reliably destroy or sync DMA mappings + * of the fragments. + * + * When pp_frag_count reaches 0 we can either recycle the page, if the page + * refcnt is 1, or return it back to the memory allocator and destroy any + * mappings we have. + */ static inline void page_pool_fragment_page(struct page *page, long nr) { atomic_long_set(&page->pp_frag_count, nr);