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.6 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 0135EC433ED for ; Sun, 9 May 2021 19:40:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 63AB96135C for ; Sun, 9 May 2021 19:40:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63AB96135C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BA2146B0070; Sun, 9 May 2021 15:40:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B783D6B0071; Sun, 9 May 2021 15:40:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A67F46B0072; Sun, 9 May 2021 15:40:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id 883C26B0070 for ; Sun, 9 May 2021 15:40:42 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3A82F9422 for ; Sun, 9 May 2021 19:40:42 +0000 (UTC) X-FDA: 78122709924.06.6BA9AE9 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id DA9A46000104 for ; Sun, 9 May 2021 19:40:30 +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=xOmB/YchRcK/qsDYZe5ppZqxGiNZtOWSH9+LUL6fPJg=; b=HJjS0h92Sfk7cPS9WLCURlJssA uTON3a7sl2fCTC7bFektNVtZcttBLPer2KIx6FTorRNbgyL6b7CyM4UlEDkHu7kj2buDV5aJBrRN0 qfI/HIc7WY1bbM3NlxL/3abjtiJoyUnRT3ereHR2Zdr3qSzqXccbdruZxLtS0cZBerWdMeEvCA1rC Ich11TyO4bH+GZLnLJ8aIJxTNpeBTTkTKeyH/6rywtJfZ3B7oXWHncrNO/7M0wVrPOuBrkQis1mFt VaMSgcrsov3zhjQ7wb6QwIqWSkJOqKtzcbuunaW4SpMbJwOUwyupu/YdoCXDhM7vdychH4s0RN95u maaoPo3A==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lfpHt-005NQn-Fz; Sun, 09 May 2021 19:40:30 +0000 Date: Sun, 9 May 2021 20:40:25 +0100 From: Matthew Wilcox To: Linus Torvalds Cc: Andrew Morton , Jens Axboe , Jan Kara , Linux-MM , mm-commits@vger.kernel.org Subject: Re: [patch 041/178] mm: provide filemap_range_needs_writeback() helper Message-ID: References: <20210429225251.02b6386d21b69255b4f6c163@linux-foundation.org> <20210430055518.KCtlWixJr%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam01 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HJjS0h92; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Stat-Signature: udj8db8z8kh6qbnrg3br4mbykmrgs73e X-Rspamd-Queue-Id: DA9A46000104 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620589230-290557 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, Apr 30, 2021 at 09:50:29AM -0700, Linus Torvalds wrote: > Wait, what? > > On Thu, Apr 29, 2021 at 10:55 PM Andrew Morton > wrote: > > > > + if (!mapping_needs_writeback(mapping)) > > + return false; > > + if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) && > > + !mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK)) > > + return false; > > + if (end_byte < start_byte) > > + return false; > > Ok, good, get rid of the trivial cases first. > > > + rcu_read_lock(); > > + xas_for_each(&xas, page, max) { > > + if (xas_retry(&xas, page)) > > + continue; > > + if (xa_is_value(page)) > > + continue; > > + if (PageDirty(page) || PageLocked(page) || PageWriteback(page)) > > + break; > > + } > > + rcu_read_unlock(); > > Whee. This looks very very expensive indeed. > > Why is is going to each page, why does it care about locked when the > simple early cases did not? I was hoping Jens would answer this, but I guess he missed it so far. I don't know why it now cares about whether the page is locked or not. I presume it's not even the slightest bit slow for Jens because the common case is that there are no pages in the range, and so we never check any pages. > Why isn't this just using xas_for_each_marked(), or maybe even just a > single "xa_find()", since all it cares about is "is _any_ page.." We don't have an iterator that looks for either mark A or mark B, so we'd have to iterate twice, once to look for dirty and once to look for writeback. For the common case of there being no pages in the range, that'd be slower. I could add an iterator that returns the next entry in the given range that has any mark set (almost trivial; OR the mark bitmaps together before scanning them). But I don't know why we care about the Locked case, so I don't know if it'd be the right thing to do. xa_find() isn't quite right because that'll return shadow entries, and we do want to skip those.