Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Jan 2020 12:58:28 +0100
From:      Hans Petter Selasky <hps@selasky.org>
To:        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:  <100f4e72-ef8b-07dc-b1e1-2a3ef4853d31@selasky.org>
In-Reply-To: <f0c4c466-c20f-8824-0138-6b5d45004256@selasky.org>
References:  <4164.1578563950@critter.freebsd.dk> <4e52b23e-32ed-6556-a74e-22c809a17fe0@selasky.org> <f0c4c466-c20f-8824-0138-6b5d45004256@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------3C8BFF9F6C786E18FE56DE12
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

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".

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

See attached patch.

--HPS

--------------3C8BFF9F6C786E18FE56DE12
Content-Type: text/x-patch; charset=UTF-8;
 name="domainset.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="domainset.diff"

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);

--------------3C8BFF9F6C786E18FE56DE12--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?100f4e72-ef8b-07dc-b1e1-2a3ef4853d31>