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 E1027D743F9 for ; Thu, 21 Nov 2024 00:24:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71CF76B007B; Wed, 20 Nov 2024 19:24:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CBF16B0083; Wed, 20 Nov 2024 19:24:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56C806B0085; Wed, 20 Nov 2024 19:24:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 335016B007B for ; Wed, 20 Nov 2024 19:24:16 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E1952A0444 for ; Thu, 21 Nov 2024 00:24:15 +0000 (UTC) X-FDA: 82808202624.01.09CD456 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf13.hostedemail.com (Postfix) with ESMTP id B03BB2000A for ; Thu, 21 Nov 2024 00:23:17 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CNFelpT8; spf=pass (imf13.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.222.169 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=1732148407; 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=Crp+IcQCRiftgYHXyQw6BFOWQbGOsJ2xVelhVLyogFA=; b=pfs/BpXvnNoYW1dB9QTyewJn6liCxyPbVMNtIUIFLJR9lez6vcY1bjRoDvejI73/CXxiuy HcwSBaal3Wu5K+gCmeVz+opTYximR3qC3RXkv3m9seZTnRIL+7Ybnc4RM3mO0hrXcKL7qk dZhlspHBE9Bx04LunmTH5rjvGirG8wo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CNFelpT8; spf=pass (imf13.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.222.169 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=1732148407; a=rsa-sha256; cv=none; b=ryd87uQLrknqlhbJtcS21qJUnyfFegFsNbGKeKhpMZSuVo92Expvfb1T0zq/WljVDDD26k GlVi6iZFGPJXa2VLKBtZvGIvDnm2lvrErcsFslZHcL4TmhIa9NxbTsswE4iZ+94S9jlFwg EriBttPSTvhe5J0OaWxSdw2xox11e/U= Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7b35b1ca0c2so158400285a.0 for ; Wed, 20 Nov 2024 16:24:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732148653; x=1732753453; darn=kvack.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=Crp+IcQCRiftgYHXyQw6BFOWQbGOsJ2xVelhVLyogFA=; b=CNFelpT8WxZ/eHRzR+bUnGS168aJdE9+QsPtj8kyS1PZvC4JXGs8oVPnXZpLFmfZQ0 xcXRomoH167vDY/JdMplHSWjL0SofqiUDU9H37lcMwbYwiMjVJVkkyPvAX0JEH5o4Y1y SbLUWq/+Zy6NcC+/ps26STlDBj2d8o+FmHb/Ce1vVJO0wCmu5WsEug0fneK/oo91gIV0 aDXLkynzR0nGmmIKtCWK8hsUT5C8yrv1QazPzC7tQx/HehvlIjRr+5UR1ELGBGznp+eM oyeNfUpvQXtRcbD2PLCrz8kTP3onEL3XIKH3pT5zlkQ6xCpZZR3r+0RYgT6XK46y247T 2n8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732148653; x=1732753453; h=in-reply-to:content-transfer-encoding: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=Crp+IcQCRiftgYHXyQw6BFOWQbGOsJ2xVelhVLyogFA=; b=cironvdyHEJhTinYSAX0HkGpqFblCiGhNUD2+NJ41FUjCw2Ha9/W3salmPseIUcSBE K3svfMIwaCbpvRcAkPTI1AUkpjWfbTlFHoN4YOD62VDXIA/CReLdKUv+qx/qEOUcVtrw KiVWnhDvsqBCkoTlIz3bCDRzynmLwshZcHkZOy2eBqILRv+p5AY97qD6S+qshgqjomfg X4RrMP5Vn3Ku377h5Bkm4MyNigtmMSW8IltKrMDdN/tgIHL7LYkwttUE2lHlFEbCnr+w gxGO0lUX3kW2eDde+ecNYwIzn7rwaZxT6qKXnhX41ojaZhLuWrWC6nME7npto6J+VACe kl1Q== X-Forwarded-Encrypted: i=1; AJvYcCVyoyM22EMO2niQ5/73nkM4cSqbK6dvUgG5NXmR+PCGcwuiph86CCwRZSonJg9ntn5Vx2IlIIgx3g==@kvack.org X-Gm-Message-State: AOJu0Yz6LeTWSwZrcMKeQ4T2icbcuEkPiPK2VO+MrqYcJNPrAlnjdmeJ 1a+PLKEIP5wjlBbj5wHAKpJePw3E+CMfzZnQ03LLK9sFzi5vRFSZ X-Google-Smtp-Source: AGHT+IEBDDj0Raio/gPETKzVbxOw7TpObvjm7y/a3RwxurvYsIKjuFIgxdHo4/kTlZbbvmfHus/ggw== X-Received: by 2002:ad4:5ce9:0:b0:6c3:6477:16e7 with SMTP id 6a1803df08f44-6d4423b38a8mr23112616d6.11.1732148652822; Wed, 20 Nov 2024 16:24:12 -0800 (PST) Received: from fauth-a1-smtp.messagingengine.com (fauth-a1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d43814e9bdsm16427066d6.126.2024.11.20.16.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 16:24:12 -0800 (PST) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfauth.phl.internal (Postfix) with ESMTP id B59321200066; Wed, 20 Nov 2024 19:24:11 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Wed, 20 Nov 2024 19:24:11 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrfeehgddvudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtjeen ucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrd gtohhmqeenucggtffrrghtthgvrhhnpeevgffhueevkedutefgveduuedujeefledthffg heegkeekiefgudekhffggeelfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhi thihqdeiledvgeehtdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmh grihhlrdgtohhmsehfihigmhgvrdhnrghmvgdpnhgspghrtghpthhtohepudelpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegrsgguihgvlhdrjhgrnhhulhhguhgvsehgmh grihhlrdgtohhmpdhrtghpthhtohepfihilhhlhiesihhnfhhrrgguvggrugdrohhrghdp rhgtphhtthhopegrlhhitggvrhihhhhlsehgohhoghhlvgdrtghomhdprhgtphhtthhope hruhhsthdqfhhorhdqlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehojhgvuggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrlhgvgidrghgrhi hnohhrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhn vghtpdhrtghpthhtohepsghjohhrnhefpghghhesphhrohhtohhnmhgrihhlrdgtohhmpd hrtghpthhtohepsggvnhhnohdrlhhoshhsihhnsehprhhothhonhdrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 20 Nov 2024 19:24:11 -0500 (EST) Date: Wed, 20 Nov 2024 16:24:10 -0800 From: Boqun Feng To: Abdiel Janulgue Cc: Matthew Wilcox , Alice Ryhl , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Trevor Gross , Danilo Krummrich , Wedson Almeida Filho , Valentin Obst , open list , Andrew Morton , "open list:MEMORY MANAGEMENT" , airlied@redhat.com Subject: Re: [PATCH v3 0/2] rust: page: Add support for existing struct page mappings Message-ID: References: <20241119112408.779243-1-abdiel.janulgue@gmail.com> <98a46b27-c4bb-4540-8f75-f176c3f2fae1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <98a46b27-c4bb-4540-8f75-f176c3f2fae1@gmail.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B03BB2000A X-Stat-Signature: 7w6kseqgoetcjnuzt1ien1tb96cjpmk4 X-Rspam-User: X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g9txYw+IUt7EGY0qAPDnVskq8pTmFHAV7FU7EqMQkX203SZbB3l7Ao9hcyhA7ABcKfFpWt3Q27ofMvSlIupe3UGikZxBfQ2ZEuO2AQI+mG4q1yDH3sZzsV4RGNPMMs7Z9E71TwlQDtIOrErX/orh9dOryKwTyHcLkAjI9ONjhjy09H+MA/vTLPEVGa2mqayAifhV+AHiqPrPsuR+Esg0tiEGRXvUBqWabKe9esKeau0XnlHiHv+PVb9Ol/Wu36mPtdI6xZOXJPQs3hO7cYrrG1mIUqlQSzHB0w4H+klnVuKCv8QRjbwr5HC9r2+fuHBnkunv/hdovqBB1SHTV4e5x5xKr1ZFJgoCfG8XYU4nVHrORvg4Zjh9LyLJZOvIpAX22Rcu2VZnp+KB4Shn4qe4/yWJ6I1u6x4dqz0RNO3Mo0u5x6kw2WtVMIi1K876mTTjzXQHxinTh+0dLvzB+B1Au3g== 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, Nov 21, 2024 at 12:56:38AM +0200, Abdiel Janulgue wrote: > On 20/11/2024 19:25, Boqun Feng wrote: > > On Wed, Nov 20, 2024 at 05:02:14PM +0000, Matthew Wilcox wrote: > > > On Wed, Nov 20, 2024 at 08:20:16AM -0800, Boqun Feng wrote: > > > > On Wed, Nov 20, 2024 at 10:10:44AM +0100, Alice Ryhl wrote: > > > > > On Wed, Nov 20, 2024 at 5:57 AM Matthew Wilcox wrote: > > > > > > > > > > > > On Tue, Nov 19, 2024 at 01:24:01PM +0200, Abdiel Janulgue wrote: > > > > > > > This series aims to add support for pages that are not constructed by an > > > > > > > instance of the rust Page abstraction, for example those returned by > > > > > > > vmalloc_to_page() or virt_to_page(). > > > > > > > > > > > > > > Changes sinve v3: > > > > > > > - Use the struct page's reference count to decide when to free the > > > > > > > allocation (Alice Ryhl, Boqun Feng). > > > > > > > > > > > > Bleh, this is going to be "exciting". We're in the middle of a multi-year > > > > > > project to remove refcounts from struct page. The lifetime of a page > > > > > > will be controlled by the memdesc that it belongs to. Some of those > > > > > > memdescs will have refcounts, but others will not. > > > > > > > > > > > > > > One question: will the page that doesn't have refcounts has an exclusive > > > > owner? I.e. there is one owner that's responsible to free the page and > > > > make sure other references to the page get properly invalidated (maybe > > > > via RCU?) > > > > > > It's up to the owner of the page how they want to manage freeing it. > > > They can use a refcount (folios will still have a refcount, for example), > > > or they can know when there are no more users of the page (eg slab knows > > > when all objects in a slab are freed). RCU is a possibility, but would > > > be quite unusual I would think. The model I'm looking for here is that > > > 'page' is too low-level an object to have its own lifecycle; it's always > > > defined by a higher level object. > > > > > > > Ok, that makes sense. That's actually aligned with the direction we are > > heading in this patch: make `struct Page` itself independent on how the > > lifetime is maintained. Conceptually, say we can define folio in pure > > Rust, it could be: > > > > struct Folio { > > head: Page, /* or a union of page */ > > ... > > } > > > > and we can `impl AlwaysRefcounted for Folio`, which implies there is a > > refcount inside. And we can also have a `Foo` being: > > > > struct Foo { > > inner: Page, > > } > > > > which doesn't implement `AlwaysRefcounted`, and that suggests a > > different way the page lifetime will be maintained. > > > > > > > > We don't have a fully formed destination yet, so I can't give you a > > > > > > definite answer to a lot of questions. Obviously I don't want to hold > > > > > > up the Rust project in any way, but I need to know that what we're trying > > > > > > to do will be expressible in Rust. > > > > > > > > > > > > Can we avoid referring to a page's refcount? > > > > > > > > > > I don't think this patch needs the refcount at all, and the previous > > > > > version did not expose it. This came out of the advice to use put_page > > > > > over free_page. Does this mean that we should switch to put_page but > > > > > not use get_page? > > > > > > Did I advise using put_page() over free_page()? I hope I didn't say > > > > We have some off-list discussion about free_page() doesn't always free > > the page if you could remember. > > > > > that. I don't see a reason why binder needs to refcount its pages (nor > > > use a mapcount on them), but I don't fully understand binder so maybe > > > it does need a refcount. > > > > I don't think binder needs it either, but I think Abdiel here has a > > different usage than binder. > > > > > > > > > I think the point is finding the exact lifetime model for pages, if it's > > > > not a simple refcounting, then what it is? Besides, we can still > > > > represent refcounting pages with `struct Page` and other pages with a > > > > different type name. So as far as I can see, this patch is OK for now. > > > > > > I don't want Page to have a refcount. If you need something with a > > > refcount, it needs to be called something else. > > > > So if I understand correctly, what Abdiel needs here is a way to convert > > a virtual address to the corresponding page, would it make sense to just > > use folio in this case? Abdiel, what's the operation you are going to > > call on the page you get? > > Yes that's basically it. The goal here is represent those existing struct > page within this rust Page abstraction but at the same time to avoid taking > over its ownership. > > Boqun, Alice, should we reconsider Ownable and Owned trait again? :) > Could you use folio in your case? If so, we can provide a simple binding for folio which should be `AlwaysRefcounted`, and re-investigate how page should be wrapped. Regards, Boqun > Regards, > Abdiel