Re: M_TEMP trouble in 13.0-CURRENT #0 r355131M

From: Mark Johnston <markj_at_freebsd.org>
Date: Thu, 9 Jan 2020 10:16:48 -0500
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
> _at__at_ -669,8 +669,10 _at__at_ 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);
> _at__at_ -699,7 +701,8 _at__at_ 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"
Received on Thu Jan 09 2020 - 14:17:00 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:22 UTC