From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2840B1D5CFE for ; Sat, 26 Jul 2025 16:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753546430; cv=none; b=gtZ0i8ASa4vgIkiXToMJ9qYkp7tkr9XP11JsBjQmT+qxMWmddo9Ixnh7kzWBsT4oxEoLldR2RhcZwTtvMvcLJOr8nY4M/QjdTNc3wgkUiPjt4ggVrOrKEr7+PluEx996lEfb0tr7q+wN9peE0XTmfEwG3DioCwEckYi4qVuA1Oo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753546430; c=relaxed/simple; bh=KOVFTwTb/EuQIM6jQ7hDcils7oA9qFQIBrqpPTPpKw0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CXKFW3UIBuetLgAJWVEpCmI8uYJXWc6LQvkz9eHxV33Qgw6HtHyeR3nSjbFMyYrhfekgYxGf8exzMHwsSB5jn2A2vIV+R6uae25wcBTcHOC2WelsCp/sBKHXn83jqLQHCapdhwUNx3u6jyLl2g1b5yeMzJJTLr6Vc2y7HPIrcos= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ghxkkvlp; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ghxkkvlp" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-455b00339c8so20141615e9.3 for ; Sat, 26 Jul 2025 09:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1753546427; x=1754151227; darn=vger.kernel.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=xSmE2/IG78aP+245fYXp3PxN702DvxPZXYlkAkGpEZk=; b=ghxkkvlp+WMayusNf93yr2OrOxrpaSQx5G23EGm+dH8giUTIBtO5oGOgjOYyZOOu4+ sMSBoJQtLbtstYX9/Qj4uU7vml6UEMv8YeXB8jFTTAkGFJAGuG27FOtYSbllmFdrL8ot oTWxtydUooqUcUxXCUnuuxaWyUvpm2iqhIhlUz5n8chLyiTMp7LSG5TGXXHogZ5abCoY 2Kog4pVBHkBCMrCPfR6lu+S0w10eDL6S7LnDY2aDXOWn2uQ1Rnae4m1Hw7tuvNrrY0z/ apSHoP2TA1DByBfx8yEDvcLB0sKeKPFIoykwuOJ1O3b/n3AYjtz2ABCYNBQRUfZ8h9CZ 3ItA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753546427; x=1754151227; 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=xSmE2/IG78aP+245fYXp3PxN702DvxPZXYlkAkGpEZk=; b=ZEyAeU8KFjp0utAzPdlBzkkRESxZKQHhlwQr6GiV4ZUez6hSjp9kxrS0HW4EFuAdIX LrrA+H/v/+fgunmaL9OygNR3YjbkmjclAvdL/OIti4gJTNgUH2oArXwpEsDPPe/mCvZ9 YjHEFAsTsNcfCznCXgl4jE1AwLdko3PNaJJwp0W/Oo5z2Cd5DINVYICByATSKecSO7NZ jmbCF626kPLks1IvNsV51pBPlpnTnq0prfMaaVaJkeMmw6T5a/CdolMXYrL44m5lVHF+ GT0StMw7j4mQfFBe+ZxIHwJ0ldOdg09k0T8HS5DjlL1y8nx3ePOgzYDFWfJR9n/xNel0 A9Lw== X-Forwarded-Encrypted: i=1; AJvYcCX29x6UHrfiXRPLduEKYCCTNHsaEaMNWXMq3H5GUuIQ2mJKySAXTvu0N2wnLWsmy8rhII+w+eZbW2gPAJLa7g==@vger.kernel.org X-Gm-Message-State: AOJu0Yz9G9spLxM5TRIxfmz0AtEsM2Kyi6c88JMHQDXvptwVM/w2RftG c4bnX95MDebkC6Pb7IPF6qjGOh+qVmSrkLYICMRreHVSQmF1S0bMf1W+FT2w27o8aN5M7QVM3jn B3tOKd+gSmL4T+jYmJOqR7oKy+Ls8FbrTqmRaMOaG X-Gm-Gg: ASbGncu7dqDdqaLrLxXlGDenmOoGGafESwW5Ka7Vv7zZnpmubO0GHCI1dHqtIXMbKNd d1Ut81HJLhWWTibP2eWwSw4DnEOOzWf0jWMqmrmBIwOdY/uTLCiKcBO18Ty2a4VR9H70D3LvyVS 6AP3BvDHL44Nw9Q1PDTh5XEyJbl/Phmdv+HUnVioj3jtu0R4h9ixkxNy0VuZSucrya10ig1ILdX MBwstgH X-Google-Smtp-Source: AGHT+IGjmxfhiuSOXZOdKrAjq/2iLUvcoITJyFtLrM3SVjwxEvIE+xW4uFMAM5xc3aH0PtQ9ZEiVJc9cs0p0ckcKSlA= X-Received: by 2002:a05:600c:4f87:b0:456:133f:a02d with SMTP id 5b1f17b1804b1-4587644278emr60085665e9.17.1753546427335; Sat, 26 Jul 2025 09:13:47 -0700 (PDT) Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20250726-maple-tree-v1-0-27a3da7cb8e5@google.com> <20250726-maple-tree-v1-3-27a3da7cb8e5@google.com> <20250726165446.2768c6ee.gary@garyguo.net> In-Reply-To: <20250726165446.2768c6ee.gary@garyguo.net> From: Alice Ryhl Date: Sat, 26 Jul 2025 18:13:34 +0200 X-Gm-Features: Ac12FXxFtdvvjbSWz68LToYZuz9O8rpVTX_BUoiCo2Gz6b2RLEu8Wxik0sZefPk Message-ID: Subject: Re: [PATCH 3/3] rust: maple_tree: add MapleTreeAlloc To: Gary Guo Cc: Andrew Morton , "Liam R. Howlett" , Lorenzo Stoakes , Miguel Ojeda , Andrew Ballance , Boqun Feng , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Jul 26, 2025 at 5:54=E2=80=AFPM Gary Guo wrote: > > On Sat, 26 Jul 2025 13:23:24 +0000 > Alice Ryhl wrote: > > > To support allocation trees, we introduce a new type MapleTreeAlloc for > > the case where the tree is created using MT_FLAGS_ALLOC_RANGE. To ensur= e > > that you can only call mtree_alloc_range on an allocation tree, we > > restrict thta method to the new MapleTreeAlloc type. However, all > > methods on MapleTree remain accessible to MapleTreeAlloc as allocation > > trees can use the other methods without issues. > > > > Signed-off-by: Alice Ryhl > > --- > > rust/kernel/maple_tree.rs | 158 ++++++++++++++++++++++++++++++++++++++= ++++++++ > > 1 file changed, 158 insertions(+) > > > > diff --git a/rust/kernel/maple_tree.rs b/rust/kernel/maple_tree.rs > > index c7ef504a9c78065b3d5752b4f5337fb6277182d1..8c025d2c395b6d57f1fb162= 14b4e87d4e7942d6f 100644 > > --- a/rust/kernel/maple_tree.rs > > +++ b/rust/kernel/maple_tree.rs > > > > /// Error type for failure to insert a new value. > > pub struct InsertError { > > /// The value that could not be inserted. > > @@ -378,3 +499,40 @@ fn from(insert_err: InsertError) -> Error { > > Error::from(insert_err.cause) > > } > > } > > + > > +/// Error type for failure to insert a new value. > > +pub struct AllocError { > > + /// The value that could not be inserted. > > + pub value: T, > > + /// The reason for the failure to insert. > > + pub cause: AllocErrorKind, > > +} > > + > > +/// The reason for the failure to insert. > > +#[derive(PartialEq, Eq, Copy, Clone)] > > +pub enum AllocErrorKind { > > + /// There is not enough space for the requested allocation. > > + Busy, > > + /// Failure to allocate memory. > > + Nomem, > > + /// The insertion request was invalid. > > + InvalidRequest, > > +} > > + > > +impl From for Error { > > + #[inline] > > + fn from(kind: AllocErrorKind) -> Error { > > + match kind { > > + AllocErrorKind::Busy =3D> EBUSY, > > + AllocErrorKind::Nomem =3D> ENOMEM, > > + AllocErrorKind::InvalidRequest =3D> EINVAL, > > + } > > + } > > +} > > + > > +impl From> for Error { > > + #[inline] > > + fn from(insert_err: AllocError) -> Error { > > + Error::from(insert_err.cause) > > + } > > +} > > > > This looks identical to `InsertError`? They differ on whether the error code is EBUSY or EEXIST. Alice