* [PATCH] Free the DIFO for a probe once it is loaded
@ 2025-07-25 4:01 Kris Van Hees
2025-07-25 18:39 ` Nick Alcock
0 siblings, 1 reply; 3+ messages in thread
From: Kris Van Hees @ 2025-07-25 4:01 UTC (permalink / raw)
To: dtrace, dtrace-devel
When a lot of probes are being probed, keeping all DIFO around consumes
a lot of memory. Once the BPF program is loaded, the DIFO can be freed.
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
---
libdtrace/dt_bpf.c | 23 ++++++++++++++++-------
libdtrace/dt_prov_uprobe.c | 22 +++++++++++++++-------
2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index ccec8b43..56b6b01d 100644
--- a/libdtrace/dt_bpf.c
+++ b/libdtrace/dt_bpf.c
@@ -1339,6 +1339,7 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
*/
dtrace_getopt(dtp, "destructive", &dest_ok);
+ dp = NULL;
for (prp = dt_list_next(&dtp->dt_enablings); prp != NULL;
prp = dt_list_next(prp)) {
int fd;
@@ -1353,28 +1354,36 @@ dt_bpf_load_progs(dtrace_hdl_t *dtp, uint_t cflags)
continue;
if (dt_link(dtp, prp, dp, NULL) == -1)
- return -1;
+ goto fail;
DT_DISASM_PROG_LINKED(dtp, cflags, dp, stderr, NULL, prp->desc);
if (dp->dtdo_flags & DIFOFLG_DESTRUCTIVE &&
- dest_ok == DTRACEOPT_UNSET)
- return dt_set_errno(dtp, EDT_DESTRUCTIVE);
+ dest_ok == DTRACEOPT_UNSET) {
+ dt_set_errno(dtp, EDT_DESTRUCTIVE);
+ goto fail;
+ }
fd = dt_bpf_load_prog(dtp, prp, dp, cflags);
if (fd == -1)
- return -1;
+ goto fail;
if (prp->prov->impl->attach)
rc = prp->prov->impl->attach(dtp, prp, fd);
if (rc < 0) {
close(fd);
- return dt_attach_error(dtp, rc,
- prp->desc->prv, prp->desc->mod,
- prp->desc->fun, prp->desc->prb);
+ dt_attach_error(dtp, rc,
+ prp->desc->prv, prp->desc->mod,
+ prp->desc->fun, prp->desc->prb);
+ goto fail;
}
}
return 0;
+
+fail:
+ dt_difo_free(dtp, prp->difo);
+ prp->difo = NULL;
+ return -1;
}
diff --git a/libdtrace/dt_prov_uprobe.c b/libdtrace/dt_prov_uprobe.c
index f60bdceb..8e7aa4b0 100644
--- a/libdtrace/dt_prov_uprobe.c
+++ b/libdtrace/dt_prov_uprobe.c
@@ -609,32 +609,40 @@ static int add_probe_uprobe(dtrace_hdl_t *dtp, dt_probe_t *prp)
/* Make program. */
dp = dt_construct(dtp, prp, cflags, NULL);
if (dp == NULL)
- return 0; // FIXME in dt_bpf_make_progs() this is a fatal error; should we do the same here?
+ return 0;
prp->difo = dp;
/* Load program. */
if (dt_link(dtp, prp, dp, NULL) == -1)
- return 0; // FIXME in dt_bpf_load_progs() this is a fatal error; should we do the same here?
+ goto fail;
dtrace_getopt(dtp, "destructive", &dest_ok);
if (dp->dtdo_flags & DIFOFLG_DESTRUCTIVE &&
- dest_ok == DTRACEOPT_UNSET)
- return dt_set_errno(dtp, EDT_DESTRUCTIVE);
+ dest_ok == DTRACEOPT_UNSET) {
+ dt_set_errno(dtp, EDT_DESTRUCTIVE);
+ goto fail;
+ }
fd = dt_bpf_load_prog(dtp, prp, dp, cflags);
if (fd == -1)
- return 0; // FIXME in dt_bpf_load_progs() this is a fatal error; should we do the same here?
+ goto fail;
if (prp->prov->impl->attach)
rc = prp->prov->impl->attach(dtp, prp, fd);
if (rc < 0) {
close(fd);
- return dt_attach_error(dtp, rc, prp->desc->prv, prp->desc->mod,
- prp->desc->fun, prp->desc->prb);
+ dt_attach_error(dtp, rc, prp->desc->prv, prp->desc->mod,
+ prp->desc->fun, prp->desc->prb);
+ goto fail;
}
return 0;
+
+fail:
+ dt_difo_free(dtp, prp->difo);
+ prp->difo = NULL;
+ return 0; // FIXME in dt_bpf_make_progs() this is a fatal error; should we do the same here?
}
static int add_probe_usdt(dtrace_hdl_t *dtp, dt_probe_t *prp)
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Free the DIFO for a probe once it is loaded
2025-07-25 4:01 [PATCH] Free the DIFO for a probe once it is loaded Kris Van Hees
@ 2025-07-25 18:39 ` Nick Alcock
2025-07-25 18:55 ` Kris Van Hees
0 siblings, 1 reply; 3+ messages in thread
From: Nick Alcock @ 2025-07-25 18:39 UTC (permalink / raw)
To: Kris Van Hees; +Cc: dtrace, dtrace-devel
On 25 Jul 2025, Kris Van Hees verbalised:
> When a lot of probes are being probed, keeping all DIFO around consumes
> a lot of memory. Once the BPF program is loaded, the DIFO can be freed.
DIFO? BPFO, surely :)
... the attached patch only seems to free anything new on failure, not
on after-loading.
> +fail:
> + dt_difo_free(dtp, prp->difo);
> + prp->difo = NULL;
> + return -1;
[...]
> +fail:
> + dt_difo_free(dtp, prp->difo);
> + prp->difo = NULL;
> + return 0; // FIXME in dt_bpf_make_progs() this is a fatal error; should we do the same here?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Free the DIFO for a probe once it is loaded
2025-07-25 18:39 ` Nick Alcock
@ 2025-07-25 18:55 ` Kris Van Hees
0 siblings, 0 replies; 3+ messages in thread
From: Kris Van Hees @ 2025-07-25 18:55 UTC (permalink / raw)
To: Nick Alcock; +Cc: Kris Van Hees, dtrace, dtrace-devel
On Fri, Jul 25, 2025 at 07:39:51PM +0100, Nick Alcock wrote:
> On 25 Jul 2025, Kris Van Hees verbalised:
>
> > When a lot of probes are being probed, keeping all DIFO around consumes
> > a lot of memory. Once the BPF program is loaded, the DIFO can be freed.
>
> DIFO? BPFO, surely :)
>
> ... the attached patch only seems to free anything new on failure, not
> on after-loading.
Oops, yes, will fix and send out a new one.
> > +fail:
> > + dt_difo_free(dtp, prp->difo);
> > + prp->difo = NULL;
> > + return -1;
> [...]
> > +fail:
> > + dt_difo_free(dtp, prp->difo);
> > + prp->difo = NULL;
> > + return 0; // FIXME in dt_bpf_make_progs() this is a fatal error; should we do the same here?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-25 18:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-25 4:01 [PATCH] Free the DIFO for a probe once it is loaded Kris Van Hees
2025-07-25 18:39 ` Nick Alcock
2025-07-25 18:55 ` Kris Van Hees
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).