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 A29FBC8303C for ; Sat, 5 Jul 2025 07:17:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3AD06B03F7; Sat, 5 Jul 2025 03:17:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CEBBF6B03F8; Sat, 5 Jul 2025 03:17:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C026E6B03F9; Sat, 5 Jul 2025 03:17:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B0B146B03F7 for ; Sat, 5 Jul 2025 03:17:26 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1F2821084B3 for ; Sat, 5 Jul 2025 07:17:26 +0000 (UTC) X-FDA: 83629355292.01.EEA257F Received: from mailrelay-egress16.pub.mailoutpod3-cph3.one.com (mailrelay-egress16.pub.mailoutpod3-cph3.one.com [46.30.212.3]) by imf23.hostedemail.com (Postfix) with ESMTP id 77DFC140007 for ; Sat, 5 Jul 2025 07:17:23 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=IINvfj+C; dkim=pass header.d=konsulko.se header.s=ed1 header.b=A0EWOTTC ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751699844; a=rsa-sha256; cv=none; b=Guf0GFiI6s8Q+602ifgbTuxqiYjOCHHGDsnbgmJiITLd1/lXJPyk5tQDiRH8kQzsLVbkDJ IXyHwGibMAOMGsE/dxaOLTMS8BpB4vzQLArtaw2+e1BT6SxSuYr1OyKtszp8aeT6rCgjfs FjOKBtg+omXoKwBp5cTVJpBsEAn8NSY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=konsulko.se header.s=rsa1 header.b=IINvfj+C; dkim=pass header.d=konsulko.se header.s=ed1 header.b=A0EWOTTC; dmarc=none; spf=none (imf23.hostedemail.com: domain of vitaly.wool@konsulko.se has no SPF policy when checking 46.30.212.3) smtp.mailfrom=vitaly.wool@konsulko.se ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751699844; 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=0dF08nZ5AD94cqmTG2oD0kbPc0AyPxw2HHR1baJXYOw=; b=3CilGo8XqgeZty7YBlQa6tSp04emwgTQqdq+m2ce7PPIT9CysoFFt3UleSt3fdjmmrSyLu Kid8FAzdwkQJChFy27g96pzz14ffWMQnZlABQW+TylOX8e0hUDq+DLjDThmgZx6qeXXcl6 fK68Zg0gOpZru6FXb0khjx0tIbDBODE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1751699841; x=1752304641; d=konsulko.se; s=rsa1; h=to:references:message-id:content-transfer-encoding:cc:date:in-reply-to:from: subject:mime-version:content-type:from; bh=0dF08nZ5AD94cqmTG2oD0kbPc0AyPxw2HHR1baJXYOw=; b=IINvfj+C2bWDaUPKaeQ1dp124mX5RlbM2RmbMnDyDotbJvcQNyb/bDNcgdB8yTEETYpj1kKAV/3QM I29dOHvkouxSZI5kfF254SmD0bTUS3kN+91/2C1HyehRGePIBjZm6qJMR0xlrZVmvbbWiLN8c3QUXy Ib66Zyg/eLvppeS70jCNdgtsH0UnNpaXhDX8Pdg/rAkhWJJVticB5XJUHhk9k5LsUwaAZWFkD5r2E0 x6d9XvEi9EN4E5W0cITxN80BplO6UkfVuC2BFdClu1ldQARZl9dMYkXrvQt/oU/g3fAqv3f4WvUzy0 4tVI7Kjs9kMYbqBwqLySjJgc6VX+yYA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1751699841; x=1752304641; d=konsulko.se; s=ed1; h=to:references:message-id:content-transfer-encoding:cc:date:in-reply-to:from: subject:mime-version:content-type:from; bh=0dF08nZ5AD94cqmTG2oD0kbPc0AyPxw2HHR1baJXYOw=; b=A0EWOTTCHcbh2Whz4NRwaAMrW8SmMbqKP0RmpN38wNQC1MDBxxPf59eA8ZD4nsnqLfeJvMVUcbTjQ nm3e4qWCw== X-HalOne-ID: 16b71226-5970-11f0-b992-f78b1f841584 Received: from smtpclient.apple (c188-150-224-8.bredband.tele2.se [188.150.224.8]) by mailrelay1.pub.mailoutpod2-cph3.one.com (Halon) with ESMTPSA id 16b71226-5970-11f0-b992-f78b1f841584; Sat, 05 Jul 2025 07:17:20 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.200.121\)) Subject: Re: [PATCH v10 3/4] rust: add support for NUMA ids in allocations From: Vitaly Wool In-Reply-To: Date: Sat, 5 Jul 2025 09:17:10 +0200 Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Alice Ryhl , rust-for-linux@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <5BDED328-4E79-4E39-95C3-21C3FB80593C@konsulko.se> References: <20250702160758.3609992-1-vitaly.wool@konsulko.se> <20250702160910.3610134-1-vitaly.wool@konsulko.se> To: Danilo Krummrich X-Mailer: Apple Mail (2.3826.200.121) X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 77DFC140007 X-Stat-Signature: 5ax145h11yzttm5j9affghx166s3n5a6 X-Rspam-User: X-HE-Tag: 1751699843-656257 X-HE-Meta: U2FsdGVkX18cQihg56tQ3Exx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VOl92oWc5wqB9rS2/NC4/k56WNLaOvqP+73ZFC7SaSEPCxKR41zFDitFmeRTTMCQihJWSAOLC3dcXcb6CioH56///uIxJiTJZGCb/yQNozdPNvpuSlJc0E6kWMWcweJwg= 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 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 = free 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, AllocError> { >> unsafe { Self::realloc(None, layout, Layout::new::<()>(), = flags) } >> } >>=20 >> - /// Re-allocate an existing memory allocation to satisfy the = requested `layout`. >> + /// Allocate memory based on `layout`, `flags` and `nid`. >> + /// >> + /// On success, returns a buffer represented as `NonNull<[u8]>` = that satisfies the layout >> + /// constraints (i.e. minimum size and alignment as specified by = `layout`). >> + /// >> + /// This function is equivalent to `realloc_node` when called = with `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 = safety 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 = requested `layout` and >> + /// a specific NUMA node request to allocate the memory for. >> + /// >> + /// Systems employing a Non Uniform Memory Access (NUMA) = architecture contain collections of >> + /// hardware resources including processors, memory, and I/O = buses, that comprise what is >> + /// commonly known as a NUMA node. >> + /// >> + /// `nid` stands for NUMA id, i. e. NUMA node identifier, which = is a non-negative >> + /// integer if a node needs to be specified, or NO_NODE if the = caller 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 = still 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 = requested `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, = NumaNode::NO_NODE) } >> + } >=20 > I think Alice suggested to just drop alloc_node() and realloc_node() = and 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. I don=E2=80=99t have a strong preference either but if I modify alloc() = and realloc(), I=E2=80=99ll have to change KVec and KBox in the same = patch, would that be okay with you? ~Vitaly