Get the latest tech news
Why top and free in containers don't show the correct container memory (2018)
Go through the reason why free and top show the host's memory instead of container memory.
To get a testbed for the rest of the article, consider the case of running a single container with a memory limit of 10MB in a system that has 2GB of RAM available: Differently from other things like listing pids from/proc, when the file_operations that procfs implements reach the point of gathering memory information, it doesn’t acquire a namespaced view of it. Using bpftrace, we’re able to tailor a small program that inspects the page_counter used in page_counter_try_charge and see how the limit changes over time (until the point that we reach the exhaustion - receiving an OOM then).
Or read this on Hacker News