Linux Performance Tuning Getting to combat: Chapter 13 Memory: Memory indicators / Tools Summary, locate the problem and tuning

Memory Performance

System Memory index

  • Used memory and free memory is easy to understand, is not yet been used, and memory use.
  • Shared memory is implemented by tmpfs, so its size is to use tmpfs memory size. tmpfs is actually a special kind of cache.
  • Available memory is a new process that can be used with maximum memory, which includes the remaining cache memory and recyclable.
  • Cache consists of two parts, one is the disk to read the file page cache used to cache data read from disk, speed up speed again in the future can be accessed. Another part, the dispenser is recyclable Slab memory.
  • A buffer temporarily storing the original disk blocks for the cache to be written to disk. In this way, the kernel can be dispersed to write together, unified optimize disk writes.

Process Memory index

  • Virtual memory , including the process of code segments, data segments, shared memory, heap memory has applied for and has been swapped out of memory. Here we must note that the memory has been filed, even if no physical memory allocation, to be regarded as virtual memory.
  • Permanent memory is the physical memory of the process actually used, however, it does not include Swap and shared memory.
  • Shared memory , both real shared memory with other processes commonly used, also includes a dynamic link library code segment, and program loading, and the like.
  • Swap memory refers to memory swapped out to disk by the Swap.

Abnormal missing page

  • When it can be assigned directly from physical memory, known as sub-page-missing fault .
  • When required disk I / O intervention (such as Swap), it is known as the main missing page abnormalities .

Swap Index

  • 已用空间剩余空间很好理解,就是字面上的意思,已经使用和没有使用的内存空间。
  • 换入速度换出速度,则表示每秒钟换入和换出内存的大小。

内存性能工具

  • 系统指标工具:free、sar
  • 进程指标工具:top 、ps
  • 动态内存指标工具:vmstat
  • 内存指标的来源:proc 文件系统(/proc/zoneinfo。。。)
  • 系统缓存命中工具:cachestat
  • 进程缓存命中工具:cachetop
  • 内存泄漏工具:memleak

内存问题定位

内存问题调优

内存调优的核心是,保证应用程序的热点数据放到内存中,并尽量减少换页和交换。

  1. 最好禁止 Swap。如果必须开启 Swap,降低 swappiness 的值,减少内存回收时 Swap 的使用倾向。
  2. 减少内存的动态分配。比如,可以使用内存池、大页(HugePage)等。
  3. 尽量使用缓存和缓冲区来访问数据。比如,可以使用堆栈明确声明内存空间,来存储需要缓存的数据;或者用 Redis 这类的外部缓存组件,优化数据的访问。
  4. 使用 cgroups 等方式限制进程的内存使用情况。这样,可以确保系统内存不会被异常进程耗尽。
  5. 通过 /proc/pid/oom_adj ,调整核心应用的 oom_score。这样,可以保证即使内存紧张,核心应用也不会被 OOM 杀死。

Guess you like

Origin www.cnblogs.com/qccz123456/p/11204172.html