Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4608390pxf; Tue, 16 Mar 2021 19:13:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpmMvXYEZ/uOFM/ClugTPV0JTHsstNGeh0QO+COyyGRn7XOq4cMtNrN6pDLi4ZFo71naUO X-Received: by 2002:a05:6402:1d1a:: with SMTP id dg26mr38857574edb.266.1615947225271; Tue, 16 Mar 2021 19:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615947225; cv=none; d=google.com; s=arc-20160816; b=JkC1ZUjWjDZ0UKw7YrlXyAVDw6H+i7k45x9RG9/e/CX6tLy4DHQ8zl5xhA740G6Gwd LLtCQu4lQimPerUGDJXOVD1NTh8W9p5VzRLufk6Zy9mi9AKQYEcVyYKTP7jb3ipTw/Zg eZEzwH6sbDQlcal5EJHEQNri9JqflDs7Y3rNwa3qgVnsMZmzHMkcodADQFgraAdWmKh1 90ETbHvbyqJZw7wLeOS9hpWWj10Q3dVFHG2ZPFiKjp6TZ7HUBhSTyh8PybY0v5XTZD5s nxQT7oHnBXgAxSw6BHe2xlCsU1YHN34A4W7zAiP8XFGTS8EGPMvFnxy7Guen8ni64+3z peAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=KA0cQX0H+fedUmZSqotKHkFt9nfBS2lV4mSDduYC1Vo=; b=dJ/IGQnWIRpS8I+DtTL+DzWe6cwQbZs7OX2/zTTlqfrNWHzlxFoutYJhQEHVPsk4Hz oElOWzlDgIYf2XXGGUazcz6N0/eVdpOfVT78msiFEnkjtHklkxq7SPq0OLU5IaPhpoOL T+fIBR5g7EadKz7JeiHUOlfRDar6ZicdQ4MggC7d86WNRb+eVvPkVf9AKOAs4k/owFZa UHAUOJ59FL8BDiyUm81o0+zjv0W0y8RvXr0wH1nnAqqzd7aBZTrgiNQtpIaxCaOjbhN5 8Q1vUibKMUnpVGi/I9JD/JuepoDK2srHEcXKJhxu/qg++AcBfwbQCi4kslid0wGgGp6d bmqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=CfwgdSSK; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si15602659edv.488.2021.03.16.19.13.14; Tue, 16 Mar 2021 19:13:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=CfwgdSSK; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbhCQCM2 (ORCPT + 99 others); Tue, 16 Mar 2021 22:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbhCQCMZ (ORCPT ); Tue, 16 Mar 2021 22:12:25 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0356EC061763 for ; Tue, 16 Mar 2021 19:12:24 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id o19so751401qvu.0 for ; Tue, 16 Mar 2021 19:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=KA0cQX0H+fedUmZSqotKHkFt9nfBS2lV4mSDduYC1Vo=; b=CfwgdSSKwnQ510ZsN0+CUYSCMnJvGTNOF0qgo3PkrJT/Da/ZELVOKWL/gvdjXbwGIJ +O24SS0hCf6GGdRpdBSk7N5NbLn2iWfl25SUnaP3oNJ7WiJXrG4UqOuQVtPZMqv1UvLq 1k9Y29haYQb7OJLIFpq9Ca/2lmePu+tE/YxOqCC7/pjN0ZJm/td3809+dpAOb2cIbaOB JIelDCwL+8ebDLqZ3W53s0y9QKt1RRSRn3jACZJpraJ6VtSZoPGPLIHKRuVw6WXLF8mu NSaPFQU3F6l0ReQyu9G5Yv+r+f2QbaVUKOhZkjsn1XroEHm2K1q3C9v7SyUY5WN5Z7ln hDeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=KA0cQX0H+fedUmZSqotKHkFt9nfBS2lV4mSDduYC1Vo=; b=JNhCPs/J876hcH+JBfOSPWr9S7K45fOYmKGsQEcYnuMAOZk3+M0aoO7UYHA5zJavxZ uuI9CP+AhS1j2VwTboPXwEfh8NnXbcqORweAAqbP6vH2BZRMunMzP5ESyRGZQv2UEYWC +1F292TK7ZZfiK+zcI036CAXGa6qE9FWVSspQ8RD17hDO6FOcUwwSffzB0zTfEmZEK/Q WtxZDQQCIyjhIqp9pwNwjNtNoINlywLJJ0VcwJUbF0zUABVGXy4l+J0CYU3hGeP4dhjf DkSZpAzmEhB/xMSSWaLFCELSWEFvoVsyDDMdnZ6GweNntHtcGBujVYfigdKTc+YI9TyY MVWw== X-Gm-Message-State: AOAM530XiEJJiFVmQwQtRkEZ2QYIUVj4WovPeQEsRkxoCwJ4tbzzYexZ 2stZCdrrnaPLerq6ORPyptJP1g== X-Received: by 2002:a05:6214:1744:: with SMTP id dc4mr2746704qvb.40.1615947143864; Tue, 16 Mar 2021 19:12:23 -0700 (PDT) Received: from [192.168.1.45] (cpe-174-109-172-136.nc.res.rr.com. [174.109.172.136]) by smtp.gmail.com with ESMTPSA id r3sm16393336qkm.129.2021.03.16.19.12.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 19:12:23 -0700 (PDT) Subject: Re: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache To: Linus Torvalds , Matthew Wilcox , Chris Mason , David Sterba Cc: David Howells , Trond Myklebust , Anna Schumaker , Steve French , Dominique Martinet , Christoph Hellwig , Alexander Viro , Linux-MM , linux-cachefs@redhat.com, linux-afs@lists.infradead.org, "open list:NFS, SUNRPC, AND..." , CIFS , ceph-devel@vger.kernel.org, v9fs-developer@lists.sourceforge.net, linux-fsdevel , Jeff Layton , David Wysochanski , Linux Kernel Mailing List References: <161539526152.286939.8589700175877370401.stgit@warthog.procyon.org.uk> <161539528910.286939.1252328699383291173.stgit@warthog.procyon.org.uk> <20210316190707.GD3420@casper.infradead.org> From: Josef Bacik Message-ID: <887b9eb7-2764-3659-d0bf-6a034a031618@toxicpanda.com> Date: Tue, 16 Mar 2021 22:12:21 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On 3/16/21 8:43 PM, Linus Torvalds wrote: > [ Adding btrfs people explicitly, maybe they see this on the fs-devel > list, but maybe they don't react .. ] > > On Tue, Mar 16, 2021 at 12:07 PM Matthew Wilcox wrote: >> >> This isn't a problem with this patch per se, but I'm concerned about >> private2 and expected page refcounts. > > Ugh. You are very right. > > It would be good to just change the rules - I get the feeling nobody > actually depended on them anyway because they were _so_ esoteric. > >> static inline int is_page_cache_freeable(struct page *page) >> { >> /* >> * A freeable page cache page is referenced only by the caller >> * that isolated the page, the page cache and optional buffer >> * heads at page->private. >> */ >> int page_cache_pins = thp_nr_pages(page); >> return page_count(page) - page_has_private(page) == 1 + page_cache_pins; > > You're right, that "page_has_private()" is really really nasty. > > The comment is, I think, the traditional usage case, which used to be > about page->buffers. Obviously these days it is now about > page->private with PG_private set, pointing to buffers > (attach_page_private() and detach_page_private()). > > But as you point out: > >> #define PAGE_FLAGS_PRIVATE \ >> (1UL << PG_private | 1UL << PG_private_2) >> >> So ... a page with both flags cleared should have a refcount of N. >> A page with one or both flags set should have a refcount of N+1. > > Could we just remove the PG_private_2 thing in this context entirely, > and make the rule be that > > (a) PG_private means that you have some local private data in > page->private, and that's all that matters for the "freeable" thing. > > (b) PG_private_2 does *not* have the same meaning, and has no bearing > on freeability (and only the refcount matters) > > I _)think_ the btrfs behavior is to only use PagePrivate2() when it > has a reference to the page, so btrfs doesn't care? > > I think fscache is already happy to take the page count when using > PG_private_2 for locking, exactly because I didn't want to have any > confusion about lifetimes. But this "page_has_private()" math ends up > meaning it's confusing anyway. > > btrfs people? What are the semantics for PG_private_2? Is it just a > flag, and you really don't want it to have anything to do with any > page lifetime decisions? Or? > Yeah it's just a flag, we use it to tell that the page is part of a range that has been allocated for IO. The lifetime of the page is independent of the page, but is generally either dirty or under writeback, so either it goes through truncate and we clear PagePrivate2 there, or it actually goes through IO and is cleared before we drop the page in our endio. We _always_ have PG_private set on the page as long as we own it, and PG_private_2 is only set in this IO related context, so we're safe there because of the rules around PG_dirty/PG_writeback. We don't need it to have an extra ref for it being set. Thanks, Josef