From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB770C433FE for ; Wed, 27 Oct 2021 15:50:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4552D610C7 for ; Wed, 27 Oct 2021 15:50:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4552D610C7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 783536B0071; Wed, 27 Oct 2021 11:50:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7333F6B0072; Wed, 27 Oct 2021 11:50:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FAA7940007; Wed, 27 Oct 2021 11:50:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 50BE56B0071 for ; Wed, 27 Oct 2021 11:50:58 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D08FC31ED0 for ; Wed, 27 Oct 2021 15:50:57 +0000 (UTC) X-FDA: 78742655754.09.50D4022 Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) by imf08.hostedemail.com (Postfix) with ESMTP id 0416D3000251 for ; Wed, 27 Oct 2021 15:50:49 +0000 (UTC) Received: by mail-io1-f54.google.com with SMTP id v65so4259489ioe.5 for ; Wed, 27 Oct 2021 08:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=UmEiVd56uxCBfYVCrAIrqJWeH7UWYmcDb5px/zcfIIQ=; b=RvoNIZTO/Vg6CRvLWTxAUD8tGIK+KbSL9q4utULvct4x4IXK/vmoDAepU7aN/k3xmk l82G37x0EkA9OO/Slzs6T6v6UCwrJodMDJPc2gAOROzajpZ/8/Sw5o8Fd9ZTeP2d3HxC DsqxOlKFaz+jUzCj5iCVzrZVYx+fTjN1mBaVFVD9HYGLo7Vu3sjPq7l7R3Am/BLdmFW9 uLjfofCJLnPypG846GsZRG6cVVNRYYZp8xOr3/m5/Ra9PsGXhiWe2qb3AXE4lmic2SnQ COBhPnwkLbVrFzhvrW4BLBXplOMFz/AIiYLpiydK6gH+g6U0MkazQBRrAbpR1X2z5h61 iSmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UmEiVd56uxCBfYVCrAIrqJWeH7UWYmcDb5px/zcfIIQ=; b=QFnJlWKaFrjkVOYTPRuM6aU7P5Rsgl29FPs5RlKfyCwktHDxoD/voOgN15PNLVQIFn iChbhwNafCXGQrBFq1UEs23olLtHOWXNRR1RXYseQPZcT+o6S1xVYg1XNYs0Nitrkgi0 nYYum7iVhhPC/gkQRyDHr38Ltk9zbdeZt38e8o0UGamNj7JQl5b0RoPa/mRElEWneb/7 qIpqxuIVRWbRlf6Kj4hZ/+QL6fJZI0ulk2fRNjsE8aP7lN7x+K8MowigfUHGwB6x5Zxv eJvBbhQzElceQEd1CYUosBFF/ZJ28NM4LgxyyRbzUX8n+XWbE5patdHxJrTPROcRz+gg hloQ== X-Gm-Message-State: AOAM53084wEebvF2qxdrcIuFMtR/zqS6qCg8bDHkBZBsTB+Wih9bBcSv 2fQyd91wG6jKyTcglQA84f/hCA== X-Google-Smtp-Source: ABdhPJybAU8wujcK1UkmwgEfErgDodVvZtlHe3owVu1nGa9biDysYR/KyAbNoJgVPZA2oa9J3fX9hw== X-Received: by 2002:a5d:9d46:: with SMTP id k6mr3640586iok.55.1635349856273; Wed, 27 Oct 2021 08:50:56 -0700 (PDT) Received: from [192.168.1.30] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id a4sm126847ild.52.2021.10.27.08.50.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 08:50:55 -0700 (PDT) Subject: Re: mm: don't read i_size of inode unless we need it To: Chris Mason Cc: Andrew Morton , Dave Chinner , "linux-fsdevel@vger.kernel.org" , Linux Memory Management List , Pavel Begunkov References: <6b67981f-57d4-c80e-bc07-6020aa601381@kernel.dk> <9383DBC8-0C0E-4EF7-A3E3-272FFA9F14D2@fb.com> From: Jens Axboe Message-ID: Date: Wed, 27 Oct 2021 09:50:55 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <9383DBC8-0C0E-4EF7-A3E3-272FFA9F14D2@fb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Stat-Signature: k8uijntc3ay17srkr6ej89ximo19ha7f Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=RvoNIZTO; spf=pass (imf08.hostedemail.com: domain of axboe@kernel.dk designates 209.85.166.54 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0416D3000251 X-HE-Tag: 1635349849-833199 Content-Transfer-Encoding: quoted-printable 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: On 10/26/21 1:11 PM, Chris Mason wrote: >=20 >> On Oct 26, 2021, at 2:15 PM, Jens Axboe wrote: >> >> We always go through i_size_read(), and we rarely end up needing it. P= ush >> the read to down where we need to check it, which avoids it for most >> cases. >> >> It looks like we can even remove this check entirely, which might be >> worth pursuing. But at least this takes it out of the hot path. >> >> Acked-by: Chris Mason >> Signed-off-by: Jens Axboe >> >> --- >> >> I came across this and wrote the patch the other day, then Pavel point= ed >> me at his original posting of a very similar patch back in August. >> Discussed it with Chris, and it sure _seems_ like this would be fine. >> >> In an attempt to move the original discussion forward, here's this >> posting. >> >=20 > I had the same concerns Dave Chinner did, but I think the i_size check > inside generic_file_read_iter() is dead code at this point. Checking > ki_pos against i_size was added for Btrfs: >=20 > commit 66f998f611897319b555364cefd5d6e88a205866 > Author: Josef Bacik > Date: Sun May 23 11:00:54 2010 -0400 >=20 > fs: allow short direct-io reads to be completed via buffered IO >=20 > And we=E2=80=99ve switched to btrfs_file_read_iter(), which does the ch= eck the > same way PavelJens have done it here. >=20 > I don=E2=80=99t think checking i_size before or after O_DIRECT makes th= e race > fundamentally different. We might return a short read at different > times than we did before, but we won=E2=80=99t be returning stale/incor= rect > data. Andrew, can you queue this one up in the mm branch? --=20 Jens Axboe