Article View: linux.kernel.netdev
Article #685Re: [PATCH net-next v1 2/2] docs: netmem: document netmem and memory provider design principles
From: Pavel Begunkov
Date: Thu, 08 Oct 2026 13:15
Date: Thu, 08 Oct 2026 13:15
84 lines
13408 bytes
13408 bytes
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
Technical Details
Message-ID:
<78a72b62-7c35-4eae-8d6c-ab6dd8c20db2@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342990-linux-kernel-netdev=dewy.ruReferences:
<20261005004958.3603059-1-almasrymina@google.com> <20261005004958.3603059-3-almasrymina@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342990-linux-kernel-netdev=dewy.ru
From: asml.silence@gmail.com (Pavel Begunkov)
Newsgroups: linux.kernel.netdev
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
Organization: Usenet Network
Message-ID: <78a72b62-7c35-4eae-8d6c-ab6dd8c20db2@gmail.com>
References: <20261005004958.3603059-1-almasrymina@google.com>
<20261005004958.3603059-3-almasrymina@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="888167"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:whY0c/nYmUBZcsuRtucujWRPMKw= sha256:Ozn+arshfa34+Szy/BpindXYLFUWLzVuexbMSNb97l0=
sha1:Asm885GsRCsBrmWX2VN/1WBmVRY= sha256:UNPTWbSNJWZZ2DFtHfzQoFkP4T2xajosk9+Clw7cy00=
Content-Language: en-US
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 5B38E10F3FA; Thu, 8 Oct 2026 16:17:31 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id zkqrLBU2RBZF;
Thu, 8 Oct 2026 16:17:28 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-342990-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 1F27110F3F7; Thu, 8 Oct 2026 16:17:24 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sto.lore.kernel.org (Postfix) with ESMTP id BEB9D609958; Thu, 8 Oct 2026 13:16:02 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 709434A4829;
Thu, 8 Oct 2026 13:15:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LD7ZoR0C"
X-Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A8C6439327
for <netdev@vger.kernel.org>; Thu, 8 Oct 2026 13:15:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791465352; cv=none; b=Go5JgQPi+Lunw+lu3xhCmJq/CpKwxrO0BNHaP5RkHSmYfwFWqnPskoIfcnp/xKcesd4EpC8GlFDPeX1qa7Ey5kQF5VNOSfymrOU1fAEoinqTgmC03lAsI+4gw+OCeONqmsxLhnkfzgRWNm3kn5U57NExvpUp3/1oK4v1WmKnRAU=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791465352; c=relaxed/simple;
bh=IZORgLSswiz9QmuNMURLt7UkMWrabxvr9qyMUZFB970=;
h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:
In-Reply-To:Content-Type; b=oOrv2ga8LWZ1XQukMPZM0MbyS7jQOZ/XALHFGvLAAlcLXe8u0YrTTvvLXI7jCrjIRI+3xARX/eOL0MrHbnoBevxuLfDVTtSjutjFHw5LBOzgv6qsbwQfmTgfiJJGBrBtIBk//2llZxd5r5NVxzMvRggFvHlRAqKU8W36vAmhqok=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LD7ZoR0C; arc=none smtp.client-ip=209.85.221.49
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-48441a2ba1bso3100604f8f.1
for <netdev@vger.kernel.org>; Thu, 08 Oct 2026 06:15:50 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791465349; x=1792070149; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:cc:to:subject:user-agent:mime-version
:date:message-id:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=1GZXZQLgqCvw5WtP3CtocqOoYfauPu8d359Zy0nEiQg=;
b=LD7ZoR0CffQAQ9pdy6beoeQ2xnS+awZSAS4Nw3T6vrj9i0ZvcnspUaDIof6FhhdcSF
YrY3+Lap/ELeU6uIQpIuwnSWK47V+ldHSMuzspXtQhFHByzHA+F6CVzYnwEbx4ZnsMyQ
3pDro/Yv9ciQJ9dBSIA2Kywbi1k+iE5lRD1DfgdwOa90eYN1FVEBg8ygdUUSO6dRTnDw
iOJkbzEMMflchRvFYq9ntDRVfdmvrjc9ysndKQmBCnBzHlrdb0AN4gBEAbvh4r+5KTYN
12vGvn3nDgrX67laM4ICmjW3GhIxAcTm4Y3uwJssTHtUpmw+0lb20Ka2xIz7V0bxcfUn
aXng==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791465349; x=1792070149;
h=content-transfer-encoding:content-type:in-reply-to:from
:content-language:references:cc:to:subject:user-agent:mime-version
:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=1GZXZQLgqCvw5WtP3CtocqOoYfauPu8d359Zy0nEiQg=;
b=u9rS2vsNOwxK3VsuR+reF61GvEl4DV6dvhgqhFZQkAi7/A3Zda1PkUkJZIOm5+A81Y
dhqBfX8Cls4gJTNI6wmHJfAUo39KG7WcD4kgvpLbW602kVdoTdxGx7rR1Oh0nfn3Jhzk
KrlX5rbZOxQZ8xYXccxY5mIJU4AfjVz5QDqdbbcPVQukLxWrsqewrVBxVaEnyuwNlYd1
xOpgIllLcKPR7V1BagStJs+llc2LuA5vi6PDtcw2niasNahsWyel0I9i4baq/b4NpjPb
tFCMEBrJ6pRurU98t5pQ/eQAqWRF4zMIk+gSKU97EuW9y4Zw4+2Xg9slWCtjfFPnLl/R
5zyA==
X-Forwarded-Encrypted: i=1; AKwUvByoEfY1I/LoHc0zm05Jy+4aUsbwCFwu7z+ndeWOJWd4PGjLZXsYaEqGs43ucWRmXTK38570YEk=@vger.kernel.org
X-Gm-Message-State: AFq9FYKm7cts6JppAvIXD6eURg2Qpq+Y0wckFu0zPv7yaWv3NIH5GSNh
DugRpmKg1d6lLj5kVHIomMBZFzV0OIYQ3mfIZDaSpSG4GfgrD7hwOOy3
X-Gm-Gg: AYBFou0UA2BFs7sK7qUyyabal37HJxKo+F0lWSbKhEQHuBg3CbAo+qP6r2yZyCCHZS8
BkRM7ut+aOgZbBO2avQwbQ6uZsh8rkJ93EYXe3xnrVR93CxYLxjzOXVKX5KS7rUnUPnDnN8e8Xy
el3oHClDNPHamfMawJTlgfRxpgEtfXxmqT/WpqWDvOVnqrlQE7zv31QvrroLZREx1kWLoQtBgTf
E4UnQ4I9Nb3RC2fWry2wgvzbUk16T8/J18r7TNDwNg2FYhd9s9/YR3/VPGgVvC1PUMVzCgPAGwe
4MY+mxug+EvVu0V3JVF5B9KBkvqMSvO7C1D+DOdDENKLeav8JF1h2/slpNk4ClJkUsd+iEZ/xYH
PY89c+53Gvbbx7MPSc2j69fq7z2OotPPkQQWfVHqDQu0d48BMSmoY51EWIccvC5tVx6RxDZph0f
uqRvC0+n7viQmHX40139JuurpFPV+N6W0+hr3JC/pnk/0XrgxxWX6NQGrCNF/syzGWOXPOQ7nNY
EPqIT0jcWU9ZjxByZvrXHqPrmMf68JwqXfLNxgKj7Sg1ohyUv3X7RtCMablQtF7mkAqPoI5O3dA
6FlY7S64mQpYwmypnofHM11JGXLiK614Pdx8TxN6M5FKr1EL
X-Received: by 2002:a05:6000:230f:b0:48c:7f53:960c with SMTP id ffacd0b85a97d-48c7f539971mr5090297f8f.10.1791465348301;
Thu, 08 Oct 2026 06:15:48 -0700 (PDT)
X-Received: from ?IPV6:2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c? ([2a01:4b00:bd21:4f00:7cc6:d3ca:494:116c])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c71b786d8sm11392383f8f.0.2026.10.08.06.15.46
(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
Thu, 08 Oct 2026 06:15:47 -0700 (PDT)
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-User-Agent: Mozilla Thunderbird
X-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>
X-In-Reply-To: <20261005004958.3603059-3-almasrymina@google.com>