Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2254394
  • 博文数量: 318
  • 博客积分: 8752
  • 博客等级: 中将
  • 技术积分: 4944
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-23 07:56
文章分类

全部博文(318)

文章存档

2019年(1)

2017年(2)

2016年(12)

2015年(2)

2014年(1)

2013年(17)

2012年(22)

2011年(9)

2010年(37)

2009年(33)

2008年(44)

2007年(43)

2006年(95)

分类: LINUX

2012-11-30 10:41:22


  • VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
  • RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
  • PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
  • USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)


/proc/meminfo

/proc/pagetypeinfo

all page info of free pages allocated by buddy algorithm. the sum of the pages equal free mem.

/proc/vmstat

 pgpgin: the total page number for pages of reading from emmc

 pgpgout;  the total page number for pages of writing to emmc

procrank: list out the memory usage of Linux processes in order from highest to lowest usage.

procmem: display  the memory usage of the specific process.

vmstat: 是Virtual Meomory Statistics(虚拟内存统计)的缩写, 1、观察磁盘活动情况 2、观察cpu活动情况 3. 进程运行情况。 包括中断数,进程切换数,idle,  io_wait, block的进程数等。其中,bi/bo 是以KB/s 为单位的。vmstat 是通过从 /proc/vmstat 中多次读取的pgpgin/pgpgout(分别对应bi, bo)值, 并与上一次读取的值做差,再除以这两次的时间间隔,得到bi/bo.而pgpgin/pgpgout 是以KB 为单位的。

lsof: list open files, 是一个列出当前系统打开文件的工具,结合grep使用。

fuser : 可以显示出当前哪个程序在使用磁盘上的某个文件,挂载点,甚至网络端口。也可杀死使用某文件或某磁盘的进程。

stat :以文字的格式来显示inode的内容,包括文件/文件系统的大小,块数(sectors), uid,gid and so on.

ls -i: 显示文件的inode 号。

find -inum  **: 利用inode来查找文件。

nohup : nohup program &, 可以使程序不间断地运行,即使shell退出

debugfs: 调试恢复文件系统的工具,可以icheck ncheck stat 等命令来查询 block号(非sector),inode号及文件之间的关联。

smem: give numerous reports on memory usage on Linux systems, reference:
   
   

setup_per_zone_wmarks: 用来根据min_free_kbytes来设置每个zone的pages_min, pages_low, pages_high. 而min_free_kbytes可由/proc/sys/vm/min_free_kbytes 来进行设置。

在wakeup_kswapd函数中,zone_watermark_ok_safe()会利用pages_min, pages_low, pages_high参数决定是否调用唤醒kswapd.

页面回收主要是通过两种方式触发的,一种是由“内存严重不足”事件触发的;一种是由后台进程 kswapd 触发的,该进程周期性地运行(??],一旦检测到内存不足,就会触发页面回收操作。对于第一种情况,系统会调用函数 try_to_free_pages() 去检查当前内存区域中的页面,回收那些最不常用的页面。对于第二种情况,函数 balance_pgdat() 是入口函数。它们都调用 shrink_zone与shrink_slab进行页面回收。
__alloc_pages_nodemask() -->
      if get_page_from_freelist() failed
         __alloc_pages_slowpath()-->
            wake_all_kswapd()
             if get_page_from_freelist() __alloc_pages_high_priority() still can not alloc pages,
             __alloc_pages_direct_reclaim()-->
                    try_to_free_pages()-->
                        do_try_to_free_pages()-->
                               shrink_zones()
                               shrink_slab()
                               wakeup_flusher_threads()

函数 shrink_zone()

其中,shrink_zone() 函数是 Linux 操作系统实现页面回收的最核心的函数之一,它实现了对一个内存区域的页面进行回收的功能,该函数主要做了两件事情:

  • 将某些页面从 active 链表移到 inactive 链表,这是由函数 shrink_active_list() 实现的。
  • 从 inactive 链表中选定一定数目的页面,将其放到一个临时链表中,这由函数 shrink_inactive_list() 完成。该函数最终会调用 shrink_page_list() 去回收这些页面。
函数 shrink_slab()
  •  是用来回收磁盘缓存所占用的页面的。Linux 操作系统并不清楚这类页面是如何使用的,所以如果希望操作系统回收磁盘缓存所占用的页面,那么必须要向操作系统内核注册 shrinker 函数,shrinker 函数会在内存较少的时候主动释放一些该磁盘缓存占用的空间。函数 shrink_slab() 会遍历 shrinker 链表,从而对所有注册了 shrinker 函数的磁盘缓存进行处理。

    从实现上来看,shrinker 函数和 slab 分配器并没有固定的联系,只是当前主要是 slab 缓存使用 shrinker 函数最多。

    shrink_dcache_memory();
    shrink_icache_memory();
    ashmem_shrink();
    mb_cache_shrink_fn()
    shrink_dqcache_memory();
    lowmem_shrink();

/proc/sys/vm/drop_caches:主要调用以下两个函数来进行页面回收:
1. drop_pagecache_sb():遍历所有已打开的文件(inode), 并回收其所占用的页面,包含Active(file),Inactive(file)的非脏的页面。而shrink_zone()主要是更新active/inactive链表,并回收Inactive(file), Inactive(anon)的页面。
2. drop_slab(): do the same job as shrink_slab().
we may place the drop_pagecache_sb() in balance_pgdat() to relieve the low_mem stress.
we can use d_find_alias() to get the file name from inode:
       struct dentry *de = NULL;
       de = d_find_alias(inode);
        if (de != NULL)
               printk(KERN_INFO "%s file name= %s size= %ld", __func__, de->d_name.name,inode->i_size);


阅读(2352) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~