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 831E2C43334 for ; Fri, 10 Jun 2022 21:39:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4A508D00E6; Fri, 10 Jun 2022 17:39:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF99C8D00E2; Fri, 10 Jun 2022 17:39:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC0B98D00E6; Fri, 10 Jun 2022 17:39:37 -0400 (EDT) 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 AA9168D00E2 for ; Fri, 10 Jun 2022 17:39:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5AC06335F6 for ; Fri, 10 Jun 2022 21:39:37 +0000 (UTC) X-FDA: 79563643194.22.35B8464 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 54F482006E for ; Fri, 10 Jun 2022 21:39:36 +0000 (UTC) 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: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654897176; a=rsa-sha256; cv=none; b=6xq3FVKXXKRgnzCTEzvxUGuLdwWNmBNVouDJLOAnNklCsHcAJCv3z9/oKU3MQ8JP8WR0N4 Vs15kqZgZ7GhZOvW0UB7OEH0fI8/B/wbSRE3SoETm4FgI6q76aoqwDsD+qcGsKakQ+4woR V1gxAY+I+IxxNOzVXyrnVofYZ0oMXvI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=j0pcJcUh; dmarc=none; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654897176; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=99zlQwcPvvmzVYoPFUX+YY7MW7h9pMosRlHEuBShaHg=; b=P+Xz+fBZkoYHoOhdk+Wz6XbWYEp54/1HAQVvlgOVCzupUMaAC0lv/i9g6mh4dgwRj3Hgg+ oSAQkwoEoovrGCC++1HFfKIR1bxS5xvrZmLzbNEl5K/3s0H9WKbA1KB0Vqhn/LvHuEjt0Q sn9UnRNvPr+yNHAfSDnnQ9OT2/vglAA= X-Stat-Signature: 8aqttx9oz5wrk1cfri4fiyfqarz735mh X-Rspamd-Queue-Id: 54F482006E X-Rspam-User: X-Rspamd-Server: rspam10 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=j0pcJcUh; dmarc=none; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1654897176-835315 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: 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()).