From patchwork Wed Feb 24 16:44:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12102147 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.5 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 16CBDC433DB for ; Wed, 24 Feb 2021 16:45:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1269464F04 for ; Wed, 24 Feb 2021 16:45:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1269464F04 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 4D9626B0006; Wed, 24 Feb 2021 11:45:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42CAD6B0071; Wed, 24 Feb 2021 11:45:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 340FE6B0070; Wed, 24 Feb 2021 11:45:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 187BE6B0005 for ; Wed, 24 Feb 2021 11:45:09 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C090A80222D9 for ; Wed, 24 Feb 2021 16:45:08 +0000 (UTC) X-FDA: 77853736296.20.C2C36D7 Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 2FA9A2000393 for ; Wed, 24 Feb 2021 16:44:51 +0000 (UTC) Received: by mail-il1-f179.google.com with SMTP id q9so2298771ilo.1 for ; Wed, 24 Feb 2021 08:45:00 -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=Owukme2spaP1zcM9AHe/6hJeoYkmBs9bd0Xi7g8qADI=; b=GeDAo7Bc1lkwEaS/OFb6vd+jmpQQkTiXXvshs4eXK221ZcL0dZcaVB0lb1WFKvgKym h0uKM1lq1iBvNdNmz7EVIEvEJb11qjJD2oK+PEdz+G1oZ4zhUj+M23frgBZzvgV0Qnw8 troypsZkvPWeHDTHKC6Lha9WQQyh1Ud5MFj/W33jd8LRmE/S3zkeI5irCh2jwDOR75di l3toWqZJZLqiwSUzh9mQL4k45w6vwvBh0jMS0ibTJiQjz2YqgUaF647VT5OM+staaOsZ kTohBAGlscOR7g+W4RQGn8p66TiBRohVf94DEJWLbIY7qmev2STOMA9WutevYPxjtYP9 lWIw== 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=Owukme2spaP1zcM9AHe/6hJeoYkmBs9bd0Xi7g8qADI=; b=GwmokhjtYnCggFfQVpo9ONP0Of0dLlaufMpMToYhX3uQY1MkL3W7sj/DQCexE7n9uO 0w9amEgGMVOdoK14F+6h47ADiF0WWfuWufbgFIIju0yCDxMWhcENux3sY3NHW1R5CUAl w5TFsnib7dbqBCbc/HlPNZFPXYGNd7zx0WQXxb+5DrLVMwU6OBFr7lI60d6YmW2jNP51 2X/t2Q9a0XuUX/kWLKQ/yFdB/0CtMspHfmELQCjGKYwdb06yXWfSRRvL59AWmitsSREJ eOc3WqnohzHw/R6KmPaPJIqlkn9THed/2K4fq90ZkWUD11r0Xu/e9iwQhbRVgVBqq86o 4r6w== X-Gm-Message-State: AOAM5306GpL9WvNaiRv1yXmbUOHGfX9x5h804C5AcMOmT0z5cM0YEduK E6xFc33qcxVEs7dX0EqYv8yHvw== X-Google-Smtp-Source: ABdhPJzpcC+zKFW8OqpZDD687rXHdYoKLtmGUfTu+b4vervy16l9zQ+Zel7Wo9F6htsMLjpgyNRD8A== X-Received: by 2002:a05:6e02:1aa5:: with SMTP id l5mr23894877ilv.278.1614185099819; Wed, 24 Feb 2021 08:44:59 -0800 (PST) Received: from p1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id f1sm2273652iov.3.2021.02.24.08.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 08:44:59 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 1/3] mm: provide filemap_range_needs_writeback() helper Date: Wed, 24 Feb 2021 09:44:53 -0700 Message-Id: <20210224164455.1096727-2-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210224164455.1096727-1-axboe@kernel.dk> References: <20210224164455.1096727-1-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: cdxybak9za4ux5ss1sk8osjoo5isb7jr X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2FA9A2000393 Received-SPF: none (kernel.dk>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mail-il1-f179.google.com; client-ip=209.85.166.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614185091-638725 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 Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara --- 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 From patchwork Wed Feb 24 16:44:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12102149 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.5 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 35A36C433E0 for ; Wed, 24 Feb 2021 16:45:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE8B064EF1 for ; Wed, 24 Feb 2021 16:45:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE8B064EF1 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 B7E376B0005; Wed, 24 Feb 2021 11:45:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABBDA6B0071; Wed, 24 Feb 2021 11:45:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90FC06B0073; Wed, 24 Feb 2021 11:45:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 6A9616B0005 for ; Wed, 24 Feb 2021 11:45:09 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 24904180B372C for ; Wed, 24 Feb 2021 16:45:09 +0000 (UTC) X-FDA: 77853736338.05.56C3CCB Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) by imf05.hostedemail.com (Postfix) with ESMTP id AA73BE00011A for ; Wed, 24 Feb 2021 16:45:05 +0000 (UTC) Received: by mail-io1-f42.google.com with SMTP id f6so2641451iop.11 for ; Wed, 24 Feb 2021 08:45:01 -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=AeRNuJwb26jecYMYshpZyYXTh8+P3sXAHEYap904nwc=; b=dBA4tatNquPbOX9jozxTqfDTxIugjGjAaNp/E8p8mGSEaTf5Vqp/X2Sw5upZoy3oDb pKdTyXBY9+G1HNiWIozAwLiNrkcVZAbzkYnNk/sNvi4BppTDVq4wssMn69Or3nAZsIlG v3LjOfV6S/1W4hQuCoMuHjMsC/pcXEoiiXEULEZz4wS177ArMHr3z3iwb8bRenhSE25f eeyzttn95ulHx2s/BeJYlKx5yl+y/Dp8N1ob3lU7vmNhs6JB5t7LrsdLLuCF9YwnNIwe jebKdgOpTuYtwITGdHusRTNV4F7qTXbXVTib5OaPnacajl1jSsgrlea0/N6CPKtsbiPm WQjQ== 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=AeRNuJwb26jecYMYshpZyYXTh8+P3sXAHEYap904nwc=; b=HzrMI9GD0PnpQD+ZpYK94xrfEPBsqqCkNm6CpjlizEQJ6a5rnZwOu9/6oaZLOdvkz+ pARAGJuUy572OF1c99pu4CXoC7YVhU5xF4rOBrBubVCa9l/55stdXVGYI9RZ0gamJN34 Yz+86Ugkc2TneYK/LZRpjXm+CCSxc72LUd5O1r7ye+JhUHS9pnPv22q+KeV9nJQAZqkx nwxbYoQ5ykzaconG1Rt2dRKYr/gFMxuI3xf8aWj+VygmyxMtdmhDRp2E4h9dIJAOgqiN fY07HMqOZ2bz7eEFNUoBXerFlkyCaHo4CGy+1qlDntOEpSgGuaWOLLA/JbXD2uKZG2ML C7fA== X-Gm-Message-State: AOAM532p+F1px5ux7oZixFxm1JcJm0Ew29VLX83mDEiHfVcjj/un3wxN YKWPmG4uUNTEk4/v7oZpnATBbg== X-Google-Smtp-Source: ABdhPJyu6UQs/JPMF8a5cuR5B6fkZaVUvjWgzmMcs7a1pMpBdTKtP4C9yXuvh99wpYZ8leey8BJdkw== X-Received: by 2002:a05:6638:22e:: with SMTP id f14mr20097775jaq.96.1614185100654; Wed, 24 Feb 2021 08:45:00 -0800 (PST) Received: from p1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id f1sm2273652iov.3.2021.02.24.08.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 08:45:00 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 2/3] mm: use filemap_range_needs_writeback() for O_DIRECT reads Date: Wed, 24 Feb 2021 09:44:54 -0700 Message-Id: <20210224164455.1096727-3-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210224164455.1096727-1-axboe@kernel.dk> References: <20210224164455.1096727-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: AA73BE00011A X-Stat-Signature: owp4bptuat9716ikcry3y3rubwcup564 Received-SPF: none (kernel.dk>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=mail-io1-f42.google.com; client-ip=209.85.166.42 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614185105-985961 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 Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Jan Kara --- mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 13338f877677..77f1b527541e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2645,8 +2645,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 Wed Feb 24 16:44:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12102151 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.5 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 A5A1BC433E0 for ; Wed, 24 Feb 2021 16:45:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F03864ECB for ; Wed, 24 Feb 2021 16:45:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F03864ECB 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 A22866B0071; Wed, 24 Feb 2021 11:45:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D2E66B0072; Wed, 24 Feb 2021 11:45:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C1E46B0073; Wed, 24 Feb 2021 11:45:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 741D96B0071 for ; Wed, 24 Feb 2021 11:45:23 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 15F64A77A for ; Wed, 24 Feb 2021 16:45:23 +0000 (UTC) X-FDA: 77853736926.16.6E646D6 Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by imf01.hostedemail.com (Postfix) with ESMTP id E985A20053D0 for ; Wed, 24 Feb 2021 16:45:06 +0000 (UTC) Received: by mail-il1-f174.google.com with SMTP id f7so2252588ilk.12 for ; Wed, 24 Feb 2021 08:45:07 -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=4g79Wmg8HssdJE1RJFj1xs5Uw0vA1HddswvKOPj7R1c=; b=DkLjVfUkguWaeFLE9AhCxvUdXSBU0OTGcMJaMx+3ID1I9uA7hXf9W9q8nqi7wqtwVF /FpzzWFMDl44NRXBrvcwlOnyUE2dsX3rxEBpBDowXWcp87ExSVjSysLiPU5LQHqNBM+Y osHATKreCyqupnk3K5AJHzE1y6FFM+yVK5KjxRUA7a4LRSySq27pp9JtLAo/pOuWOAjW 2C9xLWqtMLKz0icTCYEomt3TkFvmDrT7IxlN3j2yjOD6sV977/2pjpRoi0xBMIiD+3la 1ufbCW9sMUyxrKXIzujZOdASCb22RjXDLqMumtqUMuRYNXstr/2sBYW7WlLSCGPVVuDg qXqQ== 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=4g79Wmg8HssdJE1RJFj1xs5Uw0vA1HddswvKOPj7R1c=; b=J2mupxB0E8mB00h6Ierh3F6LmyWZyady/NbXg3alJbrRGGcv8bhHt4Sgo8C2OSkOl1 8y6gkSiSeVpWplT8lKlUCspxc/qPJpw+v7zrSBkLj7SC4DTtLgxHf/VsOYDqQ4B73nXh SX2ZmycUgxBJRBeYuDsbsT8icVHkAbSUADmeHK5ly6DM5nGGW2m5dlYtXVpEgviYCXdR tW8Wjyfl1pCxXB8YJtZZfUEGXE7w+fu5HZ0xVCaJHxEe/qykfxzt/0CEpeSmKmjHvwf8 KP+VI+lZJi3sXdoRx2TNtlDYveemnlaa3FsEq6G0IxgpX+sYUHHW5+CTcHTB6vgv9KFZ 64xw== X-Gm-Message-State: AOAM530rlvY2bHqmW5bvfVMMJctcwws7no86uMo2GQEQ9aVZy2k60RG5 U0CILEgTNrXBg954wDzE3GnFjQ== X-Google-Smtp-Source: ABdhPJxEPgjN8zxQ212St/12AqeiWIWDjQI3YqfduoU93Dcr2prsac+4S/oGDBcIqaN1gg3rLi2aGg== X-Received: by 2002:a92:1a4a:: with SMTP id z10mr22531390ill.4.1614185101811; Wed, 24 Feb 2021 08:45:01 -0800 (PST) Received: from p1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id f1sm2273652iov.3.2021.02.24.08.45.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 08:45:00 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org, Jens Axboe Subject: [PATCH 3/3] iomap: use filemap_range_needs_writeback() for O_DIRECT reads Date: Wed, 24 Feb 2021 09:44:55 -0700 Message-Id: <20210224164455.1096727-4-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210224164455.1096727-1-axboe@kernel.dk> References: <20210224164455.1096727-1-axboe@kernel.dk> MIME-Version: 1.0 X-Stat-Signature: a151b4waey7q3uiq5hfb6daghpnk4cfj X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E985A20053D0 Received-SPF: none (kernel.dk>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mail-il1-f174.google.com; client-ip=209.85.166.174 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614185106-501801 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 Reviewed-by: Jan Kara --- fs/iomap/direct-io.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index e2c4991833b8..8c35a0041f0f 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -487,12 +487,28 @@ __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; + } + iomap_flags |= IOMAP_NOWAIT; + } + if (iter_is_iovec(iter)) dio->flags |= IOMAP_DIO_DIRTY; } else { iomap_flags |= IOMAP_WRITE; dio->flags |= IOMAP_DIO_WRITE; + if (iocb->ki_flags & IOCB_NOWAIT) { + if (filemap_range_has_page(mapping, pos, end)) { + ret = -EAGAIN; + goto out_free_dio; + } + iomap_flags |= IOMAP_NOWAIT; + } + /* for data sync or sync, we need sync completion processing */ if (iocb->ki_flags & IOCB_DSYNC) dio->flags |= IOMAP_DIO_NEED_SYNC; @@ -507,14 +523,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; - } - iomap_flags |= IOMAP_NOWAIT; - } - if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) { ret = -EAGAIN; if (pos >= dio->i_size || pos + count > dio->i_size)