Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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?)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...