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 5A199C77B7F for ; Fri, 27 Jun 2025 22:32:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A94C6B00A0; Fri, 27 Jun 2025 18:32:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6599E6B00A3; Fri, 27 Jun 2025 18:32:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 522046B00A4; Fri, 27 Jun 2025 18:32:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3C69E6B00A0 for ; Fri, 27 Jun 2025 18:32:12 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E61921403EC for ; Fri, 27 Jun 2025 22:32:11 +0000 (UTC) X-FDA: 83602630062.01.20D2A34 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf08.hostedemail.com (Postfix) with ESMTP id B3E82160007 for ; Fri, 27 Jun 2025 22:32:09 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A9UQeIVS; spf=pass (imf08.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.177 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751063529; 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=br5WSiRr6YbBvyoEMMiPobuOWBhVPC69Q743GJByIzg=; b=rFqa2sf+LHG9fpjCZjtjZC3FzgFBu9s02yuWT5FFFB2pTzTACDLzqg+t7Xn2My2X9tDP5j bCWZfLi8YqtAL4/ioGaoyhU3a/4/Ei64VriB2soPqeape3OmOn2MTXdwGHG11HAViFpCo2 NdSLCe3lUqd3TylaSjMe2oNRU9jfMco= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A9UQeIVS; spf=pass (imf08.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.160.177 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751063529; a=rsa-sha256; cv=none; b=cwrfGmCFOcJmuE6F+DXnwmwe6V3Wymop6XF3wlLF1Nsk1HQ6m8ibm+9+7GzVoGpdTmzE00 0wJ5b/Okv2AbTFfNPLX/GLF04gR6GxViCH/huOZJLZzzstIcEHsrnVb5I/u32KNwOZcDCc QmBYTxWwcuX7uDexZhi+8UQFaWL4aFo= Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-4a7f46f9bb6so4528481cf.3 for ; Fri, 27 Jun 2025 15:32:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751063529; x=1751668329; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=br5WSiRr6YbBvyoEMMiPobuOWBhVPC69Q743GJByIzg=; b=A9UQeIVSt6VxLMOBiF3KF2fCZlQGV6kqt7UVy6RTbsCdla4fnOz/JcwrBBL0sagSSv 2pd1DjAHBmo1ly6BX5W8a3yy5UU9u6rMs+k+z7H1ElKVv1Vr1NJSi3fPjpBbud3DjRdW 7H0d9jctSyYqjJQi6NpFHFV4z1hRJ/L1nS6pGbCL5ZIjtrDtKvVjt+djeVS32CSS3oy0 SYjWCVWRLexIFyrZPOYfnq2L3C6jCndBC7AxLagnWXbofIoTrvhOvfW8mtj6BeR7Qr4N hkkshhR7XdTvznMQ7eUtiDIqUSNmSG/5FrG9zAEjUDdKH7q7k6D45jptkVvVsMllbckC M2Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751063529; x=1751668329; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=br5WSiRr6YbBvyoEMMiPobuOWBhVPC69Q743GJByIzg=; b=Q7rccILEsJPw5fvO7GWIYgj9zwIeHQQ2NSvirdOuiWo3z56lUXsEYcoYKUa85B1Vd2 +hw+x485530CwWGS7CHjWDmE76EerJAG+6Iq2WkczlwQQ5zxATxOk8zZ6+sB/Zj1Z0YB QOKJ5yEAkNPic9l55+8RevLozub46BTQ73o/Z1QJ3oaGa+EcSd+52meWHrDEkf0nXgRt Ym3n4WWMrAjt/7xVfNR/oMbKITCnfI7du2A2CGRuOMultBfZ6w/7lvnLQaAigIRaFod0 NOlDaX/jk0jStNETwrepJt0GBQP7Nhh5X7CQdaU17dWg9QT3HD/nnr5NYhgYS+rPkpXH sG6Q== X-Gm-Message-State: AOJu0YwIjASCTgef0b4R9qlcioZTSrFwXPjiXDPqrdC2oS3+rL/xJNbE DnOJGq5cyyXruH6dZrHQCk7VXorPlWqB4ACvx91KFbknEQuPfRMWgpb8 X-Gm-Gg: ASbGncv8CCIOpSJ33NpdpnANAdjwQJbXXUaU+L3PAwcM/LaE+uK54oQyLkCP7RNhQDk 16BH2eEg+DYcF6Ke35wlmx/FGl623qzl9VVV0uPPtSq+Xz3epqXoJDPNj3nbHOGj0KYTkJk+HKL FNMMVJMHxbHgZb++h/Ott0CnfDbCGO+CSTx3WjyAjGx5H1igPYplBBrMcnuFvpqjaXCTpz84lSw HHDC7j24wXA5E0ENzSUSKlRNaEU+1PNu9EEYC8ILWINwpiaslATyqJxtETspFLiOzwFn69QyGDw zcTOWnaIFBS6ZNMsZDfO4YeLb5yj6YvjTpp/be8F2UfPPVfyJ3JjI8mYY8i3ocJQ1q1XvrUG6AM bTPNRWPeHzwwnFfK3k3wxbfI0gODd+l5ODu0XWFJjEd1mjJYg2wUZ X-Google-Smtp-Source: AGHT+IGrGoNO23RnYbA0hwXK2OwZ60t3Mr3Ath3PpQcdK2eZ53KfEnsVhXmf8Ug6jq21JyDENypSUg== X-Received: by 2002:ac8:5f82:0:b0:4a7:f57a:2fa7 with SMTP id d75a77b69052e-4a805066516mr41045941cf.52.1751063528691; Fri, 27 Jun 2025 15:32:08 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4a7fc5ad641sm19712881cf.77.2025.06.27.15.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jun 2025 15:32:08 -0700 (PDT) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfauth.phl.internal (Postfix) with ESMTP id C232AF40066; Fri, 27 Jun 2025 18:32:07 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 27 Jun 2025 18:32:07 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdegvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhunhcuhfgv nhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrghtthgvrh hnpefhtedvgfdtueekvdekieetieetjeeihedvteehuddujedvkedtkeefgedvvdehtden ucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhhphgvrhhs ohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunhdrfhgvnh hgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgvpdhnsggprhgtphhtthhopeel pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehvihhtrghlhidrfihoohhlsehkoh hnshhulhhkohdrshgvpdhrtghpthhtoheplhhinhhugidqmhhmsehkvhgrtghkrdhorhhg pdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunhgurghtihhonhdrohhrghdprh gtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdp rhgtphhtthhopehurhgviihkihesghhmrghilhdrtghomhdprhgtphhtthhopegurghkrh eskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghlihgtvghrhihhlhesghhoohhglhgv rdgtohhmpdhrtghpthhtoheprhhushhtqdhfohhrqdhlihhnuhigsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtohepsghoqhhunhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Jun 2025 18:32:07 -0400 (EDT) Date: Fri, 27 Jun 2025 15:32:06 -0700 From: Boqun Feng To: Vitaly Wool Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , Alice Ryhl , rust-for-linux@vger.kernel.org Subject: Re: [PATCH v7 3/4] rust: add support for NUMA ids in allocations Message-ID: References: <20250627212451.2181627-1-vitaly.wool@konsulko.se> <20250627212556.2181749-1-vitaly.wool@konsulko.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250627212556.2181749-1-vitaly.wool@konsulko.se> X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B3E82160007 X-Stat-Signature: chkmhf5897kz6qmxh19rgngorqmrt1tu X-HE-Tag: 1751063529-294339 X-HE-Meta: U2FsdGVkX1/UWiQ6xjCTNYTOHpRqz+s0hdJjQ6rK4ONci45Vy8tN/AsiBX/q02ZhR78s+bgHRoK/P78Ta5z9ErEYFW6YuJTJxSLzmJhsJ+nJ9RekaR0TJZNsSB+NgvGQsLgYVTJ7ctUVfkuTDdawswzKKFFFqTS6Wk7fhRvZHekq5YgQ9y9Jd4IoSvLRaqPfEUHp7EqnywIk/ASM5yGYdIR+1RQJlqcORr3lYwm6bsTYPpHSpBds/rvOM8x4rgTM9EO5YSMQjAP/Ex3jSogpdDh4t+3U7fJ2NcQCVLJ2CUGyYo5J+EhYIlX6M8C9WW6V425612dkHreKnH5fpdaJ+LKaC6vOpbRUi/GPNNwHM8iYLHVcGhGolJ+osyck0z/nGGuySutL/9XoB3j2YNv/su8uhxR+9uyII7Q/cxbuxLOvZBEOY0cxenpGlFIVu86aL04JglNNJUBvhCRl9fr1l7AMwJjxshaENYNixBWBNq0GMZALPP8IsDMS1r/GPCYSuZwRHMxEorjh7aBSOK/gp6zk3GHckBmLnjy/QURuSWLu+iarQNvZFf5kMmeKe2/N0ibdULTz7xb5Exh+QwDI9sVsM4mg2syGMG7Mo3pE80b3IYlHQZ8Ryprrg1TYdARxhYPeXPBaVm3hkLl56EBthd9KWxUB/PRsjiec3ga2JG747O3PawsrwpOPLhAZMm8Jj2xL45G+3MrubM2Y967PfVX1GpHl++Ug2093PZ9gCSvoRcah7OyV9pdUilUbHZ9cMsz7ASGvd/J/SKAoaBYurUEIWRGGk6ENlM5O6dzk4+AFaDOdJLcMzjofIUdikPLpcni6xXNrfHFJTE3TSA67zxuWHoVh7yxjZkyH1eIyrpcVcpebjSP4qstJSZ7SlgnrmRWa5/vxDeKrHiIF7NOQKg3Tye/q5KRLp2nQoeX3L342K005/1uldgTGtSAABtdQujhJfKIZE1CkZTmc1lJ 4sEgVKip S5aSfsX/UMI8ubtEbwMJfQB8d4qJlMZInUE0ebUf3xo/zVmFQb5MwJLe1ImxsrnoJCM5q6NOzboLQZ1ug3u9qDHOz5izKJGorkQIeK5TjQ6+jDwxguzpXQY8dtAvvTC+BjKRbASgHKA9Du3e+5Zp30eJOriHzjHV1G0bPHr8egI2KSnE2c9yHQcbziL5hfLBzhTYeRxt8juacRyxd4cAG9QfAWvlSxxobqAvgD5g0pWRweRwd/tsQcw3kTUKH6sWzOvFm+JH2YfYYZhrsEZI1ODpbPKcxnbpWtg4+/VTEdWPcAugNiTi0Zy+NyCwALjST8Zfik03o1p+jsHGuinOwXZyXP1wn8rUIeJlkNSqru6GE9DzC3ui3xxmbi/73vhI/7qZ53i9rfgxi7QPOW5WOMuFOkRpY0yYVHxXIf7X9uT3c56DSTJhD5PdzTtO0zETzgsfuhiBjFJxBqvA= 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 Fri, Jun 27, 2025 at 11:25:56PM +0200, Vitaly Wool wrote: [...] > +/// Indicates an attempt to specify wrong NUMA node > +#[derive(Copy, Clone, PartialEq, Eq, Debug)] > +pub struct NumaError; Do we need a separate error? I think we can just use EINVAL... > use core::{alloc::Layout, ptr::NonNull}; > > /// Flags to be used when allocating memory. > @@ -115,6 +119,28 @@ pub mod flags { > pub const __GFP_NOWARN: Flags = Flags(bindings::__GFP_NOWARN); > } > > +/// Non Uniform Memory Access (NUMA) node identifier > +#[derive(Clone, Copy, PartialEq)] > +pub struct NumaNode(i32); > + > +impl NumaNode { > + /// create a new NUMA node identifer (non-negative integer) > + /// returns NumaError if a negative id is specified > + pub fn new(node: i32) -> Result { .. then this will be just -> Result > + if node >= 0 { Ok(Self(node)) } > + else { Err(NumaError) } Have you run `make rustfmt`? This code style looks weird to me. > + } > +} > + > +/// Specify necessary constant to pass the information to Allocator that the caller doesn't care > +/// about the NUMA node to allocate memory from > +pub mod numa_node { Nit: I think we can name this mod as just 'numa'. > + use super::NumaNode; > + > + /// No preference for NUMA node > + pub const NUMA_NO_NODE: NumaNode = NumaNode(bindings::NUMA_NO_NODE); > +} > + > /// The kernel's [`Allocator`] trait. > /// > /// An implementation of [`Allocator`] can allocate, re-allocate and free memory buffers described > @@ -156,10 +182,41 @@ 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_node(None, layout, Layout::new::<()>(), flags, numa_node::NUMA_NO_NODE) > + } I don't think this change is necessary, because you implement `Self::relloc()` below based on `Self::realloc_node()`? > } > > - /// 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` when called with `None`. s/realloc/realloc_node > + /// > + /// # 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`], /// [`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` is valid by its safety requirements and asks for a s/realloc/realloc_node Regards, Boqun > + // 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 > + /// optionally 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 NUMA_NO_NODE if the caller doesn't care. > /// > /// If the requested size is zero, `realloc` behaves equivalent to `free`. > /// [...]