From patchwork Fri Aug 6 11:42:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12423329 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 4912CC4338F for ; Fri, 6 Aug 2021 11:43:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B28FF60EBB for ; Fri, 6 Aug 2021 11:43:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B28FF60EBB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DBE146B006C; Fri, 6 Aug 2021 07:43:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6E3C6B0071; Fri, 6 Aug 2021 07:43:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5CFF8D0001; Fri, 6 Aug 2021 07:43:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id AA09D6B006C for ; Fri, 6 Aug 2021 07:43:19 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5BE3A18080 for ; Fri, 6 Aug 2021 11:43:19 +0000 (UTC) X-FDA: 78444470118.38.9C43630 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by imf22.hostedemail.com (Postfix) with ESMTP id 13F388EC5 for ; Fri, 6 Aug 2021 11:43:18 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id m12so10671098wru.12 for ; Fri, 06 Aug 2021 04:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gc3S+v0WYsSbPNetify2yT5xI0BcVIWyyU5ydgMV3Sc=; b=IPbfNVB0w3ZpEq6jRu9ETKWlaCzP45JOcCfWweUo5iZF1eVw0on9idRjVRaSg1Qyij oD8oJSofTL9dREYjOSjIr3YMCjTCg3m7RTbd/7OrKMDxLVuDB4twmwDKAECE0ht+pe/f idcVWBZMZ+7XaGLrSeWT6JK0kYCQySg7jzCIxIZja4671pXEFqvJ39J/Aj4fiRd+k1tN Y67kQ1c3fEK2p5CcjLwq7P4af1qCrt+oruboPf/PmwaenQNnfSsWtFjKQojRIU7V4/B5 qYy6af+ICpIQdk1+OOVJaIA2P1ZslTGdoFS9wr34WCqTfdJeQYRi6P5UTgfwO9/dLFdR l/kw== 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:mime-version :content-transfer-encoding; bh=gc3S+v0WYsSbPNetify2yT5xI0BcVIWyyU5ydgMV3Sc=; b=gbAV2Knz8L9AlQbCL9OgSrNICwkgMor7a4LZT3D//nNSUMiegrIyP7roMUS2tQ7dPj QhFBFmDV8KaLvu4TDdK8PtxdJFKdLJheKUiy2RSXBhObu83EtI69ZVqB+cxIhzylyAQ5 aC6BEzEHIautk+Dq1lgYKE+4eg6jw4k8N40f8yDAW+avUo8eGAuF7YGxHuPVS/eTZV0c jeRVmbt6JRo/s8ekiI9CpItPlap7Z7uJJ5D7aUIGzpRfS64cEM+/asNH/8muyVIQTLOM aPJnmdgyksVqT1/TdPJGXi3D+4LzQl83tm/N3iYoOZE2z5LNd2KEb+FYRZ/etX82aRUQ /syw== X-Gm-Message-State: AOAM533nOg0XmSKdUEdf5FSLFFCM8tDzBn7cTef5bFOUnKirQszn8Et5 h/9XSpP5Jrs9YD4x5KlOhAhNUEoml5w= X-Google-Smtp-Source: ABdhPJwiytsZL5qmxhuH0TmtWLFQN7lk4RhxQtowzzxVSQeJLkjGg1Dr/gT+LkmO+CRdUDo0JhnCQA== X-Received: by 2002:adf:f046:: with SMTP id t6mr10640255wro.266.1628250197835; Fri, 06 Aug 2021 04:43:17 -0700 (PDT) Received: from localhost.localdomain ([85.255.237.205]) by smtp.gmail.com with ESMTPSA id a12sm11720548wmj.22.2021.08.06.04.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Aug 2021 04:43:17 -0700 (PDT) From: Pavel Begunkov To: Andrew Morton , linux-mm@kvack.org Cc: Alexander Viro , linux-fsdevel@vger.kernel.org, Jens Axboe , linux-kernel@vger.kernel.org Subject: [RFC] mm: optimise generic_file_read_iter Date: Fri, 6 Aug 2021 12:42:43 +0100 Message-Id: <07bd408d6cad95166b776911823b40044160b434.1628248975.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=IPbfNVB0; spf=pass (imf22.hostedemail.com: domain of asmlsilence@gmail.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=asmlsilence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 13F388EC5 X-Stat-Signature: htfh8qwngk86od59a5egt1on7ke4s3fx X-HE-Tag: 1628250198-421768 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: Unless direct I/O path of generic_file_read_iter() ended up with an error or a short read, it doesn't use inode. So, load inode and size later, only when they're needed. This cuts two memory reads and also imrpoves code generation, e.g. loads from stack. Signed-off-by: Pavel Begunkov --- NOTE: as a side effect, it reads inode->i_size after ->direct_IO(), and I'm not sure whether that's valid, so would be great to get feedback from someone who knows better. mm/filemap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index d1458ecf2f51..0030c454ec35 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2658,10 +2658,8 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) if (iocb->ki_flags & IOCB_DIRECT) { struct file *file = iocb->ki_filp; struct address_space *mapping = file->f_mapping; - struct inode *inode = mapping->host; - loff_t size; + struct inode *inode; - size = i_size_read(inode); if (iocb->ki_flags & IOCB_NOWAIT) { if (filemap_range_needs_writeback(mapping, iocb->ki_pos, iocb->ki_pos + count - 1)) @@ -2693,8 +2691,10 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) * the rest of the read. Buffered reads will not work for * DAX files, so don't bother trying. */ - if (retval < 0 || !count || iocb->ki_pos >= size || - IS_DAX(inode)) + if (retval < 0 || !count) + return retval; + inode = mapping->host; + if (iocb->ki_pos >= i_size_read(inode) || IS_DAX(inode)) return retval; }