How to determine available physical memory on Linux

I am trying to figure out if my software works on linux suffers from memory leak . I tried to measure the available physical memory found in /proc/meminfo (see below), but I could figure out which field represents the available memory and what is the relationship between MemFree, Cached, Buffers, Active, Inactive .

 cat /proc/meminfo MemTotal: 124128 kB MemFree: 62872 kB Buffers: 0 kB Cached: 15624 kB SwapCached: 0 kB Active: 38724 kB Inactive: 11148 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 34272 kB Mapped: 14640 kB Slab: 5564 kB SReclaimable: 424 kB SUnreclaim: 5140 kB PageTables: 504 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 62064 kB Committed_AS: 57936 kB VmallocTotal: 655360 kB VmallocUsed: 1016 kB VmallocChunk: 654328 kB 
+4
source share
5 answers

This is a simpler command to test memory usage:

 free 
+17
source

/ proc / meminfo - general information about system memory. / proc / [pid] / status has memory usage information for a single process. (it is also located in / proc / [pid] / stat in machine-parsing format).

In particular, VmData (data segment size) and VmStk (stack segment size) are most likely for you. Or just use ps or top instead of reading the data yourself.

Other numbers are probably just confused, because the general use of system memory is complicated by shared memory, various types of buffers, etc.

+4
source

If you are looking for memory leaks, use Valgrind .

For a quick check of application memory usage , use getrusage() (the latest Linux kernel is required) and look at the value of ru_maxrss . /proc/meminfo gives information about the system as a whole.

+3
source

If you want to find out if your software has a memory leak, look at โ€œpsโ€ or โ€œtopโ€ to look at your program. See if Virtual Size (VSS) increases over time.

To debug such memory issues, use Valgrind or (my personal favorite) dmalloc.

+1
source

Your question is asked by something else, but since this is # 2 Google hit for โ€œLinux physical memoryโ€ -

Newer x86 kernel versions have DirectMap4k , DirectMap2M and potentially DirectMap4M and DirectMap1G at the end of /proc/meminfo . Adding them and multiplying by 1024 seems to give the number of bytes of physical memory.

0
source

Source: https://habr.com/ru/post/1343463/


All Articles