Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18064137rwd; Tue, 27 Jun 2023 11:04:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4PrN78DqPP3HGlBKj3Fbp4TJUcMDst/SFsiLLMAr78lw3rb2hvGwtTamMmxnrWPJQuzO2i X-Received: by 2002:a17:902:dacc:b0:1b1:a4e2:a2e6 with SMTP id q12-20020a170902dacc00b001b1a4e2a2e6mr12219037plx.12.1687889075338; Tue, 27 Jun 2023 11:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687889075; cv=none; d=google.com; s=arc-20160816; b=oyEUX6D8DDKcpaxjzsvDCYnq2S1sQmYqyJ0S+xDMrB3W0bXOeACUb2vbyR8sDp1Hvy RDAfCYXXmQY4haP0/mY3ZWci4BYtVN9LnT8/nlL/iPlxhuf9y0Km2I6LVuCiN0YWJ05Q IgzCQWHxOzIlg1qIxiJCh4uDeqflmioaOOAaRz1n1lcJ/wIjVFR6+98Bv+xTBGHXU6ut j8vnjNktvoaFPJi5D2b3ydGYQ41zifj8q7tfcG+kQkEroN+2yXgtM1kIZ1V5ihG9d2mk mSEIcUUfsq2sHpB3ttiM4+tVVhlnEj0WYrXWNhsU/DFslCWVt8FlZx35cH8TUdfuY8iC wxuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=se2ReXfTDI0bXoCNygO1qTaRa/855o/ehreExnjKHr4=; fh=XjfgmoRDrILL6w2Fv352UdLWQaGMeBLGa5ELCOloFxk=; b=wBSnDGqkQ9+5gKj+VaEp4FTxSar6PJwB7Z6n/kS6J/NTvCOqQ4eqaPoVrtpHxzFSA8 JZ4fXtD/Nb/2fGh8P/cpNEEjiSe0q4wr9uSQxOX4Zwaaa18EVQmMo4j50SYbQ+z3Jx4q R6YIecxxY3bmDjcfnLLnt0ZghvrFK2Lh5wxN8Gr4u7FI8Q+RXUF+ufZb4Q0HA4ugaI6F Mid9W45i0vLSJ6DFfq2AyBZ2Q4Dzh5ajfi+Wz0TqKCnDLSWaZwQMO7G1dq4vbyPZw4qU CaUsa86Ez7W3gGXHiZQs5nVpMSKvZv0M31JWFkEF+wzHBoLFZ6vRiy/ycYO49j3DY717 g5Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=UbiFd6Yo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x10-20020a17090300ca00b001b1be13179csi6886015plc.385.2023.06.27.11.04.23; Tue, 27 Jun 2023 11:04:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@google.com header.s=20221208 header.b=UbiFd6Yo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbjF0Rgj (ORCPT + 99 others); Tue, 27 Jun 2023 13:36:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231657AbjF0Rgg (ORCPT ); Tue, 27 Jun 2023 13:36:36 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 559F72D53 for ; Tue, 27 Jun 2023 10:36:33 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-5702415be17so39954417b3.2 for ; Tue, 27 Jun 2023 10:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687887392; x=1690479392; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=se2ReXfTDI0bXoCNygO1qTaRa/855o/ehreExnjKHr4=; b=UbiFd6YoylHJILWdhk6BfqhqffX7VZGyKqllKO+PLZxQgyXEVk7mLWiCPmMOH0eG1A mz4x3Z55tg1CsUsg9y5/38jsuMiEGWpTEQsU8IHLE6s9l73ZN4tt6JHXtzXyWoSqZodT CJ4SOcXTjvD3Ab6tdreO3k/QraNDuA04zVIsO7NwaQ1mUyQ18XfMQcxX0xfbLkyTZ0ka bRPn6/iTaf0QK3v/2n1QveesbyfGhn4ArML8353gQvj9YDEgvbAF7kJoEi6lJNa+zf4H Q/aAUDW/oj0lYLERWPtfXkfaFIGuITEF8dIbtHK1BFK4Vx5rVC1d2fjbye7WlBFg9M3Z aEEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687887392; x=1690479392; h=content-transfer-encoding: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=se2ReXfTDI0bXoCNygO1qTaRa/855o/ehreExnjKHr4=; b=k9eqUzIYPOoemUwIGpzmT1CArIdk5y8EYxSL6IsEbAPPDpe1upDMow84g4GCmDyzgy G8G6Uv0YkbhmdubVzJ9OYadXWSPqJkTGjrZsaj4hljkPb4EUbxX8yMKRs61A4dzzROZb q7m0l2MNKnwZyERNgqgHSb4O82OGjLBvEWC45rPzb5MHXDuvC9QnKec1fqg+hC1GZPL0 XKLJcOqY1k5U50K2esGj71VgfffDovYIY3uUbph7P9dohzyxLAMMdzBc7H3iWhtr5Abi LHJlbZFODSxaxvn+1SlS4lW1ZcXtf8VRf4qu5yzPWcesGAxIoCs6bq4wH59iUueI/Pje iL7Q== X-Gm-Message-State: AC+VfDzRQEu9tobEcTwTsIX0RuNH2vRD3S2xtov6b/HxIE35+7wkYg8K mJj0YTaJFoRIUT//ZKXJwbor7RHtK40Ay4nwD7VHJw== X-Received: by 2002:a25:549:0:b0:bc7:947e:2fcd with SMTP id 70-20020a250549000000b00bc7947e2fcdmr20991175ybf.35.1687887392275; Tue, 27 Jun 2023 10:36:32 -0700 (PDT) MIME-Version: 1.0 References: <20230626201713.1204982-1-surenb@google.com> <20230627-kanon-hievt-bfdb583ddaa6@brauner> <20230627-ausgaben-brauhaus-a33e292558d8@brauner> In-Reply-To: <20230627-ausgaben-brauhaus-a33e292558d8@brauner> From: Suren Baghdasaryan Date: Tue, 27 Jun 2023 10:36:21 -0700 Message-ID: Subject: Re: [PATCH 1/2] kernfs: add kernfs_ops.free operation to free resources tied to the file To: Christian Brauner Cc: Tejun Heo , gregkh@linuxfoundation.org, peterz@infradead.org, lujialin4@huawei.com, lizefan.x@bytedance.com, hannes@cmpxchg.org, mingo@redhat.com, ebiggers@kernel.org, oleg@redhat.com, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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-kernel@vger.kernel.org On Tue, Jun 27, 2023 at 10:30=E2=80=AFAM Christian Brauner wrote: > > On Tue, Jun 27, 2023 at 10:09:27AM -0700, Suren Baghdasaryan wrote: > > On Tue, Jun 27, 2023 at 1:24=E2=80=AFAM Christian Brauner wrote: > > > > > > On Mon, Jun 26, 2023 at 10:31:49AM -1000, Tejun Heo wrote: > > > > On Mon, Jun 26, 2023 at 01:17:12PM -0700, Suren Baghdasaryan wrote: > > > > > diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h > > > > > index 73f5c120def8..a7e404ff31bb 100644 > > > > > --- a/include/linux/kernfs.h > > > > > +++ b/include/linux/kernfs.h > > > > > @@ -273,6 +273,11 @@ struct kernfs_ops { > > > > > */ > > > > > int (*open)(struct kernfs_open_file *of); > > > > > void (*release)(struct kernfs_open_file *of); > > > > > + /* > > > > > + * Free resources tied to the lifecycle of the file, like a > > > > > + * waitqueue used for polling. > > > > > + */ > > > > > + void (*free)(struct kernfs_open_file *of); > > > > > > > > I think this can use a bit more commenting - ie. explain that relea= se may be > > > > called earlier than the actual freeing of the file and how that can= lead to > > > > problems. Othre than that, looks fine to me. > > > > > > It seems the more natural thing to do would be to introduce a ->drain= () > > > operation and order it before ->release(), no? > > > > I assume you mean we should add a ->drain() operation and call it when > > kernfs_drain_open_files() causes kernfs_release_file()? That would > > work but if any existing release() handler counts on the current > > behavior (release() being called while draining) then we should find > > and fix these. Hopefully they don't really depend on the current > > behavior but I dunno. > > Before I wrote that I did a naive > > > git grep -A 20 kernfs_ops | grep \\.release > kernel/cgroup/cgroup.c- .release =3D cgroup_file_r= elease, > kernel/cgroup/cgroup.c- .release =3D cgroup_file_r= elease, > > which only gave cgroup_release_file(). Might be I'm missing some convolut= ed > callchains though or macro magic... > > ->release() was added in > > commit 0e67db2f9fe91937e798e3d7d22c50a8438187e1 > kernfs: add kernfs_ops->open/release() callbacks > > Add ->open/release() methods to kernfs_ops. ->open() is called when > the file is opened and ->release() when the file is either released o= r > severed. These callbacks can be used, for example, to manage > persistent caching objects over multiple seq_file iterations. > > Signed-off-by: Tejun Heo > Acked-by: Greg Kroah-Hartman > Acked-by: Acked-by: Zefan Li > > > which mentions "either releases or severed" which imho already points to > separate methods. Interesting. I guess we can add op->drain() and make all existing handlers of ops->release() to handle ops->drain() with the same handler. That should keep them happy and for my case I'll be releasing resources only inside ops->release(). Does that sound good? > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >