--------------------------------------
In libsysinfo-0.2.2/Linux/sysinfo_linux.c fucntion get_mem_size(void):
--------------------------------------
long long get_mem_size(void) {
long long mem_size=0;
/* First try any arch-specific memsize functions */
mem_size=get_arch_specific_mem_size();
if (mem_size == MEM_USE_MEMINFO) {
mem_size = 0;
goto use_meminfo;
}
if (mem_size == MEM_USE_SYSINFO) {
mem_size = 0;
goto use_sysinfo;
}
/* Next try the 2.4.x+ method of iomem */
if (mem_size == 0) mem_size = get_mem_size_iomem();
/* Try stat-ing /proc/kcore */
if (mem_size == 0) mem_size = get_mem_size_stat();
use_sysinfo:
/* sysinfo should return same as /proc/meminfo */
/* which, sadly, is often from 1MB-20MB off */
if (mem_size == 0) mem_size = get_mem_size_sysinfo();
use_meminfo:
/* If all else fails, try using /proc/meminfo */
if (mem_size == 0) mem_size = get_mem_size_meminfo();
return mem_size;
}
--------------------------------------
1) a call is made to get_arch_specific_mem_size()
-- this will either return 0, MEM_USE_MEMINFO, or MEM_USE_SYSINFO.
-- certain cpu_archs will return 0 (such as x86/x86_64)
2) if the return value is 0 it will call get_mem_size_iomem() [otherwise
it will call get_mem_size_meminfo() or get_mem_size_sysinfo as appropriate]
-- if not run as root the return value will always be 0 (or the system
memsize, if run as root)
3) if the return value of iomem was 0 (and it will be, again without root)
a call is made to get_mem_size_stat() reading from /proc/kcore --
currently this returns 128TB
$ sudo file /proc/kcore
/proc/kcore: ELF 64-bit LSB core file x86-64, version 1 (SYSV),
SVR4-style, from 'BOOT_IMAGE=/boot/vmlinuz-4.7.0-1-amd64
root=UUID=8d8c2528-acc4-47a8-b815-967b59'
$ sudo ls -lh /proc/kcore
-r-------- 1 root root 128T Oct 3 21:30 /proc/kcore
Note that /proc/kcore cannot be relied upon because it is a mapping
of the maximum amount of memory that the kernel can allocate and
not how much ram is actually installed (at least not for 64-bit cpus)
--------------------------------------
The usefulness of these memory function(s):
1) get_mem_size_meminfo() and get_mem_size_sysinfo() -- are unreliable
they will report less RAM than is actually installed
2) get_mem_size_stat() -- /proc/kcore unreliable on 64bit cpus (maybe
even 32bit if less ram is installed than the 32bit max)
3) get_mem_size_iomem() -- fairly reliable in all cases, but requires
root privs to read
--------------------------------------
The only reliable memory function is get_mem_size_iomem(), but -- in my
opinion -- requiring linuxlogo to be executed as root is unnecessary and
unacceptable.
As as result my recommendation would be to remove the feature altogether.