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 52482C7EE30 for ; Tue, 1 Jul 2025 11:52:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0A526B00A2; Tue, 1 Jul 2025 07:52:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ABACA6B00A6; Tue, 1 Jul 2025 07:52:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A9BA6B00A8; Tue, 1 Jul 2025 07:52:46 -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 864776B00A2 for ; Tue, 1 Jul 2025 07:52:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 274E0160467 for ; Tue, 1 Jul 2025 11:52:46 +0000 (UTC) X-FDA: 83615533932.16.5D3C8AB Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by imf24.hostedemail.com (Postfix) with ESMTP id 329FE18000F for ; Tue, 1 Jul 2025 11:52:43 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MooG23nI; spf=pass (imf24.hostedemail.com: domain of aliceryhl@google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=aliceryhl@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=1751370764; 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=veoFO+1wdpPDWz3qRkvkxT3szkUu/z2wjkK1DneZyWM=; b=yUq5QghfJcy8lCti1XRC2GgJu2GM2DHzoab7dDRXjJtV1+zhRiQRcQ84wEy5S7skFo/q1f 0iZoHexT7DXH9pTebTWAq5Kjrz7oducIYaovlBEPW21pdakcRUXYrxU4XZ5Grz/rkOCJ1M DPuANfLW7KIQrcuVHydGL0JsHdfT3rk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751370764; a=rsa-sha256; cv=none; b=iAbYQNL1jXL1R9gvvz5Df1Mt7IOiSob/cerkIErQGas3ywzwtw2tcRRPTKvQoUTtE2DoBt dgiiQYqjnqDwDCi/8gtwVhaf0MxXcoTIVCKbbKFrx+f81rDmvi6K1umXVe+CLvvHKLUu+I rnhBNjlV06XeN57ApGxDROQ+51xYE7U= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MooG23nI; spf=pass (imf24.hostedemail.com: domain of aliceryhl@google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4538bc52a8dso36285355e9.2 for ; Tue, 01 Jul 2025 04:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751370762; x=1751975562; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=veoFO+1wdpPDWz3qRkvkxT3szkUu/z2wjkK1DneZyWM=; b=MooG23nIqXyE1dBYAOnPfSGwCsyKvyQeRnLxKZxoWJYgHLRlnnX4Cor801jSJao68Z bt2XWMeiu1zs1+pL0hqp3THT6sLaXKDBor+oKh3hg9hbKlmpDizkLpd5k7cvAvTPvMSA vZ48OpA45U7CXUZwaKatEd+sMq8E6ouGIppjMIuvYX3846G5XQybJUi/DZl0rOtWra+p +nUHLr6HYZEWa7+ysm+d34M/yDa23JHH3dtunvrXJcklmBLCgTWHifH7n3nRp+k87a3D NznZCEzB4v1hGpMzVJ48Rk01pYLbawQIMWQ+VvD7w3ouEPJa0a0RFtGrlxgWiRwPrRMF uvTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751370762; x=1751975562; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=veoFO+1wdpPDWz3qRkvkxT3szkUu/z2wjkK1DneZyWM=; b=nxsAj4h5UpqPM8BUkQ2tFho8W/e/qYofd71gtUqtAV3UK4Ok7Ry5j4bHiJtwX+nCTy FONwnwSv+lBG0m9971f1f2hq+0akKMsUNSjHrULfqCCQIbKD+M8oxhEz80lSVrKJ51gt zEtTN5xqnmTlqcTz8H276+mfuz17TPcmX0DIka3AxyufEHx4rxwt+D0ft04/+kSD7LdV t0BeaZY4agfaJXAMW1naH2LUTrCHyTyrljsfpU7m1g9vuqUWDB2kUM0o0YYZmWGiAakF Z2+neaUrgY3JUywFQYPcQwRbSvwo0/IsOSP/mazCF2rdZxbFfugZoQkcMRNqyXG2DOhn sSvQ== X-Gm-Message-State: AOJu0Yyp3tNFnq+qmgkDTLYA0lumAHw7JgvIbAdD+l4xnjAQFYrBelQs DSTluJ1dY7w0xKxc97dCDfJsNX8mhqEiC1vwsiJlSzRi8SYUesQqQ6NSpUsNMbRZNCjtKDaDXRN Z21sQAIcpF3h/g6G10jleSyFqZM8mc4oYRjpoQFpd X-Gm-Gg: ASbGncu1r5keVVWgLzCdj1h/HhV1Af14x9aU6c4rwBZwVRqX7IQJTl2QuZPVEpsh+lZ Wpv2lom2Iy4a2TxLkcAEmtUWTwMEOGo5etEMJtqwMWRlyUjhOmefOTlqaA6t++gZPu0G4WzLKtl c2oC3kOkqTO1jqHeHRrErXV+b9oxDW7eCEp+azu3j+EQimIxXhbxSlgig= X-Google-Smtp-Source: AGHT+IFUlJySjsgWCyutnog4gDVqPy3/yBi31gYRy/p63NPCINHZ/bW019+CCuJmHTVh0LKrHnBPA0F6FZ0BNIhxi30= X-Received: by 2002:a05:6000:2188:b0:3a5:2465:c0c8 with SMTP id ffacd0b85a97d-3a8fdb2acd9mr11587808f8f.7.1751370762366; Tue, 01 Jul 2025 04:52:42 -0700 (PDT) MIME-Version: 1.0 References: <20250630221511.3325123-1-vitaly.wool@konsulko.se> <20250630221640.3325306-1-vitaly.wool@konsulko.se> <3D58CB40-CB1C-47A2-BB71-5C32B3609AE0@konsulko.se> In-Reply-To: <3D58CB40-CB1C-47A2-BB71-5C32B3609AE0@konsulko.se> From: Alice Ryhl Date: Tue, 1 Jul 2025 13:52:29 +0200 X-Gm-Features: Ac12FXzcpTlny4SSlNLGwk5zd2CXwwCXOFc_w3xt_vRf8kazpRdDDaXsreX05Ek Message-ID: Subject: Re: [PATCH v9 3/4] rust: add support for NUMA ids in allocations To: Vitaly Wool Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Danilo Krummrich , rust-for-linux@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 329FE18000F X-Stat-Signature: gu8hhciuz4ehd6pmogz9opjk5ogzhqbu X-HE-Tag: 1751370763-594300 X-HE-Meta: U2FsdGVkX1+cH7xAmzAka5l5sltOE2QYFvndeSIUJfGn8O1Zet12BxBkvcah/EBUCJwxHf2fOPi/tKlap2moh/72LDh7tlOg1pkmQYCQ7SDewmAdkxyErD7+tCNHQ5ChcWbPG7Kbk3iBXFGUnCs46jYiiYSN0JFe45Ylvmm7weGrNW/ucQAzGWynYHKDyo/drc+aDg+n9VQmVbAZmtmN1vqi63tmjgshmwo76eTbA/N14/LBCxduiqQBKfAomhokndUdgImYhY3RlP0JOFRVgeHFm4alGaYK2zvZUtSLKE2y//boUMAB4FPz2n9GS78+hXOoVtdLDHpTSEIq/H2ZXEwk/+w/nsh9Jd4PmurYxZyjXvwOipbCPDbFu422YmrNjkhzN7LbFE3FI5AzyNnXhKIatBEyNBG2pLkjMAZDpl+j8akoF4MRsFYvcUW0J7R9LypfqVfVaAPnw2oSUxpTP6xkZqRWPUKbMAtfAQX17PlGDDp9Xr7qx6V6cyh8QWajpqbbAXDknUzRHf3wTr1HiDSGYR98vtgjgEv3A/YUl7q+FLSVqzXVgMWahNLdAQdLK/e6v6iM65tiOYAhLOjp1zj7ZnIdz/pUS5KDmIquwOka37XwVWeJCPFB8pm4Xjv2ac+kRUimhaMs/bUkHpAWZufj1CrI3i5wusUzZDb79k7P00Ytvlze6LsmPRmFVueQdA1QBOFEws4dfCbuMpcWNUd6B+9j9nZMTujvzawb5GYe8xVMnfAvfIPQroWeLRoLat6Utwcl+8DnIj60PUtHIKe5wezcwK/dbWL++tuyNDerqP33w/EV9Mx2vUcPzYD++xYkF2tQvjfcMH21BE8j2bB8cTG2eMvd2DBULEXg6ZV7PtBSL++fLoiU3rXxILW//NxaadxXUw2hLRa7FeHcXmeMCwrP/LfSZwIsTb/Cd9XFCxjIJl27ECSZm35XID1zuSEhE+jpkPGeSljSo0E 3wZ2Ccmx TdzVBn7L2LWT5+/NovBBVRzI4kj+zMGOpn7sEHM5P1EoIz2Es9d25wAJb7pQPTQBm927uimThtWMc2487CIa4JkCfDHuAomxVWl0da0Vu3S42Golfz+172jIgP3ivq/t5PMdaTOvSKA6CamtUWuKNSfGwkZzMDHZPN5udZDBXd/4Ni3Cl7Q+FSWI/rA== 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 Tue, Jul 1, 2025 at 1:19=E2=80=AFPM Vitaly Wool wrote: > > > > > On Jul 1, 2025, at 12:34=E2=80=AFPM, Alice Ryhl = wrote: > > > > On Tue, Jul 01, 2025 at 12:16:40AM +0200, Vitaly Wool wrote: > >> Add a new type to support specifying NUMA identifiers in Rust > >> allocators and extend the allocators to have NUMA id as a > >> parameter. Thus, modify ReallocFunc to use the new extended realloc > >> primitives from the C side of the kernel (i. e. > >> k[v]realloc_node_align/vrealloc_node_align) and add the new function > >> alloc_node to the Allocator trait while keeping the existing one > >> (alloc) for backward compatibility. > >> > >> This will allow to specify node to use for allocation of e. g. > >> {KV}Box, as well as for future NUMA aware users of the API. > >> > >> Signed-off-by: Vitaly Wool > > > > My main feedback is that we should consider introducing a new trait > > instead of modifying Allocator. What we could do is have a NodeAllocato= r > > trait that is a super-trait of Allocator and has additional methods wit= h > > a node parameter. > > > > A sketch: > > > > pub unsafe trait NodeAllocator: Allocator { > > fn alloc_node(layout: Layout, flags: Flags, nid: NumaNode) > > -> Result, AllocError>; > > > > unsafe fn realloc_node( > > ptr: Option>, > > layout: Layout, > > old_layout: Layout, > > flags: Flags, > > nid: NumaNode, > > ) -> Result, AllocError>; > > } > > > > By doing this, it's possible to have allocators that do not support > > specifying the numa node which only implement Allocator, and to have > > other allocators that implement both Allocator and NumaAllocator where > > you are able to specify the node. > > > > If all allocators in the kernel support numa nodes, then you can ignore > > this. > > This is an elegant solution indeed but I think that keeping the existing = approach goes better with the overall kernel trend of having better NUMA su= pport. My point is, if we add NodeAllocator as a super-trait and in a fores= eeable future all the Rust allocators will want/be required to support NUMA= (which is likely to happen), we=E2=80=99ll have to =E2=80=9Cflatten=E2=80= =9D the traits and effectively go back to the approach expressed in this pa= tch. If we are not going to have allocators without numa support, then what you did is reasonable. Though in that case I would consider just changing the existing methods instead of having methods both with and without a numa node argument. Alice