Kernel Newbies archive on lore.kernel.org
 help / 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 --]

<div dir="ltr">Hi,<div><br></div><div>I am curious where in the kernel sources would I find the kmalloc implementation? I am curious how GFP_ATOMIC option is implemented.</div><div><br></div><div>Thanks,</div><div><br></div><div>Carter.</div></div>

[-- 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 --]

<div dir="ltr">Thanks! <br></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 10, 2019 at 12:51 AM Okash Khawaja &lt;<a href="mailto:okash.khawaja@gmail.com">okash.khawaja@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Jan 9, 2019 at 3:17 PM Carter Cheng &lt;<a href="mailto:cartercheng@gmail.com" target="_blank">cartercheng@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; I am curious where in the kernel sources would I find the kmalloc implementation? I am curious how GFP_ATOMIC option is implemented.<br>
&gt;<br>
&gt; Thanks,<br>
&gt;<br>
&gt; Carter.<br>
<br>
Hi Carter,<br>
<br>
kmalloc() implementation can be found in include/linux/slab.h.<br>
Interesting part of kmalloc() is the use of kmem_cache. kmem_cache is<br>
basically a pool of memory. kmalloc() maintains a system of<br>
kmem_cache&#39;s and allocates memory from those caches to the caller. How<br>
it allocates that memory is determined by type of request (e.g.<br>
GFP_ATOMIC) and &quot;buddy system&quot; algorithm, which is an algorithm<br>
designed to minimise fragmentation and be cache efficient.<br>
<br>
From what I remember, kmalloc system sets aside memory for &quot;emergency&quot;<br>
uses, like kmalloc calls with GFP_ATOMIC. So for normal memory<br>
allocation calls, execution may sleep until memory becomes available,<br>
even though there may be memory available in the emergence cache.<br>
<br>
Hope it helps :)<br>
<br>
Okash<br>
<br>
&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div>

[-- 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, back to index

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

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox