Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1063145ybt; Fri, 19 Jun 2020 23:23:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkLrPL/gI97IaJlAUlzHSCkqJei1nhh7ul0Nd3dHrKDNv3u1BlLTfJAcsojCDPHE8KZJH4 X-Received: by 2002:a05:6402:1244:: with SMTP id l4mr171764edw.71.1592634220984; Fri, 19 Jun 2020 23:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592634220; cv=none; d=google.com; s=arc-20160816; b=aKrgmunnTGasdVM+GZ7gWq3+ToxWuXZLabTqoML0dXFKwOVlGs8afw8zviQfysX/0u P0wY6syR4NnfazgbyciDhaSEo/wlf1Clm43tq8Ccw4rQZR3XZccR5iCqOuNZ9OIeMZkh zS8KGf+IadFu4H46evOdhGa6MPiG82lME7jHQ6klUt53iVYe4OrOwjqmAf+9ddpK/jvs sa5S4eqlJpo4R5d+ZQcOHBRIyHa/960f4fz3vAoSk6PWZGe/rKZJ6x5Ig+5r2ElltE3P 4mbnI0YQ/1BfUYRTcADQRbknP08Ent2NfzkvkoWmkNdF8GEfizKOx4ITGDqkb6aYdBVS 1Qrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xvus+uh9WtZzjywf3OG4NHlFv1zadVBBIjlELpwGoZY=; b=no+z65HkLkGxqr0HUkMMtU77Alz7Pw+cSJKc++E1GuDBlszu8Q/P3SUpBZ53wpbqol ZgvKE8JEbkxIVNqVktJd0RejJtRBo+SNYUuSKfsTDM/3dCF2Ja5/OeBtcu27dmamEcTz 2HNj+SdaQC/IM6wtjmYlqelwg01+y1ngOGjaedGHyOmvJHbu1Uh7OHqMtzAmx2SNmTpC gtiJl30HGrTQl5tGhTrh15A1G+CIHLQeo/l2gU2HHqcU3vJjpjnvDzLsfK5F7F4RCrpE 76ZPZzGtk0uiNfuRm64sVS2FFJ7Dz65+8GmBRTBu1MSVWaliNQ4VWp6Um58aYKwz252x Yi6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Iapl7XUs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si5303027edr.152.2020.06.19.23.23.18; Fri, 19 Jun 2020 23:23:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Iapl7XUs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726185AbgFTGTu (ORCPT + 99 others); Sat, 20 Jun 2020 02:19:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725446AbgFTGTt (ORCPT ); Sat, 20 Jun 2020 02:19:49 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A9B3C06174E; Fri, 19 Jun 2020 23:19:49 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id c4so245401iot.4; 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=ilp3VuDQU0yTDA+Vtx9q6aoq974xeLSyYZD9AK8cm8bp9wRbfRPdlaJPLJuiX+JMup G14rMBpL+SlAPp13vVaK906Jq6fH9nrHDA4PHcuHcxYv40PdXmK1ijoHHarRe53w4TQL Hsjg6RCgxtMQV+lFSpOf5f84qg3SHO2LZrsV50HqcIynqQ+JPG5/mYuQ8I9HLb4zh/Ly QosUsuTlW2TAt/G4fC41lgXYFqi9M31FMa0Y7OH6rJJlRwFWjLBaZjgx8MTHH+ZFdX8Q 9p1MdXnJB8Y6/XAkYevEByPZSBnpPJO/0YNPvLPmUumr3x9vUKKjZNKAIih1Noeporku sqIA== X-Gm-Message-State: AOAM531Hhkk0FtoljC2L1VAH6Hoo4BtmxLlnEFr6ExuRpIIrPKzrJcQc f+kQjyGcI3toLnsTd29apuifW5RrdTLM9Gqzhdc/f2I0 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.