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 does Linux view memory

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly shows you "Linux how to view memory", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Linux how to view memory" this article.

To view memory under Linux, we usually use the free command:

[root@scs-2 tmp] # free

Total used free shared buffers cached

Mem: 3266180 3250004 16176 0 110652 2668236

-/ + buffers/cache: 471116 2795064

Swap: 2048276 80160 1968116

The following is an explanation of these values in the Linux view memory command:

Total: the total amount of physical memory.

Used: how much has been used.

Free: how many are available?

Shared: the total amount of memory shared by multiple processes.

Buffers/cached: size of the disk cache.

The third line (- / + buffers/cached):

Used: how much has been used.

Free: how many are available?

The fourth line does not explain much.

Difference: the difference between the used/free of the second line (mem) and the third line (- / + buffers/cache) used/free. The difference between the two lies in the use point of view, * line is from the perspective of OS, because OS,buffers/cached belongs to being used, so his available memory is 16176KB, and the used memory is 3250004KB, including the kernel (OS) using + buffers+cached used by + Application (X, oracle,etc).

The third line refers to that from an application point of view, buffers/cached is equal to available for applications, because buffer/cached is designed to improve file read performance, and buffer/cached is quickly recycled when the application needs to use memory.

So from an application perspective, available memory = system free memory+buffers+cached.

As in the above example:

2795064161761106522668236

Next, explain when the memory will be swapped and where to swap. When the available memory is less than the rated value, a meeting is held to swap.

How Linux looks at ratings when viewing memory commands:

Cat / proc/meminfo

[root@scs-2 tmp] # cat / proc/meminfo

MemTotal: 3266180 kB

MemFree: 17456 kB

Buffers: 111328 kB

Cached: 2664024 kB

SwapCached: 0 kB

Active: 467236 kB

Inactive: 2644928 kB

HighTotal: 0 kB

HighFree: 0 kB

LowTotal: 3266180 kB

LowFree: 17456 kB

SwapTotal: 2048276 kB

SwapFree: 1968116 kB

Dirty: 8 kB

Writeback: 0 kB

Mapped: 345360 kB

Slab: 112344 kB

Committed_AS: 535292 kB

PageTables: 2340 kB

VmallocTotal: 536870911 kB

VmallocUsed: 272696 kB

VmallocChunk: 536598175 kB

HugePages_Total: 0

HugePages_Free: 0

Hugepagesize: 2048 kB

The results viewed with free-m:

[root@scs-2 tmp] # free-m

Total used free shared buffers cached

Mem: 3189 3173 16 0 107 2605

-/ + buffers/cache: 460 2729

Swap: 2000 78 1921

View the size of the / proc/kcore file (memory image):

[root@scs-2 tmp] # ll-h / proc/kcore

-r-1 root root 4.1G Jun 12 12:04 / proc/kcore

Note:

Measurement of memory consumption

Linux provides us with a convenient way to measure how much memory a process consumes. The / proc directory provides us with all the information. In fact, tools such as top also use this to get the corresponding information.

Memory usage information of / proc/meminfo machine

/ proc/pid/maps pid is the process number and displays the virtual address occupied by the current process.

Memory consumed by / proc/pid/statm processes

[root@localhost ~] # cat / proc/self/statm

654 57 44 0 0 334 0

Linux view the output interpretation of memory commands

CPU and CPU0. The meaning of each parameter for each line (in the case of a * behavior example) is:

Parameter interpretation / proc//status

Size (pages) the size of the virtual address space of the task VmSize/4

The size of the physical memory being used by the Resident (pages) application VmRSS/4

Number of Shared (pages) shared pages\

The size of executable virtual memory owned by the Trs (pages) program VmExe/4

Lrs (pages) the size VmLib/4 of the library that is mapped to the virtual memory space of the task

Drs (pages) program data segment and user mode stack size (VmData+ VmStk) 4

Dt (pages) 04

Check the available memory on the machine

/ proc/28248/ > free

Total used free shared buffers cached

Mem: 1023788 926400 97388 0 134668 503688

-/ + buffers/cache: 288044 735744

Swap: 1959920 89608 1870312

When we look at the machine's free memory through the free command, we find that the value of free is very small. This is mainly because there is an idea in linux that memory is not used in vain, so it tries to cache and buffer some data as much as possible to facilitate next use. But in fact, this memory can also be used immediately.

So free memory = free+buffers+cached=total-used

The above is all the contents of the article "how to check memory in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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

Servers

Wechat

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

12
Report