kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: Okash Khawaja <okash.khawaja@gmail.com>
To: Carter Cheng <cartercheng@gmail.com>
Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
Subject: Re: where to find the kmalloc implementation
Date: Wed, 9 Jan 2019 16:51:40 +0000	[thread overview]
Message-ID: <CAOtcWM1gBXCXfihsQYxrfAz5B=DAYbRLLkXPZQE=40c4LYu0Zg@mail.gmail.com> (raw)
In-Reply-To: <CALS6=qVH1rHBOSycP2gqpNvoP2r4XX8fFw2L_0pV0km8wZ-1GQ@mail.gmail.com>

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

  reply	other threads:[~2019-01-09 16:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-09 15:16 where to find the kmalloc implementation Carter Cheng
2019-01-09 16:51 ` Okash Khawaja [this message]
2019-01-10 13:51   ` Carter Cheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOtcWM1gBXCXfihsQYxrfAz5B=DAYbRLLkXPZQE=40c4LYu0Zg@mail.gmail.com' \
    --to=okash.khawaja@gmail.com \
    --cc=cartercheng@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).