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 X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBE00C433E0 for ; Wed, 17 Mar 2021 00:44:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39CDF64F8B for ; Wed, 17 Mar 2021 00:44:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39CDF64F8B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 68EF36B006E; Tue, 16 Mar 2021 20:44:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63F426B0070; Tue, 16 Mar 2021 20:44:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 507436B0071; Tue, 16 Mar 2021 20:44:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id 3322B6B006E for ; Tue, 16 Mar 2021 20:44:12 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E0AFF8249980 for ; Wed, 17 Mar 2021 00:44:11 +0000 (UTC) X-FDA: 77927519502.11.A62CF17 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by imf25.hostedemail.com (Postfix) with ESMTP id 6BCA36000102 for ; Wed, 17 Mar 2021 00:44:09 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id z8so1031637ljm.12 for ; Tue, 16 Mar 2021 17:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Hdc3Z4qXX9l8XXJJcPsajObPuLYLca+A1Hq/au570EA=; b=YqsIQMoBpBXzCzWbXra19j5jdGRkI2qmReN0oKioV0Shal06ZaKrGs1JdX7FzgzYcr nVdCUGWHZEm/QGFrHGtKf2wWR/L5xQyhWnIB3r3hvDiwBN64JQlL/ROMD8G8P5PUnBxO I6l7MXffemgprdgtj4mLDpX7ZtfZ2Y1ecu3YE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Hdc3Z4qXX9l8XXJJcPsajObPuLYLca+A1Hq/au570EA=; b=tdDhvAzKEiFBvS2mWyd34iAZdAwMFXENve/gDyvp3OkVqekIqBwJ5H75sN2QA7u3CC T5q3CCvYyPp3XlFqrR+shPST6JB+a0sv1TZRqi6LW2Vy2QlRKFfN7r0Zby7Tigu1snSx 1qs/ZUT57Qb8e+58NIMTnqj1ds96Ff4kry0VKfNg2baUO33vLEBaXb2JWoKE60mI7cK2 S1hIlEJp4dhvTBW92YB2Q+p6Wpj/9ckqz9b/4oezwPe/0KBprOFDVxwEIFZPUXzOFviS 4gyGqX01DHcHcW3dIPHNzI4yirAvclYoOZll4+Y8+axN8FWUJHHS8Na54csQzFiZRka1 fKsw== X-Gm-Message-State: AOAM532NsPM2LwKFHqqCo+Cna06N2iSVjgS/JnSMN3L3LQ3+O1FWNhmS qR4qBEaw40VsXul4csNIsfrWNZiXQJc1sg== X-Google-Smtp-Source: ABdhPJxtRmtAkLy/h4xFkngmcqpBM328+sooRpTYwMShBBS2iyssry4UYE4rzdFUgv6BOATdh3NpJA== X-Received: by 2002:a05:651c:d0:: with SMTP id 16mr813164ljr.296.1615941847681; Tue, 16 Mar 2021 17:44:07 -0700 (PDT) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com. [209.85.167.46]) by smtp.gmail.com with ESMTPSA id w23sm3365646lji.127.2021.03.16.17.44.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 17:44:07 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id e7so389910lft.2 for ; Tue, 16 Mar 2021 17:44:06 -0700 (PDT) X-Received: by 2002:ac2:4250:: with SMTP id m16mr745431lfl.40.1615941846610; Tue, 16 Mar 2021 17:44:06 -0700 (PDT) MIME-Version: 1.0 References: <161539526152.286939.8589700175877370401.stgit@warthog.procyon.org.uk> <161539528910.286939.1252328699383291173.stgit@warthog.procyon.org.uk> <20210316190707.GD3420@casper.infradead.org> In-Reply-To: <20210316190707.GD3420@casper.infradead.org> From: Linus Torvalds Date: Tue, 16 Mar 2021 17:43:50 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache To: Matthew Wilcox , Chris Mason , Josef Bacik , 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 Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 4efn31xhqud86yhxuh84zoti4qcet9ys X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6BCA36000102 Received-SPF: none (linuxfoundation.org>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from=""; helo=mail-lj1-f172.google.com; client-ip=209.85.208.172 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615941849-310247 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: [ 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? Linus