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=-2.4 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 7CDD9C76190 for ; Tue, 23 Jul 2019 08:16:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5425520449 for ; Tue, 23 Jul 2019 08:16:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=yandex-team.ru header.i=@yandex-team.ru header.b="M0CVenrM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733139AbfGWIQ4 (ORCPT ); Tue, 23 Jul 2019 04:16:56 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:59694 "EHLO forwardcorp1o.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730753AbfGWIQz (ORCPT ); Tue, 23 Jul 2019 04:16:55 -0400 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 94D392E1485; Tue, 23 Jul 2019 11:16:52 +0300 (MSK) Received: from smtpcorp1j.mail.yandex.net (smtpcorp1j.mail.yandex.net [2a02:6b8:0:1619::137]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id zrWDbtFrST-GqNCGMan; Tue, 23 Jul 2019 11:16:52 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1563869812; bh=OCdChmHdfM6D9uf2VkQAqf8PnxrZ5zOIH6aLjOH+qUU=; h=In-Reply-To:Message-ID:From:Date:References:To:Subject:Cc; b=M0CVenrM9AC4JpNV2SXPm4QsXi07w0FwQKWvlGVbaH2JKs/RvqeojUHoTdlkMrkb6 8CFoIYQtsn4RsPg8zd58p/Jtt/lPbqhJ2HhpLnLHI+NTKbR3m6d3bthLrDf6ZFMmun vcG5SDSMKJo7nRP3Se9wk2sTAFGcYTucOwL1nvjM= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:38b3:1cdf:ad1a:1fe1]) by smtpcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 7w6wmPdkO2-GpAejdNM; Tue, 23 Jul 2019 11:16:52 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: Re: [PATCH 1/2] mm/filemap: don't initiate writeback if mapping has no dirty pages To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tejun Heo , Jens Axboe , Johannes Weiner , linux-fsdevel@vger.kernel.org, Jan Kara References: <156378816804.1087.8607636317907921438.stgit@buzz> <20190722175230.d357d52c3e86dc87efbd4243@linux-foundation.org> From: Konstantin Khlebnikov Message-ID: Date: Tue, 23 Jul 2019 11:16:51 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20190722175230.d357d52c3e86dc87efbd4243@linux-foundation.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23.07.2019 3:52, Andrew Morton wrote: > > (cc linux-fsdevel and Jan) > > On Mon, 22 Jul 2019 12:36:08 +0300 Konstantin Khlebnikov wrote: > >> Functions like filemap_write_and_wait_range() should do nothing if inode >> has no dirty pages or pages currently under writeback. But they anyway >> construct struct writeback_control and this does some atomic operations >> if CONFIG_CGROUP_WRITEBACK=y - on fast path it locks inode->i_lock and >> updates state of writeback ownership, on slow path might be more work. >> Current this path is safely avoided only when inode mapping has no pages. >> >> For example generic_file_read_iter() calls filemap_write_and_wait_range() >> at each O_DIRECT read - pretty hot path. >> >> This patch skips starting new writeback if mapping has no dirty tags set. >> If writeback is already in progress filemap_write_and_wait_range() will >> wait for it. >> >> ... >> >> --- a/mm/filemap.c >> +++ b/mm/filemap.c >> @@ -408,7 +408,8 @@ int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start, >> .range_end = end, >> }; >> >> - if (!mapping_cap_writeback_dirty(mapping)) >> + if (!mapping_cap_writeback_dirty(mapping) || >> + !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) >> return 0; >> >> wbc_attach_fdatawrite_inode(&wbc, mapping->host); > > How does this play with tagged_writepages? We assume that no tagging > has been performed by any __filemap_fdatawrite_range() caller? > Checking also PAGECACHE_TAG_TOWRITE is cheap but seems redundant. To-write tags are supposed to be a subset of dirty tags: to-write is set only when dirty is set and cleared after starting writeback. Special case set_page_writeback_keepwrite() which does not clear to-write should be for dirty page thus dirty tag is not going to be cleared either. Ext4 calls it after redirty_page_for_writepage() XFS even without clear_page_dirty_for_io() Anyway to-write tag without dirty tag or at clear page is confusing.