vpsfreecz / vpsadminos

Host for Linux system containers based on NixOS, ZFS and LXC
https://vpsadminos.org
MIT License
155 stars 26 forks source link

Some applications report available memory incorrectly - sysinfo #45

Closed Gregy closed 3 years ago

Gregy commented 3 years ago

Hi, thanks for your effort on vpsadminos! Today I noticed a strange behaviour of zabbix while it was running in vpsadminos container in vpsfree. I tracked it down to this minimal example:

#include <linux/kernel.h>
#include <stdio.h>
#include <sys/sysinfo.h>

int main ()
{
 /* Conversion constants. */
 const long minute = 60;
 const long hour = minute * 60;
 const long day = hour * 24;
 const double megabyte = 1024 * 1024;
 /* Obtain system statistics. */
 struct sysinfo si;
 sysinfo (&si);
 /* Summarize interesting values. */
 printf ("system uptime : %ld days, %ld:%02ld:%02ld\n", 
     si.uptime / day, (si.uptime % day) / hour, 
     (si.uptime % hour) / minute, si.uptime % minute);
 printf ("total RAM   : %5.1f MB\n", si.totalram / megabyte);
 printf ("free RAM   : %5.1f MB\n", si.freeram / megabyte);
 printf ("process count : %d\n", si.procs);
 return 0;
}

When I compile and run this in vpsfree vpsadminos container I get:

system uptime : 23 days, 5:58:19
total RAM   : 257908.4 MB
free RAM   : 30818.6 MB
process count : 24665

The values for total RAM, free RAM and process count are wrong. This could lead to excesive memory usage as the application thinks it has a lot more ram than it really has.

aither64 commented 3 years ago

Yes, this is because currently we use LXCFS, which is mounted over /proc/meminfo (see grep lxcfs /proc/mounts), but cannot intercept syscalls. @snajpa is actually working on virtualization of /proc/meminfo and sysinfo syscall within the kernel, you can see the progress in devel branch and it's also already deployed on our staging (node1.stg), it should get to production nodes with the next update.

Gregy commented 3 years ago

Awesome, thank you!

Gregy commented 3 years ago

I just tried on the staging node and I can confirm the memory information is reported correctly. Uptime and process count remain incorrect. I am not sure if that could be problematic or not (it won't affect me).

snajpa commented 3 years ago

By all acounts solved in 5.9.2+ kernels :)