Memory available in Linux

Source: Internet
Author: User

In Linux, you can enter the free command to obtain the current {
Tagshow (Event)
} "> System memory usage.
# Busybox free
Total used free shared Buffers
Mem: 55636 52808 2828 0 3132
Swap: 0 0 0
Total: 55636 52808 2828
When I typed the above command with joy, I received a burst of cold sweat, 2828 kb. My system only has more than 2 MB of memory. Can the system still run, is there a command error !!!
Let's take a look at what the results look like in a Linux system on a PC.
# Free
Total used free shared buffers cached
Mem: 4091524 4021016 70508 0 7656 1824312
-/+ Buffers/cache: 2189048 1902476
Swap: 4088532 2891732 1196800
Here I will explain several key concepts first.
Buffers: it is mainly used to buffer Block devices in Linux.
Cached: Used to buffer {
Tagshow (Event)
} "> File.
Memory is a very valuable resource in the system. Linux uses memory to cache some files if the memory is sufficient and you do not need to use it for whitelist. This speeds up the process; when the memory is insufficient, the memory will be recycled again {
Tagshow (Event)
} "> Program usage.
Therefore, the real available memory is free + buffers + cached = 70508 + 7656 + 1824312 = 1902476.
In this way, we know that busybox has a defect in implementing free. It lacks a key column of cache, so we cannot obtain the exact idle memory value.
Since the free command does not work, our focus is on the free {
Tagshow (Event)
} "> Where did the data come from!
The answer is:/proc
/Proc {
Tagshow (Event)
} "> A directory is a special file system that does not occupy disk space {
Tagshow (Event)
} "> User request information, generated in real time by the Linux kernel. Therefore, we can access some data in the Linux Kernel through the proc directory.
We can obtain the memory usage of the current system from the meminfo file in the proc directory.
# Cat/proc/meminfo
Memtotal: 55880 KB
Memfree: 2252 KB
Buffers': 3760 KB
Cached: 26112 KB
Swapcached: 0 KB
Active: 34652 KB
Inactive: 8716 KB
Hightotal: 0 KB
Highfree: 0 KB
Lowtotal: 55880 KB
Lowfree: 2252 KB
Swaptotal: 0 KB
Swapfree: 0 KB
Dirty: 0 KB
Writeback: 0 KB
Mapped: 34220 KB
Slab: 4504 KB
Commitlimit: 27940 KB
Committed_as: 109704 KB
Pagetables: 1876 KB
Vmalloctotal: 196608 KB
Vmallocused: 2360 KB
Vmallocchunk: 4112384 KB
From the above results, we can know that the system currently has a total of K physical memory,
Where
Free 2252kb
Buffers 3760 KB
Cached 26112 KB
So the current available physical memory = 2252 + 3760 + 26112 = 32124kb, it should be said that there are still a lot.
At last, we had a hard time getting the available system memory, which makes it easy to calculate
Physical memory used = 55880-32124 = 23756kb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.