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: 12076609 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 3D7C7C433DB for ; Mon, 8 Feb 2021 22:18:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BCE1F64E50 for ; Mon, 8 Feb 2021 22:18:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCE1F64E50 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 968DF6B006E; Mon, 8 Feb 2021 17:18:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 84A6A6B0070; Mon, 8 Feb 2021 17:18:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7133C6B0071; Mon, 8 Feb 2021 17:18:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id 4EB596B006E for ; Mon, 8 Feb 2021 17:18:40 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1FF258248047 for ; Mon, 8 Feb 2021 22:18:40 +0000 (UTC) X-FDA: 77796516000.29.price89_1b07f1127602 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id F2FD4181A5F8E for ; Mon, 8 Feb 2021 22:18:39 +0000 (UTC) X-HE-Tag: price89_1b07f1127602 X-Filterd-Recvd-Size: 4305 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Mon, 8 Feb 2021 22:18:39 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id u11so8587881plg.13 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=pzMnecl9GZ+JhaP1H8LU2T1V9RFQPadD30zQC0A/PpVSAx5Roc+F2lh6Pyczf2Utkq Y2cRYs5CzTBqjIWOTEekOXit1sNk2Gtscl/tGy+Xtio6W5AOXZCK/dBaVcoiH7U6dVr+ KPaWF+klP9PPxebJkeZDmu5H6dzLa39WYdak62ZyyePjkqn12rT2JDShlhY75H7Ff7KL Tlc7Aaob5ymRTNcdCBM5GzwjehplvWdzyjzKUC9360mECIoGXG8+Hhsw4uxgtUsa0g2u hELrpoaEUr3oC9+ojUYip/bHsC4y7Kr7yBjwYF5f4Z6owP6aVG4Tm31vOYmuLbnWbZ+X 2MSQ== X-Gm-Message-State: AOAM530+L4rhDSoS0Fig7BCFlY66YlKAJFVFEBMlrOf5jKEGJ57Moi3c PIjvtCv8oMJTd/ngAGUuKf9ttQ== 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 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 --- 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 {