Article View: linux.kernel.netdev
Article #7802Re: [RFC 04/11] dma-mapping: add dma_alloc_attrs_node() and dma_alloc_coherent_node()
From: Björn Töpel
Date: Tue, 27 Oct 2026 09:03
Date: Tue, 27 Oct 2026 09:03
62 lines
10410 bytes
10410 bytes
Jakub Kicinski <kuba@kernel.org> writes: > Coherent DMA memory is always allocated on the NUMA node of the device. > That's the right choice for memory mostly accessed by the device, but > some coherent allocations are accessed by the CPU on every operation. > For example a NIC's descriptor and completion rings are written and > read by the CPU servicing the queue, which may well be on a different > node than the device. Placing such rings on the device's node means > the CPU accesses remote memory in the fast path. > > Drivers work around this today by temporarily changing the node > of the device with set_dev_node() around dma_alloc_coherent() > (mlx4, mlx5, ixgbe, xgbe). This is racy against anything else > looking at the device's node at the same time. > > Add dma_alloc_attrs_node() which takes the node explicitly, and > a dma_alloc_coherent_node() wrapper. dma_alloc_attrs() now passes > dev_to_node(). The node is only a preference, the same as for > kmalloc_node(). It is honored by dma-direct and iommu-dma, for both > the page allocator and the per-numa CMA areas. Allocations from fixed > pools and from dma_map_ops->alloc implementations ignore it. > > The memory is freed with the existing dma_free_attrs() / > dma_free_coherent(), freeing does not depend on the node. > > Signed-off-by: Jakub Kicinski <kuba@kernel.org> > --- > Documentation/core-api/dma-api.rst | 15 ++++++++++++++ > include/linux/dma-mapping.h | 14 +++++++++++++ > kernel/dma/mapping.c | 32 ++++++++++++++++++++++++++---- > 3 files changed, 57 insertions(+), 4 deletions(-) > > diff --git a/Documentation/core-api/dma-api.rst b/Documentation/core-api/dma-api.rst > index ba23a472f794..f9a32b8c338f 100644 > --- a/Documentation/core-api/dma-api.rst > +++ b/Documentation/core-api/dma-api.rst > @@ -57,6 +57,21 @@ The flag parameter allows the caller to specify the ``GFP_`` flags (see > kmalloc()) for the allocation (the implementation may ignore flags that affect > the location of the returned memory, like GFP_DMA). > > +:: > + > + void * > + dma_alloc_coherent_node(struct device *dev, size_t size, > + dma_addr_t *dma_handle, gfp_t flag, int node) > + > +Same as dma_alloc_coherent(), but places the memory on the given NUMA node > +rather than on the node of the device. This is useful for memory accessed > +frequently by both the device and a CPU on a different node, for example > +descriptor rings serviced by that CPU. Pass NUMA_NO_NODE for no preference. nit: maybe mention that callers that want the device-node semantics need to pass dev_to_node(dev) themselves? Björn
Technical Details
Message-ID:
<87ik2n5xcg.fsf@all.your.base.are.belong.to.us>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-352301-linux-kernel-netdev=dewy.ruReferences:
<20261027022528.633359-1-kuba@kernel.org> <20261027022528.633359-5-kuba@kernel.org>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-352301-linux-kernel-netdev=dewy.ru From: bjorn@kernel.org (Björn Töpel) Newsgroups: linux.kernel.netdev Subject: Re: [RFC 04/11] dma-mapping: add dma_alloc_attrs_node() and dma_alloc_coherent_node() Date: Tue, 27 Oct 2026 10:03:43 +0100 Organization: Usenet Network Message-ID: <87ik2n5xcg.fsf@all.your.base.are.belong.to.us> References: <20261027022528.633359-1-kuba@kernel.org> <20261027022528.633359-5-kuba@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="1498353"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:C52GBEoA871ziTI1XsYnK7GxkLM= sha256:6oznRV8P5L7IHMuBqiATeatoHJqP8GKDQZ0zvbtRNho= sha1:aIsxPc/BBrh0W02epAGuqvStM3g= sha256:2dShL2yAnkDUjKTj5vWXNUrRtBwFabOn/5hSr3ekvx4= 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 EF05C125BE4; Tue, 27 Oct 2026 12:04:27 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.739 X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org 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 0DHelgwwRNl4; Tue, 27 Oct 2026 12:04:24 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-352301-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 6631B125BE3; Tue, 27 Oct 2026 12:04:05 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 7F3862763E; Tue, 27 Oct 2026 09:03:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793091837; b=HtlvAEAP68MakjVcdo0SaVGcK6Z2TI1S63X3/yGIEqJlofW+Kr8oU5nHlhMtQ52dt6fa 76+oe2h7JpCvlhGzoZXaahvb2k54pK1s8kf/szhU8PFj7z6QGy9IWHOIhQ6jsRXA41KI+ 7+T64xTfKGVQR3RyHIpy1FDhhR2GNn7ZCwwNvCP/xiFKFSeYfowaa5WQoPbZ4tlKfix9s Gifqctpgb0UimdeBH5WCre1zMbYWIzWEDVx4T/aJBWeF7/zDGgcVQNc7YRMQXshfiZN68 xaTusc4JMVePKco5AAQnkhtFW0H7dtJNHoOxrthTJpdVW0EWkBv7M34FhEvPiWz1ung== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793091837; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: In-Reply-To:References:Date:Message-ID:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=Oq/NLq0hF0YNbjoxEYrSRua4DzcQtn2MtQoJ/wISxKs=; b=UZXapmyFP+QB2aeghjclEiMUT9xp9Us/BrM0xUfzgYonVPGAYmRXrGVpdghHGQw0Gv3b Hqa7h8nboJ8sVjbXIJ3mGhIN8FLXj0+y/cYNPwCEJBHuX7TFWUNgD6PiVoXCESCSmthn+ WJ/TsBoWlDJtRLgCxgPmH9T3h/NQEHH9DI4wPoeGqjP3vJt6GOD1iVi4tgJXKgdj7ymSq MQZe9Ow0FGob5tDhsNu3xfR+/zl5CyBjP4f/XT9wqU12fSUbqc0+VfexzJKB1DC1GHEUd iz+cKCTRdKBYRN5YIRJQPYdPGonxTMcK4E6kze1h4vFUdmasv/7rrhqJRDMr0FsFkZw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PUjbFXxi; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4332E606A31F; Tue, 27 Oct 2026 09:03:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PUjbFXxi X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793091826; b=u7XQtIosImkm5nBoxYOPX+TbX+KUw0tile6BcF5vF09C2DUruP5J20ZrHAyZY1CAqf5J h5P4OcNNB9SegdEa0T4CmvdmXGCgxxltAj5RXHTIjs4DPW0J90ZY91WqfZtJoHxXUDCOX KCaCzHbQlQjWACkpuxBu5h71AUUO9PGEnMfD3AUV+ngqmA7S8sfAh9rjViQ85ln3KIUTA ZOMK9oZbQx0VQaRXXbSpM/E++FXqVEKHAYF/YSREiT+OcxWUE4LIQhB2igv/aGP67J6YY rHilfqLD6Vhw187ydTLapDl/ABPo/XyfgVQDdoExi1t8tLmu3Jp1jmU14g2FEy36G3w== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793091826; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=Oq/NLq0hF0YNbjoxEYrSRua4DzcQtn2MtQoJ/wISxKs=; b=LIzw167C5fDnbOanWSBc0EN/vBwF0cVrj6BIxd0pgbI3x56/3PToamf9WHHjuI1dUPd0 fu3htOD4lpKYB8Kpnpf5HhLHgzGqfec3juWwswb7hLDvzAeWPuovPVfJ8766K9ZpaPPTt JpzW3RSyYtDyZJU0O1sqdRJb9AyjyerpDztepIU8RnE47ztDdc5OudAieB2vLb4ALIXBc N+R1+GnSvSxBSN/tg8HijU+la+rQjP6AtQwK0pRcXnjw/o+RCC9bpdkIngDja5kk/hyMf zWf60Sx1J8KvIAURu1DDUldlp0GMTGO1JWsPO+X5g5cFUUsyPdnzrmHBQ5+P7mH67lA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PUjbFXxi; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 219A3606A31A; Tue, 27 Oct 2026 09:03:45 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AC441F01828; Tue, 27 Oct 2026 09:03:44 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793091825; bh=Oq/NLq0hF0YNbjoxEYrSRua4DzcQtn2MtQoJ/wISxKs=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=PUjbFXximrgiOdbmR5Cjl83J0obwP/45C15xDJy56g/3Tdqv4LTHbPbMFHGoYGQt0 9bdyJZzNhRnnV5MZ6KFgIn6BwIz94Wj/CF9fauDgpnCDPEHkK6V6r0ZLFS02AgZTgo tsd77CFb+OVNW6nz9mXuR7QhlBDNczNUJqsvu3KwFffmjrnnfhI0LN3L9Ip0B2iEMq x2s2R44DqmYgGTMOTuVPKhsMQHQzWsg+ufQPc377+DV2p+gobOG9EgkXmDbsqvb9fI G5py3vHYZmA5zecmFyEiKXf3vVuW752jZkcFxOH9ch9cNdm5JHZTJbqwo0jS34kIB4 ieB0Q9IozveCQ== X-Cc: tglx@kernel.org, dave.hansen@linux.intel.com, x86@kernel.org, joro@8bytes.org, will@kernel.org, leon@kernel.org, mbloch@nvidia.com, iommu@lists.linux.dev, netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org> X-In-Reply-To: <20261027022528.633359-5-kuba@kernel.org> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list