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,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 952BFC43387 for ; Wed, 9 Jan 2019 16:53:23 +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 3EB2A206BA for ; Wed, 9 Jan 2019 16:53:23 +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="gFf+7r/E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EB2A206BA 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 1ghH6A-000207-Ra; Wed, 09 Jan 2019 11:52:58 -0500 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]) by shelob.surriel.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1ghH67-000200-3K for kernelnewbies@kernelnewbies.org; Wed, 09 Jan 2019 11:52:55 -0500 Received: by mail-oi1-x244.google.com with SMTP id y1so6811909oie.12 for ; Wed, 09 Jan 2019 08:52:54 -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=GtjfOiSHCb9/V8OSrY+fE4XpTI9jUBbl8q7/q1RXSOo=; b=gFf+7r/Eslw9TSRMgRYmHGkv7JSoV9Bjv6Z/kLwnuA+uwLZKUVWwhjaRkDc934qGuJ sB2jyR3VkydRjjMM6jLUFQm1ouIOj9rcuCvI6rkErkDFCoGjkgV+yIDeC9KgT+wP6raW 0X6SbhXVug7z7//99ZNOFNazlKEvJpcPehmTvqGGClufZOjTHYCBXOwTKblq1Qg/tarN K1/JX0BOCBsU4fbXjwonwM+WGSJby5FxdPx5HEZ6yFcHLX2lSlLbdZafF851ouGv6nj1 6Cs3Qd5rMKiJm6XdQV650zcSo5jzAIis3kQ0Yg2ABuv12kxwbdw/2BymMOvL17HW0Ovv PmFw== 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=GtjfOiSHCb9/V8OSrY+fE4XpTI9jUBbl8q7/q1RXSOo=; b=LrAOzfsrFTN49OXgQmMMtjwEmNpu4tNyNdVLAs50NY//FryROCy+I4+uKt1FPuoadG t9DZk6Ob349VxGPc8zTm1BRfGrhtCa7uKQU3wh08FjUSwxpzEgOHEJfqdXatFrnkcokC tmYEK68P8YPvCmyLhaZMKqFE3cLhy1wuqjnN/quRQJJiQ9WCjxEou3Qm+Uh5PVXKT9T4 6QatV3E5vN4QF7YGSRKQ7ca0YfUrtHx/heFeH/VKV0PKeSSY8hgzpPjWegFuW7tGFzoa dUo/FcEnKpjCyNAnA0T1hujA4C6q2xB1VPiZAfAMFnKKjZ3oJwIt/9quabvjjNj6P+cv xvvA== X-Gm-Message-State: AJcUukdEpPS7Znwm168SKQ1rwD8wtm2+z4614MrDaElF/jvodK5qphI5 NpfL2V1gTFrYDLkHO7UU7MQgtOaBJ1Fg6xpnaEc= X-Google-Smtp-Source: ALg8bN5whS6z8wj2VkWJY96A3L+Cb6b8W4tiI2qUfdxAxBoPo484kOoUKUT4fofS9Y163YjirdEGBAmbaR+75C0msbs= X-Received: by 2002:aca:d8c1:: with SMTP id p184mr4463736oig.22.1547052712734; Wed, 09 Jan 2019 08:51:52 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Okash Khawaja Date: Wed, 9 Jan 2019 16:51:40 +0000 Message-ID: Subject: Re: where to find the kmalloc implementation To: Carter Cheng 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: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org 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 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies