kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* where to find the kmalloc implementation
@ 2019-01-09 15:16 Carter Cheng
  2019-01-09 16:51 ` Okash Khawaja
  0 siblings, 1 reply; 3+ messages in thread
From: Carter Cheng @ 2019-01-09 15:16 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 156 bytes --]

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.

[-- Attachment #1.2: Type: text/html, Size: 249 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: where to find the kmalloc implementation
  2019-01-09 15:16 where to find the kmalloc implementation Carter Cheng
@ 2019-01-09 16:51 ` Okash Khawaja
  2019-01-10 13:51   ` Carter Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Okash Khawaja @ 2019-01-09 16:51 UTC (permalink / raw)
  To: Carter Cheng; +Cc: kernelnewbies

On Wed, Jan 9, 2019 at 3:17 PM Carter Cheng <cartercheng@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@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: where to find the kmalloc implementation
  2019-01-09 16:51 ` Okash Khawaja
@ 2019-01-10 13:51   ` Carter Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Carter Cheng @ 2019-01-10 13:51 UTC (permalink / raw)
  To: Okash Khawaja; +Cc: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1337 bytes --]

Thanks!

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

> On Wed, Jan 9, 2019 at 3:17 PM Carter Cheng <cartercheng@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@kernelnewbies.org
> > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

[-- Attachment #1.2: Type: text/html, Size: 2012 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-10 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-09 15:16 where to find the kmalloc implementation Carter Cheng
2019-01-09 16:51 ` Okash Khawaja
2019-01-10 13:51   ` Carter Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).