Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5354665rwl; Sun, 8 Jan 2023 13:33:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXsa2RbEDHMt/Nmaoo/+3ThBeNhH439vO03L5YKyNOx7HCOaXtvJurjpE29V4Gi+rDX8/Uhu X-Received: by 2002:a17:907:9d08:b0:82d:1727:f620 with SMTP id kt8-20020a1709079d0800b0082d1727f620mr53562383ejc.68.1673213623259; Sun, 08 Jan 2023 13:33:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673213623; cv=none; d=google.com; s=arc-20160816; b=rdzX6B+4P0pFyC6kUn9zZu/p8qFYGqvF+euEsRqWke77BkQrpDOiuUDAlCm629uVIi +hehLOatizBYV+oJKBrPuIwBQhEKfXMY9hxKUxDuz+L0UGFqSJLhLcVdjLAVkummyVLV 79Pa4NSsxM9Jmbx9Kx3YK+ukO/7LbAQGRARpXYC8EflUdFcoXF1XYBQJosP22TWkAQXa 09IR9zaWgnIGYMYSQawleJANu7e5Zm3TUrwbxxj7S8ywny3ipo6EfeB77SjmdoZVe7pK IQfrEf9WiD3d9Hlx7LWekmXI1wbeDyDQ0CCCZkMKDbwvLGBeLxOpkidwawsswWuAi6gs 0YSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QJgOaIuyYqhKXDJUJknk+fSZ5Pa0AYwz5MAMP9q3MIE=; b=RNepQKUYdjvjZZdHrYIo6/KsDZ7MIWhzRVEFZrhXKnG9Z6cJnG5MmMK62UAeNPOHCR QTm+wtI9wjghfjg+uU7skokNwVHSObdG48TXpN4G72YjR/Ke+BgW1xWiRHYn/BnxvkZ0 7W0WhlR1qni4at2CN19Njg4qAGuKQczibOMy5+SrNOnS89DGHcRk0AYA0UFc7x5zNsDF 3s/7XUFZ2aLXPg9fxVtGCRV2akLOV+Gx1ceAe14eelAsWv6Uo5xiHynwg2hk5cd3YBFF 0TdKRy+Q8n4FcByZOweYNRuNMU8IkCPZxeGnapM8B/qkNaMp9YNDOpLbkEyzE0v1O+S6 0NcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fromorbit-com.20210112.gappssmtp.com header.s=20210112 header.b=I2mGiER0; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr5-20020a170907720500b007c12e19ba40si7789181ejc.666.2023.01.08.13.33.15; Sun, 08 Jan 2023 13:33:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@fromorbit-com.20210112.gappssmtp.com header.s=20210112 header.b=I2mGiER0; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236008AbjAHVdM (ORCPT + 99 others); Sun, 8 Jan 2023 16:33:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233656AbjAHVdM (ORCPT ); Sun, 8 Jan 2023 16:33:12 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88363E0B for ; Sun, 8 Jan 2023 13:33:09 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id 7so4688467pga.1 for ; Sun, 08 Jan 2023 13:33:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QJgOaIuyYqhKXDJUJknk+fSZ5Pa0AYwz5MAMP9q3MIE=; b=I2mGiER04mQKKr/G1GEYZHSSxGAg6dDLnCDe+qVmEg1QRkSzL3EWBmZI79hAAnRDgR rE6fEEuTXrTLzyhYS6u41epGG5sJztaWCr0LDjVHcxG729WJOF2xxcxIm+AqiRhANw3C m+HGxBt2vRZn9t751ZjEIhuxOmNGSXzhn9VmFBw6N3+FS7E9u4rp4RkHudJiQ1KvTQDv r97ijCNsjdAOt+xGMUUJ0+Bx43BrcgfjbR1+c0igVuZSNYumj7idCIPGMd+QZQsp0XRY RJ5Evpls2A88+Ppm2DXkeYRXwpRKXMpzyOdY/pdGh/C2h1q0ahTRLRuCvlx7rZXdM7ek 36oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QJgOaIuyYqhKXDJUJknk+fSZ5Pa0AYwz5MAMP9q3MIE=; b=IqGU5lQdUaxyO9zSxSsjarMrtreh2b4lrIx6OWpTQnQujWKFQVXPoruwctwBzEGpX1 EO7MytJ5jT28h6kw0BZoE9bY/Lul6ZOYQhvb9S9G8MI2CJd9/5bpoxvo6lUs2uZY+iWq RFqCfj8tetVy6SMNhpIkGQV3aJUZEjUdzCRwCrA/WdQBRSCttIMv7BFCo8zvtamCZ0ri JCxlq8DIu0yod0y2CatBNZRJE6x0/Gg3ghB5Tw6cgNCmBOqijc4b3qvX8YPqX/d2ewFe 5ZMviU3JfcroDalgzzBS3CsBMRi86h8kUhXAObmfoXSAnUeF2cKzXDdVbS8Lw53ZJjHZ C0gQ== X-Gm-Message-State: AFqh2kpmqnL8KmYmp61isXRQIXe8gGFpQXtGbyddhWV/K69Rxfn7u5UK f5fHE9f7b6HhPE8eYmBreAQSEQ== X-Received: by 2002:a05:6a00:1c82:b0:587:4171:30c9 with SMTP id y2-20020a056a001c8200b00587417130c9mr3550129pfw.18.1673213589019; Sun, 08 Jan 2023 13:33:09 -0800 (PST) Received: from dread.disaster.area (pa49-186-146-207.pa.vic.optusnet.com.au. [49.186.146.207]) by smtp.gmail.com with ESMTPSA id a13-20020aa7970d000000b00582197fa7b4sm4631425pfg.7.2023.01.08.13.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 13:33:08 -0800 (PST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1pEdHt-000kZs-Cn; Mon, 09 Jan 2023 08:33:05 +1100 Date: Mon, 9 Jan 2023 08:33:05 +1100 From: Dave Chinner To: Andreas Gruenbacher Cc: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com, Christoph Hellwig Subject: Re: [RFC v6 04/10] iomap: Add iomap_get_folio helper Message-ID: <20230108213305.GO1971568@dread.disaster.area> References: <20230108194034.1444764-1-agruenba@redhat.com> <20230108194034.1444764-5-agruenba@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230108194034.1444764-5-agruenba@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sun, Jan 08, 2023 at 08:40:28PM +0100, Andreas Gruenbacher wrote: > Add an iomap_get_folio() helper that gets a folio reference based on > an iomap iterator and an offset into the address space. Use it in > iomap_write_begin(). > > Signed-off-by: Andreas Gruenbacher > Reviewed-by: Darrick J. Wong > Reviewed-by: Christoph Hellwig > --- > fs/iomap/buffered-io.c | 39 ++++++++++++++++++++++++++++++--------- > include/linux/iomap.h | 1 + > 2 files changed, 31 insertions(+), 9 deletions(-) > > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c > index d4b444e44861..de4a8e5f721a 100644 > --- a/fs/iomap/buffered-io.c > +++ b/fs/iomap/buffered-io.c > @@ -457,6 +457,33 @@ bool iomap_is_partially_uptodate(struct folio *folio, size_t from, size_t count) > } > EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); > > +/** > + * iomap_get_folio - get a folio reference for writing > + * @iter: iteration structure > + * @pos: start offset of write > + * > + * Returns a locked reference to the folio at @pos, or an error pointer if the > + * folio could not be obtained. > + */ > +struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos) > +{ > + unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; > + struct folio *folio; > + > + if (iter->flags & IOMAP_NOWAIT) > + fgp |= FGP_NOWAIT; > + > + folio = __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, > + fgp, mapping_gfp_mask(iter->inode->i_mapping)); > + if (folio) > + return folio; > + > + if (iter->flags & IOMAP_NOWAIT) > + return ERR_PTR(-EAGAIN); > + return ERR_PTR(-ENOMEM); > +} > +EXPORT_SYMBOL_GPL(iomap_get_folio); Hmmmm. This is where things start to get complex. I have sent a patch to fix a problem with iomap_zero_range() failing to zero cached dirty pages over UNWRITTEN extents, and that requires making FGP_CREAT optional. This is an iomap bug, and needs to be fixed in the core iomap code: https://lore.kernel.org/linux-xfs/20221201005214.3836105-1-david@fromorbit.com/ Essentially, we need to pass fgp flags to iomap_write_begin() need so the callers can supply a 0 or FGP_CREAT appropriately. This allows iomap_write_begin() to act only on pre-cached pages rather than always instantiating a new page if one does not exist in cache. This allows that iomap_write_begin() to return a NULL folio successfully, and this is perfectly OK for callers that pass in fgp = 0 as they are expected to handle a NULL folio return indicating there was no cached data over the range... Exposing the folio allocation as an external interface makes bug fixes like this rather messy - it's taking a core abstraction (iomap hides all the folio and page cache manipulations from the filesystem) and punching a big hole in it by requiring filesystems to actually allocation page cache folios on behalf of the iomap core. Given that I recently got major push-back for fixing an XFS-only bug by walking the page cache directly instead of abstracting it via the iomap core, punching an even bigger hole in the abstraction layer to fix a GFS2-only problem is just as bad.... -Dave. -- Dave Chinner david@fromorbit.com