# Kernel Panic: Kmem_malloc(110592): kmem_map too small



## ac1115 (Feb 1, 2011)

Hello all,

I'm a Linux/Solaris convert here trying out BSD for the first time.  I've a file server I'm trying to get setup with ZFS on root.  I followed this guide  https://www.dan.me.uk/blog/2010/02/08/booting-from-zfs-raid0156-in-freebsd/

Install went fine without any issues and I began the work of setting up services and restoring data from backups.  However 30 minutes later I got that lovely kernel panic in the subject.  A quick search told me ZFS uses a lot of kernel memory and I can allocate more by changing loader.conf.  I've 8GB memory total in this box so I went ahead and gave the kernel 2gb of memory, thinking that'll solve it for good.

```
vm.kmem_size_max="2040M"
vm.kmem_size="2048M"
vm.zfs.arc_max="512M"
```

Restarted and I began the work of moving over data, but 8 hours later I get this.

```
Kernel Panic: Kmem_malloc(110592): kmem_map too small: 2180715000
```
So, the kernel went through all 2g of allocated memory! 

Now, I could allocate even more, but I've the feeling there is a leak and all I'll get is just more time before the next crash.
I really do want to stick with FreeBSD, any suggestions?  

I'm running 8.1 release 64bit.


----------



## da1 (Feb 1, 2011)

Are you moving the data from an UFS FS ?


----------



## ac1115 (Feb 1, 2011)

No, from ext4. However I'm copying it over through NFS from the backup box.


----------



## phoenix (Feb 1, 2011)

If this is the 64-bit version of FreeBSD, don't meddle with *vm.kmem_size_max* and set *vm.kmem_size* to 1.5x RAM.  In your case, set it to 12 GB.

Then set *vfs.zfs.arc_max* to somewhere around half of your RAM, depending on what else you will be running on that box.

This really is a FAQ, and searching the forums will bring up many threads on this issue.  As will searching the FreeBSD mailing lists.


----------



## ac1115 (Feb 1, 2011)

yes this is the 64bit version.  This is a strictly a file serving box. AFP, SMB, NFS.  

I removed the max line and upped the kmem_size to 12288M (12gb).  I also set the arc max is 4096m.

We'll see how it goes. Thanks.


----------



## phoenix (Feb 1, 2011)

If you will be doing a lot of NFS traffic, you will want to invest in a pair of fast (write-optimised) SSDs to use as a separate log (SLOG aka ZIL) device.  It has to be mirrored if you are using ZFSv18 or older as the loss of a log device will cause the entire pool to be unimportable (ie, total data loss).  Using ZFSv19 or newer allows you to recover from the loss of a log device, so it doesn't need to be mirrored.

NFS does a lot of sync writes.  Each sync write is written to the ZIL in ZFS (the "journal"), the write is marked as complete, and then later on, the data is actually written out to the pool and removed from the ZIL.  If the ZIL is part of the pool (the default; no separate log device), performance will suffer.

There's lots of information regarding ZIL/log devices in the freebsd-fs mailing list archives, the zfs-discuss mailing list archives, and the forums.


----------



## romanr (Apr 4, 2013)

*panic: kmem_malloc(4096): kmem_map too small: 38055936 total allcated*

9.1-RELEASE, i386, 128MB RAM. Panic on excessive filesystem writes, sysctls are set to defaults.







On 256MB RAM it seems to run fine. Is there a way to make it run on 128MB RAM?


----------



## romanr (Apr 5, 2013)

*kmem_map too small, 128MB RAM, 9.1-RELEASE*

The problem was solved by specifying the vm.kmem_size_scale=1 sysctl in the /boot/loader.conf (the default is *3*). Actually it needed just several MB RAM extra, about 9MB exactly, so vm.kmem_size_scale=2 should work too.


----------



## Tomse (Apr 25, 2013)

I hope this works for me too. *H*aving problems on 9.1 i386, 1.5GB RAM, reading from NTFS filesystem, a simple `ls -R | wc -l` in the root of the NTFS disk was enough to crash the server.


----------

