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;