[Click] kernel mode click memory allocation

Eddie Kohler kohler at cs.ucla.edu
Sun Sep 12 14:45:11 EDT 2004


Erik VandeKieft wrote:
> Hi,
> 
> I have some Click elements that require a substantial amount of state
> information and thus tend to use up a lot of memory. Beyond a certain
> point I get a kernel panic due to, I assume, a failed memory allocation.
> How does memory allocation work when running Click in the kernel? When in
> kernel mode, does anyone have some suggestions as to the best way to
> figure out exactly how much memory I'm actually using up and how much I
> can expect to get allocated?

Hi Eric,

There are two possibilities, one unlikely and one likely.

The unlikely possibility is that you're just running out of memory.  If this is 
true I don't think there's anything you can do.

The likely possibility is that you're trying to allocate an object larger than 
the maximum size kmalloc() supports.

In Click's kernel module, "operator new" and "operator new[]" -- which are used 
to allocate everything -- are bound to kmalloc().  See lib/glue.cc.  But 
kmalloc()'s general purpose slab allocator has a maximum size that, depending on 
your kernel, can be as small as 131072 bytes.  If you try to allocate a single 
object larger than 131072 bytes -- or, for example, if you grow a Vector so 
large that its array size would be > 131072 bytes -- then "operator new" will 
fail, even though the system has plenty of memory.

Two ways to address this.  The "hack" is to add larger sizes to Linux's 
kmalloc() pool; I think the way to do this is by editing "cache_sizes" in 
Linux's mm/slab.c.  The "non-hack" is to use Linux's page allocator, vmalloc(), 
for large objects.  It would be relatively easy to change the basic Click data 
structures -- Vectors and HashMaps -- to use kmalloc() for small objects and 
vmalloc() for large ones.  We'd accept patches along those lines.  It'd be 
slightly harder to globally change "operator new"/"operator delete" to use 
kmalloc() for small objects and vmalloc() for large ones, because you'd have to 
keep track of the object size for "operator delete".

Eddie


More information about the click mailing list