aboutsummaryrefslogtreecommitdiff
path: root/lib/libmemstat
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2020-11-06 21:33:59 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2020-11-06 21:33:59 +0000
commitbdcc2226441ed191f614ed854f6ea7cb06986cd2 (patch)
tree3a11e336ea855d9c76b61e52874a8f708f4f0b8f /lib/libmemstat
parent0244378f43a60cf7f52154014c2f64c34e2c77ad (diff)
downloadsrc-bdcc2226441ed191f614ed854f6ea7cb06986cd2.tar.gz
src-bdcc2226441ed191f614ed854f6ea7cb06986cd2.zip
malloc: move malloc_type_internal into malloc_type
According to code comments the original motivation was to allow for malloc_type_internal changes without ABI breakage. This can be trivially accomplished by providing spare fields and versioning the struct, as implemented in the patch below. The upshots are one less memory indirection on each alloc and disappearance of mt_zone. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D27104
Notes
Notes: svn path=/head/; revision=367432
Diffstat (limited to 'lib/libmemstat')
-rw-r--r--lib/libmemstat/memstat_malloc.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/libmemstat/memstat_malloc.c b/lib/libmemstat/memstat_malloc.c
index 63e72105ef7a..6b8fe49ca333 100644
--- a/lib/libmemstat/memstat_malloc.c
+++ b/lib/libmemstat/memstat_malloc.c
@@ -317,7 +317,7 @@ memstat_kvm_malloc(struct memory_type_list *list, void *kvm_handle)
int hint_dontsearch, j, mp_maxcpus, mp_ncpus, ret;
char name[MEMTYPE_MAXNAME];
struct malloc_type_stats mts;
- struct malloc_type_internal mti, *mtip;
+ struct malloc_type_internal *mtip;
struct malloc_type type, *typep;
kvm_t *kvm;
@@ -372,18 +372,17 @@ memstat_kvm_malloc(struct memory_type_list *list, void *kvm_handle)
list->mtl_error = ret;
return (-1);
}
+ if (type.ks_version != M_VERSION) {
+ warnx("type %s with unsupported version %lu; skipped",
+ name, type.ks_version);
+ continue;
+ }
/*
* Since our compile-time value for MAXCPU may differ from the
* kernel's, we populate our own array.
*/
- mtip = type.ks_handle;
- ret = kread(kvm, mtip, &mti, sizeof(mti), 0);
- if (ret != 0) {
- _memstat_mtl_empty(list);
- list->mtl_error = ret;
- return (-1);
- }
+ mtip = &type.ks_mti;
if (hint_dontsearch == 0) {
mtp = memstat_mtl_find(list, ALLOCATOR_MALLOC, name);
@@ -404,7 +403,7 @@ memstat_kvm_malloc(struct memory_type_list *list, void *kvm_handle)
*/
_memstat_mt_reset_stats(mtp, mp_maxcpus);
for (j = 0; j < mp_ncpus; j++) {
- ret = kread_zpcpu(kvm, (u_long)mti.mti_stats, &mts,
+ ret = kread_zpcpu(kvm, (u_long)mtip->mti_stats, &mts,
sizeof(mts), j);
if (ret != 0) {
_memstat_mtl_empty(list);