Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp806834lql; Mon, 11 Mar 2024 19:56:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKxr7hNER0avSsXJlPOleslCffKJz5x8RbKj7s7u3MOJXfc5Ta6cd0AvLzj2L55AF3eLIzLeVKteUTgrQ1HvqYVXRKQUhJ8TJiGwq+6Q== X-Google-Smtp-Source: AGHT+IGGccokvTuGGQ5Pt3nmf9Y2IrTQJVL1InGRBXUi3ZSyU92ct5yyXbTgfwJX9RaIpXOQSNo3 X-Received: by 2002:a05:620a:831c:b0:788:2b1c:1e57 with SMTP id pa28-20020a05620a831c00b007882b1c1e57mr8902939qkn.55.1710212209084; Mon, 11 Mar 2024 19:56:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710212209; cv=pass; d=google.com; s=arc-20160816; b=WuaIhlFdNITD2BBx1O2asfJ6uxTCjJgA8DteqKRi/CvFrIgzNgrv0MgA1oLZwoeDDr bZ9XuIVt1sLnb1Jrv7Beawtd4dP3YA3dohxZarK/sDDXvt4hWt2XlJRuA4DWd4DoU9ft IANYaB1+DLdygRYA6z42zZv3MgESvTFek6/BfOjeKcEDBQ+rVoydn8/CdaPy5no5ZQCU ppB9+RjLXyx/HQes8+Lv2PDdtTPVGU1J5G5DiFRQc+O6lkh7QRbeYUS5J6usm/AyTW/y ttfSnE5fN5T2+kn4rTsBKd1UJvWGfxpA6If5TfwXmE+hpSQWWMf5cyJOiw8fOsdauKg6 G+ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=8duYlw7yiLaMQiEjvPs64/nXpWh4xT1l7do/uy0Ifvk=; fh=E+JuT0ZpXL+nWqy3ecLkY76oTIvgOl/kiiaLKR3tRls=; b=lHwdKwFQfyLrGorI3bTRecDYLwSFEufR0P+LFiChzFFI2AXRrWOnTu7RLCNSwgkv3K zMO+JCGsghCAvAgGwpZGvxWTOOZGPA04doVKpt01HXxjm/8yXerJy5A8IBTf2+OSTUs9 xCfeFD/PJx559yz7V8EyNZqV7pSGU5Y+HcyZmwVFI8bbwInmK6jOGKeTQJp8lwW/QC9e ZH7AaByW/d50Iur93LTbhv63AQun/RC/r8orB90h2PNP9Um71xDrNoTt4E/QXfF5ixJP bIECaqloBr0+rWRKUkJjfgDZeqmN11AbtFmK8ugihXgcMFgwDLg6A5+y73CYfTxlHGzj prHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=d2Ova4t3; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-99782-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x13-20020ae9e64d000000b0078822f49d79si6600749qkl.631.2024.03.11.19.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 19:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99782-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=d2Ova4t3; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-99782-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99782-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AF99B1C21A77 for ; Tue, 12 Mar 2024 02:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E899AD5A; Tue, 12 Mar 2024 02:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="d2Ova4t3" Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4180B67F for ; Tue, 12 Mar 2024 02:56:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710212195; cv=none; b=UfAJ451iNtlMxjRieErBMTD90ZlxBvdZX75J2FJwn409wESBj98AtxlB+Ge8In9BwiyLhrLrPtmRIKb4K8RL+ztzOHN947pOwiE42QHEMjnTtG/jn08c1cjfNOMPqomFzUYYEIIPV6hNhCD3NARdj3bqx+QsG9jxx/X/iPwHsQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710212195; c=relaxed/simple; bh=8duYlw7yiLaMQiEjvPs64/nXpWh4xT1l7do/uy0Ifvk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=HagPZUrwZOCzDoPRxuK8qtlqBDVdU2yyfqIjL7URJVjz2lHrQ8jP57j+79S6rWJhGo4rfjq1qAf5VUwgSeO61W7pqESy+MT9PGjUbpkKX9hZ4DXQf0NCtk4guahbU8q4KTl9E2/cdnU0c8XEeVFa3sLS33LK+r2UIZLpEEdES94= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=d2Ova4t3; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-29bf998872fso1081556a91.3 for ; Mon, 11 Mar 2024 19:56:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1710212192; x=1710816992; darn=vger.kernel.org; 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=8duYlw7yiLaMQiEjvPs64/nXpWh4xT1l7do/uy0Ifvk=; b=d2Ova4t3LH8K/YV1te1DCzhVl3PLbvJaG/iY2pzTDJkcosWx6A/MdUZ/mM4MW9sfUR GQ5sY5+buMi0xl8pZAl6oybDues4UiLqfZLkGdHy7hPxqm0DSdeog5UKj7At1YM1DJbF l6UuGZe+F+ck+GPIQFyxK9ZWsB8KHcJnj8TP5e3nSaFDsrIcxIZjimixhc84Rouc2Ru1 jU20/9p6MyfoCzVO+QitGrjhtK31dySWPAfyxG2PMVfo2ka/f/+TxRDVMZ2SEVhhX4tC +C70CU73YnvAnGtEokTXbWYERGIAFzRa+RhVapWsKkGeZhM3DUaa0u5ykhQUncKB7WlF EL8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710212192; x=1710816992; 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=8duYlw7yiLaMQiEjvPs64/nXpWh4xT1l7do/uy0Ifvk=; b=GxAzvbaeTkewoD2RM4A19WdoAOcL8wrQVYBtoyEelsZfymxk9bnL/iblaEblwZJFYT Ix9XY1PgA+GJ9xqhEX2OhL591u/kmZ+IuP/R9wLp/R7O6nCkArwllijbFdyiqBgUm269 WZbv8B+btDMNiOfToSfFEBJm7M+3NXZeWxHlEFFDFkYQ2x+UblAUO9RYtlnuR9+qMSKw y7MqlXdV086tU6Wlwy92TwnHj34FHImbZzu3U5nT2Rqw5GaJyDdgj83M0Clq2CIiLJi5 +4ryAPBaddbH6yPAVVJJv+18VCNMfpwg9GcAzXDjxVRSDaLzoG0lDUrQJNuJl2YTx5hF el1Q== X-Forwarded-Encrypted: i=1; AJvYcCXkNTgrv8HaAWKdXWs/1VMyF5JpBzktTgzEdhcbTOfEbYu0feVAHdLg28jxdG1Td9DpJowsityAwxmxvn6IHtYvUK7QMlng0jkZ7xXN X-Gm-Message-State: AOJu0Ywi7xgIIJPuqvKWf/Pa5TPZcfoupuFBf04IcRdKa69Mrq02e4/W 74LPKlBguzA3x63gBiqyw4fiIk+QOxkb46bqrdZ+0nMxlPyWN3JziaWRM0mvWP4KZhDes2BC64E dmjv2s/JZyxx/QW8wdruMtbexnT11yvWlyv3mjA== X-Received: by 2002:a17:90a:f305:b0:299:63fe:3a27 with SMTP id ca5-20020a17090af30500b0029963fe3a27mr5454778pjb.19.1710212192599; Mon, 11 Mar 2024 19:56:32 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240311093526.1010158-1-dongmenglong.8@bytedance.com> <20240311093526.1010158-8-dongmenglong.8@bytedance.com> In-Reply-To: From: =?UTF-8?B?5qKm6b6Z6JGj?= Date: Tue, 12 Mar 2024 10:56:21 +0800 Message-ID: Subject: Re: [External] Re: [PATCH bpf-next v2 7/9] libbpf: don't free btf if program of multi-link tracing existing To: Alexei Starovoitov Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Eddy Z , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "David S. Miller" , David Ahern , Dave Hansen , X86 ML , Steven Rostedt , Mathieu Desnoyers , Quentin Monnet , bpf , linux-arm-kernel , LKML , linux-riscv , linux-s390 , Network Development , linux-trace-kernel@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 12, 2024 at 10:13=E2=80=AFAM Alexei Starovoitov wrote: > > On Mon, Mar 11, 2024 at 7:05=E2=80=AFPM =E6=A2=A6=E9=BE=99=E8=91=A3 wrote: > > > > > > > > > > +LIBBPF_API void bpf_object__free_btfs(struct bpf_object *obj); > > > > + > > > > > > It shouldn't be exported. > > > libbpf should clean it up when bpf_object is freed. > > > > Yes, libbpf will clean up the btfs when bpf_object is freed in > > this commit. And I'm trying to offer a way to early free the btfs > > by the users manual to reduce the memory usage. Or, the > > btfs that we opened will keep existing until we close the > > bpf_object. > > > > This is optional, I can remove it if you prefer. > > Let's not extend libbpf api unless we really need to. > bpf_program__attach_trace_multi_opts() and > *skel*__attach() can probably free them. That's a good idea! Should we add a "bool free_btf" field to struct bpf_trace_multi_opts? bpf_program__attach_trace_multi_opts() can be called multi times for a bpf_object, which has multi bpf program of type tracing multi-link. Or, can we free the btfs automatically if we found all tracing multi-link programs are attached? Thanks! Menglong Dong > I don't see a use case where you'd want to keep them afterwards.