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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 B9C49C433E0 for ; Wed, 24 Feb 2021 17:24:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 37F8464F0E for ; Wed, 24 Feb 2021 17:24:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37F8464F0E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A08916B0070; Wed, 24 Feb 2021 12:24:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B8306B0071; Wed, 24 Feb 2021 12:24:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A7D86B0072; Wed, 24 Feb 2021 12:24:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id 7614E6B0070 for ; Wed, 24 Feb 2021 12:24:35 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3B3AB18084CC2 for ; Wed, 24 Feb 2021 17:24:35 +0000 (UTC) X-FDA: 77853835710.09.3158F62 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf15.hostedemail.com (Postfix) with ESMTP id 2EED6A0000FF for ; Wed, 24 Feb 2021 17:24:32 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9B3F4AEE7; Wed, 24 Feb 2021 17:22:50 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 5D74F1E14EE; Wed, 24 Feb 2021 18:22:50 +0100 (CET) Date: Wed, 24 Feb 2021 18:22:50 +0100 From: Jan Kara To: Jens Axboe Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org Subject: Re: [PATCH 1/3] mm: provide filemap_range_needs_writeback() helper Message-ID: <20210224172250.GD849@quack2.suse.cz> References: <20210224164455.1096727-1-axboe@kernel.dk> <20210224164455.1096727-2-axboe@kernel.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210224164455.1096727-2-axboe@kernel.dk> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2EED6A0000FF X-Stat-Signature: gzhxq611wqfh3hr9rtuuyyytfphynriz Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1614187472-898666 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 Wed 24-02-21 09:44:53, Jens Axboe wrote: > For O_DIRECT reads/writes, we check if we need to issue a call to > filemap_write_and_wait_range() to issue and/or wait for writeback for any > page in the given range. The existing mechanism just checks for a page in > the range, which is suboptimal for IOCB_NOWAIT as we'll fallback to the > slow path (and needing retry) if there's just a clean page cache page in > the range. > > Provide filemap_range_needs_writeback() which tries a little harder to > check if we actually need to issue and/or wait for writeback in the > range. > > Signed-off-by: Jens Axboe Looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > include/linux/fs.h | 2 ++ > mm/filemap.c | 43 +++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 45 insertions(+) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 6d8b1e7337e4..4925275e6365 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2633,6 +2633,8 @@ static inline int filemap_fdatawait(struct address_space *mapping) > > extern bool filemap_range_has_page(struct address_space *, loff_t lstart, > loff_t lend); > +extern bool filemap_range_needs_writeback(struct address_space *, > + loff_t lstart, loff_t lend); > extern int filemap_write_and_wait_range(struct address_space *mapping, > loff_t lstart, loff_t lend); > extern int __filemap_fdatawrite_range(struct address_space *mapping, > diff --git a/mm/filemap.c b/mm/filemap.c > index 6ff2a3fb0dc7..13338f877677 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -635,6 +635,49 @@ static bool mapping_needs_writeback(struct address_space *mapping) > return mapping->nrpages; > } > > +/** > + * filemap_range_needs_writeback - check if range potentially needs writeback > + * @mapping: address space within which to check > + * @start_byte: offset in bytes where the range starts > + * @end_byte: offset in bytes where the range ends (inclusive) > + * > + * Find at least one page in the range supplied, usually used to check if > + * direct writing in this range will trigger a writeback. Used by O_DIRECT > + * read/write with IOCB_NOWAIT, to see if the caller needs to do > + * filemap_write_and_wait_range() before proceeding. > + * > + * Return: %true if the caller should do filemap_write_and_wait_range() before > + * doing O_DIRECT to a page in this range, %false otherwise. > + */ > +bool filemap_range_needs_writeback(struct address_space *mapping, > + loff_t start_byte, loff_t end_byte) > +{ > + XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT); > + pgoff_t max = end_byte >> PAGE_SHIFT; > + struct page *page; > + > + 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; > + > + 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(); > + return page != NULL; > +} > +EXPORT_SYMBOL_GPL(filemap_range_needs_writeback); > + > /** > * filemap_write_and_wait_range - write out & wait on a file range > * @mapping: the address_space for the pages > -- > 2.30.0 > -- Jan Kara SUSE Labs, CR