From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E46CC43387 for ; Thu, 10 Jan 2019 13:52:28 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D52820879 for ; Thu, 10 Jan 2019 13:52:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SYZmf4dP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D52820879 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.91) (envelope-from ) id 1ghakZ-0007vT-Ub; Thu, 10 Jan 2019 08:51:59 -0500 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1ghakW-0007vM-RY for kernelnewbies@kernelnewbies.org; Thu, 10 Jan 2019 08:51:56 -0500 Received: by mail-ed1-x542.google.com with SMTP id f9so10230940eds.10 for ; Thu, 10 Jan 2019 05:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Nq8dXVSqD8DOxUtgvcaO24I23jZPOa3lHsn4/vW7GDI=; b=SYZmf4dPge2uSEDyGpbGb7XyJbAByTBfAyvlRhbFYgzWAwZp2WVRZ0QvF+lkyvGDeI NsNn5Sx4/GOTbIqOEA9lSBtFYF0CYlTEWKqBaaNSWh9V2w7o4lEAsgxPtHaXWiuuXnEd 4t3nQK+cfIpLDQlepp6DRFcmRXQYg937Dkf7BL6sPbQIXzNDoiAqdf4Ee9sif63vYQNn lHpB4zEkoEn7U20ZKgfbcYFo1uw0rdnommQqlHl8wtXEogmezdSGvE/XxmgT7jBnk9OL 8Uh/rZ2xG4S4Z8R8HADu1v3qI0V0iriWGfB3KHs75JNkqdXXvij7oYPGjgNubgHwDima bFwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Nq8dXVSqD8DOxUtgvcaO24I23jZPOa3lHsn4/vW7GDI=; b=NyBoeeTuFsyq74+foZTQPEZmsKqrLWW7YwCxWN9k05zGfE03AbXs77i48haK3MBcB/ qiR8B2D8b68T5ZAEJt4nmIbjV8+XB4jUQyw5crFyNC7xUOML5/ppUcWbhvXJDoxOvQnD gv7WQ/jN51arfbWKpEBVzdECzdFM0sygiYY+0zaSSaPrdCujGW+5uskpfHHrYbtXCbH6 KCF9U9hxjplL9Zg/kbm+bo/Xaap/NPMVecz3A9tYFqaCuzJvVhVKPnbNkAa48rqCQXlS B+VqjnT7cuPmHhf6CMC8zFQ4RZtC3STlXI+V+Dg43fgbly4XfeRZZkI/DcRivJKT2MP4 dK/g== X-Gm-Message-State: AJcUukeHKk371axutD1M0Mri0eumPOvBO2aga7NUBPdVP5r4IB6ehdw2 BTp5zPxlEnZqctloBCFXZwa8XWVkuIg9OCfodHs= X-Google-Smtp-Source: ALg8bN5ELm8zw65OnRyUHDR2QAl89L7rJ9lhsC0TMLvSo2kOE5Q9q34nUTFiiUJ+N2/XyVHWNRwPHdMLYhNV7PM7SNU= X-Received: by 2002:a50:de88:: with SMTP id c8mr9700406edl.129.1547128314011; Thu, 10 Jan 2019 05:51:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Carter Cheng Date: Thu, 10 Jan 2019 21:51:44 +0800 Message-ID: Subject: Re: where to find the kmalloc implementation To: Okash Khawaja Cc: kernelnewbies X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============8758555745965212223==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============8758555745965212223== Content-Type: multipart/alternative; boundary="000000000000942633057f1ae114" --000000000000942633057f1ae114 Content-Type: text/plain; charset="UTF-8" Thanks! On Thu, Jan 10, 2019 at 12:51 AM Okash Khawaja wrote: > On Wed, Jan 9, 2019 at 3:17 PM Carter Cheng 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 > --000000000000942633057f1ae114 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks!=C2=A0

On Thu, Jan 10, 2019 at 12:51 AM Okash Khawaja <okash.khawaja@gmail.com> wrote:
<= /div>
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 impl= ementation? 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<= br> 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&= quot;
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
> K= ernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/m= ailman/listinfo/kernelnewbies
--000000000000942633057f1ae114-- --===============8758555745965212223== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============8758555745965212223==--