Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux free command

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people don't understand the knowledge points of this article "how to use Linux free command", so Xiaobian summarizes the following contents for everyone, the contents are detailed, the steps are clear, and there is certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "how to use Linux free command".

The free command displays the amount of unused and used memory currently on the system, and also displays the memory buffers used by the kernel.

free Displays memory usage

Syntax free(option) option-b #Displays memory usage in bytes; -k #Displays memory usage in KB; -m #Displays memory usage in MB; -g #Displays memory usage in GB. -o #Do not display buffer adjustment column; -s #Keep watching memory usage; -t #Display memory sum column; -V #Display version information. Example free -t #Display memory usage information as a sum free -s 10 #Periodically query memory usage information, execute the command every 10s to display memory usage

free -m total used free shared buffers cached Mem: 2016 1973 42 0 163 1497 -/+ buffers/cache: 312 1703 Swap: 4094 0 4094 Part 1 Mem Line Explanation:

total: total memory; used: used memory; free: free memory; shared: currently unused; buffers Buffer: cached memory; cached Page: cached memory. Total = used + free

Part 2 (-/+ buffers/cache) explains:

(-buffers/cache) used memory: used-buffers-cached (+buffers/cache) free memory: free + buffers + cached visible-buffers/cache reflects the actual memory consumed by the program, while +buffers/cache reflects the total memory that can be appropriated.

The third part refers to the swap partition.

The fourth line of the output is the swap partition SWAP, which is commonly referred to as virtual memory. Difference: used/free in the second line (mem) and used/free in the third line (-/+ buffers/cache). The difference between these two is that from the point of view of use, the first line is from the OS point of view, because for OS, buffers/cached belong to be used, so its available memory is 2098428KB, used memory is 30841684KB, including, kernel (OS) use +Application(X, oracle,etc) use +buffers+cached.

The third line indicates that from the application perspective, buffers/cached is equal to available for the application, because buffer/cached is used to improve file read performance, and buffer/cached is quickly reclaimed when the application needs to use memory.

So from an application perspective, available memory = system free memory+buffers+cached. For example, the available memory in the local case is:

18007156=2098428KB+4545340KB+11363424KB

Next explain when memory is swapped and in what direction.

When the available memory is less than the rated value, a meeting will be held to exchange. How to view ratings:

cat /proc/meminfo MemTotal: 16140816 kB MemFree: 816004 kB MemAvailable: 2913824 kB Buffers: 17912 kB Cached: 2239076 kB SwapCached: 0 kB Active: 12774804 kB Inactive: 1594328 kB Active(anon): 12085544 kB Inactive(anon): 94572 kB Active(file): 689260 kB Inactive(file): 1499756 kB Unevictable: 116888 kB Mlocked: 116888 kB SwapTotal: 8191996 kB SwapFree: 8191996 kB Dirty: 56 kB Writeback: 0 kB AnonPages: 12229228 kB Mapped: 117136 kB Shmem: 58736 kB Slab: 395568 kB SReclaimable: 246700 kB SUnreclaim: 148868 kB KernelStack: 30496 kB PageTables: 165104 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 16262404 kB Committed_AS: 27698600 kB VmallocTotal: 34359738367 kB VmallocUsed: 311072 kB VmallocChunk: 34350899200 kB HardwareCorrupted: 0 kB AnonHugePages: 3104768 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 225536 kB DirectMap2M: 13279232 kB DirectMap1G: 5242880 kB Swap will reduce the number of physical pages used in the system in three ways:

Reduce buffer and page cache size,

Swap out memory pages of system type V,

Replace or discard pages. (The memory page occupied by the Application, that is, the physical memory is insufficient).

In fact, using swap sparingly does not affect system performance.

Buffers and cached are both caches. What's the difference?

To improve disk access efficiency, Linux has made some careful design. In addition to caching dentries (used for VFS, speeding up file path name to inode conversion), it also adopts two main caching methods:

Buffer Cache and Page Cache. The former is for reading and writing disk blocks, while the latter is for reading and writing file inode. These caches effectively shorten the time of I/O system calls (such as read,write,getdents). Disk operations have logical (file system) and physical (disk block) levels, and these two caches cache logical and physical data, respectively.

Page cache is actually for file system, is the cache of files, data at the file level will be cached to page cache. The logical layer of the file needs to be mapped to the actual physical disk, and this mapping is done by the file system. When the data in the page cache needs to be refreshed, the data in the page cache is handed over to the buffer cache, because the Buffer Cache is the cache disk block. However, this process has been simplified since kernel version 2.6, with no cache operations in the true sense.

Buffer cache is a cache for disk blocks, that is, in the absence of a file system, data directly operated on the disk will be cached in buffer cache, for example, metadata of the file system will be cached in buffer cache.

Simply put, page cache is used to cache file data, buffer cache is used to cache disk data. In the case of a file system, if you operate on files, the data will be cached in the page cache. If you directly use dd and other tools to read and write to the disk, the data will be cached in the buffer cache.

So we look at linux, as long as you do not swap swap space, you do not have to worry about their memory is too small. If swap is often used a lot, you may want to consider adding physical memory. This is also the linux to see if there is enough memory criteria.

If it is an application server, then generally only look at the second line,+buffers/cache, that is, too little free memory for the application, it is also time to consider optimizing the program or adding memory.

The above is about "Linux free command how to use" the content of this article, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report