diff options
author | harti <harti@FreeBSD.org> | 2003-07-18 16:04:36 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2003-07-18 16:04:36 +0000 |
commit | de9698a4f74f4eda820744c0fbf7f6b1d2856ded (patch) | |
tree | 32bacb13d8ba87886ad4b4286506d1ee13cd305e /sys | |
parent | cfce6c2d5ef6123e0fee1278046c0fa82f71da7b (diff) | |
download | FreeBSD-src-de9698a4f74f4eda820744c0fbf7f6b1d2856ded.zip FreeBSD-src-de9698a4f74f4eda820744c0fbf7f6b1d2856ded.tar.gz |
When INVARIANTS is defined make sure that uma_zalloc_arg (and hence
uma_zalloc) is called with exactly one of either M_WAITOK or M_NOWAIT and
that it is called with neither M_TRYWAIT or M_DONTWAIT. Print a warning
if anything is wrong. Default to M_WAITOK of no flag is given. This is the
same test as in malloc(9).
Diffstat (limited to 'sys')
-rw-r--r-- | sys/vm/uma_core.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c index fba9474..d887f3c 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include <sys/proc.h> #include <sys/smp.h> #include <sys/vmmeter.h> +#include <sys/mbuf.h> #include <vm/vm.h> #include <vm/vm_object.h> @@ -1320,6 +1321,25 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags) printf("Allocating one item from %s(%p)\n", zone->uz_name, zone); #endif +#ifdef INVARIANTS + /* + * To make sure that WAITOK or NOWAIT is set, but not more than + * one, and check against the API botches that are common. + * The uma code implies M_WAITOK if M_NOWAIT is not set, so + * we default to waiting if none of the flags is set. + */ + cpu = flags & (M_WAITOK | M_NOWAIT | M_DONTWAIT | M_TRYWAIT); + if (cpu != M_NOWAIT && cpu != M_WAITOK) { + static struct timeval lasterr; + static int curerr, once; + if (once == 0 && ppsratecheck(&lasterr, &curerr, 1)) { + printf("Bad uma_zalloc flags: %x\n", cpu); + backtrace(); + once++; + } + } +#endif + if (!(flags & M_NOWAIT)) { KASSERT(curthread->td_intr_nesting_level == 0, ("malloc(M_WAITOK) in interrupt context")); |