? malloc_make_failures.diff ? maxim_chroot.diff ? vfs_mount.c.rootdev.diff Index: kern_malloc.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_malloc.c,v retrieving revision 1.119 diff -u -r1.119 kern_malloc.c --- kern_malloc.c 10 Mar 2003 20:24:54 -0000 1.119 +++ kern_malloc.c 26 Mar 2003 19:27:28 -0000 @@ -138,6 +138,20 @@ /* time_uptime of last malloc(9) failure */ static time_t t_malloc_fail; +#ifdef MALLOC_MAKE_FAILURES +/* + * Cause malloc failures ever (n) mallocs with M_NOWAIT. If set to 0, + * don't cause failures. + */ +static int malloc_failure_rate; +static int malloc_nowait_count; +static int malloc_failure_count; +SYSCTL_INT(_debug, OID_AUTO, malloc_failure_rate, CTLFLAG_RW, + &malloc_failure_rate, 0, "Every (n) mallocs with M_NOWAIT will fail"); +SYSCTL_INT(_debug, OID_AUTO, malloc_failure_count, CTLFLAG_RD, + &malloc_failure_count, 0, "Number of imposed malloc failures"); +#endif + int malloc_last_fail(void) { @@ -187,6 +201,15 @@ #if 0 if (size == 0) Debugger("zero size malloc"); +#endif +#ifdef MALLOC_MAKE_FAILURES + if ((flags & M_NOWAIT) && (malloc_failure_rate != 0)) { + atomic_add_int(&malloc_nowait_count, 1); + if ((malloc_nowait_count % malloc_failure_rate) == 0) { + atomic_add_int(&malloc_failure_count, 1); + return (NULL); + } + } #endif if (flags & M_WAITOK) KASSERT(curthread->td_intr_nesting_level == 0,