From patchwork Tue Feb 9 02:30:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12077051 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 06AC0C433E6 for ; Tue, 9 Feb 2021 02:30:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7C4B464EBA for ; Tue, 9 Feb 2021 02:30:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C4B464EBA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D82F46B006C; Mon, 8 Feb 2021 21:30:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D09966B006E; Mon, 8 Feb 2021 21:30:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE80B6B0070; Mon, 8 Feb 2021 21:30:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 896376B006C for ; Mon, 8 Feb 2021 21:30:17 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4D2FA1730855 for ; Tue, 9 Feb 2021 02:30:17 +0000 (UTC) X-FDA: 77797150074.27.uncle93_4203b8527603 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 2F5593D669 for ; Tue, 9 Feb 2021 02:30:17 +0000 (UTC) X-HE-Tag: uncle93_4203b8527603 X-Filterd-Recvd-Size: 6187 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 02:30:16 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id gx20so771658pjb.1 for ; Mon, 08 Feb 2021 18:30:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lORwaaiPEScAng7B1o0PI3rE/Z/yT/4jNBxJ0rOXsDA=; b=SjQuZzcSz5/ors8H2c2fFiZya7IIdg+5e48zKW4Xry1PtdKCTBUPuv313R/WdoitzW wuCwqdW24Ut65txynzjDs1N06SiK7i4h+TXbTxmVE5MkXz+USPW5zsA9Wocpj5tU4zEE yBMQpAILtUgKvPnWuksDPdo6J5vxwbq7s3ydpDYJIE896kYhYJOD6KEI+lyq41fVWXet bp74ML+EBujxIPO+SJEvOXIL7wEimkfU8xQv0A/wiZO6zt4LBuBqqVhIvlYrS41ufJfN 49znuQDexZiOgIImZMVJboqYj5OvZTTmWAJJmPj54xT9oaNxc83hpzZNct6bgz48I8E3 lWdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lORwaaiPEScAng7B1o0PI3rE/Z/yT/4jNBxJ0rOXsDA=; b=llt6ERs5TmdtsPsxNXlx4O3f5cq14OeFuGn7I8woiU/UDPG1CkuXseTsosuI5gXcrF aT8Bhk6vvyIy1HZfEBG9nBQn2oMsYY0m1DTEQgURQ+OT3i3uI6+cZYtomgCS4gO/GqLl My0zdTVXCvdjS24rm5A+1f0prGAin5ATrX2SnTiJBPZjwDp9CKwT5Sway1azp5FGChBN DiEmGtDGxGXYDtXEW1Ook3/1P/H7wLPsXwNMk1TDD6kmuKxBYmufX/b+OHCUpPuEPA6u WEfmL92iWv0bBfPauFnvUHnmggvkyM+CrlcbnJ5fOkc+cPxUU76T4jt7wgBF5RA+jjxN PWXA== X-Gm-Message-State: AOAM531tpiJItWk5A+Y93xNIBYRlnIE1a6fMKSRvTkeCB1NGQA6F+m1J nyO60dCA805wTEUb43/r3YS5Cw== X-Google-Smtp-Source: ABdhPJzRjq3VJvcakEyMmh+N1e9dpfs3Ljn9RDCUa5pfoyICkb5FgskLto2S5Lg49P8ke0tXi65jCw== X-Received: by 2002:a17:90a:cc03:: with SMTP id b3mr1854414pju.2.1612837815702; Mon, 08 Feb 2021 18:30:15 -0800 (PST) Received: from localhost.localdomain ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id y2sm19070597pfe.118.2021.02.08.18.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 18:30:15 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: hch@infradead.org, akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 1/3] mm: provide filemap_range_needs_writeback() helper Date: Mon, 8 Feb 2021 19:30:06 -0700 Message-Id: <20210209023008.76263-2-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210209023008.76263-1-axboe@kernel.dk> References: <20210209023008.76263-1-axboe@kernel.dk> MIME-Version: 1.0 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: 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 --- 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 fd47deea7c17..def89222dfe9 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 aa0e0fb04670..6a58d50fbd31 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -633,6 +633,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 From patchwork Tue Feb 9 02:30:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12077053 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 24060C433DB for ; Tue, 9 Feb 2021 02:30:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9F1FC64EAC for ; Tue, 9 Feb 2021 02:30:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F1FC64EAC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C99FB6B006E; Mon, 8 Feb 2021 21:30:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BAB376B0070; Mon, 8 Feb 2021 21:30:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D4216B0075; Mon, 8 Feb 2021 21:30:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 814176B006E for ; Mon, 8 Feb 2021 21:30:18 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4EBE1824805A for ; Tue, 9 Feb 2021 02:30:18 +0000 (UTC) X-FDA: 77797150116.19.heat81_5f1495727603 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 2F8511ACC3C for ; Tue, 9 Feb 2021 02:30:18 +0000 (UTC) X-HE-Tag: heat81_5f1495727603 X-Filterd-Recvd-Size: 3954 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 02:30:17 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id 18so8812127pfz.3 for ; Mon, 08 Feb 2021 18:30:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NeAk3PJLifKVqc2Uhcs4FSpHilknKrj5z1MFAaW43Ag=; b=1ias4FnzK1VNFg9SZDY3ZUQe4V9wOj9t9t9923MKJpPj4Sogo47GefH2KPemZbZsox IfaITZ1qCeBJu/ZhxPyhuFhs9u8v0hk01hGMSC16iv9eahk8oyAZ2xGU1N/IUdxrtQqW B+ouKmxnuPJoERPIiXefe6b5cM9xlm6EPqr1aZ5GqG1H5O4bsST+CTLPGrhgkLMRII7P 3RdnxMkp0b/EFTk7h6S0PVBqf3kRtzEnGoYS5FfdU5d0OO6OaJM9Qrr2Bgyt/+ZDAkmN qZMd+smoKKXipq4SNPfR5FGk4iQPca47fR6SipLXy3SCcwBNSE1wslLJ8TUTnN4Ohqm9 rHoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NeAk3PJLifKVqc2Uhcs4FSpHilknKrj5z1MFAaW43Ag=; b=lm8w0I4MACSX7SREhG2Eii9aSKwNgeh7lZgpPNMe7qM5lT4VyJ2gT8rruNYC1CyXtk HyxeosUXRArpX5eDzsQmaDeQVHWzSMwvljTabOzB0ldYmU7XzGbuU/otXy9n4XHZrcpy 2dQ+KqZrwM5Y5d72fIeh9aqMnv45tVSorgEpIYOk6GROakme6tgSlv/qpd/+8OPv67ms VHhrUCLZ4nNodI2jdDyGlYQ/SMAq90Se7BvrRdX83qrfniuoN7XDw4JuK/7wHkGg0zj8 FoZoGs9rVEHpkOglqV3p2+Wx0vsYKdY7euQ9PsBwhduEe3GGVOZtl5R0m0GN2OvUWzfz A+FQ== X-Gm-Message-State: AOAM530sCREPiXtqR+E6TKNt2jtsjQTcRtb3fhXnCzDmK2ooGWUcJnpZ MlC5F4t/gJ8mhr2Dii3YIsGn8A== X-Google-Smtp-Source: ABdhPJzIodUg5PR3R81qsg3WhYeJzNk6dOAQUyTI4+Gq/PEaHHOneG01zD8/fBvd5h7Imb7eWrJ4vg== X-Received: by 2002:a05:6a00:a8d:b029:1ba:71d1:fe3c with SMTP id b13-20020a056a000a8db02901ba71d1fe3cmr20553833pfl.51.1612837816706; Mon, 08 Feb 2021 18:30:16 -0800 (PST) Received: from localhost.localdomain ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id y2sm19070597pfe.118.2021.02.08.18.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 18:30:16 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: hch@infradead.org, akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 2/3] mm: use filemap_range_needs_writeback() for O_DIRECT reads Date: Mon, 8 Feb 2021 19:30:07 -0700 Message-Id: <20210209023008.76263-3-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210209023008.76263-1-axboe@kernel.dk> References: <20210209023008.76263-1-axboe@kernel.dk> MIME-Version: 1.0 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: For the generic page cache read helper, use the better variant of checking for the need to call filemap_write_and_wait_range() when doing O_DIRECT reads. This avoids falling back to the slow path for IOCB_NOWAIT, if there are no pages to wait for (or write out). Signed-off-by: Jens Axboe --- mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 6a58d50fbd31..c80acb80e8f7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2643,8 +2643,8 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) size = i_size_read(inode); if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_has_page(mapping, iocb->ki_pos, - iocb->ki_pos + count - 1)) + if (filemap_range_needs_writeback(mapping, iocb->ki_pos, + iocb->ki_pos + count - 1)) return -EAGAIN; } else { retval = filemap_write_and_wait_range(mapping, From patchwork Tue Feb 9 02:30:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12077055 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 343D8C433DB for ; Tue, 9 Feb 2021 02:30:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B893E64EB4 for ; Tue, 9 Feb 2021 02:30:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B893E64EB4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C20446B0070; Mon, 8 Feb 2021 21:30:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BAB7E6B0075; Mon, 8 Feb 2021 21:30:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9B816B0078; Mon, 8 Feb 2021 21:30:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id 8D2606B0070 for ; Mon, 8 Feb 2021 21:30:19 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 573BA824805A for ; Tue, 9 Feb 2021 02:30:19 +0000 (UTC) X-FDA: 77797150158.19.robin63_41178b027603 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 359AE1ACC3C for ; Tue, 9 Feb 2021 02:30:19 +0000 (UTC) X-HE-Tag: robin63_41178b027603 X-Filterd-Recvd-Size: 4587 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 02:30:18 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id n10so11499839pgl.10 for ; Mon, 08 Feb 2021 18:30:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B3Rk7GfRZkBxeNjU7Kh2bYrh55ud7n78YGybFpQpjSk=; b=16kACgxMGBZehZBaxowbj13gbI/eye+R6F4RoVlRlXWybq8eTBEDzKVDtapQgd+H5D OB7C2HHew7WFUYVvngutI0mymaHtZF+jhsHiffcBZU69I2hCEUpIsZ8ynEfxcGsEw164 wAsWCh7DYnRZa/NgROpaa1mNhpO+xI5ZzonDCKEEwO6Yxo9uBPgskUmbfvxr2TkBUSbG MsTZFCp6CcDdX/9Ye9U72bkvp2e53t8jBli23b8FFJCVrsCg59rH1PJltCb8jxrap7Cc 27mdsD3OJzyronye6gaXdow8VcQTC48U4LFruthYCkqis2pv8BY+U6N6LwLCQ8u+8lsx 2mUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B3Rk7GfRZkBxeNjU7Kh2bYrh55ud7n78YGybFpQpjSk=; b=p+B9qizqpH25taxxDRHECjs37ZfOCh7so6LMjnx66G/OynUaslsBEQfQaQn5EbsRrW ATUp6RcEib5YsDYpLbcb0arnLUaRCMqfzmzJjUmX74FvKIhuZ2nOcZcCEcWcYdmFaBjz wCESeUd1kZAzVu+QQEQUrMn9QKe9+fcmHuTKFHLQg6ZqRx98Cjq6ipxmWYHSOBczURB0 pwkfp3BtD7ygkrro3n1F9LDeXx6XMKuvVgMHoNGV8TqHWGCQzFF/G9vHWVbDPycH90SE 2h3QklXgtYljBaR8SwPk4dRagBhxbburHGxFDE5Hs35mNRVD6LWERGLrWOcpJ+arqeYy D19A== X-Gm-Message-State: AOAM5331gGlTfGIfChDZANdl2yIjOez4PXxbUzKIRQtbiAzmBTBYyuj1 AWKaPwdyxPg1/OQ8Ya5YyihuwQ== X-Google-Smtp-Source: ABdhPJyqaoja4NK3VKz/84pycA5yyMWjTKdCPC0AlBIyGsuH/6UaH2NbIQvUjEEZV3DGm/CWaVMRWw== X-Received: by 2002:a62:8fd4:0:b029:1de:d484:e1f7 with SMTP id n203-20020a628fd40000b02901ded484e1f7mr5031886pfd.78.1612837817672; Mon, 08 Feb 2021 18:30:17 -0800 (PST) Received: from localhost.localdomain ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id y2sm19070597pfe.118.2021.02.08.18.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 18:30:17 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: hch@infradead.org, akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 3/3] iomap: use filemap_range_needs_writeback() for O_DIRECT reads Date: Mon, 8 Feb 2021 19:30:08 -0700 Message-Id: <20210209023008.76263-4-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210209023008.76263-1-axboe@kernel.dk> References: <20210209023008.76263-1-axboe@kernel.dk> MIME-Version: 1.0 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: For reads, use the better variant of checking for the need to call filemap_write_and_wait_range() when doing O_DIRECT. This avoids falling back to the slow path for IOCB_NOWAIT, if there are no pages to wait for (or write out). Signed-off-by: Jens Axboe --- fs/iomap/direct-io.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 933f234d5bec..5b111d1635ab 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -458,9 +458,24 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, if (pos >= dio->i_size) goto out_free_dio; + if (iocb->ki_flags & IOCB_NOWAIT) { + if (filemap_range_needs_writeback(mapping, pos, end)) { + ret = -EAGAIN; + goto out_free_dio; + } + flags |= IOMAP_NOWAIT; + } if (iter_is_iovec(iter)) dio->flags |= IOMAP_DIO_DIRTY; } else { + if (iocb->ki_flags & IOCB_NOWAIT) { + if (filemap_range_has_page(mapping, pos, end)) { + ret = -EAGAIN; + goto out_free_dio; + } + flags |= IOMAP_NOWAIT; + } + flags |= IOMAP_WRITE; dio->flags |= IOMAP_DIO_WRITE; @@ -478,14 +493,6 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, dio->flags |= IOMAP_DIO_WRITE_FUA; } - if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_has_page(mapping, pos, end)) { - ret = -EAGAIN; - goto out_free_dio; - } - flags |= IOMAP_NOWAIT; - } - ret = filemap_write_and_wait_range(mapping, pos, end); if (ret) goto out_free_dio;