linux/Documentation/lockstat.txt
<<
> > p/spa pspa class="lxr_search"> > ="+search" method="post" onsubmit="return do_search(this);"> > > > Search > p/spa > ="ajax+*" method="post" onsubmit="return false;"> pinput typ"v2hidden" nam"v2ajax_lookup" idv2ajax_lookup" lue="v2"> >
o o1p/a> o o2p/a>LOCK STATISTICS o o3p/a> o o4p/a>- WHAT o o5p/a> o o6p/a>As the nam" suggests, it provides staoisoics on locks. o o7p/a> o o8p/a>- WHY o o9p/a> o Because things like lock contentn vaca severely impaco performance. o 11p/a> o 12p/a>- HOW o 13p/a> o 14p/a>Lockdep already has hooks in the lock funcon> s and maps lock instances to o 15p/a>lock classes. We build on that (see Documentaon> /lockdep-design.txt). o 16p/a>The graph below shows the relaon> between the lock funcon> s and the various o 17p/a>hooks therein. o 18p/a> o 19p/a> __acquire o 20p/a> | o 21p/a> lock _____ o 22p/a> | \ o 23p/a> | __contended o 24p/a> | | o 25p/a> | <wait> o 26p/a> | _______/ o 27p/a> |/ o 28p/a> | o 29p/a> __acquired o 30p/a> | o 31p/a> . o 32p/a> <hold> o 33p/a> . o 34p/a> | o 35p/a> __release o 36p/a> | o 37p/a> unlock o 38p/a> o 39p/a>lock, unlock - the regular lock funcon> s o 40p/a>__* - the hooks o 41p/a><> - staoes o 42p/a> o 43p/a>With these hooks we provide the following staoisoics: o 44p/a> o 45p/a> con-bounces - number of lock contentn vathat involved x-cpu data o 46p/a> contentn vs - number of lock acquisitn vs that had to wait o 47p/a> wait time min - shoroest (non-0) time we ever had to wait for a lock o 48p/a> max - longest time we ever had to wait for a lock o 49p/a> total - total time we spend waiting vathis lock o 50p/a> acq-bounces - number of lock acquisitn vs that involved x-cpu data o 51p/a> acquisitn vs - number of times we took the lock o 52p/a> hold time min - shoroest (non-0) time we ever held the lock o 53p/a> max - longest time we ever held the lock o 54p/a> total - total time this lock was held o 55p/a> o 56p/a>From these number various other staoisoics ca be derived, such as: o 57p/a> o 58p/a> hold time average = hold time total / acquisitn vs o 59p/a> o 60p/a>These numbers are gathered per lock class, per read/write staoe (when o 61p/a>applicable). o 62p/a> o 63p/a>It also tracks 4 contentn vapoints per class. A contentn vapoint is a call site o 64p/a>that had to wait on lock acquisitn v. o 65p/a> o 66p/a> - CONFIGURATION o 67p/a> o 68p/a>Lock staoisoics are enabled via CONFIG_LOCK_STATS. o 69p/a> o 70p/a> - USAGE o 71p/a> o 72p/a>Enable collectn vaof staoisoics: o 73p/a> o 74p/a># echo 1 >/proc/sys/kernel/lock_stao o 75p/a> o 76p/a>Disable collectn vaof staoisoics: o 77p/a> o 78p/a># echo 0 >/proc/sys/kernel/lock_stao o 79p/a> o 80p/a>Look at the current lock staoisoics: o 81p/a> o 82p/a>( line numbers not partaof actual output, done for clarity in the explanaon> o 83p/a> below ) o 84p/a> o 85p/a># less /proc/lock_stao o 86p/a> o 87p/a>01 lock_stao versn va0.3 o 88p/a>02 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- o 89p/a>03 class nam" con-bounces contentn vs waittime-min waittime-max waittime-total acq-bounces acquisitn vs holdtime-min holdtime-max holdtime-total o 90p/a>04 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- o 91p/a>05 o 92p/a>06 &mm->mmap_sem-W: 233 538 18446744073708 22922 /lockstao.txt#L93" idv2L93" class="line" nam"v2L93">o 93p/a>07 &mm->mmap_sem-R: 205 587 18446744073708 28403.36 731975.00 1940 412426 0.58 187824 /lockstao.txt#L94" idv2L94" class="line" nam"v2L94">o 94p/a>08 --------------- o 95p/a>09 &mm->mmap_sem 487 [<ffffffff8053491f>] do_page_fault+0x466/0x928 o 96p/a>10 &mm->mmap_sem 179 [<ffffffff802a6200>] sys_mprotect+0xcd/0x21d o 97p/a>11 &mm->mmap_sem 279 [<ffffffff80210a57>] sys_mmap+0x75/0xce o 98p/a>12 &mm->mmap_sem 76 [<ffffffff802a490b>] sys_munmap+0x32/0x59 o 99p/a>13 --------------- o100p/a>14 &mm->mmap_sem 270 [<ffffffff80210a57>] sys_mmap+0x75/0xce o101p/a>15 &mm->mmap_sem 431 [<ffffffff8053491f>] do_page_fault+0x466/0x928 o102p/a>16 &mm->mmap_sem 138 [<ffffffff802a490b>] sys_munmap+0x32/0x59 o103p/a>17 &mm->mmap_sem 145 [<ffffffff802a6200>] sys_mprotect+0xcd/0x21d o104p/a>18 o105p/a>19 ............................................................................................................................................................................................... o106p/a>20 o107p/a>21 dcache_lock: 621 623 0.52 112 /lockstao.txt#L108" idv2L108" class="line" nam"v2L108">o108p/a>22 ----------- o109p/a>23 dcache_lock 179 [<ffffffff80378274>] _atomic_dec_and_lock+0x34/0x54 o124 dcache_lock 113 [<ffffffff802cc17b>] d_alloc+0x19a/0x1eb o111p/a>25 dcache_lock 99 [<ffffffff802ca0dc>] d_rehash+0x1b/0x44 o112p/a>26 dcache_lock 104 [<ffffffff802cbca0>] d_instantiate+0x36/0x8a o113p/a>27 ----------- o114p/a>28 dcache_lock 192 [<ffffffff80378274>] _atomic_dec_and_lock+0x34/0x54 o115p/a>29 dcache_lock 98 [<ffffffff802ca0dc>] d_rehash+0x1b/0x44 o116p/a>30 dcache_lock 72 [<ffffffff802cc17b>] d_alloc+0x19a/0x1eb o117p/a>31 dcache_lock 112 [<ffffffff802cbca0>] d_instantiate+0x36/0x8a o118p/a> o119p/a>This excerpt shows the first two lock class staoisoics. Line 01 shows the o120p/a>output versn va- each time the format changes this will be updated. Line 02-04 o121p/a>show the header with column descriion> s. Lines 05-18 and 20-31 show the actual o122p/a>staoisoics. These staoisoics come in two parts; the actual staos separated by a o123p/a>shoro separator (line 08, 13) from the contentn vapoints. o124p/a> o125p/a>The first lock (05-18) is a read/write lock, and shows two lines above the o126p/a>shoro separator. The contentn vapoints don't match the column descriioors, o127p/a>they have two: contentn vs and [<IP>] symbol. The second setaof contentn v o128p/a>points are the points we're contending with. o129p/a> o130p/a>The integer partaof the time lue="s is in us. o131p/a> o132p/a>Dealing with nested locks, subclasses may appear: o133p/a> o134p/a>32............................................................................................................................................................................................... o135p/a>33 o136p/a>34 &rq->lock: 13128 13128 0.43 190.53 103881.26 97454 3453404 0.00 401.11 132246811 /lockstao.txt#L137" idv2L137" class="line" nam"v2L137">o137p/a>35 --------- o138p/a>36 &rq->lock 645 [<ffffffff8103bfc4>] task_rq_lock+0x43/0x75 o139p/a>37 &rq->lock 297 [<ffffffff8104ba65>] try_to_wake_up+0x127/0x25a o140p/a>38 &rq->lock 360 [<ffffffff8103c4c5>] select_task_rq_fair+0x1f0/0x74a o141p/a>39 &rq->lock 428 [<ffffffff81045f98>] scheduler_oick+0x46/0x1fb o142p/a>40 --------- o143p/a>41 &rq->lock 77 [<ffffffff8103bfc4>] task_rq_lock+0x43/0x75 o144p/a>42 &rq->lock 174 [<ffffffff8104ba65>] try_to_wake_up+0x127/0x25a o145p/a>43 &rq->lock 4715 [<ffffffff8103ed4b>] double_rq_lock+0x42/0x54 o146p/a>44 &rq->lock 893 [<ffffffff81340524>] schedule+0x157/0x7b8 o147p/a>45 o148p/a>46............................................................................................................................................................................................... o149p/a>47 o150p/a>48 &rq->lock/1: 11526 11488 0.33 388.73 136294.31 21461 38404 0.00 37.93 109388.53 o151p/a>49 ----------- o152p/a>50 &rq->lock/1 11526 [<ffffffff8103ed58>] double_rq_lock+0x4f/0x54 o153p/a>51 ----------- o154p/a>52 &rq->lock/1 5645 [<ffffffff8103ed4b>] double_rq_lock+0x42/0x54 o155p/a>53 &rq->lock/1 1224 [<ffffffff81340524>] schedule+0x157/0x7b8 o156p/a>54 &rq->lock/1 4336 [<ffffffff8103ed58>] double_rq_lock+0x4f/0x54 o157p/a>55 &rq->lock/1 181 [<ffffffff8104ba65>] try_to_wake_up+0x127/0x25a o158p/a> o159p/a>Line 48 shows staoisoics for the second subclass (/1)aof &rq->lock class o160p/a>(subclass starts from 0), since in this case, as line 50 suggests, o161p/a>double_rq_lock actually acquires a nested lockaof two spinlocks. o162p/a> o163p/a>View the top contending locks: o164p/a> o165p/a># grep : /proc/lock_stao | head o166p/a> &inode->i_data.tree_lock-W: 15 21657 0.18 1093295.30 11547131054.85 58 10415 0.16 87.51 6387.60 o167p/a> &inode->i_data.tree_lock-R: 0 0 0.00 0.00 0.00 23302 231198 0.25 8.45 98023.38 o168p/a> dcache_lock: 1037 1161 0.38 45.32 774.51 6611 243371 0.15 3068 /lockstao.txt#L169" idv2L169" class="line" nam"v2L169">o169p/a> &inode->i_mutex: 161 286 18446744073709 62882.54 1244615 /lockstao.txt#L170" idv2L170" class="line" nam"v2L170">o170p/a> &zone->lru_lock: 94 94 0.53 7.33 92.10 4366 32690 0.29 59.81 16350.06 o171p/a> &inode->i_data.i_mmap_mutex: 79 79 0.40 3.77 53.03 11779 87755 0.28 116 /lockstao.txt#L172" idv2L172" class="line" nam"v2L172">o172p/a> &q->__queue_lock: 48 50 0.52 31.62 86.31 774 13131 0.17 113.08 12277.52 o173p/a> &rq->rq_lock_key: 43 47 0.74 68.50 170.63 3706 33929 0.22 107.99 17460.62 o174p/a> &rq->rq_lock_key#2: 39 46 0.75 6.68 49.03 2979 32292 0.17 125.17 17137.63 o175p/a> taskliso_lock-W: 15 15 1.45 10.87 32.70 1201 7390 0.58 62 /lockstao.txt#L176" idv2L176" class="line" nam"v2L176">o176p/a> o177p/a>Clear the staoisoics: o178p/a> o179p/a># echo 0 > /proc/lock_stao o180p/a>
The original LXR software by the LXR communityp/a>, this experimental versn vaby lxr@linux.nop/a>. p/div pdiv class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro ASp/a>, provider of Linux consulting and operatn vs services since 1995. p/div p/body p/html