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 267BBC3DA4A for ; Wed, 14 Aug 2024 23:21:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EB476B008C; Wed, 14 Aug 2024 19:21:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B0D6B0092; Wed, 14 Aug 2024 19:21:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 689D16B0095; Wed, 14 Aug 2024 19:21: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 4ADB56B008C for ; Wed, 14 Aug 2024 19:21:09 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B06A6A11D6 for ; Wed, 14 Aug 2024 23:21:08 +0000 (UTC) X-FDA: 82452423816.10.A533C2C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 0FD3DC0016 for ; Wed, 14 Aug 2024 23:21:06 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OFotiRHu; spf=pass (imf22.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723677631; 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=ibzv5lEZnyuoPkTskOYkW2b47U6o5+5uGh6uKDp4YCQ=; b=favgsBRbZapqXqA64qmjJKuxSycjXaT59TkG7JX8BL1LR91x2rCzlh5R7mGLafAJ2WwsM3 tPQUUdXHA/28NjIed3xJTYj2zgqWkJRxd9JUo5Iqpck1++uUdHnAk2qgS/EOsatYpn0HPU PNx6SxGT2vUjCOACJBtG7+O4KC0IiyU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OFotiRHu; spf=pass (imf22.hostedemail.com: domain of dakr@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=dakr@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723677631; a=rsa-sha256; cv=none; b=7dOF/w4WsgV53SeEwBc1ei8Qks+WvKpfD6Qzk78mBnSvb3ioWqtahRXcLXgE/Rxkncw7vE jy4rWyTU/8bjAWRPLOsSdIynvvEz0wbedVjpM4SN+/8nrCw0wR4YWCgah/htZ14FRLsXz0 p+pOOW0hKByelt7/k1x7/MwD3U0U9v4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id F1ECE61CAC; Wed, 14 Aug 2024 23:21:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7AFDC116B1; Wed, 14 Aug 2024 23:21:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723677665; bh=4a7ZlA74vWDlCN9VZFGaIdiwH7xx/e/zJNrlaQbo+G0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OFotiRHu7gmqVX7vYiru0C3Y+GoXeKj4bfovAzecyqAdLX1vrYBY//vVc/51GS/gX gOugq/QXhkvcSP5msIEQK9bXoWZyBnbESwu3i+xcYUHZL3BRdXYX6BZjc5W1eMdDmI Y2QBh6X7X5Qsy7/OCMD8awa4qtPRQDWMK24dmoB4QIqoj0oVF/8X5fYgujG1frAqOA ofRVHYbCeujeuEwn1GtZwQ8VY+T+PmAMEzcQRbBBCry7n9qCbyj5ykWYQBeMjbfAk6 RvYYIHvozt0Ffv565DD0BfnK/YXnz3RF1wuUmEABRjJ2rOpPiPPOXGKm8k3mY1Ymy1 LmsSX/8aIKOTg== Date: Thu, 15 Aug 2024 01:20:58 +0200 From: Danilo Krummrich To: Benno Lossin Cc: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, boqun.feng@gmail.com, gary@garyguo.net, bjorn3_gh@protonmail.com, a.hindborg@samsung.com, aliceryhl@google.com, akpm@linux-foundation.org, daniel.almeida@collabora.com, faith.ekstrand@collabora.com, boris.brezillon@collabora.com, lina@asahilina.net, mcanal@igalia.com, zhiw@nvidia.com, cjia@nvidia.com, jhubbard@nvidia.com, airlied@redhat.com, ajanulgu@redhat.com, lyude@redhat.com, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v5 06/26] rust: alloc: implement `Vmalloc` allocator Message-ID: References: <20240812182355.11641-1-dakr@kernel.org> <20240812182355.11641-7-dakr@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 0FD3DC0016 X-Stat-Signature: 79rgg5df6k6pg44uahz1efppqwj9dq4a X-HE-Tag: 1723677666-929943 X-HE-Meta: U2FsdGVkX1/LToz6d3YBDDsIYH23NmVMHoujGttB6QWpYKLqw1v1KtHK49zx2OeVHY4kZ+veyuvnppCclwIEMZamstFezEL/7udfHsCXxggHw08aRGoCj+0MT0Ww6D0gj9rbF+TeRaC6FhAnx3Ai7jEFMh8p4z1u9WmCXqrtOegOEJCiuba506LPR4Xocf1GyOOspK4WtD2j4I9mb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tnEYeJGkkGTexwsZvRXvHo+LnwPMc0= 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 Thu, Aug 15, 2024 at 12:13:06AM +0200, Danilo Krummrich wrote: > > > > > > + ptr: Option>, > > > + layout: Layout, > > > + flags: Flags, > > > + ) -> Result, AllocError> { > > > + // TODO: Support alignments larger than PAGE_SIZE. > > > + if layout.align() > bindings::PAGE_SIZE { > > > + pr_warn!("Vmalloc does not support alignments larger than PAGE_SIZE yet.\n"); > > > + return Err(AllocError); > > > > I think here we should first try to use `build_error!`, most often the > > alignment will be specified statically, so it should get optimized away. > > Sure, we can try that first. I think I spoke too soon here. I don't think `build_error!` or `build_assert!` can work here, it would also fail the build when the compiler doesn't know the value of the alignment, wouldn't it? I remember that I wasn't overly happy about failing this on runtime either when I first thought about this case, but I also couldn't think of something better. In the end it's rather unlikely to ever hit this case, and probably even more unlikely to hit it for a sane reason. > > > > > How difficult will it be to support this? (it is a weird requirement, > > but I dislike just returning an error...) > > It's not difficult to support at all. But it requires a C API taking an > alignment argument (same for `KVmalloc`). > > Coming up with a vrealloc_aligned() is rather trivial. kvrealloc_aligned() would > be a bit weird though, because the alignment argument could only be really > honored if we run into the vrealloc() case. For the krealloc() case it'd still > depend on the bucket size that is selected for the requested size. > > Adding the C API, I'm also pretty sure someone's gonna ask what we need an > alignment larger than PAGE_SIZE for and if we have a real use case for that. > I'm not entirely sure we have a reasonable answer for that. > > I got some hacked up patches for that, but I'd rather polish and send them once > we actually need it.