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 364FAC83F03 for ; Fri, 4 Jul 2025 15:23:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E8186B0377; Fri, 4 Jul 2025 11:23:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94A576B0375; Fri, 4 Jul 2025 11:23:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 812EC6B0371; Fri, 4 Jul 2025 11:23:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6B7AB6B036B for ; Fri, 4 Jul 2025 11:23:29 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9EA098011F for ; Fri, 4 Jul 2025 15:23:28 +0000 (UTC) X-FDA: 83626951296.02.BE6168F Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf25.hostedemail.com (Postfix) with ESMTP id 04ED8A0004 for ; Fri, 4 Jul 2025 15:23:26 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TtgRfuFO; spf=pass (imf25.hostedemail.com: domain of dakr@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751642607; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VNirhw0kWHn3FeDvyaTGxRXl3GshfXFAPPpNoOe/Lko=; b=J+DIWJczn2BdpwtLio3WdVzXv2EVcwlzniTARj1hDKDkYMcO3bUGeabqm2ygwaWTcViICY OiMxMlRN79FTp291c5HqE09gkZLv5rBPzS7VmraF2Z4C3PT7VUkcjpI+QVb59Nqa6p1LFt bmquz9BiRwBtVRUsEDyPis6wE5z5EBg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=TtgRfuFO; spf=pass (imf25.hostedemail.com: domain of dakr@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751642607; a=rsa-sha256; cv=none; b=RPBbx9sDKzWmKLovzN8rhrZNHj9ZR+6vXpw17eefGQJx/rKU3T3bI3cCmUIh89hP6TJvBt LJj7xJmnOQh4knUPcSGbgldLe7wt/MRbb/803k7+pcTlMSvM0ywmV4U/Qjk8F1/OGh38WN R+8qJPhWJbVt1d72IwoWLrbrGD4o0j0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 37D3760EDF; Fri, 4 Jul 2025 15:23:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43FC3C4CEE3; Fri, 4 Jul 2025 15:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751642605; bh=VMeaW3Ht2VUKwFFv83ENRZAVecXmY4f2VHjBo+Z4deM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TtgRfuFOSIlrv1J6PondeD5tMTcQPAWDgcTh/Sgpwph3ZTopWVQ21ITkHdrBkgTNw NqQNQad87f92ic6VOXt6Oa+DMzjyb9s3cJTN94jftILJLpbUjGPEqhCWwyJL3QtcoX jbkiGUU62m9ukRVMH62BXjpdDji+OtEE8JLXZPFzItwFXiUhtfHTNkdKz/2KIvfbHP Jdf/WtxGpZkiVE37RYqLxtTdnMFqIOvL1lk0XweVgaPttfvRbhq3K9ygTJ0hix34fR MnCMK3LngdKNlh35dGNm+IfEVweBqhgUoudgsKszkdVDbG+PiFKQBhO7u86HfoVPBM UbxY+imH3+kZg== Date: Fri, 4 Jul 2025 17:23:21 +0200 From: Danilo Krummrich To: Vitaly Wool Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Alice Ryhl , rust-for-linux@vger.kernel.org Subject: Re: [PATCH v10 3/4] rust: add support for NUMA ids in allocations Message-ID: References: <20250702160758.3609992-1-vitaly.wool@konsulko.se> <20250702160910.3610134-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250702160910.3610134-1-vitaly.wool@konsulko.se> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 04ED8A0004 X-Stat-Signature: hxdcubxf6gcs7xc5bc3bah3znt4ki3r3 X-Rspam-User: X-HE-Tag: 1751642606-287742 X-HE-Meta: U2FsdGVkX1+0nEcxBJzzyhstSPOVYIoJowXnLnXCPP3ka5wUHsoKzzyHPYYtMAg0aUnvStwA08kVr5TVhalWzg1BX14BeRgfH9wsLIEMXDfP2yYjUbqBLRGjldfziSVUFsCK4zcNfiJE6wxpwYVff6yI9+Z7gdYxiZXhTOuaSJcqmaKBLuyOM6AJKmrIhWpOG+yqaaQm4TboZ3Jmdhn99VCzELa1NlaU1BlbPtvzutJu3hfdFXJMGOD2b2Mku+50+6O9BUNBrfhU+6Dm5/2DxLIK6zA/bTXHzsDlmBoM7HwW3Jxd9G9NJwjw6l+MSLHJWF+mydMkPHcUYi/KKnud25OqKYzGOgY/sYElu/aYIzJHqcx6TWvXn/qm6o9lMMEGU+CS/pPY+PALfEOqcwka+dzQ8QmOcLL+axqeReBod8z1d0J8XjZwOJ5Nj+rjg95QTD1Q2QZ3WRZ4tyfd5F0EsyMR0YHjCnODpUP2H8ZXjzRZLeWAmAZJwAqi6YCrW8RMp8vtr1j9BSYUBYAVXU8IKiKtF2ZNZ3NQmbPKIaog6qkpqY1rN0bP/cIaqvIsdFf1ioloS9Z5k/XxAfTAb/qY9MaaBBvoSfHbGi7wfrfPDluJNecB4nHyAEqE50AC5I7OF9RyVpNrYEZ5iaAqw2pr2t9QQGmrK9vC3eRt/38Ra1x5AFfGcV3WguuCTTpXom1zxnylC0mo+f9IJkN/cFzjHyAOIOHw4O5FRaAUv69fRrG/HIjigUAsp3D0dRmLdsK/nl9RHEX9cS/mCljmZ0byamWlmzMy5MkXPpziaM/D3huaotj1gBub6H97Ru5dUd0KycgenFtd3Iprn23E59wmmFeEaMAxyXMR+0x3dOJO59hAB99DaUEXhEcvzdbdgFwu0GhYGrAKYJT4H0GwPV1uJAi5Irs0L8eHitDDmo0xrY4VcsRfYP8j27kcQXe6J2vCkBs4PmNhDNqfdpOH+YK gIxyg+2N DYc6c7D9hGToFgGWiPTMbiGwvIfqnWPNQn4z9MeRO+U7Yq4HZm518T01UFNNFJulIg3LDCePj22ODPjkyP9CSx7N8XRyltXWdmo6Ay6yBoXlAgS+vY9N56vlg5OYzB84cdpMGDTd4pOSgFYWHhwPm05KM/WTL8LWjAKw/PhNR0mfMVy+7q2L2EhwJVWlt+vCLOAvlzZTu1ydjz5HZUDteh5PoDiAevsNeDBQxPgIDNSCx1IgH6wQPeF9rjJG+2RS5gy4/M3pOq6kU/9+C6kVIk9+qFicxsQLw69rj646s/q/8+DY= 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 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) } > } > > - /// 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())] == > /// 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>; > > + /// 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) } > + } I think Alice suggested to just drop alloc_node() and realloc_node() and make alloc() and realloc() always take a NumaNode argument. I don't have a strong preference, but keeping only alloc() and realloc() for seems indeed simpler, so let's remove the _node() variants. Regardless, please note that realloc() as you implemented it above misses the safaety requirement, which should just mention that the safety requirements are identical to realloc_node(). The safety comment on the subsequent call to realloc_node() would then be justified with realloc() having identical safety requirements as realloc_node().