如何处理大量页面错误?

如何处理大量页面错误?

我每秒大约有 200000 个页面错误,我认为这是一个巨大的数字,它会影响整体系统性能。我使用的是带有 16G RAM 的 MBP。

如何处理如此数量的页面错误(持续)?我的意思是,有可能找到其背后的原因(比如哪个过程导致了这个问题以及为什么)?


例如:

$ sudo vm_stat 1 
Mach Virtual Memory Statistics: (page size of 4096 bytes)
    free   active   specul inactive throttle    wired  prgable   faults     copy    0fill reactive   purged file-backed anonymous cmprssed cmprssor  dcomprs   comprs  pageins  pageout  swapins swapouts
    4917    96838      529    97567        0  3289215        2   11428M  127346K 5267290K 2537359K  215040K       47481    147453 11108999   703646 3631740K 3986806K  125027K  3038713 4551661K 4575495K 
    4728   119600      514   119225        0  3290072        0   197571      160     2067    28142        2       47479    191860 11063976   658555   153524   108572       31        0    11145    18981 
    4165   104525      514   104919        0  3288821        0   130758        0     2229    74497       12       47449    162509 11094522   689295    90301   121063        3        3    18085     7894 
    4648   106152      463   105365        0  3289210        0   169256      268     8150    73677        6       47404    164576 11097078   686991   122692   126220        0        0    12751    15474 
    5364   105849      246   101327        0  3291998        0   194376       81    24019    43351       10       47189    160233 11103191   687904   121794   129662       72        0    14705    14031 
    4800   131711      234   126573        0  3289384        0   272238        0     4346   110454        0       47177    211341 11035585   639095   167782   108490        0        0    10628    23480 
    3813   114535      203   114136        0  3289283        0   235409        0     3292    39228        6       47149    181725 11065977   670501   153957   184877       12        2    18041    17254 
    4568   115828      104   116790        0  3289299        0   211943        0     2536    81178        1       46680    186042 11061206   665872   139337   134989        0        0    18848    19316 
    3273    95211      105    95156        0  3289239        0   223742      268     2123    40588        4       46670    143802 11103048   708970   156600   198575        0        0    22910     8
$ top -n1 | head
Processes: 453 total, 8 running, 16 stuck, 429 sleeping, 2870 threads 
2016/07/21 15:06:33
Load Avg: 7.95, 9.09, 9.22 
CPU usage: 9.17% user, 41.17% sys, 49.64% idle 
SharedLibs: 54M resident, 8520K data, 3092K linkedit.
MemRegions: 307835 total, 4421M resident, 11M private, 143M shared.
PhysMem: 16G used (13G wired), 4880K unused.
VM: 4577G vsize, 528M framework vsize, 4619730480(0) swapins, 4643542587(0) swapouts.
Networks: packets: 67336466/41G in, 59785188/11G out.
Disks: 620736722/18T read, 615258201/18T written.
$ uptime
15:25pm  up 17 days 23:31,  48 users,  load average: 7.95, 9.09, 9.22
$ sudo fs_usage | grep -e PgIn -e PgOut
15:25:02    PgOut[ST1P]   0.000146 W kernel_task
15:25:02    PgOut[ST1P]   0.000241 W kernel_task
15:25:02    PgOut[ST1P]   0.000234 W kernel_task
15:25:02    PgOut[ST1P]   0.000317 W kernel_task
15:25:02    PgOut[ST1P]   0.000333 W kernel_task
15:25:02    PgOut[ST1P]   0.000252 W kernel_task
15:25:02    PgOut[ST1P]   0.000248 W kernel_task
15:25:02    PgOut[ST1P]   0.000240 W kernel_task
15:25:02    PgOut[ST1P]   0.000236 W kernel_task
15:25:02    PgOut[ST1P]   0.000261 W kernel_task
15:25:02    PgOut[ST1P]   0.000257 W kernel_task
15:25:02    PgOut[ST1P]   0.000253 W kernel_task
15:25:02    PgOut[ST1P]   0.000289 W kernel_task
15:25:02    PgOut[ST1P]   0.000159 W kernel_task
15:25:02    PgOut[ST1P]   0.000120 W kernel_task

答案1

如果你的内核支持,你可以尝试记录每次缺页时的堆栈。运行此命令,然后在几秒钟后中断它:

sudo perf record -e page-faults -ag

它将创建一个大型二进制文件perf.data,您可以使用该文件进行可视化

perf report  

perf是一个巨大的课题。您可以从教程

相关内容