Calculating% of memory used in Linux

Linux noob question:

If I have 500 MB of RAM and 500 MB of swap space, can the OS and processes use 1 GB of memory?

In other words, the total amount of memory available to programs and the OS, the total size of the physical memory, and the paging size?

I'm trying to figure out what SNMP counters are being polled but need to understand how Linux uses virtual memory first.

thank

+2


source to share


4 answers


Yes, that is essentially correct. The actual numbers may be (very) marginally lower, but for all intents and purposes, if you have x

physical memory and y

virtual memory (swap on Linux), then you have x + y

memory available to the operating system and any programs running under the OS.



0


source


In fact, this is essentially correct, but your "virtual" memory is NOT adjacent to your "physical memory" (as Matthew Charlie said).

Your "virtual memory" is an abstraction layer that encompasses both "physical" (as in RAM) and "swap" (as on a hard disk, which is of course as physical as RAM).



Virtual memory is in the realm of abstraction. Your program always refers to a "virtual" address, which your OS translates to an address in RAM or disk (which must first be loaded into RAM) depending on where the data is. Therefore, your program should never worry about running out of memory.

+5


source


While this is mostly true, it is not entirely correct. For a particular process, the environment you run it in can limit the memory availability for your process. Check the output ulimit -v

.

+1


source


Nothing is ever so easy ...

Memory pages are lazily allocated. A process can malloc () a large amount of memory and never use it. So on your 500MB_RAM + 500MB_SWAP system, I could - in theory at least - allocate 2 gigabytes of memory from the heap, and everything will work fun until I try to use too much of that memory. (At what point any process could not receive more pages of memory, it receives a nucleotide. I hope this is my process. But not always.)

Individual processes can be limited to 4 gigabytes as a hard address limit for 32-bit systems. Even if the computer has more than 4 gigabytes of RAM and you use this weird segmented 36-bit attack from hell's addressing scheme, individual processes are still limited to only 4 gigs. Some of these 4 gigs must go for shared libraries and programming code. So up to 2-3 gigs of stack + heap as ADDRESSING limit.

You can embed mmap files, which gives you more memory. It basically acts as a complementary exchange. That is, instead of loading the program binary data into memory and then replacing it with a swap file, the file is simply mmapped. If necessary, the pages will be replaced by RAM directly from the file.

You can get into interesting stuff with sparse data and sliced ​​files. I've seen X-windows require huge memory usage when in reality it only used a small bit.

BTW: " free " can help you. How can " cat / proc / meminfo " or Vm lines in / proc / $ PID / status . (Especially VmData and VmStk.) Or perhaps " ps up $ PID "

+1


source







All Articles