[DTrace-devel] [PATCH 4/7] htab: add dt_htab_purge to purge an htab rapidly

Eugene Loh eugene.loh at oracle.com
Mon Oct 11 14:31:31 PDT 2021


I suppose my comments here are redundant with what I said elsewhere, but 
for completeness I'll comment on this patch.  I've not thought this 
through 100%, but how about the function concludes with a 
dt_htab_destroy(dtp, htab) call?  And, add a destructor callback 
function to htabs so that htabs can be destroyed more often with just a 
call to this function rather than having to maintain separate lists (in 
addition to the htab) for the single purpose of being able to iterate 
over the entries for destruction?  (I'm just rehashing what I said on 
the other patches.)

On 10/5/21 9:38 AM, Nick Alcock wrote:
> Destroying large htabs right before destroying their contents is
> annoying: you have to delete every entry one by one from the htab before
> you destroy it, lest you leak all the buckets: this also serves to reset
> the dt_hentry pointers in every entry.
How about a more specific adjective in place of "annoying."  Also, 
replace the colons with full stops.
> This is expensive, and (if destroying the buckets anyway) useless work.
> Add a new dt_htab_purge, which just deletes the buckets without
> adjusting the entries.  Obviously this is dangerous unless you know
> you're going to be deleting everything anyway, but in that situation it
> is a useful optimization.
>
> diff --git a/libdtrace/dt_htab.c b/libdtrace/dt_htab.c
> +/*
> + * Purge all the buckets in an htab, as if it were new (but the same size as it
> + * always was).  The hentries are *not* reset!  Should be used only before
> + * wholesale deletion of everything that might contain a hentry.
> + */
> +void dt_htab_purge(dt_htab_t *htab)
> +{
> +	int i;
> +	for (i = 0; i < htab->size; i++) {
> +		dt_hbucket_t *bucket, *next;
> +		for (bucket = htab->tab[i]; bucket; bucket = next) {
> +			next = bucket->next;
> +			free(bucket);
> +		}
> +		htab->tab[i] = NULL;
> +	}
> +	htab->nbuckets = 0;
> +}



More information about the DTrace-devel mailing list