Yagnavarahan wrote:
-----Original Message-----
From: kernelnewbies-bounce@xxxxxxxxxxxx
[mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Gaurav Dhiman
Sent: Monday, August 29, 2005 12:04 PM
To: kernelnewbies
Subject: query related to kmalloc()
Hi,
Just wanted to know, is it a good idea to kmalloc for a small structure.
For example if I define a structure in kernel of 10 bytes, and I want to get
the memory allocated
dynamically for it N number of times, is it good to kmalloc for it every
time.
I'm no kernel expert, but probably you could allocate some pages (if you
know the maximum you might need) using kmalloc and then write your own
allocator to allocate memory from this pool in desired sizes. That way there
is only one call to kmalloc.
Thanks,
YV
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/
Hi,
This would be unnecessary... just use the slab allocator. However, if
you feel you will need a minimum of 'n' objects and *cannot* afford to
have the allocation for these fail, then you may want to use mempools.
There is a nice treatment of mempools in Linux Device Drivers 3rd ed. by
Rubini et al.
thanks
rahul
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/