M_TEMP trouble in 13.0-CURRENT #0 r355131M

Mark Johnston markj at freebsd.org
Thu Jan 9 15:17:00 UTC 2020


On Thu, Jan 09, 2020 at 12:58:28PM +0100, Hans Petter Selasky wrote:
> Hi Jeff and Konstantin,
> 
> You have a logical breakage after the domainset patches for malloc. The size
> used for allocation statistics is not the same like for freeing causing
> messed up "vmstat -m".

Sorry, I committed a different patch in r356555 before seeing this.

> Also you should audit the code for zero-sized allocations, because upon
> alloc, zero-sized is not counted, while on free it is.

Can you explain further?  A zero-sized allocation should be rounded up to
16 bytes in all paths.

> See attached patch.
> 
> --HPS

> diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
> index eba9fc3e1ef..aab33873741 100644
> --- a/sys/kern/kern_malloc.c
> +++ b/sys/kern/kern_malloc.c
> @@ -669,8 +669,10 @@ malloc_domain(size_t size, int *indxp, struct malloc_type *mtp, int domain,
>  	krequests[size >> KMEM_ZSHIFT]++;
>  #endif
>  	va = uma_zalloc_domain(zone, NULL, domain, flags);
> -	if (va != NULL)
> +	if (__predict_true(va != NULL)) {
>  		size = zone->uz_size;
> +		malloc_type_zone_allocated(mtp, size, indx);
> +	}
>  	*indxp = indx;
>  
>  	return ((void *) va);
> @@ -699,7 +701,8 @@ malloc_domainset(size_t size, struct malloc_type *mtp, struct domainset *ds,
>  			ret = malloc_domain(size, &indx, mtp, domain, flags);
>  		} while (ret == NULL &&
>  		    vm_domainset_iter_policy(&di, &domain) == 0);
> -		malloc_type_zone_allocated(mtp, ret == NULL ? 0 : size, indx);
> +		if (__predict_false(ret == NULL))
> +			malloc_type_zone_allocated(mtp, 0, indx);
>  	} else {
>  		/* Policy is handled by kmem. */
>  		ret = malloc_large(&size, ds, flags);

> _______________________________________________
> freebsd-current at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org"



More information about the freebsd-current mailing list