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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0B96C43334 for ; Fri, 10 Jun 2022 21:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350919AbiFJVjj (ORCPT ); Fri, 10 Jun 2022 17:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347712AbiFJVjh (ORCPT ); Fri, 10 Jun 2022 17:39:37 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A1156777; Fri, 10 Jun 2022 14:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=99zlQwcPvvmzVYoPFUX+YY7MW7h9pMosRlHEuBShaHg=; b=j0pcJcUhoFLL9W42AkDebG5dD1 Prv1wLGsIwWJgH71ajx6VId4jx7IrdQtW2vr0q57TuyzgiXxShmbblNvNiTZOMukFvau8Jt7ZUsRN 5LlRuRPlSwOTOF5zDw2oDmt23MlfaDnFgTilQ0LTdT73c8UtOO1vGH5P5dI6QpxwzaxziL05N3+JJ rCEppRaP6+tLzPGhywT8N3BaN2Wltw3My2+/sYSR86cIODQIKi/bkO/DmY4W0dk6nF4ASJ2wnYqlv SoliIuV3rf4ctktpIGt6bssq8OBf3twjCFii4UAcVbKPgSwrxqSSBb2+gIf1jPBEBDF0iMLaoNXJE 8cwF9pGg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzmLt-00Elvy-9o; Fri, 10 Jun 2022 21:39:33 +0000 Date: Fri, 10 Jun 2022 22:39:33 +0100 From: Matthew Wilcox To: Linus Torvalds Cc: linux-fsdevel , Linux-MM , Linux Kernel Mailing List Subject: Re: [GIT PULL] Folio fixes for 5.19 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 10, 2022 at 12:56:48PM -0700, Linus Torvalds wrote: > On Fri, Jun 10, 2022 at 12:22 PM Matthew Wilcox wrote: > > > > - Don't release a folio while it's still locked > > Ugh. > > I *hate* this patch. It's just incredibly broken. > > Yes, I've pulled this, but I have looked at that readahead_folio() > function before, and I have despised it before, but this patch really > drove home how incredibly broken that function is. > > Honestly, readahead_folio() returns a folio *AFTER* it has dropped the > ref to that folio. OK, you caught me. I realised (a little too late) that the rules around refcounts in ->readpage and ->readahead are different, and that creates pain for people writing filesystems. For ->readahead, I stuck with the refcount model that was in ->readpages (there is an extra refcount on the folio and the filesystem must put it before it returns). But I don't want to change the refcounting rules on a method without changing something else about the method, because trying to find a missing refcount change is misery. Anyway, my cunning thought was that if I bundle the change to the refcount rule with the change from readahead_page() to readahead_folio(), once all filesystems are converted to readahead_folio(), I can pull the refcount game out of readahead_folio() and do it in the caller where it belongs, all transparent to the filesystems. I think it's worth doing, because it's two fewer atomic ops per folio that we read from a file. But I didn't think through the transition process clearly enough, and right now it's a mess. How would you like me to proceed? (I don't think the erofs code has a bug because it doesn't remove the folio from the pagecache while holding the lock -- the folio lock prevents anyone _else_ from removing the folio from the pagecache, so there must be a reference on the folio up until erofs calls folio_unlock()).