Expose real size of UMA allocations via libmemstat(3).

Sponsored by:	Nginx, Inc.
This commit is contained in:
Gleb Smirnoff 2014-02-10 20:09:10 +00:00
parent 49fef6a202
commit 345e3f4dd7
5 changed files with 19 additions and 1 deletions

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd February 25, 2012
.Dd February 11, 2014
.Dt LIBMEMSTAT 3
.Os
.Sh NAME
@ -80,6 +80,8 @@
.Ft uint64_t
.Fn memstat_get_size "const struct memory_type *mtp"
.Ft uint64_t
.Fn memstat_get_rsize "const struct memory_type *mtp"
.Ft uint64_t
.Fn memstat_get_memalloced "const struct memory_type *mtp"
.Ft uint64_t
.Fn memstat_get_memfreed "const struct memory_type *mtp"
@ -287,6 +289,11 @@ If the memory type supports variable allocation sizes, return a bitmask of
sizes allocated for the memory type.
.It Fn memstat_get_size
If the memory type supports a fixed allocation size, return that size.
.It Fn memstat_get_rsize
If the memory type supports a fixed allocation size, return real size
of an allocation.
Real size can exceed requested size due to alignment constraints or
implicit padding.
.It Fn memstat_get_memalloced
Return the total number of bytes allocated for the memory type over its
lifetime.

View File

@ -253,6 +253,13 @@ memstat_get_size(const struct memory_type *mtp)
return (mtp->mt_size);
}
uint64_t
memstat_get_rsize(const struct memory_type *mtp)
{
return (mtp->mt_rsize);
}
uint64_t
memstat_get_memalloced(const struct memory_type *mtp)
{

View File

@ -124,6 +124,7 @@ uint64_t memstat_get_countlimit(const struct memory_type *mtp);
uint64_t memstat_get_byteslimit(const struct memory_type *mtp);
uint64_t memstat_get_sizemask(const struct memory_type *mtp);
uint64_t memstat_get_size(const struct memory_type *mtp);
uint64_t memstat_get_rsize(const struct memory_type *mtp);
uint64_t memstat_get_memalloced(const struct memory_type *mtp);
uint64_t memstat_get_memfreed(const struct memory_type *mtp);
uint64_t memstat_get_numallocs(const struct memory_type *mtp);

View File

@ -51,6 +51,7 @@ struct memory_type {
uint64_t mt_byteslimit; /* 0, or maximum bytes. */
uint64_t mt_sizemask; /* malloc: allocated size bitmask. */
uint64_t mt_size; /* uma: size of objects. */
uint64_t mt_rsize; /* uma: real size of objects. */
/*
* Zone or type information that includes all caches and any central

View File

@ -212,6 +212,7 @@ memstat_sysctl_uma(struct memory_type_list *list, int flags)
}
mtp->mt_size = uthp->uth_size;
mtp->mt_rsize = uthp->uth_rsize;
mtp->mt_memalloced = mtp->mt_numallocs * uthp->uth_size;
mtp->mt_memfreed = mtp->mt_numfrees * uthp->uth_size;
mtp->mt_bytes = mtp->mt_memalloced - mtp->mt_memfreed;
@ -435,6 +436,7 @@ memstat_kvm_uma(struct memory_type_list *list, void *kvm_handle)
}
skip_percpu:
mtp->mt_size = kz.uk_size;
mtp->mt_rsize = kz.uk_rsize;
mtp->mt_memalloced = mtp->mt_numallocs * mtp->mt_size;
mtp->mt_memfreed = mtp->mt_numfrees * mtp->mt_size;
mtp->mt_bytes = mtp->mt_memalloced - mtp->mt_memfreed;