博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux:查看内核锁
阅读量:4028 次
发布时间:2019-05-24

本文共 8171 字,大约阅读时间需要 27 分钟。

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/lockstat.txt 

LOCK STATISTICS- WHATAs the name suggests, it provides statistics on locks.- WHYBecause things like lock contention can severely impact performance.- HOWLockdep already has hooks in the lock functions and maps lock instances tolock classes. We build on that (see Documentation/lockdep-design.txt).The graph below shows the relation between the lock functions and the varioushooks therein.        __acquire            |           lock _____            |        \            |    __contended            |         |            |       
| _______/ |/ | __acquired | .
. | __release | unlocklock, unlock - the regular lock functions__* - the hooks<> - statesWith these hooks we provide the following statistics: con-bounces - number of lock contention that involved x-cpu data contentions - number of lock acquisitions that had to wait wait time min - shortest (non-0) time we ever had to wait for a lock max - longest time we ever had to wait for a lock total - total time we spend waiting on this lock avg - average time spent waiting on this lock acq-bounces - number of lock acquisitions that involved x-cpu data acquisitions - number of times we took the lock hold time min - shortest (non-0) time we ever held the lock max - longest time we ever held the lock total - total time this lock was held avg - average time this lock was heldThese numbers are gathered per lock class, per read/write state (whenapplicable).It also tracks 4 contention points per class. A contention point is a call sitethat had to wait on lock acquisition. - CONFIGURATIONLock statistics are enabled via CONFIG_LOCK_STAT. - USAGEEnable collection of statistics:# echo 1 >/proc/sys/kernel/lock_statDisable collection of statistics:# echo 0 >/proc/sys/kernel/lock_statLook at the current lock statistics:( line numbers not part of actual output, done for clarity in the explanation below )# less /proc/lock_stat01 lock_stat version 0.402-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------03 class name con-bounces contentions waittime-min waittime-max waittime-total waittime-avg acq-bounces acquisitions holdtime-min holdtime-max holdtime-total holdtime-avg04-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------0506 &mm->mmap_sem-W: 46 84 0.26 939.10 16371.53 194.90 47291 2922365 0.16 2220301.69 17464026916.32 5975.9907 &mm->mmap_sem-R: 37 100 1.31 299502.61 325629.52 3256.30 212344 34316685 0.10 7744.91 95016910.20 2.7708 ---------------09 &mm->mmap_sem 1 [
] khugepaged_scan_mm_slot+0x57/0x28019 &mm->mmap_sem 96 [
] __do_page_fault+0x1d4/0x51011 &mm->mmap_sem 34 [
] vm_mmap_pgoff+0x87/0xd012 &mm->mmap_sem 17 [
] vm_munmap+0x41/0x8013 ---------------14 &mm->mmap_sem 1 [
] dup_mmap+0x2a/0x3f015 &mm->mmap_sem 60 [
] SyS_mprotect+0xe9/0x25016 &mm->mmap_sem 41 [
] __do_page_fault+0x1d4/0x51017 &mm->mmap_sem 68 [
] vm_mmap_pgoff+0x87/0xd01819.............................................................................................................................................................................................................................2021 unix_table_lock: 110 112 0.21 49.24 163.91 1.46 21094 66312 0.12 624.42 31589.81 0.4822 ---------------23 unix_table_lock 45 [
] unix_create1+0x16e/0x1b024 unix_table_lock 47 [
] unix_release_sock+0x31/0x25025 unix_table_lock 15 [
] unix_find_other+0x117/0x23026 unix_table_lock 5 [
] unix_autobind+0x11f/0x1b027 ---------------28 unix_table_lock 39 [
] unix_release_sock+0x31/0x25029 unix_table_lock 49 [
] unix_create1+0x16e/0x1b030 unix_table_lock 20 [
] unix_find_other+0x117/0x23031 unix_table_lock 4 [
] unix_autobind+0x11f/0x1b0This excerpt shows the first two lock class statistics. Line 01 shows theoutput version - each time the format changes this will be updated. Line 02-04show the header with column descriptions. Lines 05-18 and 20-31 show the actualstatistics. These statistics come in two parts; the actual stats separated by ashort separator (line 08, 13) from the contention points.The first lock (05-18) is a read/write lock, and shows two lines above theshort separator. The contention points don't match the column descriptors,they have two: contentions and [
] symbol. The second set of contentionpoints are the points we're contending with.The integer part of the time values is in us.Dealing with nested locks, subclasses may appear:32...........................................................................................................................................................................................................................3334 &rq->lock: 13128 13128 0.43 190.53 103881.26 7.91 97454 3453404 0.00 401.11 13224683.11 3.8235 ---------36 &rq->lock 645 [
] task_rq_lock+0x43/0x7537 &rq->lock 297 [
] try_to_wake_up+0x127/0x25a38 &rq->lock 360 [
] select_task_rq_fair+0x1f0/0x74a39 &rq->lock 428 [
] scheduler_tick+0x46/0x1fb40 ---------41 &rq->lock 77 [
] task_rq_lock+0x43/0x7542 &rq->lock 174 [
] try_to_wake_up+0x127/0x25a43 &rq->lock 4715 [
] double_rq_lock+0x42/0x5444 &rq->lock 893 [
] schedule+0x157/0x7b84546...........................................................................................................................................................................................................................4748 &rq->lock/1: 1526 11488 0.33 388.73 136294.31 11.86 21461 38404 0.00 37.93 109388.53 2.8449 -----------50 &rq->lock/1 11526 [
] double_rq_lock+0x4f/0x5451 -----------52 &rq->lock/1 5645 [
] double_rq_lock+0x42/0x5453 &rq->lock/1 1224 [
] schedule+0x157/0x7b854 &rq->lock/1 4336 [
] double_rq_lock+0x4f/0x5455 &rq->lock/1 181 [
] try_to_wake_up+0x127/0x25aLine 48 shows statistics for the second subclass (/1) of &rq->lock class(subclass starts from 0), since in this case, as line 50 suggests,double_rq_lock actually acquires a nested lock of two spinlocks.View the top contending locks:# grep : /proc/lock_stat | head clockevents_lock: 2926159 2947636 0.15 46882.81 1784540466.34 605.41 3381345 3879161 0.00 2260.97 53178395.68 13.71 tick_broadcast_lock: 346460 346717 0.18 2257.43 39364622.71 113.54 3642919 4242696 0.00 2263.79 49173646.60 11.59 &mapping->i_mmap_mutex: 203896 203899 3.36 645530.05 31767507988.39 155800.21 3361776 8893984 0.17 2254.15 14110121.02 1.59 &rq->lock: 135014 136909 0.18 606.09 842160.68 6.15 1540728 10436146 0.00 728.72 17606683.41 1.69 &(&zone->lru_lock)->rlock: 93000 94934 0.16 59.18 188253.78 1.98 1199912 3809894 0.15 391.40 3559518.81 0.93 tasklist_lock-W: 40667 41130 0.23 1189.42 428980.51 10.43 270278 510106 0.16 653.51 3939674.91 7.72 tasklist_lock-R: 21298 21305 0.20 1310.05 215511.12 10.12 186204 241258 0.14 1162.33 1179779.23 4.89 rcu_node_1: 47656 49022 0.16 635.41 193616.41 3.95 844888 1865423 0.00 764.26 1656226.96 0.89 &(&dentry->d_lockref.lock)->rlock: 39791 40179 0.15 1302.08 88851.96 2.21 2790851 12527025 0.10 1910.75 3379714.27 0.27 rcu_node_0: 29203 30064 0.16 786.55 1555573.00 51.74 88963 244254 0.00 398.87 428872.51 1.76Clear the statistics:# echo 0 > /proc/lock_stat

转载地址:http://deobi.baihongyu.com/

你可能感兴趣的文章
新基建
查看>>
Google SRE Four Golden Signals
查看>>
统一智能运维管理平台
查看>>
任正非告别荣耀讲话—-陌生的感动
查看>>
什么是POC
查看>>
标记一下
查看>>
一个ahk小函数, 实现版本号的比较
查看>>
IP报文格式学习笔记
查看>>
autohotkey快捷键显示隐藏文件和文件扩展名
查看>>
Linux中的进程
查看>>
学习笔记4——猜数字游戏,随机数
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
学习设计模式(5)——装饰器模式
查看>>
学习设计模式(6)——建造者模式
查看>>
rep movsd ,N - move all of our dwords--【解决办法】
查看>>
查找连续相同值的算法,并给出连续相同值的个数以及位置
查看>>
关于STL中的Vector,list和deque
查看>>
错误:常量中有换行符
查看>>
学习设计模式(8)——单例模式2
查看>>