Index: share/man/man9/malloc.9 =================================================================== RCS file: /space2/ncvs/src/share/man/man9/malloc.9,v retrieving revision 1.36 diff -u -p -r1.36 malloc.9 --- share/man/man9/malloc.9 8 Sep 2003 19:57:21 -0000 1.36 +++ share/man/man9/malloc.9 2 Feb 2004 19:50:27 -0000 @@ -173,6 +173,9 @@ functions cannot return .Dv NULL if .Dv M_WAITOK +is specified, +unless +.Dv M_SAFE is specified. .It Dv M_USE_RESERVE Indicates that the system can dig into its reserve in order to obtain the @@ -182,6 +185,16 @@ This option used to be called but has been renamed to something more obvious. This option has been deprecated and is slowly being removed from the kernel, and so should not be used with any new programming. +.It Dv M_SAFE +Indicates that the system must not panic if it is being asked too much memory. +In such a case, +.Fn malloc +will return +.Dv NULL +instead. +This is only relevant if +.Dv M_WAITOK +is specified. .El .Pp Exactly one of either Index: sys/vm/vm_kern.c =================================================================== RCS file: /space2/ncvs/src/sys/vm/vm_kern.c,v retrieving revision 1.112 diff -u -p -r1.112 vm_kern.c --- sys/vm/vm_kern.c 10 Jan 2004 00:22:33 -0000 1.112 +++ sys/vm/vm_kern.c 2 Feb 2004 20:14:39 -0000 @@ -336,9 +336,9 @@ kmem_malloc(map, size, flags) } return (0); } - if ((flags & M_NOWAIT) == 0) - panic("kmem_malloc(%ld): kmem_map too small: %ld total allocated", - (long)size, (long)map->size); + if (!(flags & M_NOWAIT) && !(flags & M_SAFE)) + panic("kmem_malloc(%ju): kmem_map too small: %ju total " + "allocated", (uintmax_t)size, (uintmax_t)map->size); return (0); } offset = addr - VM_MIN_KERNEL_ADDRESS; Index: sys/sys/malloc.h =================================================================== RCS file: /space2/ncvs/src/sys/sys/malloc.h,v retrieving revision 1.75 diff -u -p -r1.75 malloc.h --- sys/sys/malloc.h 19 Aug 2003 16:41:12 -0000 1.75 +++ sys/sys/malloc.h 2 Feb 2004 18:16:32 -0000 @@ -51,6 +51,7 @@ #define M_ZERO 0x0100 /* bzero the allocation */ #define M_NOVM 0x0200 /* don't ask VM for pages */ #define M_USE_RESERVE 0x0400 /* can alloc out of reserve memory */ +#define M_SAFE 0x0800 /* don't panic if kmem_map too small */ #define M_MAGIC 877983977 /* time when first defined :-) */