where to find the kmalloc implementation

Carter Cheng cartercheng at gmail.com
Thu Jan 10 08:51:44 EST 2019


Thanks!

On Thu, Jan 10, 2019 at 12:51 AM Okash Khawaja <okash.khawaja at gmail.com>
wrote:

> On Wed, Jan 9, 2019 at 3:17 PM Carter Cheng <cartercheng at gmail.com> wrote:
> >
> > Hi,
> >
> > I am curious where in the kernel sources would I find the kmalloc
> implementation? I am curious how GFP_ATOMIC option is implemented.
> >
> > Thanks,
> >
> > Carter.
>
> Hi Carter,
>
> kmalloc() implementation can be found in include/linux/slab.h.
> Interesting part of kmalloc() is the use of kmem_cache. kmem_cache is
> basically a pool of memory. kmalloc() maintains a system of
> kmem_cache's and allocates memory from those caches to the caller. How
> it allocates that memory is determined by type of request (e.g.
> GFP_ATOMIC) and "buddy system" algorithm, which is an algorithm
> designed to minimise fragmentation and be cache efficient.
>
> From what I remember, kmalloc system sets aside memory for "emergency"
> uses, like kmalloc calls with GFP_ATOMIC. So for normal memory
> allocation calls, execution may sleep until memory becomes available,
> even though there may be memory available in the emergence cache.
>
> Hope it helps :)
>
> Okash
>
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20190110/13383b31/attachment.html>


More information about the Kernelnewbies mailing list