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 understand Buffer and Cache in Linux memory management

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to understand Buffer and Cache in Linux memory management". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

In Linux, the free command is generally used to view memory usage.

[root@localhost ~]# free total used free shared buff/cache availableMem: 3873760 143548 3322324 8788 407888 3453708Swap: 1048572 0 1048572[root@localhost ~]#

You can view the meaning of the above output items by commanding man free

DESCRIPTION free displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo. The displayed columns are: total Total installed memory (MemTotal and SwapTotal in /proc/meminfo) used Used memory (calculated as total - free - buffers - cache) free Unused memory (MemFree and SwapFree in /proc/meminfo) shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available on kernels 2.6.32, displayed as zero if not available) buffers Memory used by kernel buffers (Buffers in /proc/meminfo) cache Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo) buff/cache Sum of buffers and cache available Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, oth‐ erwise the same as free)

The free command displays information such as idle + physical use + swap area, which is obtained by parsing/proc/meminfo. The contents of this file are as follows:

[root@localhost ~]# cat /proc/meminfoMemTotal: 3873760 kBMemFree: 3322052 kBMemAvailable: 3453436 kBBuffers: 3252 kBCached: 320316 kBSwapCached: 0 kBActive: 256968 kBInactive: 124468 kBActive(anon): 58264 kBInactive(anon): 8392 kBActive(file): 198704 kBInactive(file): 116076 kBUnevictable: 0 kBMlocked: 0 kBSwapTotal: 1048572 kBSwapFree: 1048572 kBDirty: 0 kBWriteback: 0 kBAnonPages: 57868 kBMapped: 27384 kBShmem: 8788 kBSlab: 84320 kBSReclaimable: 42580 kBSUnreclaim: 41740 kBKernelStack: 3120 kBPageTables: 4492 kBNFS_Unstable: 0 kBBounce: 0 kBWritebackTmp: 0 kBCommitLimit: 2985452 kBCommitted_AS: 293568 kBVmallocTotal: 34359738367 kBVmallocUsed: 180372 kBVmallocChunk: 34359326716 kBHardwareCorrupted: 0 kBAnonHugePages: 4096 kBHugePages_Total: 0HugePages_Free: 0HugePages_Rsvd: 0HugePages_Surp: 0Hugepagesize: 2048 kBDirectMap4k: 81728 kBDirectMap2M: 3063808 kBDirectMap1G: 3145728 kB[root@localhost ~]#

total -Total memory size

used -memory size used

free -unused memory size

shared - tmpfs Memory used

buffers -kernel cache size (Buffers in/proc/members info)

cache -page cache and tabs (Cached and Slab in/proc/meminfo)

buff/cache - buffers + cache

available -available memory size (swap excluded)

Buffers and cache are still not explained in detail in man free, check kernel doc for further explanation

... Buffers: Relatively temporary storage for raw disk blocks shouldn't get tremendously large (20MB or so)Cached: in-memory cache for files read from the disk (the pagecache). Doesn't include SwapCachedSlab: in-kernel data structures cacheSReclaimable: Part of Slab, that might be reclaimed, such as cachesSUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure

Buffers -Temporary storage of bare disk blocks (usually not small, around 20MB)

Cached -A cache that reads files from disk (i.e. page cache). Excluding SwapCached

Slab -Data structure cache in kernel

SReclaimable -part of Slab, recyclable

SUnreclaim -Another part of Slab that cannot be recycled

Use vmstat to monitor memory usage

[root@localhost ~]# echo 3 > /proc/sys/vm/drop_caches[root@localhost ~]# vmstat 1procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 1 0 3648060 0 96964 0 0 4 5158 151 174 5 6 89 0 0 0 0 0 3648248 0 97424 0 0 296 0 311 331 0 1 99 0 0... "How to understand Buffer and Cache in Linux memory management" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

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

Database

Wechat

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

12
Report