Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp511275lqz; Sat, 30 Mar 2024 06:30:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKCo34U5oxwq4g2GTB9ZuzCn4Br2HyslDygHbOur3zTxTMD+Ru8ZWSjWJ98fXEzqTU4rZXH91Fk/gt2IpLgdzt5iZZe7VOcgiAvcYuug== X-Google-Smtp-Source: AGHT+IH5DOeBs5TUQqmntzUUP1uvZP+QJsYRSJeVqjRsSdeJCcDqQhd3ILPHkMdZ5eOrqMj1LrYo X-Received: by 2002:a05:6a00:23ca:b0:6ea:e2d2:5e68 with SMTP id g10-20020a056a0023ca00b006eae2d25e68mr5759825pfc.27.1711805440294; Sat, 30 Mar 2024 06:30:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711805440; cv=pass; d=google.com; s=arc-20160816; b=KrZpBIq9v9XSlHLjFBsgbtzGhfNKdJHWSajE/uMj8rd2c3okXbhZqhjH8kNaAJ83LB TjP8OKQ2qDG7ZX/6ycbSQ/Nci8Adsk/ZNtjxSwXLvzNHJHM16TctZ2c938BPj2aEoXrv T2yakflc8zmKfs85eOeW9P1QICXPiR4VihNrJ7zB2ppwymF2+zHjih4OKjAjeZ9MfI6I lSl2PNDS2Z39reATvlEvm2AuPJ/0cQOTvv6Kdbf8s7HJ320FsRAOiLxq9DlQx6fG9r4a zQN65TYdkf7bxLUSC9CrSoxjxYXJGggPeWFwLlnuBNObE+5wlMH80LkK5vMycQvW7aAW 5KjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=+HEtdPx7OqmXqU11OfG7F3JXZQBoM0zTuzWJZUMp+2c=; fh=ILXzPT3nbZXhvwVwwPDMnlxaRbCVxHwkAsH+01sTnAQ=; b=JkkO5cqIqb9c3bPwORlWrRYpvWssKB+qRDvpYUwDZHFkg3QaROtRKrbVVRh6Dy8Bul UtnDWcHda90Z1vxiAqE70t1fW7to4XYwMtuSo2YQh9LoTIJ2XMNoTaKoJ1gPTyud6UhW /bcrY55DQ5sw5PCqPdTLHib/T2qXOZ4IsowpcEu351M+Ftgyhwy1yURkFRv6G7LBf59d 4mvXzwbIssJ0YIxE+VoprF1cnEuTxyyVgVfBqhOL4prw7Zs26A5eR+Rx89firNnwHvBY raXDgGHpxObXd4GCd9/AzzLTZrvUbAYSfFnB1gOQY597iv1lHx8bxbyaijBHTMNT6Ju+ m6kg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=MGxxuQcr; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-125733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125733-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ln8-20020a056a003cc800b006eaba98802bsi6117453pfb.49.2024.03.30.06.30.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 06:30:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=MGxxuQcr; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-125733-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125733-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5D7B3B21EC4 for ; Sat, 30 Mar 2024 13:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABD4C28DC1; Sat, 30 Mar 2024 13:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="MGxxuQcr" Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80CB0125DB for ; Sat, 30 Mar 2024 13:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711805427; cv=none; b=c8dpjMgCBeqJQkwTmXAQUnzZOE2yFH71jSeUWBp4vWuXjqX1PKXvGNEtXAZ/5Us8rxmVF4D6ONTc7RMCbHC6Hb15l6ye1EX+i9knXOs8PkgXeR4Cf14Q9aDtZ17X3LdpfOVArupE9md86AXvkPdbvwvdTDh8t6gLq499EG70WSg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711805427; c=relaxed/simple; bh=GLLwLtiEelDru1aU0jJLyGv2vCHKaxAMXL3mAm4EGIc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I6JuroylYZcs/MrEjN6DbxiS09VnrkAiqoVZxe1MWAN+4iG8WGopZFpUezSRrUt5Ers8xaS0uS06wtsBQI3uJr9E7uGcrq8+R4DTOx/yAvWoVpClOwfrCXTjnQVL/BWjiz7MKqyb7ZYnr8L8YT6k5vx9qN0eLMdgvseQmf3jLMM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=MGxxuQcr; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1711805423; x=1712064623; bh=+HEtdPx7OqmXqU11OfG7F3JXZQBoM0zTuzWJZUMp+2c=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=MGxxuQcr8IDcwNs75Wb20ZUSh4dEwScMcwvr4+oBW1H1aF5OYZpns20LEjjMbfUUo /IT0ZWxhu9Nv1SUShOWgh+grbfEGPGbvwKvHOmLL71f62SaLJ/5mysAiuIV+2BvmOX AzeIjxotNW4ObdrOKteOPCuFNjbY56gKSk+L5V8xArLG5eSiuXEjtRbKna5cM4X39N inXZ7IBj99QAHRpqMFis5Tb7m+Zu6mjbzRuqO+tQkYYYufj5ueytc1AxZ15WdJnxCG CF77vZ4UCUnvY0n9fSQfx8hiU8IDKszenaXJybL4ypGaToUSirluVSTqWADeUTqSss MCXgjZvF426EA== Date: Sat, 30 Mar 2024 13:30:17 +0000 To: Wedson Almeida Filho , rust-for-linux@vger.kernel.org From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: Re: [PATCH v3 07/10] rust: alloc: update `VecExt` to take allocation flags Message-ID: <59c5bda5-6116-42f1-bf8e-47eba02e2ecb@proton.me> In-Reply-To: <20240328013603.206764-8-wedsonaf@gmail.com> References: <20240328013603.206764-1-wedsonaf@gmail.com> <20240328013603.206764-8-wedsonaf@gmail.com> Feedback-ID: 71780778:user:proton Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 28.03.24 02:36, Wedson Almeida Filho wrote: > From: Wedson Almeida Filho >=20 > We also rename the methods by removing the `try_` prefix since the names > are available due to our usage of the `no_global_oom_handling` config > when building the `alloc` crate. >=20 > Reviewed-by: Boqun Feng > Signed-off-by: Wedson Almeida Filho > --- > rust/kernel/alloc/vec_ext.rs | 158 +++++++++++++++++++++++++++++++---- > rust/kernel/error.rs | 11 +-- > rust/kernel/lib.rs | 1 - > rust/kernel/str.rs | 6 +- > rust/kernel/types.rs | 4 +- > samples/rust/rust_minimal.rs | 6 +- > 6 files changed, 152 insertions(+), 34 deletions(-) Reviewed-by: Benno Lossin [...] > impl VecExt for Vec { > - fn try_with_capacity(capacity: usize) -> Result { > + fn with_capacity(capacity: usize, flags: Flags) -> Result { > let mut v =3D Vec::new(); > - v.try_reserve(capacity)?; > + >::reserve(&mut v, capacity, flags)?; > Ok(v) > } >=20 > - fn try_push(&mut self, v: T) -> Result<(), TryReserveError> { > - if let Err(retry) =3D self.push_within_capacity(v) { > - self.try_reserve(1)?; > - let _ =3D self.push_within_capacity(retry); > - } > + fn push(&mut self, v: T, flags: Flags) -> Result<(), AllocError> { > + >::reserve(self, 1, flags)?; > + let s =3D self.spare_capacity_mut(); > + s[0].write(v); I haven't checked the codegen, but this could result in an additional bound check. We don't need to care about this now, but at some point we should do a performance test. There are probably other things that I have missed. --=20 Cheers, Benno > + > + // SAFETY: We just initialised the first spare entry, so it is s= afe to increase the length > + // by 1. We also know that the new length is <=3D capacity becau= se of the previous call to > + // `reserve` above. > + unsafe { self.set_len(self.len() + 1) }; > Ok(()) > } [...]