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: 12076611 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 697A4C433E0 for ; Mon, 8 Feb 2021 22:18:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F2C4464E9A for ; Mon, 8 Feb 2021 22:18:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F2C4464E9A 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 9FA646B0070; Mon, 8 Feb 2021 17:18:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 95D406B0071; Mon, 8 Feb 2021 17:18:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 763386B0072; Mon, 8 Feb 2021 17:18:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 5CC1E6B0070 for ; Mon, 8 Feb 2021 17:18:41 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1C607181C34ED for ; Mon, 8 Feb 2021 22:18:41 +0000 (UTC) X-FDA: 77796516042.30.roll69_611560627602 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id EB260181D0AB1 for ; Mon, 8 Feb 2021 22:18:40 +0000 (UTC) X-HE-Tag: roll69_611560627602 X-Filterd-Recvd-Size: 4188 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Feb 2021 22:18:40 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id e9so8612675plh.3 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=Kk2+yeigcVn9lr4oLqjXH/8HzQhRse6bdZYBopdhu7Vv29KjCrls2wI/dZ8DMeFD+J mLQZPn4O7t32BGNEwGrhfPVjgXiA8EmQ0OPsRYAjKBlGGAe9w1Ss1sf+UOh5uMxyD6BD 09JSMA7+LImzFqs2p3q4gEY7FbT79Y52Ac8+3quBYcpB1Q+2jtSSaXpObMDt3I6xSdqr tqeH0qL1Ee0MAh6a8Ga0JKjYX9iJNTAY1KKPf1VrlwQ60zyKXIbMEFXDgALSC+gB6C84 cWehmCVdW2dftSCnjIVgwxskuYOXu+6zr8QFgO92m07kjaoCqrm0umpGO/H4nOnerkKZ iRdQ== X-Gm-Message-State: AOAM532FdMAXPLB/u9dO2Ct3yWd4Wi2jzj3x/irCvUpmW64EfqbyeOTK J6/0qd30g5HgHFoWvDHyjz3/7w== 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 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/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.