Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp1193232rwj; Fri, 23 Dec 2022 14:26:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXvKFNvAlL+NMhSHqbYlkKXyJmxq/NY/1FHB3cOvK/Mm/qThIo0jONL5lblpVOXylZcGoJEt X-Received: by 2002:aa7:d8da:0:b0:474:5de4:a5d1 with SMTP id k26-20020aa7d8da000000b004745de4a5d1mr9751740eds.39.1671834407071; Fri, 23 Dec 2022 14:26:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671834407; cv=none; d=google.com; s=arc-20160816; b=Sbbwxa6qE1zfPvTuQcFwoz3LPuuOR8R0gWQXLigcjymM51qsUJcOzoczLZwkjtnPlL laweanejYeTY27U78J5ww9MkZANsGbmH8zlGMIpFaiyyon0Inkp0m95jANK7we8zJZyI 7s0pkwYQufD2qRgx6uCT3uNruOiWaIE0fNPl+jaw98htS6WkhMy13fHk2QTfF3i62uLd GL2bSuBwqMPkWgywasUtg2wWT/m4cLB3EqSJUD2OUREjh1P7mmPxWVSFgnqxK8mULnoa +g1Eyf4kbcCzdA6PCsQlIiRidYqGzOtRA69fk5fsbyqk369IVjMjmo8t7rFD0QetZmya t1dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=XOJ5z7kFjWc68B5B6Sh1NWt9teGCI8E34Z2/SZr41S8=; b=EE4D/C1oxq80R+8MP5mORRhnEEsJ6wLHX1Zwlg19kGwn1qBVs+mE1MLCb+cfM26TVF qrdV0iEnvbfdBGhB1pbfhdq9pw8uEYeSZhxZceLPQMaQW4BNldtamo87Kf0ttzm6a4dx ZHndtoHBRCFghtQ28Oa4tHbj5ULUju+wr1CvGjCu5fHlq0nJGgjMqts/8erCHTqPvx0C 7kNaMdRFAXPZetVMvw6Jg2PdxCoxwZrMByH8Wjowsqi1X+YsBCM37ftPAKyaWzSEI7m2 P2RmSDUO3SVwzIEpFYmRfSkNgNbPCNYYiqyV65wWshOZw/cCTlQSCpKegF2M+IcE4zsM 8JVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CaDLvp1Q; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a056402515100b0046c8d52c8c7si3198283edd.177.2022.12.23.14.26.16; Fri, 23 Dec 2022 14:26:47 -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=@gmail.com header.s=20210112 header.b=CaDLvp1Q; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231153AbiLWWFH (ORCPT + 99 others); Fri, 23 Dec 2022 17:05:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbiLWWFF (ORCPT ); Fri, 23 Dec 2022 17:05:05 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEBCE1C435; Fri, 23 Dec 2022 14:05:04 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id bp44so2057258qtb.0; Fri, 23 Dec 2022 14:05:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XOJ5z7kFjWc68B5B6Sh1NWt9teGCI8E34Z2/SZr41S8=; b=CaDLvp1QLFx2Hzqz3sPsHWemPlSRGIVm6N0Ga8quwoX390HaGi6C/ooR/jUv1tMncn EAHfSzlVh7lg8HE7dlsOVfNt1aRvMKnylga/ihg1jTkePYaOSPOk26xGxzFUN1n+kULd 31rZLbaBrNcWdfmGI9utk6Jt6MRev80E/G15Yzt63eA9U2dWEwNtaqsWq/B3UuPMhjDw QNmanZbagRuK/IDoRljUMi2u8Gml6zKNvOK9DkEgqLmRIEHvHZIvj0vApRbArdAb0OtN kL85EmMcMOM1LTnJBA0ann4v1DzewhMieom0TfuLVs0sXLxUqRVZt8otJPdK943rUnIk SvdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XOJ5z7kFjWc68B5B6Sh1NWt9teGCI8E34Z2/SZr41S8=; b=cgaCEcMrxFaiixLKBOCFSj2dwJ8zhZ3YwQXabk1VvRkjf2o6HjmOxjTXtaWtVFy418 ekTGsVrSgI4Ec1QhLDyWsQAdM/VV0PeFkR4YU4Wh7DmO24IwcoaziRmRtBZO5TEK+fXv /vRTY7YKJ0uTW/DOQcaYbXrh80B9qNfwWQa1ee/K5zCftEJ2m3ruCQZzLe5faQTtlR87 OprOx2iZ1C8vavRTZn5uFrOtZMdEW+sjMT2i8myq4y+eqAL93md3mM21mh/N3dCLWFMD iXUrZLxGCiAkD6lw/PRtAIPt8fLziLKMetJWechI3Tt7+mm1UFYEVZSWzf3lj3qxf8wQ 3agw== X-Gm-Message-State: AFqh2kripjgXQ8S791MlpdKvKPJ3usHDz2S/oZu0B8m731M1r8b0l4RI I6iUqousRflBgqRfuQpXllaQRDU+j7R+Bsl6TCwfPKn7orCDYg== X-Received: by 2002:a05:622a:244c:b0:3a8:12f6:69ff with SMTP id bl12-20020a05622a244c00b003a812f669ffmr451928qtb.567.1671833103695; Fri, 23 Dec 2022 14:05:03 -0800 (PST) MIME-Version: 1.0 References: <20221216150626.670312-1-agruenba@redhat.com> <20221216150626.670312-2-agruenba@redhat.com> In-Reply-To: From: =?UTF-8?Q?Andreas_Gr=C3=BCnbacher?= Date: Fri, 23 Dec 2022 23:04:51 +0100 Message-ID: Subject: Re: [RFC v3 1/7] fs: Add folio_may_straddle_isize helper To: Christoph Hellwig Cc: Andreas Gruenbacher , "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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Am Fr., 23. Dez. 2022 um 16:06 Uhr schrieb Christoph Hellwig : > On Fri, Dec 16, 2022 at 04:06:20PM +0100, Andreas Gruenbacher wrote: > > Add a folio_may_straddle_isize() helper as a replacement for > > pagecache_isize_extended() when we have a locked folio. > > I find the naming very confusing. Any good reason to not follow > the naming of pagecache_isize_extended an call it > folio_isize_extended? A good reason for a different name is because folio_may_straddle_isize() requires a locked folio, while pagecache_isize_extended() will fail if the folio is still locked. So this doesn't follow the usual "replace 'page' with 'folio'" pattern. > > Use the new helper in generic_write_end(), iomap_write_end(), > > ext4_write_end(), and ext4_journalled_write_end(). > > Please split this into a patch per caller in addition to the one > adding the helper, and write commit logs explaining the rationale > for the helper. The obious ones I'm trying to guess are that > the new helper avoid a page cache radix tree lookup and a lock > page/folio cycle, but I'd rather hear that from the horses mouth > in the commit log. Yes, that's what the horse says. > > --- a/fs/buffer.c > > +++ b/fs/buffer.c > > @@ -2164,16 +2164,15 @@ int generic_write_end(struct file *file, struct address_space *mapping, > > * But it's important to update i_size while still holding page lock: > > * page writeout could otherwise come in and zero beyond i_size. > > */ > > - if (pos + copied > inode->i_size) { > > + if (pos + copied > old_size) { > > This is and unrelated and undocument (but useful) change. Please split > it out as well. > > > + * This function must be called while we still hold i_rwsem - this not only > > + * makes sure i_size is stable but also that userspace cannot observe the new > > + * i_size value before we are prepared to handle mmap writes there. > > Please add a lockdep_assert_held_write to enforce that. > > > +void folio_may_straddle_isize(struct inode *inode, struct folio *folio, > > + loff_t old_size, loff_t start) > > +{ > > + unsigned int blocksize = i_blocksize(inode); > > + > > + if (round_up(old_size, blocksize) >= round_down(start, blocksize)) > > + return; > > + > > + /* > > + * See clear_page_dirty_for_io() for details why folio_set_dirty() > > + * is needed. > > + */ > > + if (folio_mkclean(folio)) > > + folio_set_dirty(folio); > > Should pagecache_isize_extended be rewritten to use this helper, > i.e. turn this into a factoring out of a helper? I'm not really sure about that. The boundary conditions in the two functions are not identical. I think the logic in folio_may_straddle_isize() is sufficient for the extending-write-under-folio-lock case, but I'd still need confirmation for that. If the same logic would also be enough in pagecache_isize_extended() is more unclear to me. > > +EXPORT_SYMBOL(folio_may_straddle_isize); > > Please make this an EXPORT_SYMBOL_GPL just like folio_mkclean. Thanks, Andreas