Estimating total memory usage in any Linux system
Pintu Agarwal
pintu.ping at gmail.com
Wed May 20 00:56:50 EDT 2020
On Wed, 20 May 2020 at 09:31, Valdis Klētnieks <valdis.kletnieks at vt.edu> 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 ?
Thanks,
Pintu
More information about the Kernelnewbies
mailing list