* [PATCH v2] Free the DIFO for a probe once it is loaded
@ 2025-07-25 19:34 Kris Van Hees
2025-07-25 22:51 ` [DTrace-devel] " Eugene Loh
0 siblings, 1 reply; 2+ messages in thread
From: Kris Van Hees @ 2025-07-25 19:34 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 | 26 +++++++++++++++++++-------
libdtrace/dt_prov_uprobe.c | 22 +++++++++++++++-------
2 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
index ccec8b43..ad8cc0e1 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,39 @@ 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;
}
+
+ dt_difo_free(dtp, prp->difo);
+ prp->difo = NULL;
}
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.43.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [DTrace-devel] [PATCH v2] Free the DIFO for a probe once it is loaded
2025-07-25 19:34 [PATCH v2] Free the DIFO for a probe once it is loaded Kris Van Hees
@ 2025-07-25 22:51 ` Eugene Loh
0 siblings, 0 replies; 2+ messages in thread
From: Eugene Loh @ 2025-07-25 22:51 UTC (permalink / raw)
To: Kris Van Hees, dtrace, dtrace-devel
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
On 7/25/25 15:34, Kris Van Hees via DTrace-devel wrote:
> 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 | 26 +++++++++++++++++++-------
> libdtrace/dt_prov_uprobe.c | 22 +++++++++++++++-------
> 2 files changed, 34 insertions(+), 14 deletions(-)
>
> diff --git a/libdtrace/dt_bpf.c b/libdtrace/dt_bpf.c
> index ccec8b43..ad8cc0e1 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,39 @@ 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;
> }
> +
> + dt_difo_free(dtp, prp->difo);
> + prp->difo = NULL;
> }
>
> 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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-25 22:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-25 19:34 [PATCH v2] Free the DIFO for a probe once it is loaded Kris Van Hees
2025-07-25 22:51 ` [DTrace-devel] " Eugene Loh
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).