Re: about kmalloc and kmem_cache_alloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Nov 6, 2010 at 2:09 AM, Rajat Sharma <fs.rajat@xxxxxxxxx> wrote:
>> as i know,kmalloc is based on kmem_cache_alloc ,so what's the different?
> kmalloc uses the generic slab caches available to any kernel code. so your
> module will share slab cache with other components in kernel, but if you
> specifically want a better slab cache management dedicated to your module
> only, that too for a specific type of objects, use the lower function i.e.
> kmem_cache_alloc, it will allocate objects from a dedicated slab cache for
> your module objects only, you must create the slab cache by calling
> kmem_cache_create before allocating any object. kmem_cache_create takes
> sizeof your object you want to create slab of, a name which appears in
> /proc/slabinfo and flags to govern behavior of your slab cache.
> Rajat

My two cents to add to the fine comment above, which re probably not
even worth that much, but your getting for free :)

If you are asking this question I would probably guess you should just
stick to kmalloc, that sounds rude, but I say it with all respect.

Unless you are creating your own subsystem(or complex driver) and will
be responsible for allocating a lot of one specific data structure
there is no reason to create your own cache.  Even in the driver case
you will often know ahead of time the number of data structures to
preallocate and just use those in a ring buffer or similar.

--
john

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux