Tips for Optimization Linux Memory Usage
来源:互联网 发布:淘宝会员名 编辑:程序博客网 时间:2024/06/05 06:39
内存泄露的查看与检测:
Linux Free 命令的输出:
total used free shared buffers cached
Mem: 8298904 6202940 2095964 0 400124 5291536
-/+ buffers/cache: 511280 7787624
Swap: 2048276 0 2048276
buffers 和 cached 主要是为了提高磁盘的读取效率,除了对dentry进行缓存外,还采取了两种cache方式:Buffer Cache和Page Cache,前者主要针对磁盘块的读写,后者主要针对inode的读写;
buffers 主要指Buffer Cache,cached 主要指Page Cache。
-/+ buffers/cache: 意思是减去(buffers + cached)后真正地内存使用量,和加上(buffers + cached)后真正地内存空闲量。
used数值包括了进城所使用的内存和一部分磁盘缓存;
那used的数值比较异常,是发生了内存泄露吗?非也!!
Usually the kernel handles memory utilization pretty well it cachesmemory for dentry cache, page cache and inodes which improves IO speedand performance generally. But in some cases user applications needslots of memory and we need to clear what’s called dirty memory whichcould be inodes already written to the disk, so now the kernel given usthe option to manage this manually. Used memory 几乎总是会包含磁盘缓存,所以文件读写过多之后导致可用内存就会急剧下降,其他应用需要内存的时候就会发生disk buffer的sync操作,以至于系统性能大受影响。
Linux Kernel提供了有效地方法来清除磁盘缓存:/proc/sys/vm/drop_caches (具体在哪个版本后的kernel才支持,尚未查阅)
echo 1 > /proc/sys/vm/drop_caches free page cache
echo 2 > /proc/sys/vm/drop_caches free dentry and inodes cache
echo 3 > /proc/sys/vm/drop_caches free both of the two above
在执行这些操作之前,最好先执行sync (flush file system buffers)
Linux principals:
When extra physical memory is not in use, the kernel attemptsto put it to work as a disk buffer cache. The disk buffer storesrecently accessed disk data in memory; if the same data is neededagain it can be quickly retrieved from the cache, improvingperformance. The buffer grows and shrinks dynamically to use thememory available, although priority is given to using the memoryfor paging. Thus, all the memory you have is put to gooduse.
- Tips for Optimization Linux Memory Usage
- Code Optimization: Effective Memory Usage
- Three Optimization Tips for C++
- Linux Memory Usage: free
- 40 Developer Tips for Android Optimization
- Understanding memory usage on Linux
- [Linux][Android] Analyzing Memory Usage.
- Understanding memory usage on Linux
- 50.Tips.and.Tricks.for.MongoDB.Developers --- Optimization Tips
- General formula for calculating memory usage
- Collecting Memory Usage Information For a Process
- Typical memory usage for objects in java
- C++优化三板斧:Three Optimization Tips for C++
- MEMORY OPTIMIZATION FOR IOS APPS DEVELOPED IN UNITY
- Transact-SQL Optimization Tips
- CUDA Optimization tips
- Optimization of memory allocations
- Cacti 'Linux - Get Memory Usage' Remote Command Execution Vulnerability
- 转帖
- LM && NTLM && ophcrack && RainBow table
- 例行公事的琐碎
- 滑动图片展示效果(js+css)
- iframe属性
- Tips for Optimization Linux Memory Usage
- T-SQL_1 创建数据库
- 开通blog第一帖
- 在vb.NET 中使用配置文件
- QC9数据迁移到QC10中使用
- 点滴(一)
- 我的故事
- [献给想深入学习Linux开发的网友] Linux 应用程序开发到内核开发的简明指南。
- Linux下的Chromium的字体问题