How can you physically determine the size of physical RAM in Linux?

This can be found on the command line using the "free" utility and "cat / proc / meminfo". What would be the different ways to find out the physical size of RAM in Linux programmatically with:

  • User application
  • Kernel module

What API calls are available?

+3
source share
4 answers
#include <unistd.h>

long long physical_mem_bytes = (long long) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGESIZE);

Besides the ulimit command line, I don’t know how to find the maximum memory for an individual process.

+4
source

Programmatically, Linux will not tell you the actual physical size. Instead, you should read this information with SMBIOS using, for example,

sudo dmidecode -t memory | fgrep -ie 'size:'

( 4 RAM, 2 ):

Maximum Memory Module Size: 16384 MB
Maximum Total Memory Size: 65536 MB
Installed Size: 2048 MB (Single-bank Connection)
Enabled Size: 2048 MB (Single-bank Connection)
Installed Size: Not Installed
Enabled Size: Not Installed
Installed Size: 2048 MB (Single-bank Connection)
Enabled Size: 2048 MB (Single-bank Connection)
Installed Size: Not Installed
Enabled Size: Not Installed
Size: 2048 MB
Size: No Module Installed
Size: 2048 MB
Size: No Module Installed

( Enabled Size s, BIOS, ), ( ) 4096 . ( , , , , .)

,

fgrep -e 'MemTotal:' /proc/meminfo

, /proc/meminfo, , dmidecode.

MemTotal:        3988616 kB
+1

cat /proc/meminfo

-1

specially from memory, I got this result from what Jared said sudo dmidecode -t memory there you can read the specifications for each individual memory slot, so you read something like 2048 MB, in my case I have 2 of them 4gb, despite the fact that the kernel without PAE shows only 3.3 GB, and all other applications will not say that real physical memory is only dmidecode, thanks!

-1
source

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


All Articles