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.4 required=3.0 tests=DKIMWL_BL,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 F3331C433DF for ; Tue, 19 May 2020 17:03:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A528620708 for ; Tue, 19 May 2020 17:03:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="r1SW0/5V" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A528620708 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 37D9A80008; Tue, 19 May 2020 13:03:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28E39900002; Tue, 19 May 2020 13:03:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17D3C80008; Tue, 19 May 2020 13:03:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id EF02E900002 for ; Tue, 19 May 2020 13:03:28 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A2676181AEF1F for ; Tue, 19 May 2020 17:03:28 +0000 (UTC) X-FDA: 76834089696.09.room50_759f449ec8d4f X-HE-Tag: room50_759f449ec8d4f X-Filterd-Recvd-Size: 5909 Received: from mail-vs1-f66.google.com (mail-vs1-f66.google.com [209.85.217.66]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 May 2020 17:03:28 +0000 (UTC) Received: by mail-vs1-f66.google.com with SMTP id u2so4585825vsi.13 for ; Tue, 19 May 2020 10:03:28 -0700 (PDT) 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; bh=POmRUUk7Xuz74mursmskmK0WHU+iSvBpkntW/uXx760=; b=r1SW0/5VYcPeXHaW+kHiMiPeHJOytjS4tXvuPT7ywRO2AtMamwVB0p9rri2PFZRCmO HyGErSVAyI3W+HSahgPhR7lRS+ENbQ5nU2EWbWEjLWVsKpE4P2XEgMoqppdSTdCtQfh6 3/+P+S0GTiHoLWlqnmUkUmMCUfSeYvQqkPhpKeL6T/28XwPZgExw2DYw/ipMpG+Z5cAY Sbgc46XxfLWivNK/iSWUDo+i7lWr7FpLa/frfApuJW0dz2Uz+/e6XPIY9XmX/gjX8h2o 3jqlXbQNpU/cG7KvOr1FRELMDm1hLW6wkXcSeZQBdx7UcnjzrQFZtJXIPT9Im3/ZY4BG sW6Q== 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; bh=POmRUUk7Xuz74mursmskmK0WHU+iSvBpkntW/uXx760=; b=kRvvLoGsb8OTcCuWZ9HvarEgKR44fFPugWgBw/zx41vHQkjMmY4x6TtBotVPEYokWy 7slj1YKyLGC5+5G2OTmIX0VOTFRvBFGP/9ur8BjCjQOTrljWwVZkoD4Q/2tk8eCwBGgH 5e41gMm6y4ojMbihUO3teg6fVwFKBpT2ljkgwfLgAn4UxZJRA4TO/i6L0mFLB+HvcOhV GOvDIoSftBchfH4RkkNxLPRnLKfmfxp0krWOlV5q4n5T25SVRW6jSkUTKsKpXDt65znd MH+XF0KhrUtjoKYFDVmnyf/EoVwT0KQ1n5k3pP7trI5NSkDo1vhqUtZIx0IwLY9CE+nf LriA== X-Gm-Message-State: AOAM531FghgwaVwKuhB0RTSVv/pMWbutVWgS8PL42K5uF72DMuKMB3Bd +fzLrg9k9m4EDDtCt+CXwaDAun6jnSvq1gFklrs= X-Google-Smtp-Source: ABdhPJx07rV70v552E6BS0y7D4LFR7arriZsNB5VGzacmgZPNoSE0sFpEQbvCjTokppNtsP2gXELfNca01YD4xU1NyM= X-Received: by 2002:a67:ee8f:: with SMTP id n15mr83074vsp.196.1589907807271; Tue, 19 May 2020 10:03:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Pintu Agarwal Date: Tue, 19 May 2020 22:33:15 +0530 Message-ID: Subject: Re: Estimating total memory usage in any Linux system To: Kernelnewbies , linux-mm Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 18 May 2020 at 23:27, Pintu Agarwal wrote: > > Hi, > > I was just trying to manually calculate the total memory available in > a system to match up the MemTotal shown in /proc/meminfo > I know "free -m" command will give the vary high level usage, but I > wanted to breakdown the MemTotal numbers to see usage in each > category. > > I am looking for a common formula that should match on almost all systems. > So, I came up with below fields from meminfo to closely match the total. > ~Total = {MemFree + Active + Inactive + Shmem + Mapped + Slab + > KernelStack + PageTables + (init freed) + (Boot Diff) + (low > watermarks)} > > But I am not sure if these fields are correct at least for arm32 system. > In some boards I could able to match up these figures, but some not. > > So I have some doubts: > * Is "Mapped" (NR_MAPPED_PAGES) already part of Active pages ? > * Is Kernel allocation (alloc_pages, etc.) accounted somewhere ? Is it > part of Anon pages ? > * What about vmalloc / ioremap pages ? Do we also need to consider VmallocUsed ? > ==> In my opinion vmalloc internally used kmalloc and page tables, so > I guess it should be already part of Slab or PageTables ?? > > Below are some data taken from a small embedded arm32 device with 512MB RAM: > Sorry, I forgot to mention the kernel version. Here it is 3.18 Kernel > Kernel Boot Logs: > Memory: 99244K/254976K available (10720K kernel code, 1336K rwdata, > 4792K rodata, 400K init, 1602K bss, 135252K reserved, 20480K > cma-reserved) > Total = 99244 + 400 (init) + 20480 (cma) = 120124 > Boot Diff = 121204 - 120124 => 1080 kB > > MemTotal: 121204 kB > MemFree: 2540 kB > MemAvailable: 51924 kB > Buffers: 0 kB > Cached: 47492 kB > SwapCached: 0 kB > Active: 42604 kB > Inactive: 24308 kB > Active(anon): 19476 kB > Inactive(anon): 92 kB > Active(file): 23128 kB > Inactive(file): 24216 kB > Unevictable: 0 kB > Mlocked: 0 kB > SwapTotal: 0 kB > SwapFree: 0 kB > Dirty: 8 kB > Writeback: 0 kB > AnonPages: 19452 kB > Mapped: 12644 kB > Shmem: 148 kB > Slab: 27560 kB > SReclaimable: 7224 kB > SUnreclaim: 20336 kB > KernelStack: 3104 kB > PageTables: 1896 kB > NFS_Unstable: 0 kB > Bounce: 0 kB > WritebackTmp: 0 kB > CommitLimit: 60600 kB > Committed_AS: 1576740 kB > VmallocTotal: 777216 kB > VmallocUsed: 53696 kB > VmallocChunk: 689148 kB > -------------------- > > These are my calculations from the above fields. > --------------------- > MemFree 2540 > Active 42604 > Inactive 24308 > Mapped 12644 > Slab 27560 > KernelStack 3104 > PageTables 1896 > Shmem 148 > init freed 400 > Diff from boot total 1080 > min_free_kbytes 1384 > user_reserve_kbytes 3537 > My Total ==> 121205 (add all the above) > > As you can see "My Total" closely matches with the MemTotal from /proc/meminfo > > But on some systems it does not match. > So, I wanted to understand if there is something wrong in my > calculation, or there is something wrong in the system itself (like > leaks etc,) > > Note: I don't want to use any tools or utilize for these, but I wanted > to manually understand it. > > I am also trying to explore every vm counter that populates these fields. > > But if you have any other opinion about it please let me know. > > > Thanks, > Pintu