Kernel Newbies archive on
 help / color / Atom feed
From: Pintu Agarwal <>
To: "Valdis Klētnieks" <>
Cc: linux-mm <>,
	Kernelnewbies <>
Subject: Re: Estimating total memory usage in any Linux system
Date: Wed, 20 May 2020 10:26:50 +0530
Message-ID: <> (raw)
In-Reply-To: <21691.1589947282@turing-police>

On Wed, 20 May 2020 at 09:31, Valdis Klētnieks <> wrote:
> On Tue, 19 May 2020 22:33:15 +0530, Pintu Agarwal said:
> > > 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
> That's a kernel from 2014.  You don't seriously expect us to remember how
> all those counters worked back then, do you?
Actually I don't care about the kernel version. This was just for reference.
I know it is weird to manually arrive a MemTotal from the values of meminfo.
But I am actually looking for general formula.
I could get some of the answers by tracing the kernel code for each counters.
But still there are some gaps which I want to clarify.
As I see there are several ways to total it: i.e; (PSS way), (Buffers,
Cached), (Active, Inactive)
According to me,
MemTotal = MemFree + Active + Inactive  + SwapCached + Mapped + Shmem
+ Slab + KernelStack + PageTables + (Init Freed from boot) + (alloc
pages) + (min_free_bytes + user_reserve_bytes)
Did I miss anything here ?

With this I could arrive to some result, but I have some doubts:
* Is Mapped already included in Active/Inactive (file) ? Because
mapped is coming from NR_FILE_MAPPED.
  ==> I see that it is accounted from mm/rmap.c
* Do we also need to incude VmallocUsed here ? I see in some cases
people include it too.
  ==> But I think vmalloc internally calls kmalloc and use page
tables, so it should be already accounted in Slab and PageTables ??
  ==> Do I still need to include these values from /proc/vmallocinfo ??
* Is it valid to include min_free_kbytes and user_reserve_kbytes here
? Its kind of reserve for internal purpose but still it contributes to
the total.
* Is kernel internal allocation (alloc_pages) statistics accounted somewhere ?
  ==> I can see that some counters like (pgalloc_normal, etc. and
pgfree) are available as part of /proc/vmstat
  ===> But this is like overall allocation and free stats.
* Apart from these, do we also need to consider Graphics/3D allocation
separately ?


Kernelnewbies mailing list

  reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-18 17:57 Pintu Agarwal
2020-05-19 17:03 ` Pintu Agarwal
2020-05-20  4:01   ` Valdis Klētnieks
2020-05-20  4:56     ` Pintu Agarwal [this message]
2020-05-20  5:32       ` Valdis Klētnieks
2020-05-20  6:11         ` Pintu Agarwal

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:

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

  git send-email \
    --in-reply-to='' \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Kernel Newbies archive on

Archives are clonable:
	git clone --mirror 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/ \
	public-inbox-index kernelnewbies

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone