From andrey.zverev@electro-com.ru  Wed Aug  9 08:39:46 2006
Return-Path: <andrey.zverev@electro-com.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CAF9A16A4E0
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Aug 2006 08:39:46 +0000 (UTC)
	(envelope-from andrey.zverev@electro-com.ru)
Received: from mail.electro-com.ru (mail.electro-com.ru [86.110.161.242])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5B8A143D5C
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Aug 2006 08:39:46 +0000 (GMT)
	(envelope-from andrey.zverev@electro-com.ru)
Received: from az by mail.electro-com.ru with local (Exim 4.63 (FreeBSD))
	(envelope-from <andrey.zverev@electro-com.ru>)
	id 1GAjbM-0002N7-CV
	for FreeBSD-gnats-submit@freebsd.org; Wed, 09 Aug 2006 12:39:44 +0400
Message-Id: <E1GAjbM-0002N7-CV@mail.electro-com.ru>
Date: Wed, 09 Aug 2006 12:39:44 +0400
From: Andrej Zverev <az@freebsd.org>
Sender: Andrej Zverev <andrey.zverev@electro-com.ru>
Reply-To: Andrej Zverev <az@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [panic] kmem_malloc in UMA
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         101689
>Category:       kern
>Synopsis:       [panic] kmem_malloc in UMA
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 09 08:40:13 GMT 2006
>Closed-Date:    Tue Sep 05 20:44:18 GMT 2006
>Last-Modified:  Tue Sep 05 20:47:01 GMT 2006
>Originator:     Andrej Zverev
>Release:        
>Organization:
>Environment:


	
>Description:
	I'm trying to create > 20000 vlan interfaces.
	#!/usr/bin/perl

	for ($i=0; $i<20000; $i++)
	{
		system ("ifconfig vlan$i create");
		system ("ifconfig vlan$i vlan 10 vlandev rl0 10.10.10.10/24");
	}

	and then system out of memory, panic happens, but it's not right.
	Trace of panic attached, if i can provide extra detail, just ask

	
>How-To-Repeat:
	
>Fix:

	

--- trace.txt begins here ---
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd".

Unread portion of the kernel message buffer:
panic: kmem_malloc(4096): kmem_map too small: 83427328 total allocated
Uptime: 16m43s
Dumping 255 MB (2 chunks)
  chunk 0: 1MB (160 pages) ... ok
  chunk 1: 255MB (65264 pages) 239 223 207 191 175 159 143 127 111 95 79 63 47 31 15

#0  doadump () at pcpu.h:165
165		__asm __volatile("movl %%fs:0,%0" : "=r" (td));
(kgdb) 
(kgdb) f 1
#1  0xc064dee1 in boot (howto=260) at ../../../kern/kern_shutdown.c:402
402			doadump();
(kgdb) f 2
#2  0xc064e178 in panic (
    fmt=0xc08bb065 "kmem_malloc(%ld): kmem_map too small: %ld total allocated") at ../../../kern/kern_shutdown.c:558
558		boot(bootopt);
(kgdb) f 3
#3  0xc07bc41d in kmem_malloc (map=0xc14430c0, size=4096, flags=2)
    at ../../../vm/vm_kern.c:299
299				panic("kmem_malloc(%ld): kmem_map too small: %ld total allocated",
(kgdb) f 4
#4  0xc07b3cea in page_alloc (zone=0xc144d780, bytes=4096, pflag=0x0, wait=2)
    at ../../../vm/uma_core.c:958
958		p = (void *) kmem_malloc(kmem_map, bytes, wait);
(kgdb) f 5
#5  0xc07b3821 in slab_zalloc (zone=0xc144d780, wait=2)
    at ../../../vm/uma_core.c:823
823		mem = keg->uk_allocf(zone, keg->uk_ppera * UMA_SLAB_SIZE,
(kgdb) f 6
#6  0xc07b4fc0 in uma_zone_slab (zone=0xc144d780, flags=2)
    at ../../../vm/uma_core.c:2025
2025			slab = slab_zalloc(zone, flags);
(kgdb) f 7
#7  0xc07b51dc in uma_zalloc_bucket (zone=0xc144d780, flags=2)
    at ../../../vm/uma_core.c:2134
2134			flags |= M_NOWAIT;
(kgdb) f 8
#8  0xc07b4e51 in uma_zalloc_arg (zone=0xc144d780, udata=0x0, flags=2)
    at ../../../vm/uma_core.c:1942
1942		if (uma_zalloc_bucket(zone, flags)) {
(kgdb) f 9
#9  0xc06437d2 in malloc (size=32, mtp=0xc091c280, flags=2) at uma.h:275
275		return uma_zalloc_arg(zone, NULL, flags);
(kgdb) f 10
#10 0xc066fb4a in ioctl (td=0xc27c9600, uap=0xd0e40d04)
    at ../../../kern/sys_generic.c:580
580			memp = malloc((u_long)size, M_IOCTLOPS, M_WAITOK);
(kgdb) f 11
#11 0xc084211b in syscall (frame=
      {tf_fs = 59, tf_es = 59, tf_ds = 59, tf_edi = 134581856, tf_esi = -1077940715, tf_ebp = -1077943160, tf_isp = -790360732, tf_ebx = 3, tf_edx = 9, tf_ecx = 7, tf_eax = 54, tf_trapno = 12, tf_err = 2, tf_eip = 672405375, tf_cs = 51, tf_eflags = 642, tf_esp = -1077943188, tf_ss = 59})
    at ../../../i386/i386/trap.c:979
979			PTRACESTOP_SC(p, td, S_PT_SCE);
(kgdb) f 12
#12 0xc0830d5f in Xint0x80_syscall () at ../../../i386/i386/exception.s:194
194		movl	$KDSEL,%eax		/* switch to kernel segments */
Current language:  auto; currently asm
(kgdb) f 13
#13 0x00000033 in ?? ()
(kgdb) quit
--- trace.txt ends here ---


>Release-Note:
>Audit-Trail:

From: Kris Kennaway <kris@obsecurity.org>
To: Andrej Zverev <az@FreeBSD.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/101689: [panic] kmem_malloc in UMA
Date: Sat, 19 Aug 2006 16:17:54 -0400

 Your ran your kernel out of memory.  Try to tune VM_KMEM_SIZE_MAX in
 your kernel, e.g. on my heavily loaded servers I use:
 
 options         VM_KMEM_SIZE_MAX=419430400      #400MB
 
 Kris
State-Changed-From-To: open->closed 
State-Changed-By: az 
State-Changed-When: Tue Sep 5 20:44:17 UTC 2006 
State-Changed-Why:  
Close PR, since a had good explanation from Ruslan Ermilov (ru@) and good 
hint from Kris. From Ruslan explanation i understand what we can choose
perfomance or panic, in this case better panic when out of kmem for me.
But it's will be nice someday to saw solution where i god "no more kmem for you"
instead kpanic. Now i don't see reasons to hold this PR open.

http://www.freebsd.org/cgi/query-pr.cgi?pr=101689 
>Unformatted:
