From patchwork Mon Feb 8 22:18:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12076599 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 9EDABC433E0 for ; Mon, 8 Feb 2021 22:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5EC2464EA4 for ; Mon, 8 Feb 2021 22:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbhBHWTV (ORCPT ); Mon, 8 Feb 2021 17:19:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbhBHWTR (ORCPT ); Mon, 8 Feb 2021 17:19:17 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC68BC061788 for ; Mon, 8 Feb 2021 14:18:37 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id b145so10626455pfb.4 for ; Mon, 08 Feb 2021 14:18:37 -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=/11CO3rYWuI/f/YHyMz9MjwWlbtuyR7jns8drX5Z6GM=; b=mb2oFeIEVgDEViUTWxQhJRn8gyfghyhp/ElayDIuXqgeaBC3HYBqXz/VyGWRwyfxyX xNOVUOTlqZOiwoPZvGkawIKvPSdaiRywSD983pANIibOlTA45T3D/u9hBzhvPIaon/tU WBt2X4roLHiAAxx56l/gFiUa/HQcYyqIS4SHHtGj51uM/gYRzdJCOrOubTCc7icgPz/e TBPf1d33DE2Lp+z5ek0LEGD8l0kYthWmJBknCrZPLXoi744YaRuxo52NTOvbjN+Hl6oI shdmBniDyS8xzu99iHg+R7lPS9r9fejFakjX/txkrDqm21gvQbo2V0UeFU7OjW3KBDZA ushw== 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=/11CO3rYWuI/f/YHyMz9MjwWlbtuyR7jns8drX5Z6GM=; b=WWEuHCrVGIuJnoXaH8kSHyZWql78yaHqc3OQmSfZAOz6X/EW3e62jRFXNcWFP4a/nW 6G1OlfI8toA8LIiq+A9mrcsqW/VKKSNfVkmgWhZbSCubL376M+ujPtNRKk7RAbdHoanj AKSPE22lVAf4oJpneL6VwVSPYKT9tVdGEDGA1JiYEb0e1hyYUH1voDSyKbGf3GKJIHz3 ldhXnu8F2YtBv/INmn9aKPjUoY0mkOzYfHfsGVxoR7gcT9E7H+XPBWiMYI0BxXoTaAIu GTysXcWaeWo8XA+ZrD6CrNsAuPUcXdjhV82Q7QAPMkc4CpT+m+lIdMaH2r8btHEwyMMk L1SQ== X-Gm-Message-State: AOAM530TZelSiXjGODz8PbxAU7Baysxz8oNSaqUbnQmhav0kOFfGNZ5n 5ypj44da6qeAknJD+vC/jdQxJVP7LhOlrQ== X-Google-Smtp-Source: ABdhPJzusnHUSOjH31Tu9aj2qgCr38CSB6bRtXmJ7daXvBLWnpK3G1cjMgphD7zjBJsZ8VTZxUZ39g== X-Received: by 2002:a63:416:: with SMTP id 22mr18850742pge.286.1612822716935; Mon, 08 Feb 2021 14:18:36 -0800 (PST) Received: from localhost.localdomain ([2600:380:4a36:d38a:f60:a5d4:5474:9bbc]) by smtp.gmail.com with ESMTPSA id o10sm19324472pfp.87.2021.02.08.14.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 14:18:36 -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 15:18:27 -0700 Message-Id: <20210208221829.17247-2-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208221829.17247-1-axboe@kernel.dk> References: <20210208221829.17247-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 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..1ed7acac8a1b 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -633,6 +633,52 @@ 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) +{ + struct page *page = NULL, *head; + XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT); + pgoff_t max = end_byte >> PAGE_SHIFT; + + 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, head, max) { + if (xas_retry(&xas, head)) + continue; + if (xa_is_value(head)) + continue; + page = find_subpage(head, xas.xa_index); + if (PageDirty(page) || PageLocked(page) || PageWriteback(page)) + break; + page = NULL; + } + 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 Mon Feb 8 22:18:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12076603 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 53911C433E9 for ; Mon, 8 Feb 2021 22:19:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 055B564E9D for ; Mon, 8 Feb 2021 22:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbhBHWTc (ORCPT ); Mon, 8 Feb 2021 17:19:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230127AbhBHWTT (ORCPT ); Mon, 8 Feb 2021 17:19:19 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E500BC06178A for ; Mon, 8 Feb 2021 14:18:38 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id l18so426548pji.3 for ; Mon, 08 Feb 2021 14:18:38 -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=l21CUn6uOrJ6V+uVH7pfm2X9pDOAs2Cr5X1HAOPDvBM=; b=CkUpTf4LsCzZxBf8xCPGD9HLztKuswz0Wz7mkj/6AHj1jEV5viIjhGkLl/M0cI8J// YP5VkdWIj0dzDanvSVirVQ0PK3pZDI05qlB8A3d3pKAsbn2yW/gNuOSraXYqSYQ7DFoN K6eFLBvv5XjfRIG+oPbxqWY8tjvUgjLhfz39BTfw5axsankjScRZtVRa1990CQs+sz5k RsaBW81w/If5OHKriQMeTrp1A/pJQVLqD1USt/TlJvccTgyyVy7XzH94Dpkk2kIzDx42 zcH+/GiUASWBwFiPFFO0dc9zxHTjre3uaUtyaxw5u3SJeVRq7W2SeEWYM7qpyL5eVVM+ to7A== 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=l21CUn6uOrJ6V+uVH7pfm2X9pDOAs2Cr5X1HAOPDvBM=; b=awBKRLgc/GBwIo5ssF/qEPNhF6gtF2GHeixOnR+wnsKgQf4G/CmfhNor5SCYMJVEFp HAuvrXT4RIYS3jmm4zrrHCPnIPdqhQzXw8UWSrChoB7aC5yL/vv92guFmqZ3ucp+yLJN 9KKNF0kAfDoJ6BOtDq/CPpnyAvSjnw+EN8L4q6B8ojYwaiWSTaQ068q/AQZRQw91ZROK 2WONohA9iJ8SuDthCbxs04C5bejqT1Qd412rTPlaWOc9Z7hYs8iMqNYb8sB1vfG5mzYx 9eb0Rjhso5WdMyZ9CsZV2XUvgTwxF6RKXBXDZHLUMJ1+L/Jv5GAf4Ff1Ag4NsGU0R97g bQHQ== X-Gm-Message-State: AOAM530UZlT8CPKUxOeAl2xGqOGOMO0X4xG/5GUNc5KeZMK5POmzKDxm /5miCSIrsaGYBHdg8FBRVfWru2nPocGP+//I X-Google-Smtp-Source: ABdhPJwk636mSXsDJfOY2icC7pKLKXKi13Hf9+733aw6b6XHlVfNF13HD2wUVVO8AIxkBCDamgOU6g== X-Received: by 2002:a17:90a:e292:: with SMTP id d18mr940078pjz.66.1612822718274; Mon, 08 Feb 2021 14:18:38 -0800 (PST) Received: from localhost.localdomain ([2600:380:4a36:d38a:f60:a5d4:5474:9bbc]) by smtp.gmail.com with ESMTPSA id o10sm19324472pfp.87.2021.02.08.14.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 14:18:37 -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 IO Date: Mon, 8 Feb 2021 15:18:28 -0700 Message-Id: <20210208221829.17247-3-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208221829.17247-1-axboe@kernel.dk> References: <20210208221829.17247-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org For the generic page cache read/write helpers, use the better variant of checking for the need to call filemap_write_and_wait_range() when doing O_DIRECT reads or writes. 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 1ed7acac8a1b..3bc76f99ddc3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2646,8 +2646,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, @@ -3326,7 +3326,7 @@ generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) if (iocb->ki_flags & IOCB_NOWAIT) { /* If there are pages to writeback, return */ - if (filemap_range_has_page(file->f_mapping, pos, + if (filemap_range_needs_writeback(file->f_mapping, pos, pos + write_len - 1)) return -EAGAIN; } else { From patchwork Mon Feb 8 22:18:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12076601 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 BFA11C433E6 for ; Mon, 8 Feb 2021 22:19:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82A6B64E9C for ; Mon, 8 Feb 2021 22:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230236AbhBHWTW (ORCPT ); Mon, 8 Feb 2021 17:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230132AbhBHWTU (ORCPT ); Mon, 8 Feb 2021 17:19:20 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 587EEC06178B for ; Mon, 8 Feb 2021 14:18:40 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id cv23so385650pjb.5 for ; Mon, 08 Feb 2021 14:18:40 -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=AtwT2ZfoQKaKnaabpu4kFZ0j7fEVsXXg7Hy23jxR6Pw=; b=XmLr2CKghggmDeCSd5heWb4BPbgYpjgCBFjyGVpMGkKuw0vapjlCDgYeqtIhPGAjCK BZAQRcsiw03nXg8BtJvGnPx/CUYZd6jfu9/uaQtm5Mclrkp2RIBtUYf7NowfHS24NOp6 waPVpXtm1hKAoNMLw9gcuEueTXC6+inn1ZAA5pxKhoOu9vO2hpVPsVc9GsNF/21E/ksG kmb7ZvR98qkO16507A7eSSoPpV9y+rdXNpy56tRsXuNyrsWkTjDbTV+VTmV7kub+F6+3 CIc6+3PGNpOMC+RjKBwVyObhxtDFvP740bOfwpEkkTFDU/8HXbTNmldZoANNV734U1t7 ZEKQ== 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=AtwT2ZfoQKaKnaabpu4kFZ0j7fEVsXXg7Hy23jxR6Pw=; b=H+b88KyQ7RCNX7jgFu5/dafFLdDDOINR3y33IMg1tI6UFIavuVLGNZYPGw2biUBsGc EAx5FXYLAx+Pwpyei5c6A0nY0/r+LzvdoHLRN7EXuqq7uxr5NxtMM+DNenXnZxMD64Uf rfdxJbesni47ds4XlT2199xEMe0Q6lXVzBQInCy9fqU5hV2zb801iqawamZvGhNFITZn 2bm+I38cvn5J35mo+UCf57zjTzgzDE2Zt7ALMq7RZ+B8Lfts/vea/dEKvV43tObOxFvp /6ZdF6iOpUwIjWwfBljjG/fbuh0PrtctlT2wwHQ9UaPGXOe/uoVmgASs/nmVz1bLfV1j XWoA== X-Gm-Message-State: AOAM533By9YwU5jrUnYABZxEJ7AK5gbld1bCoupOL+/OxiqOD7vVySmh CnegAkP7pcOd2uPZXYIJ8VKND4Gm8tRtFqI+ X-Google-Smtp-Source: ABdhPJxOdCSPAs/K5CvefCqaIjsci+duFqzpTsXJG3UqGOHWM/ef3x/ClRU21S5b0HiKKoAX3OYAKw== X-Received: by 2002:a17:90a:d3d5:: with SMTP id d21mr893477pjw.228.1612822719725; Mon, 08 Feb 2021 14:18:39 -0800 (PST) Received: from localhost.localdomain ([2600:380:4a36:d38a:f60:a5d4:5474:9bbc]) by smtp.gmail.com with ESMTPSA id o10sm19324472pfp.87.2021.02.08.14.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 14:18:39 -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 IO Date: Mon, 8 Feb 2021 15:18:29 -0700 Message-Id: <20210208221829.17247-4-axboe@kernel.dk> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208221829.17247-1-axboe@kernel.dk> References: <20210208221829.17247-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org For the generic page cache read/write helpers, use the better variant of checking for the need to call filemap_write_and_wait_range() when doing O_DIRECT reads or writes. 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 933f234d5bec..2561e50c763a 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -479,17 +479,17 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, } if (iocb->ki_flags & IOCB_NOWAIT) { - if (filemap_range_has_page(mapping, pos, end)) { + if (filemap_range_needs_writeback(mapping, pos, end)) { ret = -EAGAIN; goto out_free_dio; } flags |= IOMAP_NOWAIT; + } else { + ret = filemap_write_and_wait_range(mapping, pos, end); + if (ret) + goto out_free_dio; } - ret = filemap_write_and_wait_range(mapping, pos, end); - if (ret) - goto out_free_dio; - if (iov_iter_rw(iter) == WRITE) { /* * Try to invalidate cache pages for the range we are writing.