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 DADBAC77B7C for ; Wed, 25 Jun 2025 18:56:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 445786B00BA; Wed, 25 Jun 2025 14:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F5446B00BE; Wed, 25 Jun 2025 14:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E49A6B00C0; Wed, 25 Jun 2025 14:56:09 -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 161886B00BA for ; Wed, 25 Jun 2025 14:56:09 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 885B11D711F for ; Wed, 25 Jun 2025 18:56:08 +0000 (UTC) X-FDA: 83594828016.06.9267DAA Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id D0B721A000A for ; Wed, 25 Jun 2025 18:56:06 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KpV8Fk4w; spf=pass (imf19.hostedemail.com: domain of dakr@kernel.org designates 147.75.193.91 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=1750877766; 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=ZG/aas4QijMicHw+rEKjDMg29pxsYPLxjuYhyOwzYI0=; b=PxTn9kR89qqj6FvOMVVRx8phiUC+Jc+OVsZttcobKToc67VR2MjTOR+eONFjFag4VxxgBR og1in/vk8sCsxOWlBu4AAVle2jezasJv4Nv4RsQ+MpM1FxcKogrByCdIVLA63Z0W4U0b2t W740ebzJpv7U89aPqM8eL/jyQz4UAzE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750877766; a=rsa-sha256; cv=none; b=x9vL5G38dpKum3fBRp+fpiJI7r4DSR2o2AaCQxMcIbH4in9tyXM6uzbbm8lX2cNDturOto 9zFi40TB9Da1faGpwl6IzzsveqxDT4mNFM+7IqQYELm8+L2zqjxvdRoolDJ0PpVZDmZSdG IdcaVZnqAsuWKjwLcI5GAc6abhwH/eI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KpV8Fk4w; spf=pass (imf19.hostedemail.com: domain of dakr@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 25F78A52103; Wed, 25 Jun 2025 18:56:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 331A3C4CEEA; Wed, 25 Jun 2025 18:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750877765; bh=xOFkaPALEr96n45ZXxDSSZiyNX3n+26t1/APa5EPG6w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KpV8Fk4wsOTCJ3F3AtTznHgsqgYKNDh8sLJiuj0nYF8J3Y5RULc+AdRPI7rhxlTNg x2XAWU6ybjtHLxU8/dMJ451MxNjgBIpErQ4kFIbqc6q0Bv+P5lz1Lv4JkGIv+pGsa3 i+E8oQt9XZDSAHD84wquU+7alWnYb96T4ed3DNmx8Np4g8tRBP2P+IDfZJ9fYfCyAI y50sjF/Dur0QuvfXYVVEFR1DFuSun3GJVF1xvWdBsOJMCtheNbJYrpDVhl5kEWE8S/ MWWfUXbUWmETzq4yZATnGKLJRAXpmuVY9OSqgf3dv0Vm3qRicUhH/72tkSQGiw2T6q ElabgicGpHggw== Date: Wed, 25 Jun 2025 20:56:01 +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 v3 2/2] rust: support align and NUMA id in allocations Message-ID: References: <20250625062917.3379804-1-vitaly.wool@konsulko.se> <20250625063026.3379921-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250625063026.3379921-1-vitaly.wool@konsulko.se> X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D0B721A000A X-Stat-Signature: qiyzm95s3n1z88dhy6mgow9o4u89ncaw X-Rspam-User: X-HE-Tag: 1750877766-477230 X-HE-Meta: U2FsdGVkX18CeFsR/+SK9y0RDCFgRLkEfzQ69Qjn8RPrr19EVgv/M64cm7VgY6WFei1kMpiPtNKA3z/0/+ngxrMck2FalBuiSkn8RR94+HhOgmTvOgx4hV2D3TJpHX2AJCOeCpgdHYHL9e8ezYNa8LPFZfqEsCE8K8DephlAFr1CSHRdmSnuT1DxJpuJIKqpeIun9c+IMl8u807BTNvzdCbgJRkI5zf7l8LpdFzFRaeAEFIvslfF+ILanr1s6Ibc8qeHGaPnZNhfgVLcboN+2Zskh/mrwKax3ceCkE9nSXDZoM2AeB56TYw9KHwo3qgb4aZZvZWixxw8fyaTS6Or29GfoiuNKEAQnIFMjZblieWh0dSxYKx858X2VxJI3JjXeVHo6bBBLhoN8fMjws0wFXTeN9CSLgqBZsqU1IIgAhfsTPUdq2K+oGWQf0ByrRHts9+7AHhKl5lsg8JyyXKdmzlKt6yZHQjPClRF/TJlh/ZiRo6xkzBdpa2rMsnBAIA6jY/qkT26rzCZnkI27mfsry0v3rTSZmd1NNNydIU1ORE7flVpsYLBjfH2WFOv2SKtLIfPcRpfXNTSEyZHPW01yl7vfMq82i/cQUSxfn1jR3NWcnKirH1bfDz1ogXcIQt/RLRSAL3pEuT6PBjLqp9KKSnj9JlSAt7PKGY3u06sj9HPvc43MmAgTl+62yAy6E4ddLz/UxV0LZ8RumqMSU4nEEssCBtMq7MqBMeyR3AVv9IoLfRrcnYupOU29illAW4Q+XHEZamlFqv9W3ZKd+RB9vxZtAo0flw4lyPAkUHgfRYRk+T1JEBJ7nsa8XvG+PhDosNaKEBU05N7raaQNLL36rfFBQeXY8x2wbAOXf6rRObzzkVPCXFlam8m7Rkjp2/sSFM58QlrblxegXrZ+2twYShjF//4sWcIUeLRL37/pfceyND++dS2tM16CC9B9oHa0BoFkpEkRDwEgcxOUup vgjyQhLI QM+IHPmgQfwp4qa9XvRZ59p0IJaa7vLPSMS/bOv7jZEP0iTzotH+hs6/h59j0XiRP7nYzTNqsBMfp6w4QtEEb8Lp1zFwh+bbihKImSWPZkh2/hQiLRiar9g9z3rnpY16MYWa3juQP3fCvwKEC/4/10vAa+m7BlzY5khUf8Wv4P1Mk+TX22397CQNy0X42xnfrCIWFQ8mt+x0JJ5gTthcui4DNzBuAelSZNqG9Vupw7FUE719y1FHfRBjE10bVTVRpBeyFffrJBtuUNl8KXKIXwhklqFLOkAQhLKXHz4h+aVuCwu4= 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, Jun 25, 2025 at 08:30:26AM +0200, Vitaly Wool wrote: > Add support for large (> PAGE_SIZE) alignments in Rust allocators > (Kmalloc support for large alignments is limited to the requested > size, which is a reasonable limitation anyway). Please split this.. > Besides, add support for NUMA id to Vmalloc. and this into separate patches. Please also add some information to the commit message what you need node support for. Do you also have patches to add node support to Box and Vec? > > Signed-off-by: Vitaly Wool > --- > rust/helpers/slab.c | 8 +++++-- > rust/helpers/vmalloc.c | 4 ++-- > rust/kernel/alloc.rs | 28 ++++++++++++++++++++++-- > rust/kernel/alloc/allocator.rs | 40 +++++++++++++++++++--------------- > rust/kernel/alloc/kvec.rs | 3 ++- > 5 files changed, 59 insertions(+), 24 deletions(-) > > diff --git a/rust/helpers/slab.c b/rust/helpers/slab.c > index a842bfbddcba..221c517f57a1 100644 > --- a/rust/helpers/slab.c > +++ b/rust/helpers/slab.c > @@ -3,13 +3,17 @@ > #include > > void * __must_check __realloc_size(2) > -rust_helper_krealloc(const void *objp, size_t new_size, gfp_t flags) > +rust_helper_krealloc(const void *objp, size_t new_size, unsigned long align, gfp_t flags, int nid) This should have a comment making it obvious why the function has two arguments that are discarded. I think we should even separate it with an additional inline function. I do agree with discarding the align argument, given that it's not exposed to users though the Allocator API. I do disagree with discarding the nid argument though, since you change the generic Allocator::realloc() API to take a node argument, which for KREALLOC and KVREALLOC is silently discarded. If we introduce it, we should do so for all three allocators. > { > + if (WARN_ON(new_size & (align - 1))) > + return NULL; I don't think we should have this WARN_ON(). If we want to warn about this, we should already do so on the Rust side. The helper functions in this file should not contain any logic. > return krealloc(objp, new_size, flags); > } > > void * __must_check __realloc_size(2) > -rust_helper_kvrealloc(const void *p, size_t size, gfp_t flags) > +rust_helper_kvrealloc(const void *p, size_t size, unsigned long align, gfp_t flags, int nid) > { > + if (WARN_ON(size & (align - 1))) > + return NULL; > return kvrealloc(p, size, flags); > } Same as above. > diff --git a/rust/helpers/vmalloc.c b/rust/helpers/vmalloc.c > index 80d34501bbc0..9131279222fa 100644 > --- a/rust/helpers/vmalloc.c > +++ b/rust/helpers/vmalloc.c > @@ -3,7 +3,7 @@ > #include > > void * __must_check __realloc_size(2) > -rust_helper_vrealloc(const void *p, size_t size, gfp_t flags) > +rust_helper_vrealloc_node(const void *p, size_t size, unsigned long align, gfp_t flags, int node) > { > - return vrealloc(p, size, flags); > + return vrealloc_node(p, size, align, flags, node); > } > diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs > index 2e377c52fa07..12a723bf6092 100644 > --- a/rust/kernel/alloc.rs > +++ b/rust/kernel/alloc.rs > @@ -161,7 +161,30 @@ pub unsafe trait Allocator { > fn alloc(layout: Layout, flags: Flags) -> Result, AllocError> { > // SAFETY: Passing `None` to `realloc` is valid by its safety requirements and asks for a > // new memory allocation. > - unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags) } > + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, None) } > + } > + > + /// 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` 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`] or [`Allocator::realloc`], > + /// - aligned to `layout.align()`, > + /// > + /// Additionally, `Flags` are honored as documented in > + /// . > + fn alloc_node(layout: Layout, flags: Flags, nid: Option) > + -> Result, AllocError> { > + // SAFETY: Passing `None` to `realloc` is valid by its safety requirements and asks for a > + // new memory allocation. > + unsafe { Self::realloc(None, layout, Layout::new::<()>(), flags, nid) } > } > > /// Re-allocate an existing memory allocation to satisfy the requested `layout`. > @@ -201,6 +224,7 @@ unsafe fn realloc( > layout: Layout, > old_layout: Layout, > flags: Flags, > + nid: Option, > ) -> Result, AllocError>; I think we should rename this to realloc_node() and introduce realloc(), which just calls realloc_node() with None.