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 384B2C83F07 for ; Mon, 7 Jul 2025 07:25:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D02A96B03FE; Mon, 7 Jul 2025 03:25:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB3276B03FF; Mon, 7 Jul 2025 03:25:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF0B96B0400; Mon, 7 Jul 2025 03:25:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AEC5F6B03FE for ; Mon, 7 Jul 2025 03:25:49 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7DF8110A356 for ; Mon, 7 Jul 2025 07:25:49 +0000 (UTC) X-FDA: 83636634018.23.825430C Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf25.hostedemail.com (Postfix) with ESMTP id D5E81A0004 for ; Mon, 7 Jul 2025 07:25:47 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ytBLpo1m; spf=pass (imf25.hostedemail.com: domain of 3enZraAkKCF87IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3enZraAkKCF87IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751873148; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HjXBHIGCko1Walk5rVzDSoSA5fXEne2gWaZ0Ckd/Q/c=; b=uHOcB3leoy024lO8SnxXJddVLOigWesJriYeA1TEqr3+AoOHPgUFSgMjIUCJbuMilXUs3M 0Vts/h+pfPv46dHXTBW5kBUy2sXL9kcLmjfP2eDjHLwxVxYP4aBlHQymrmtkh7fXrT9eYQ vCvM4jyAoE10NVN6wSmU4dAMfsS1pQg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ytBLpo1m; spf=pass (imf25.hostedemail.com: domain of 3enZraAkKCF87IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3enZraAkKCF87IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751873148; a=rsa-sha256; cv=none; b=FdTlXTH54WV20BWfbuAzQLpntnyk/RTlB89G2TiQaSi/EbveFkiAcSwVfvnyerM9qRVD6L 9FpxRaGpDW5q3nIGV4wPIccFBV7SC3nAx3XS63Kmhmu/XiGCWMrWgf0I7aExqshwleDRDb GMDpkc3kGfNL52ft5E6tN3qBNCnrB2w= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4530c186394so10759085e9.0 for ; Mon, 07 Jul 2025 00:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751873146; x=1752477946; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=HjXBHIGCko1Walk5rVzDSoSA5fXEne2gWaZ0Ckd/Q/c=; b=ytBLpo1miYSg++b1R1tP2s1e0it6ghVFuynW5f31ewDyD35cB2f7VLylqvRRxHWL4Y KFPECUaHJbWI+0FIrPlD5PTL3bYECqU1TA9yQTAsuJYu7S1IH0rOw0SR0hMtmFvL0Kzf SX0uTDJ50OmQuEXXFmApjLAD95Dg3t71WbUDFDof0Tvez83aoyTs6uSxyhdURlpzqqRG zw4b+87F1adUVBfIyQJw3ZlPdW4COqu2zJ5AMpGutYFFF1OOe6QNLOBZbQ4StEai5U3o 6g2+9m7YMHOAb9DrCf7CxSlN6IsBmQ/lef+LPmYklCZVdUyewlB7KtajyfV/7w8K5M9T teHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751873146; x=1752477946; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=HjXBHIGCko1Walk5rVzDSoSA5fXEne2gWaZ0Ckd/Q/c=; b=W0wXprdensZOszfTEnVPHJVKcUqZnmocjWXW4kYcFYxZBYO9RG13Rft61TgqyDg0vh ZTX09aQMCs2IHNPKmEDQSoJDp18rAngKdE5pJNRtM4ogSIXNOWuasaMJl05E9G3Bvlwe 4oiSDfOvTTm9Ksaenrf6GZGrqeH7JEP/WWGMoiS5QekV0+YfPdtC+1le7CtcN3M+ggTE I6BoGwWnYfjM5bs1YsASuOD1mh1hbUzUIzOVm/dDZ9ESbbwVr+ygaxb+8jRDhKbuxqhx 71g+jU2Ab7br37mP1R/X0huONPmGM1fdjDs6FJc8l/rpxA9l5uLoZ+B4h9LZdjZJ+60h 3jUw== X-Forwarded-Encrypted: i=1; AJvYcCUVHcXWW0yWOcgvuKrVKPzfOAifEmFAlrZ6auL1HTdiw8IhBxVpf+iNxjpwmi9BE0xUvzkMvCSVyw==@kvack.org X-Gm-Message-State: AOJu0YxhdJOKptvNTAEFufXIwx6lS06pEbVSJSknplzMiGKds9AFHEyD L51n0WrBGh/O1UsMMGVBXuKJFcT8rvWz01AMch4dFkn9xFSqILf2MFViVwRaP8skYM3u3SW2JLC QAlyANl7yzHqhch3Nhw== X-Google-Smtp-Source: AGHT+IHnB4goyApbwUk03PZ8amZ+9lz0KfhPl/FnIn9n3QVNQffOoWFFNjsjkGnHrSVq3Tb+2bkKpL9KjoAAl3Y= X-Received: from wmsp32.prod.google.com ([2002:a05:600c:1da0:b0:442:fa3c:8612]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:190c:b0:442:f482:c42d with SMTP id 5b1f17b1804b1-454c6531885mr18514585e9.9.1751873146473; Mon, 07 Jul 2025 00:25:46 -0700 (PDT) Date: Mon, 7 Jul 2025 07:25:45 +0000 In-Reply-To: <5BDED328-4E79-4E39-95C3-21C3FB80593C@konsulko.se> Mime-Version: 1.0 References: <20250702160758.3609992-1-vitaly.wool@konsulko.se> <20250702160910.3610134-1-vitaly.wool@konsulko.se> <5BDED328-4E79-4E39-95C3-21C3FB80593C@konsulko.se> Message-ID: Subject: Re: [PATCH v10 3/4] rust: add support for NUMA ids in allocations From: Alice Ryhl To: Vitaly Wool Cc: Danilo Krummrich , linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Queue-Id: D5E81A0004 X-Rspamd-Server: rspam09 X-Stat-Signature: dkfykn81aanrczr5ywtcmiuj6fehokoa X-HE-Tag: 1751873147-816295 X-HE-Meta: U2FsdGVkX1/nzmxnAuYRx0Oajzug5F9VtoDJjzSFT3DVukYZhmyZZfQO8VaUMXd6LLPO60BQ+Fe1zf07f16qn7FxWRQGvahqwKCNDHAfurYfTDgR10eZnGoxLAnTmbqJjtpHosK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1uTZo7mGXGPKNuln1eHGUL+3U2+bs/xkewtNCLj4PcOW63P8ONinxFvZcFWnifAr3QWcBsf5bgLzmqVyVEzgTwZw== 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: On Sat, Jul 05, 2025 at 09:17:10AM +0200, Vitaly Wool wrote: >=20 >=20 > > On Jul 4, 2025, at 5:23=E2=80=AFPM, Danilo Krummrich = wrote: > >=20 > > On Wed, Jul 02, 2025 at 06:09:10PM +0200, Vitaly Wool wrote: > >> /// The kernel's [`Allocator`] trait. > >> /// > >> /// An implementation of [`Allocator`] can allocate, re-allocate and f= ree memory buffers described > >> @@ -148,7 +172,7 @@ pub unsafe trait Allocator { > >> /// > >> /// When the return value is `Ok(ptr)`, then `ptr` is > >> /// - valid for reads and writes for `layout.size()` bytes, until = it is passed to > >> - /// [`Allocator::free`] or [`Allocator::realloc`], > >> + /// [`Allocator::free`], [`Allocator::realloc`] or [`Allocator:= :realloc_node`], > >> /// - aligned to `layout.align()`, > >> /// > >> /// Additionally, `Flags` are honored as documented in > >> @@ -159,7 +183,41 @@ fn alloc(layout: Layout, flags: Flags) -> Result<= NonNull<[u8]>, AllocError> { > >> unsafe { Self::realloc(None, layout, Layout::new::<()>(), flag= s) } > >> } > >>=20 > >> - /// Re-allocate an existing memory allocation to satisfy the requ= ested `layout`. > >> + /// Allocate memory based on `layout`, `flags` and `nid`. > >> + /// > >> + /// On success, returns a buffer represented as `NonNull<[u8]>` t= hat satisfies the layout > >> + /// constraints (i.e. minimum size and alignment as specified by = `layout`). > >> + /// > >> + /// This function is equivalent to `realloc_node` when called wit= h `None`. > >> + /// > >> + /// # Guarantees > >> + /// > >> + /// When the return value is `Ok(ptr)`, then `ptr` is > >> + /// - valid for reads and writes for `layout.size()` bytes, until= it is passed to > >> + /// [`Allocator::free`], [`Allocator::realloc`] or [`Allocator:= :realloc_node`], > >> + /// - aligned to `layout.align()`, > >> + /// > >> + /// Additionally, `Flags` are honored as documented in > >> + /// . > >> + fn alloc_node( > >> + layout: Layout, > >> + flags: Flags, > >> + nid: NumaNode, > >> + ) -> Result, AllocError> { > >> + // SAFETY: Passing `None` to `realloc_node` is valid by its s= afety requirements and > >> + // asks for a new memory allocation. > >> + unsafe { Self::realloc_node(None, layout, Layout::new::<()>()= , flags, nid) } > >> + } > >> + > >> + /// Re-allocate an existing memory allocation to satisfy the requ= ested `layout` and > >> + /// a specific NUMA node request to allocate the memory for. > >> + /// > >> + /// Systems employing a Non Uniform Memory Access (NUMA) architec= ture contain collections of > >> + /// hardware resources including processors, memory, and I/O buse= s, that comprise what is > >> + /// commonly known as a NUMA node. > >> + /// > >> + /// `nid` stands for NUMA id, i. e. NUMA node identifier, which i= s a non-negative > >> + /// integer if a node needs to be specified, or NO_NODE if the ca= ller doesn't care. > >> /// > >> /// If the requested size is zero, `realloc` behaves equivalent to= `free`. > >> /// > >> @@ -191,13 +249,27 @@ fn alloc(layout: Layout, flags: Flags) -> Result= , AllocError> { > >> /// and old size, i.e. `ret_ptr[0..min(layout.size(), old_layout= .size())] =3D=3D > >> /// p[0..min(layout.size(), old_layout.size())]`. > >> /// - when the return value is `Err(AllocError)`, then `ptr` is st= ill valid. > >> - unsafe fn realloc( > >> + unsafe fn realloc_node( > >> ptr: Option>, > >> layout: Layout, > >> old_layout: Layout, > >> flags: Flags, > >> + nid: NumaNode, > >> ) -> Result, AllocError>; > >>=20 > >> + /// Re-allocate an existing memory allocation to satisfy the requ= ested `layout`. This > >> + /// function works exactly as realloc_node() but it doesn't give = the ability to specify > >> + /// the NUMA node in the call. > >> + unsafe fn realloc( > >> + ptr: Option>, > >> + layout: Layout, > >> + old_layout: Layout, > >> + flags: Flags, > >> + ) -> Result, AllocError> { > >> + // SAFETY: guaranteed by realloc_node() > >> + unsafe { Self::realloc_node(ptr, layout, old_layout, flags, N= umaNode::NO_NODE) } > >> + } > >=20 > > I think Alice suggested to just drop alloc_node() and realloc_node() an= d make > > alloc() and realloc() always take a NumaNode argument. > >=20 > > I don't have a strong preference, but keeping only alloc() and realloc(= ) for > > seems indeed simpler, so let's remove the _node() variants. >=20 > I don=E2=80=99t have a strong preference either but if I modify alloc() a= nd > realloc(), I=E2=80=99ll have to change KVec and KBox in the same patch, w= ould > that be okay with you? That's okay with me. Alice