# 关闭THP vim /etc/rc.local文件: iftest -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi iftest -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi
内存监控
top 命令
top 命令是 Linux 下常用的性能分析工具, 能够实时显示系统中各个进程的资源占用状况, 类似于 Windows 的任务管理器. top 命令是一个动态显示过程,即可以通过用户按键来不断刷新当前状态. 如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.
top 命令提供了实时的对系统处理器的状态监视.它将显示系统中 CPU 最”敏感”的任务列表. 该命令可以按 CPU 使用, 内存使用和执行时间对任务进行排序; 该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定. 另外, 内存监控的很多应用往往和 CPU 监控室一致的, 这两者在一定程度上是互相影响的.
Report virtual memory statistics. Reports information about process, memory, paging, block IO, traps, disks and cpu activity. The first report produced gives averages since the last reboot. 其输出如下:
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b 交换 空闲 缓冲 缓存 si so bi bo in cs us sy id wa st 1 0 0 513508 282512 2590320 0 0 5 12 2 103 3 0 97 0 0
# 各项说明如下 Procs r: The number of runnable processes (running or waiting for run time). 运行队列. b: The number of processes in uninterruptible(不间断)sleep. 阻塞进程.
Memory swpd: the amount of virtual memory used. free: the amount of idle(闲置) memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache. inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option)
Swap si: Amount of memory swapped in from disk (/s). 就是swap-in. so: Amount of memory swapped to disk (/s). 就是swap-out.
IO bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s).
System in: The number of interrupts per second, including the clock. cs: The number of context switches per second. 每秒上下文切换次数, 线程切换, 进程切换, 尽可能越小越好.
CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.
实例:
1 2 3 4
# 每三秒输出一条结果 vmstat 3 # 输出的active/inactive的值 vmstat -a 3