Blogs

top里面描述进程内存使用量的数据来源于/proc/$pid/statm这个文件。通过观察kernel的代码就能弄清楚SHR,VIRT和RES这些数值的具体含义。

Linux通过一个叫做 task_statm 的函数来返回进程的内存使用状况

int task_statm(struct mm_struct *mm, int *shared, int *text,
               int *data, int *resident)
{
        *shared = get_mm_counter(mm, file_rss);
        *text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
                                                           >> PAGE_SHIFT;
        *data = mm->total_vm - mm->shared_vm;
        *resident = *shared + get_mm_counter(mm, anon_rss);
        return mm->total_vm;
}

上面的代码中shared就是page cache里面实际使用了的物理内存的页数,text是代码所占用的页
数,data是总虚拟内存页数减去共享的虚拟内存页数,resident是所有在使用的物理内存的页
数。最后返回的mm->total_vm是进程虚拟内存的寻址空间大小。

函数get_mm_counter并不会做什么计算,它的功能是保证数值读取的原子性。

上面的数值最后会通过 procfs输出 到/proc/$pid/statm中去。他们与top显示的数值对应关系如下。

  • SHR: shared
  • RES: resident
  • VIRT: mm->total_vm
  • CODE: code
  • DATA: data

当然top在显示的时候做了一些页到具体数值(KB, MB,…)的转换。通过代码可以看出,VIRT = RES + SHR这种说法纯属谣言。:)

No votes yet
Tags:

在用xrandr设置双屏幕扩展显示的时候,有可能会提示下面的错误:

xrandr: screen cannot be larger than 1680×1680 (desired size 3120×1050)

该错误说明Xorg的虚拟桌面不够大,可以通过使用Xorg.conf的Virtual指令更改虚拟桌面的大小。例如:

Section "ServerLayout"
    Identifier     "Xorg Configured"
    Screen      0  "Primary Screen" 0 0
EndSection

Section "Monitor"
    Identifier "Primary Monitor"
    Modeline "1400x900"  104.23  1400 1480 1632 1864  900 901 904 932  -HSync +Vsync
EndSection

Section "Screen"
    Identifier "Primary Screen"
    Monitor    "Primary Monitor"
    DefaultColorDepth 24
    SubSection "Display"
        Depth 24
        Modes "1400x900" "1024x768"
        Virtual 3120 1050
    EndSubSection
EndSection

Section "DRI"
    Mode 0666
EndSection
No votes yet
Tags:
  • 获取SMART信息: smartctl -a -d ata /dev/sda
  • 健康检查: smartctl -H /dev/sda
  • 查看错误: smartctl -l error /dev/sda
  • 打开SMART支持: smartctl -s on -d ata /dev/sda
No votes yet
Tags:

I am doing ...

整理下载中…

2 weeks ago via web

Setup my microblog

2 weeks ago via web

Syndicate content