Why does `/proc/meminfo` show 32GB when AWS instance has only 16GB?

心已入冬 提交于 2020-05-08 15:40:48

问题


I wanted to log the total amount of memory (alternatively: used memory by the current process and available memory for the current process) of the currently running instance and used /proc/meminfo:

info = {
    i.split()[0].rstrip(":"): int(i.split()[1])
    for i in open("/proc/meminfo").readlines()
}
total_m = info["MemTotal"]

When I run it locally, it does what I expect. When I run it on a 16GB AWS instance in a Docker container it shows 32GB. Why is that the case?

(Side question: How should this be done?)


回答1:


I wanted to log the size of the currently running instance

You don't define what is an instance for you. AFAIK it has a different meaning in AWS and in Docker.

used memory by the current process

Please define what is used memory.

Read much more about virtual address space. What about the page cache ?

available memory for the current process

Please define what is available memory. Are you aware of paging ? What about shared libraries ?

Then, read documentation related to proc(5).

You really should care about the current process, not the entire system. Read a good operating system textbook and the Advanced Linux Programming book, and https://www.linuxatemyram.com/

If you care about the current process, use proc(5) thru /proc/self/stat

If you care about your AWS instances, there are some proprietary APIs for querying their status.

If you are automatizing some system administration tasks, you should explain which ones and why.

Notice that /proc/meminfo gives system-wide information and relates to virtual memory. AWS is adding hypervisor layers and so does Docker and you could have some process migration at some virtual level.



来源:https://stackoverflow.com/questions/61498709/why-does-proc-meminfo-show-32gb-when-aws-instance-has-only-16gb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!