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=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 32606C4338F for ; Sun, 15 Aug 2021 03:32:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06DAB61038 for ; Sun, 15 Aug 2021 03:32:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 06DAB61038 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 333056B0074; Sat, 14 Aug 2021 23:32:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E2D66B0075; Sat, 14 Aug 2021 23:32:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D1838D0001; Sat, 14 Aug 2021 23:32:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 01B0D6B0074 for ; Sat, 14 Aug 2021 23:32:51 -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 7C0478249980 for ; Sun, 15 Aug 2021 03:32:51 +0000 (UTC) X-FDA: 78475893342.11.A13FA5A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 14A91B000E19 for ; Sun, 15 Aug 2021 03:32:50 +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=myN/3ktl6FFXkebMKIg+oytfpFhkg7CNnOU5Il6HFzs=; b=m9c9/qWRcdjSRQ6g5Wh/GFTqBw ybJTWwwMKF4g5qPy3pOZjSzNxPMwGljYeaCc5M2l8cJfSXPIgjXmTQe+uVlCjpeHCRpKUXNIPBB1r NtbB8JCeOQBQQ1yrISnvDQQlWTdnQ9ksC+GQspSuQTEvpq+bb1Lw7kDXn30cXgTUEGxxtxyZTRNTc jWl9mlYIRdEY6DBk8vvQWuMAHRTRjrSu8SBMR2a9LN+QjAfHEfRMf+zoCbAcdNpHJGrqwK0HUfj6E 6w4/jZQJ9/5Ecn71NDO4qfoz0uD1vyRPRcVuh1dBWdolAr6jw9r7WDVDWY7YWY2qjV/W+9t4g1utp 258jXAGQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mF6rU-00HN19-HY; Sun, 15 Aug 2021 03:31:11 +0000 Date: Sun, 15 Aug 2021 04:31:00 +0100 From: Matthew Wilcox To: Vlastimil Babka Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig Subject: Re: [PATCH v14 071/138] mm/writeback: Add filemap_dirty_folio() Message-ID: References: <20210715033704.692967-1-willy@infradead.org> <20210715033704.692967-72-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 14A91B000E19 X-Stat-Signature: cdhumffdx4917u9nawwawj495wno7qyx Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="m9c9/qWR"; dmarc=none; spf=none (imf25.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: 1628998370-631212 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 Thu, Aug 12, 2021 at 06:07:05PM +0200, Vlastimil Babka wrote: > On 7/15/21 5:35 AM, Matthew Wilcox (Oracle) wrote: > > Reimplement __set_page_dirty_nobuffers() as a wrapper around > > filemap_dirty_folio(). > > I assume it becomes obvious later why the new "mapping" parameter instead of > taking it from the folio, but maybe the changelog should say it here? --- mm/writeback: Add filemap_dirty_folio() Reimplement __set_page_dirty_nobuffers() as a wrapper around filemap_dirty_folio(). Eventually folio_mark_dirty() will pass the folio's mapping to the address space's ->dirty_folio() operation, so add the parameter to filemap_dirty_folio() now. --- Nobody seems quite sure whether it's possible to truncate (or otherwise remove) a page from a file while it's being marked as dirty. viz: int set_page_dirty(struct page *page) { struct address_space *mapping = page_mapping(page); if (likely(mapping)) { ... return mapping->a_ops->set_page_dirty(page); } so ->set_page_dirty can only be called if page has a mapping (obviously, otherwise we wouldn't know whose ->set_page_dirty to call). But then in __set_page_dirty_nobuffers(), we check to see if mapping has become unset: if (!TestSetPageDirty(page)) { struct address_space *mapping = page_mapping(page); if (!mapping) { unlock_page_memcg(page); return 1; } Confusingly, the comment to __set_page_dirty_nobuffers says: * The caller must ensure this doesn't race with truncation. Most will simply * hold the page lock, but e.g. zap_pte_range() calls with the page mapped and * the pte lock held, which also locks out truncation. I believe this is left-over from commit 2d6d7f982846 in 2015. Anyway, passing mapping as a parameter is something we already do for just about every other address_space operation, and we already called page_mapping() to get it, so why make the callee call it again? Not to mention people get confused about whether to call page_mapping() or just look at page->mapping. Changing the ->set_page_dirty() operation to ->dirty_folio() is something I've postponed until the 5.17/5.18 timeframe, but we might as well pass the parameter to filemap_dirty_folio() now.