From: Pavel Begunkov <asml.silence@gmail.com>
To: Mina Almasry <almasrymina@google.com>,
netdev@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"John Fastabend" <john.fastabend@gmail.com>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Luigi Rizzo" <lrizzo@google.com>,
"Björn Töpel" <bjorn@kernel.org>
Subject: Re: [PATCH net-next v1 2/2] docs: netmem: document netmem and memory provider design principles
Date: Thu, 8 Oct 2026 14:15:38 +0100 [thread overview]
Message-ID: <78a72b62-7c35-4eae-8d6c-ab6dd8c20db2@gmail.com> (raw)
In-Reply-To: <20261005004958.3603059-3-almasrymina@google.com>
On 10/5/26 01:49, Mina Almasry wrote:
> Add a Design Principles section to Documentation/networking/netmem.rst
> covering the netmem_ref abstraction, the prohibition on direct
> downcasting in callers, decoupling memory providers from net_iov,
> decoupling net_iov from unreadability, delegating provider/type logic to
> memory_provider_ops and netmem helpers, and the homogeneous skb fragment
> memory type invariant.
>
> Cc: Luigi Rizzo <lrizzo@google.com>
> Cc: Björn Töpel <bjorn@kernel.org>
> Cc: Stanislav Fomichev <sdf@fomichev.me>
> Cc: Pavel Begunkov <asml.silence@gmail.com>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
> ---
> Documentation/networking/netmem.rst | 46 +++++++++++++++++++++++++++++
> 1 file changed, 46 insertions(+)
>
> diff --git a/Documentation/networking/netmem.rst b/Documentation/networking/netmem.rst
> index 217869d1108dd..57e52a947663d 100644
> --- a/Documentation/networking/netmem.rst
> +++ b/Documentation/networking/netmem.rst
> @@ -19,6 +19,52 @@ Benefits of Netmem :
> * Simplified Development: Drivers interact with a consistent API,
> regardless of the underlying memory implementation.
>
> +Design Principles
> +=================
> +
> +Memory providers (or the default ``page_pool`` allocator) allocate underlying
> +memory (``struct net_iov`` or ``struct page``), cast it to ``netmem_ref``, and
> +supply it to ``page_pool``. The ``page_pool``, drivers, and networking stack
> +operate on ``netmem_ref`` as the abstract type. Existing ``page_pool`` APIs
> +that allocate or free ``struct page`` are legacy compatibility wrappers for
> +drivers that do not yet support ``netmem_ref``. Code that is not yet
> +``netmem``-aware should be converted to ``netmem_ref`` unless it will never
> +need to support ``netmem``.
> +
> +1. **Operate on netmem_ref, do not downcast**: ``page_pool``, drivers, and the
> + core networking stack should deal with ``netmem_ref`` rather than
> + ``struct net_iov`` or ``struct page``. Downcasting ``netmem_ref`` to
> + ``struct net_iov`` or ``struct page`` is not allowed unless a code path
> + strictly cannot function without knowing the underlying memory type (for
> + example, ``kmap_local_page()``). In those cases, to keep call sites simple,
> + add a ``netmem`` helper that performs the operation on behalf of the caller,
> + cleanly handles all ``net_iov`` and ``page`` cases, and returns an error if
> + the ``netmem`` type cannot support the requested operation.
> +
> +2. **Decouple memory providers from net_iov**: Memory providers are not limited
> + to ``struct net_iov``. A memory provider that returns ``struct page``-backed
> + ``netmem_ref``\ s to upper layers is allowed. Code must not assume that using
> + a memory provider implies ``net_iov`` memory.
> +
> +3. **Decouple net_iov from unreadability**: ``struct net_iov`` is flexible and
> + has no inherent restrictions. While current ``net_iov`` implementations are
> + unreadable by the CPU, future readable ``net_iov`` implementations are
> + allowed. Code must not assume ``net_iov`` is unreadable; check readability
> + via ``netmem_address()`` or ``skb_frags_readable()`` instead.
> +
> +4. **Delegate complexity to the lowest layer**: Each layer must respect its
> + abstraction boundary. ``page_pool`` must not implement per-memory-provider
> + custom logic in its main code; instead, it delegates provider-specific
> + handling to ``struct memory_provider_ops``. Similarly, core networking code
> + should avoid per-``netmem``-type branching and instead delegate operations
> + to ``netmem`` helpers that handle the underlying memory type.
> +
> +5. **Homogeneous skb fragment memory types**: An ``sk_buff``'s ``frags[]`` are
> + always backed by ``netmem_ref``\ s of the same memory type. Mixing fragments
> + from different memory types within a single ``sk_buff`` is not allowed,
> + keeping ``sk_buff`` handling simple. Consequently, coalescing ``sk_buff``\ s
> + with different fragment memory types must not happen.
Would be good to expand on what's the memory type here. We have netmem
vs net_iov, and there are different memory provider types, but we need
to restrict it even further, sth in the lines of "if an skb contains a
frag from a memory provider, all its frags should be belong to the same
memory provider".
Otherwise,
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
--
Pavel Begunkov
prev parent reply other threads:[~2026-10-08 13:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 0:49 [PATCH net-next v1 0/2] net: netmem: document design principles and intended direction Mina Almasry
2026-10-05 0:49 ` [PATCH net-next v1 1/2] net: netmem: document netmem and memory provider design in comments Mina Almasry
2026-10-07 7:43 ` Jesper Dangaard Brouer
2026-10-08 2:10 ` Mina Almasry
2026-10-05 0:49 ` [PATCH net-next v1 2/2] docs: netmem: document netmem and memory provider design principles Mina Almasry
2026-10-05 16:19 ` Stanislav Fomichev
2026-10-05 16:31 ` Mina Almasry
2026-10-06 22:02 ` Stanislav Fomichev
2026-10-08 13:15 ` Pavel Begunkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78a72b62-7c35-4eae-8d6c-ab6dd8c20db2@gmail.com \
--to=asml.silence@gmail.com \
--cc=almasrymina@google.com \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lrizzo@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=sdf@fomichev.me \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®