Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Jan 2020 10:16:48 -0500
From:      Mark Johnston <markj@freebsd.org>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        Poul-Henning Kamp <phk@phk.freebsd.dk>, current@freebsd.org, Jeff Roberson <jeff@freebsd.org>, Konstantin Belousov <kib@freebsd.org>
Subject:   Re: M_TEMP trouble in 13.0-CURRENT #0 r355131M
Message-ID:  <20200109151648.GA1953@raichu>
In-Reply-To: <100f4e72-ef8b-07dc-b1e1-2a3ef4853d31@selasky.org>
References:  <4164.1578563950@critter.freebsd.dk> <4e52b23e-32ed-6556-a74e-22c809a17fe0@selasky.org> <f0c4c466-c20f-8824-0138-6b5d45004256@selasky.org> <100f4e72-ef8b-07dc-b1e1-2a3ef4853d31@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200109151648.GA1953>