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 C654DD743EA for ; Wed, 20 Nov 2024 22:56:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BE1A6B008C; Wed, 20 Nov 2024 17:56:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 246C76B0092; Wed, 20 Nov 2024 17:56:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C0576B0093; Wed, 20 Nov 2024 17:56:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DC3456B008C for ; Wed, 20 Nov 2024 17:56:45 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 553F51610C3 for ; Wed, 20 Nov 2024 22:56:45 +0000 (UTC) X-FDA: 82807983090.21.345B4D7 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 449B018001A for ; Wed, 20 Nov 2024 22:56:06 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hIq1rMly; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of abdiel.janulgue@gmail.com designates 209.85.167.43 as permitted sender) smtp.mailfrom=abdiel.janulgue@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732143267; a=rsa-sha256; cv=none; b=LDQ8PLauGr9LEZ+5jQAAbWljRccOOnINuOqLNncS+cOEUbxw1BTOBHLurWDSGeaAWRgjdL HFGsXigB2Sq0w+vX/sW3oa4+3ADZht+ESfuhboao9mjeyhycjAbMHX8WHv6YwRRGpvD+OJ yZNIbXnndD+QDm2TDm7xvt0xGpDC0RY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hIq1rMly; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of abdiel.janulgue@gmail.com designates 209.85.167.43 as permitted sender) smtp.mailfrom=abdiel.janulgue@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732143267; 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=Ro93jIqOY0loyc53cQE01JI74xq0pgbp0jULr1LtQ5A=; b=ou4ewK/gSz+SVGtP1CLZ/PntJp+0eD6nBQCdhKwXnabnqe034itNX8bGDwu+ZRurPFD0vn vIdsSNQvpG55l/Px9Up40co4JSXZBKm80txxKc6J7x14rOeTUKlBI34ddmdNzIU9O2DMl9 UojTKhkIWiVHUZ6NK6G16gSCXn00sk0= Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-53d9ff92edaso274714e87.1 for ; Wed, 20 Nov 2024 14:56:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732143401; x=1732748201; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Ro93jIqOY0loyc53cQE01JI74xq0pgbp0jULr1LtQ5A=; b=hIq1rMly3GzcABvVHMYLHJAChhbikwyzcJejXNNtSN5MGMpWLSsNH4ZBnPPJykvyHk TkGCbLHaMWVJ1qgyGm4IVAhTPSgpo0gsYQCdpn5YwG7rbpofFNfucXKA023qGG5F5Chx wfYhFaJY6GDWs5/syId/k1CODfhs03mvROPa/QwQU6a9Hm/F3HsEkwIbOu8qwY1dzKTu Rc1N3Xx0Oph9t7EKEKeAY+CjEKC8xbJEsSIxz/XTAAFr48QkMSd/uig7JjJDkVGost9c M1DG9J1Ve4wBn+Im4+ks2gryqlXzEVjqo6M4yEalgUx3jqxnfqdlNs7qLlMIZBAVO02j +x+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732143401; x=1732748201; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ro93jIqOY0loyc53cQE01JI74xq0pgbp0jULr1LtQ5A=; b=b4t8HuqI6H5EXOeN6GjiNAR5xkYlfMiFT803twDz1HdE6j98SRIXAc2ict9EUyoDB0 dRYEnuyubiSfCAXJxhnOC5XuVfmpm9twgYlAM4lICHfcc9tgXCaNNTXZ59DDqHBlArdi uQnw+bnOLqICO4J2tqbOvpkb72psH7gHJC1v1RrbA847eL3CrIpFxv+UPCNyjA3CYlGj 97gmfx7vz0My5KHyDKyQpjo3b3H9061Nqj5ujx/MEDkb8ume4V+av51/l8bOwv4HbE1F 8AM4kVAosCvBrSs95LKDOchJQE6eEbzn5r+QKKSTxFEuv48zhgNwGmljnIDI40UjCD8e ey3g== X-Forwarded-Encrypted: i=1; AJvYcCUdLkicLW+j38jnwHcmgrPWlQ8pLEyHt/E6dDawIB+l697CqDtvOjj7aP8QPRyZ8gDw6SUHJfyrMw==@kvack.org X-Gm-Message-State: AOJu0YxQSty2zXE7XhFBUZK+HQDhqbMtew45gAyxy2Eh5GhMOrkexifF 4Hl6b0gn9d6877c8IaYgB3+HTAosocPQzVC131dUGyP3xl4KaCe6 X-Google-Smtp-Source: AGHT+IF/5dP9tu2MCNl0giVhpvfxpp+VR6EDt2BSIi+BHBODzFNFCogG8QaW7BLqsCAzbPFydNBiXA== X-Received: by 2002:a05:6512:b81:b0:53d:a5c8:aaa6 with SMTP id 2adb3069b0e04-53dc1339b3fmr1922610e87.13.1732143401364; Wed, 20 Nov 2024 14:56:41 -0800 (PST) Received: from [192.168.1.146] (87-94-132-183.rev.dnainternet.fi. [87.94.132.183]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53dbd3ee4a3sm775318e87.12.2024.11.20.14.56.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Nov 2024 14:56:40 -0800 (PST) Message-ID: <98a46b27-c4bb-4540-8f75-f176c3f2fae1@gmail.com> Date: Thu, 21 Nov 2024 00:56:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 0/2] rust: page: Add support for existing struct page mappings To: Boqun Feng , Matthew Wilcox Cc: Alice Ryhl , rust-for-linux@vger.kernel.org, Miguel Ojeda , Alex Gaynor , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_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 References: <20241119112408.779243-1-abdiel.janulgue@gmail.com> Content-Language: en-US From: Abdiel Janulgue In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 449B018001A X-Stat-Signature: bg47qjweshajctdcctfd4sosx91i4d66 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732143366-112722 X-HE-Meta: U2FsdGVkX1+OnZ1ffrtCGRqQu65fVMCpPJfOQsaU/EFME0yxM3PTEAH2RMFs8jvKZtjo8j6j3Q5x6EusE/xouP02dRZuL0fl20b3LEvKffN+Xr5TKiVJQYyS4JQTAq49Cozu77dYvBCdY05zwipkyfkeZU0C6xMetPP6TuQetMjOjdH8Luo0GizhCztn9xKTwu9k3hhzozOCa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NV0kq5IYFnZ+4RyNXMfB799IUCMT2IXc2NPv6zUvT6XoNDvGgPyewQjJJ7I3edHs5ss9nUwJTOZsDYVTgt9wJ9ySXP08hjptVj2bCdEtf9CZwaGuIFLvv+AG8ACyqI80p86ncnpmDfDRU8DT2NjToBDfGflpkfxeiqi7MIJUtb/MfwjX8GE0tM+6ifOVFK9BX8r1PmK64z8O2fdrC4ZO80K+feqKABF5jtmXZ29XbSRIpQdAlefREvIjVCFybYwr5T94TYe764bt6eVEoTRhhmdDqlan6XL22w2Ts3tfRcDpcGWFbIdDEMnSpsq7FBi3TQ== 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 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? :) Regards, Abdiel