您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么理解Linux內存管理中Buffer和Cache”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
在Linux中,一般使用free命令查看內存的使用情況
[root@localhost ~]# free total used free shared buff/cache available Mem: 3873760 143548 3322324 8788 407888 3453708 Swap: 1048572 0 1048572 [root@localhost ~]#
通過命令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)
free命令顯示了空閑+物理使用+交換區等信息,通過解析/proc/meminfo獲得,該文件中的內容如下:
[root@localhost ~]# cat /proc/meminfo MemTotal: 3873760 kB MemFree: 3322052 kB MemAvailable: 3453436 kB Buffers: 3252 kB Cached: 320316 kB SwapCached: 0 kB Active: 256968 kB Inactive: 124468 kB Active(anon): 58264 kB Inactive(anon): 8392 kB Active(file): 198704 kB Inactive(file): 116076 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 1048572 kB SwapFree: 1048572 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 57868 kB Mapped: 27384 kB Shmem: 8788 kB Slab: 84320 kB SReclaimable: 42580 kB SUnreclaim: 41740 kB KernelStack: 3120 kB PageTables: 4492 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 2985452 kB Committed_AS: 293568 kB VmallocTotal: 34359738367 kB VmallocUsed: 180372 kB VmallocChunk: 34359326716 kB HardwareCorrupted: 0 kB AnonHugePages: 4096 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 81728 kB DirectMap2M: 3063808 kB DirectMap1G: 3145728 kB [root@localhost ~]#
total - 總內存大小
used - 使用的內存大小
free - 未使用內存大小
shared - tmpfs使用的內存
buffers - 內核緩存大小(/proc/meminfo中的Buffers)
cache - 頁面緩存和slabs(/proc/meminfo中的Cached和Slab)
buff/cache - buffers + cache
available - 可用內存大小(剔除交換區)
buffers和cache在man free中仍沒有詳細解釋清楚,通過查看kernel doc進一步獲得相關的解釋
... 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 SwapCached Slab: in-kernel data structures cache SReclaimable: Part of Slab, that might be reclaimed, such as caches SUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure
Buffers - 裸磁盤塊的臨時存儲(通常不會不大,20MB左右)
Cached - 從磁盤上讀取文件的緩存(即頁面緩存).不包括SwapCached
Slab - 內核中的數據結構緩存
SReclaimable - Slab中的一部分,可回收
SUnreclaim - Slab中的另一部分,不能回收
使用vmstat可監控內存的使用情況
[root@localhost ~]# echo 3 > /proc/sys/vm/drop_caches [root@localhost ~]# vmstat 1 procs -----------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 ...
“怎么理解Linux內存管理中Buffer和Cache”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。