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 X-Spam-Level: X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 5EF45C433E0 for ; Sat, 20 Jun 2020 06:19:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 030ED2376E for ; Sat, 20 Jun 2020 06:19:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Iapl7XUs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 030ED2376E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5E26F6B0024; Sat, 20 Jun 2020 02:19:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 592896B0025; Sat, 20 Jun 2020 02:19:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 481306B0028; Sat, 20 Jun 2020 02:19:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 30E8A6B0024 for ; Sat, 20 Jun 2020 02:19:50 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BDE5F824556B for ; Sat, 20 Jun 2020 06:19:49 +0000 (UTC) X-FDA: 76948589298.17.word20_5c12bd026e1f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 9ACD6180D0184 for ; Sat, 20 Jun 2020 06:19:49 +0000 (UTC) X-HE-Tag: word20_5c12bd026e1f X-Filterd-Recvd-Size: 5225 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Sat, 20 Jun 2020 06:19:49 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id s18so13831911ioe.2 for ; Fri, 19 Jun 2020 23:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xvus+uh9WtZzjywf3OG4NHlFv1zadVBBIjlELpwGoZY=; b=Iapl7XUscEsaSTUl7f4/1OFJ2gZcOnLD1M6RsHnplm3V4QO36r2/+0vhAePpDmKYz6 x4V5NHUup+AYiK1YsVz/FgtsciOlgFx5JKjIC6NgDs5czS9sGXVA8m62LdxgLAY6l5tp RSAXQpiyW68VCtYe5D6nVr5WFV6xcWVEKZFTDkVKGeK2f025YSmP9H8m+tF0am77xszf dEVEsfJ8juTkFzrppCFBoPR50llCo2oO2ix2dGeos56a3n5Qiudhqm4XHCMtz4/xJXhf X0Q/bLnEacpsWfceTHkLIZvliLCkiFxJ/XrrU4Jm7rFKyu8oqRqxmnSH2K6nD2P+ybww hBKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xvus+uh9WtZzjywf3OG4NHlFv1zadVBBIjlELpwGoZY=; b=RnOqxTh8WW6uzfyPf6cl0Tzl27/4GxvI5WEa2xCjNNNvCsOfPXUhccHizhEhhRK69R 0QmunJbBxswWR8Ou7EaafSh//E2e7KjXUhesDOdxUMSt+03ywijT4ARjX6buIlpJTdjE H8O/dxs2aKNfLBvcfKZ5UJNE1mPYrfWbK0LL7tPC9QOnQGVm3GbobThwyWM/923N3d/F G1iTrwEHulV8UDHyTdkoYT5MkzaLB/HXbz4DdmHJzylPo/Vx1u8IW2VpIKeG5BLPQzWM Lxu02FyJpfAWCnuHUVbGt0C56BYwhQMxZ3FRayGnapokI26upXROvBALfFW/fZjnD60r j62Q== X-Gm-Message-State: AOAM531odUWEBsM6uvrc15M1w5DKP/aVQKDqUOex99ohT8Fjsa4GBhdA YIYaeen61nt/sh9y4AwKjkSqNmfwk5n8DqUlDO0= X-Google-Smtp-Source: ABdhPJynW9021Zq8kkCg/MRVnSzqwZL2Wlfmu9uSNwSvVVmbW0swoGrsK/Fg+wXBa628RcVuvO1Dgho5rBEpv/UnuoM= X-Received: by 2002:a05:6602:5c8:: with SMTP id w8mr8051340iox.64.1592633988637; Fri, 19 Jun 2020 23:19:48 -0700 (PDT) MIME-Version: 1.0 References: <20200619155036.GZ8681@bombadil.infradead.org> In-Reply-To: <20200619155036.GZ8681@bombadil.infradead.org> From: Amir Goldstein Date: Sat, 20 Jun 2020 09:19:37 +0300 Message-ID: Subject: Re: [RFC] Bypass filesystems for reading cached pages To: Matthew Wilcox Cc: linux-fsdevel , Linux MM , Andreas Gruenbacher , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 9ACD6180D0184 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 Fri, Jun 19, 2020 at 6:52 PM Matthew Wilcox wrote: > > > This patch lifts the IOCB_CACHED idea expressed by Andreas to the VFS. > The advantage of this patch is that we can avoid taking any filesystem > lock, as long as the pages being accessed are in the cache (and we don't > need to readahead any pages into the cache). We also avoid an indirect > function call in these cases. > > I'm sure reusing the name call_read_iter() is the wrong way to go about > this, but renaming all the callers would make this a larger patch. > I'm happy to do it if something like this stands a chance of being > accepted. > > Compared to Andreas' patch, I removed the -ECANCELED return value. > We can happily return 0 from generic_file_buffered_read() and it's less > code to handle that. I bypass the attempt to read from the page cache > for O_DIRECT reads, and for inodes which have no cached pages. Hopefully > this will avoid calling generic_file_buffered_read() for drivers which > implement read_iter() (although I haven't audited them all to check that > > This could go horribly wrong if filesystems rely on doing work in their > ->read_iter implementation (eg checking i_size after acquiring their > lock) instead of keeping the page cache uptodate. On the other hand, > the ->map_pages() method is already called without locks, so filesystems > should already be prepared for this. > XFS is taking i_rwsem lock in read_iter() for a surprising reason: https://lore.kernel.org/linux-xfs/CAOQ4uxjpqDQP2AKA8Hrt4jDC65cTo4QdYDOKFE-C3cLxBBa6pQ@mail.gmail.com/ In that post I claim that ocfs2 and cifs also do some work in read_iter(). I didn't go back to check what, but it sounds like cache coherence among nodes. So filesystems will need to opt-in to this behavior. I wonder if we should make this behavior also opt-in by userspace, for example, RWF_OPPORTUNISTIC_CACHED. Because if I am not mistaken, even though this change has a potential to improve many workloads, it may also degrade some workloads in cases where case readahead is not properly tuned. Imagine reading a large file and getting only a few pages worth of data read on every syscall. Or did I misunderstand your patch's behavior in that case? Another up side of user opt-in flag - it can be used to mitigate the objection of XFS developers against changing the "atomic write vs. read" behavior. New flag - no commitment to an XFS specific behavior that nobody knows if any application out there relies on. Thanks, Amir.