~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/filesystems/gfs2-glocks.rst

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/filesystems/gfs2-glocks.rst (Version linux-6.11.5) and /Documentation/filesystems/gfs2-glocks.rst (Version linux-6.3.13)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 ============================                        3 ============================
  4 Glock internal locking rules                        4 Glock internal locking rules
  5 ============================                        5 ============================
  6                                                     6 
  7 This documents the basic principles of the glo      7 This documents the basic principles of the glock state machine
  8 internals. Each glock (struct gfs2_glock in fs      8 internals. Each glock (struct gfs2_glock in fs/gfs2/incore.h)
  9 has two main (internal) locks:                      9 has two main (internal) locks:
 10                                                    10 
 11  1. A spinlock (gl_lockref.lock) which protect     11  1. A spinlock (gl_lockref.lock) which protects the internal state such
 12     as gl_state, gl_target and the list of hol     12     as gl_state, gl_target and the list of holders (gl_holders)
 13  2. A non-blocking bit lock, GLF_LOCK, which i     13  2. A non-blocking bit lock, GLF_LOCK, which is used to prevent other
 14     threads from making calls to the DLM, etc.     14     threads from making calls to the DLM, etc. at the same time. If a
 15     thread takes this lock, it must then call      15     thread takes this lock, it must then call run_queue (usually via the
 16     workqueue) when it releases it in order to     16     workqueue) when it releases it in order to ensure any pending tasks
 17     are completed.                                 17     are completed.
 18                                                    18 
 19 The gl_holders list contains all the queued lo     19 The gl_holders list contains all the queued lock requests (not
 20 just the holders) associated with the glock. I     20 just the holders) associated with the glock. If there are any
 21 held locks, then they will be contiguous entri     21 held locks, then they will be contiguous entries at the head
 22 of the list. Locks are granted in strictly the     22 of the list. Locks are granted in strictly the order that they
 23 are queued.                                    !!  23 are queued, except for those marked LM_FLAG_PRIORITY which are
                                                   >>  24 used only during recovery, and even then only for journal locks.
 24                                                    25 
 25 There are three lock states that users of the      26 There are three lock states that users of the glock layer can request,
 26 namely shared (SH), deferred (DF) and exclusiv     27 namely shared (SH), deferred (DF) and exclusive (EX). Those translate
 27 to the following DLM lock modes:                   28 to the following DLM lock modes:
 28                                                    29 
 29 ==========      ====== =======================     30 ==========      ====== =====================================================
 30 Glock mode      DLM    lock mode                   31 Glock mode      DLM    lock mode
 31 ==========      ====== =======================     32 ==========      ====== =====================================================
 32     UN          IV/NL  Unlocked (no DLM lock a     33     UN          IV/NL  Unlocked (no DLM lock associated with glock) or NL
 33     SH          PR     (Protected read)            34     SH          PR     (Protected read)
 34     DF          CW     (Concurrent write)          35     DF          CW     (Concurrent write)
 35     EX          EX     (Exclusive)                 36     EX          EX     (Exclusive)
 36 ==========      ====== =======================     37 ==========      ====== =====================================================
 37                                                    38 
 38 Thus DF is basically a shared mode which is in     39 Thus DF is basically a shared mode which is incompatible with the "normal"
 39 shared lock mode, SH. In GFS2 the DF mode is u     40 shared lock mode, SH. In GFS2 the DF mode is used exclusively for direct I/O
 40 operations. The glocks are basically a lock pl     41 operations. The glocks are basically a lock plus some routines which deal
 41 with cache management. The following rules app     42 with cache management. The following rules apply for the cache:
 42                                                    43 
 43 ==========      ==============   ==========    !!  44 ==========      ==========   ==============   ==========   ==============
 44 Glock mode      Cache Metadata   Cache data    !!  45 Glock mode      Cache data   Cache Metadata   Dirty Data   Dirty Metadata
 45 ==========      ==============   ==========    !!  46 ==========      ==========   ==============   ==========   ==============
 46     UN                No            No         !!  47     UN             No              No             No            No
 47     DF                Yes           No         !!  48     SH             Yes             Yes            No            No
 48     SH                Yes           Yes        !!  49     DF             No              Yes            No            No
 49     EX                Yes           Yes        !!  50     EX             Yes             Yes            Yes           Yes
 50 ==========      ==============   ==========    !!  51 ==========      ==========   ==============   ==========   ==============
 51                                                    52 
 52 These rules are implemented using the various      53 These rules are implemented using the various glock operations which
 53 are defined for each type of glock. Not all ty     54 are defined for each type of glock. Not all types of glocks use
 54 all the modes. Only inode glocks use the DF mo     55 all the modes. Only inode glocks use the DF mode for example.
 55                                                    56 
 56 Table of glock operations and per type constan     57 Table of glock operations and per type constants:
 57                                                    58 
 58 ==============     =========================== !!  59 =============      =============================================================
 59 Field              Purpose                         60 Field              Purpose
 60 ==============     =========================== !!  61 =============      =============================================================
 61 go_sync            Called before remote state  !!  62 go_xmote_th        Called before remote state change (e.g. to sync dirty data)
 62 go_xmote_bh        Called after remote state c     63 go_xmote_bh        Called after remote state change (e.g. to refill cache)
 63 go_inval           Called if remote state chan     64 go_inval           Called if remote state change requires invalidating the cache
 64 go_instantiate     Called when a glock has bee !!  65 go_demote_ok       Returns boolean value of whether its ok to demote a glock
 65 go_held            Called every time a glock h !!  66                    (e.g. checks timeout, and that there is no cached data)
                                                   >>  67 go_lock            Called for the first local holder of a lock
                                                   >>  68 go_unlock          Called on the final local unlock of a lock
 66 go_dump            Called to print content of      69 go_dump            Called to print content of object for debugfs file, or on
 67                    error to dump glock to the      70                    error to dump glock to the log.
 68 go_callback        Called if the DLM sends a c << 
 69 go_unlocked        Called when a glock is unlo << 
 70 go_type            The type of the glock, ``LM     71 go_type            The type of the glock, ``LM_TYPE_*``
                                                   >>  72 go_callback        Called if the DLM sends a callback to drop this lock
 71 go_flags           GLOF_ASPACE is set, if the      73 go_flags           GLOF_ASPACE is set, if the glock has an address space
 72                    associated with it              74                    associated with it
 73 ==============     =========================== !!  75 =============      =============================================================
 74                                                    76 
 75 The minimum hold time for each lock is the tim     77 The minimum hold time for each lock is the time after a remote lock
 76 grant for which we ignore remote demote reques     78 grant for which we ignore remote demote requests. This is in order to
 77 prevent a situation where locks are being boun     79 prevent a situation where locks are being bounced around the cluster
 78 from node to node with none of the nodes makin     80 from node to node with none of the nodes making any progress. This
 79 tends to show up most with shared mmapped file !!  81 tends to show up most with shared mmaped files which are being written
 80 to by multiple nodes. By delaying the demotion     82 to by multiple nodes. By delaying the demotion in response to a
 81 remote callback, that gives the userspace prog     83 remote callback, that gives the userspace program time to make
 82 some progress before the pages are unmapped.       84 some progress before the pages are unmapped.
 83                                                    85 
 84 Eventually, we hope to make the glock "EX" mod !!  86 There is a plan to try and remove the go_lock and go_unlock callbacks
 85 local locking will be done with the i_mutex as !!  87 if possible, in order to try and speed up the fast path though the locking.
 86 glock.                                         !!  88 Also, eventually we hope to make the glock "EX" mode locally shared
                                                   >>  89 such that any local locking will be done with the i_mutex as required
                                                   >>  90 rather than via the glock.
 87                                                    91 
 88 Locking rules for glock operations:                92 Locking rules for glock operations:
 89                                                    93 
 90 ==============   ======================    === !!  94 =============    ======================    =============================
 91 Operation        GLF_LOCK bit lock held    gl_     95 Operation        GLF_LOCK bit lock held    gl_lockref.lock spinlock held
 92 ==============   ======================    === !!  96 =============    ======================    =============================
 93 go_sync               Yes                      !!  97 go_xmote_th           Yes                       No
 94 go_xmote_bh           Yes                          98 go_xmote_bh           Yes                       No
 95 go_inval              Yes                          99 go_inval              Yes                       No
 96 go_instantiate        No                       !! 100 go_demote_ok          Sometimes                 Yes
 97 go_held               No                       !! 101 go_lock               Yes                       No
                                                   >> 102 go_unlock             Yes                       No
 98 go_dump               Sometimes                   103 go_dump               Sometimes                 Yes
 99 go_callback           Sometimes (N/A)             104 go_callback           Sometimes (N/A)           Yes
100 go_unlocked           Yes                      !! 105 =============    ======================    =============================
101 ==============   ======================    === << 
102                                                   106 
103 .. Note::                                         107 .. Note::
104                                                   108 
105    Operations must not drop either the bit loc    109    Operations must not drop either the bit lock or the spinlock
106    if its held on entry. go_dump and do_demote    110    if its held on entry. go_dump and do_demote_ok must never block.
107    Note that go_dump will only be called if th    111    Note that go_dump will only be called if the glock's state
108    indicates that it is caching uptodate data.    112    indicates that it is caching uptodate data.
109                                                   113 
110 Glock locking order within GFS2:                  114 Glock locking order within GFS2:
111                                                   115 
112  1. i_rwsem (if required)                         116  1. i_rwsem (if required)
113  2. Rename glock (for rename only)                117  2. Rename glock (for rename only)
114  3. Inode glock(s)                                118  3. Inode glock(s)
115     (Parents before children, inodes at "same     119     (Parents before children, inodes at "same level" with same parent in
116     lock number order)                            120     lock number order)
117  4. Rgrp glock(s) (for (de)allocation operatio    121  4. Rgrp glock(s) (for (de)allocation operations)
118  5. Transaction glock (via gfs2_trans_begin) f    122  5. Transaction glock (via gfs2_trans_begin) for non-read operations
119  6. i_rw_mutex (if required)                      123  6. i_rw_mutex (if required)
120  7. Page lock  (always last, very important!)     124  7. Page lock  (always last, very important!)
121                                                   125 
122 There are two glocks per inode. One deals with    126 There are two glocks per inode. One deals with access to the inode
123 itself (locking order as above), and the other    127 itself (locking order as above), and the other, known as the iopen
124 glock is used in conjunction with the i_nlink     128 glock is used in conjunction with the i_nlink field in the inode to
125 determine the lifetime of the inode in questio    129 determine the lifetime of the inode in question. Locking of inodes
126 is on a per-inode basis. Locking of rgrps is o    130 is on a per-inode basis. Locking of rgrps is on a per rgrp basis.
127 In general we prefer to lock local locks prior    131 In general we prefer to lock local locks prior to cluster locks.
128                                                   132 
129 Glock Statistics                                  133 Glock Statistics
130 ----------------                                  134 ----------------
131                                                   135 
132 The stats are divided into two sets: those rel    136 The stats are divided into two sets: those relating to the
133 super block and those relating to an individua    137 super block and those relating to an individual glock. The
134 super block stats are done on a per cpu basis     138 super block stats are done on a per cpu basis in order to
135 try and reduce the overhead of gathering them.    139 try and reduce the overhead of gathering them. They are also
136 further divided by glock type. All timings are    140 further divided by glock type. All timings are in nanoseconds.
137                                                   141 
138 In the case of both the super block and glock     142 In the case of both the super block and glock statistics,
139 the same information is gathered in each case.    143 the same information is gathered in each case. The super
140 block timing statistics are used to provide de    144 block timing statistics are used to provide default values for
141 the glock timing statistics, so that newly cre    145 the glock timing statistics, so that newly created glocks
142 should have, as far as possible, a sensible st    146 should have, as far as possible, a sensible starting point.
143 The per-glock counters are initialised to zero    147 The per-glock counters are initialised to zero when the
144 glock is created. The per-glock statistics are    148 glock is created. The per-glock statistics are lost when
145 the glock is ejected from memory.                 149 the glock is ejected from memory.
146                                                   150 
147 The statistics are divided into three pairs of    151 The statistics are divided into three pairs of mean and
148 variance, plus two counters. The mean/variance    152 variance, plus two counters. The mean/variance pairs are
149 smoothed exponential estimates and the algorit    153 smoothed exponential estimates and the algorithm used is
150 one which will be very familiar to those used     154 one which will be very familiar to those used to calculation
151 of round trip times in network code. See "TCP/    155 of round trip times in network code. See "TCP/IP Illustrated,
152 Volume 1", W. Richard Stevens, sect 21.3, "Rou    156 Volume 1", W. Richard Stevens, sect 21.3, "Round-Trip Time Measurement",
153 p. 299 and onwards. Also, Volume 2, Sect. 25.1    157 p. 299 and onwards. Also, Volume 2, Sect. 25.10, p. 838 and onwards.
154 Unlike the TCP/IP Illustrated case, the mean a    158 Unlike the TCP/IP Illustrated case, the mean and variance are
155 not scaled, but are in units of integer nanose    159 not scaled, but are in units of integer nanoseconds.
156                                                   160 
157 The three pairs of mean/variance measure the f    161 The three pairs of mean/variance measure the following
158 things:                                           162 things:
159                                                   163 
160  1. DLM lock time (non-blocking requests)         164  1. DLM lock time (non-blocking requests)
161  2. DLM lock time (blocking requests)             165  2. DLM lock time (blocking requests)
162  3. Inter-request time (again to the DLM)         166  3. Inter-request time (again to the DLM)
163                                                   167 
164 A non-blocking request is one which will compl    168 A non-blocking request is one which will complete right
165 away, whatever the state of the DLM lock in qu    169 away, whatever the state of the DLM lock in question. That
166 currently means any requests when (a) the curr    170 currently means any requests when (a) the current state of
167 the lock is exclusive, i.e. a lock demotion (b    171 the lock is exclusive, i.e. a lock demotion (b) the requested
168 state is either null or unlocked (again, a dem    172 state is either null or unlocked (again, a demotion) or (c) the
169 "try lock" flag is set. A blocking request cov    173 "try lock" flag is set. A blocking request covers all the other
170 lock requests.                                    174 lock requests.
171                                                   175 
172 There are two counters. The first is there pri    176 There are two counters. The first is there primarily to show
173 how many lock requests have been made, and thu    177 how many lock requests have been made, and thus how much data
174 has gone into the mean/variance calculations.     178 has gone into the mean/variance calculations. The other counter
175 is counting queuing of holders at the top laye    179 is counting queuing of holders at the top layer of the glock
176 code. Hopefully that number will be a lot larg    180 code. Hopefully that number will be a lot larger than the number
177 of dlm lock requests issued.                      181 of dlm lock requests issued.
178                                                   182 
179 So why gather these statistics? There are seve    183 So why gather these statistics? There are several reasons
180 we'd like to get a better idea of these timing    184 we'd like to get a better idea of these timings:
181                                                   185 
182 1. To be able to better set the glock "min hol    186 1. To be able to better set the glock "min hold time"
183 2. To spot performance issues more easily         187 2. To spot performance issues more easily
184 3. To improve the algorithm for selecting reso    188 3. To improve the algorithm for selecting resource groups for
185    allocation (to base it on lock wait time, r    189    allocation (to base it on lock wait time, rather than blindly
186    using a "try lock")                            190    using a "try lock")
187                                                   191 
188 Due to the smoothing action of the updates, a     192 Due to the smoothing action of the updates, a step change in
189 some input quantity being sampled will only fu    193 some input quantity being sampled will only fully be taken
190 into account after 8 samples (or 4 for the var    194 into account after 8 samples (or 4 for the variance) and this
191 needs to be carefully considered when interpre    195 needs to be carefully considered when interpreting the
192 results.                                          196 results.
193                                                   197 
194 Knowing both the time it takes a lock request     198 Knowing both the time it takes a lock request to complete and
195 the average time between lock requests for a g    199 the average time between lock requests for a glock means we
196 can compute the total percentage of the time f    200 can compute the total percentage of the time for which the
197 node is able to use a glock vs. time that the     201 node is able to use a glock vs. time that the rest of the
198 cluster has its share. That will be very usefu    202 cluster has its share. That will be very useful when setting
199 the lock min hold time.                           203 the lock min hold time.
200                                                   204 
201 Great care has been taken to ensure that we       205 Great care has been taken to ensure that we
202 measure exactly the quantities that we want, a    206 measure exactly the quantities that we want, as accurately
203 as possible. There are always inaccuracies in     207 as possible. There are always inaccuracies in any
204 measuring system, but I hope this is as accura    208 measuring system, but I hope this is as accurate as we
205 can reasonably make it.                           209 can reasonably make it.
206                                                   210 
207 Per sb stats can be found here::                  211 Per sb stats can be found here::
208                                                   212 
209     /sys/kernel/debug/gfs2/<fsname>/sbstats       213     /sys/kernel/debug/gfs2/<fsname>/sbstats
210                                                   214 
211 Per glock stats can be found here::               215 Per glock stats can be found here::
212                                                   216 
213     /sys/kernel/debug/gfs2/<fsname>/glstats       217     /sys/kernel/debug/gfs2/<fsname>/glstats
214                                                   218 
215 Assuming that debugfs is mounted on /sys/kerne    219 Assuming that debugfs is mounted on /sys/kernel/debug and also
216 that <fsname> is replaced with the name of the    220 that <fsname> is replaced with the name of the gfs2 filesystem
217 in question.                                      221 in question.
218                                                   222 
219 The abbreviations used in the output as are fo    223 The abbreviations used in the output as are follows:
220                                                   224 
221 =========  ===================================    225 =========  ================================================================
222 srtt       Smoothed round trip time for non bl    226 srtt       Smoothed round trip time for non blocking dlm requests
223 srttvar    Variance estimate for srtt             227 srttvar    Variance estimate for srtt
224 srttb      Smoothed round trip time for (poten    228 srttb      Smoothed round trip time for (potentially) blocking dlm requests
225 srttvarb   Variance estimate for srttb            229 srttvarb   Variance estimate for srttb
226 sirt       Smoothed inter request time (for dl    230 sirt       Smoothed inter request time (for dlm requests)
227 sirtvar    Variance estimate for sirt             231 sirtvar    Variance estimate for sirt
228 dlm        Number of dlm requests made (dcnt i    232 dlm        Number of dlm requests made (dcnt in glstats file)
229 queue      Number of glock requests queued (qc    233 queue      Number of glock requests queued (qcnt in glstats file)
230 =========  ===================================    234 =========  ================================================================
231                                                   235 
232 The sbstats file contains a set of these stats    236 The sbstats file contains a set of these stats for each glock type (so 8 lines
233 for each type) and for each cpu (one column pe    237 for each type) and for each cpu (one column per cpu). The glstats file contains
234 a set of these stats for each glock in a simil    238 a set of these stats for each glock in a similar format to the glocks file, but
235 using the format mean/variance for each of the    239 using the format mean/variance for each of the timing stats.
236                                                   240 
237 The gfs2_glock_lock_time tracepoint prints out    241 The gfs2_glock_lock_time tracepoint prints out the current values of the stats
238 for the glock in question, along with some add    242 for the glock in question, along with some addition information on each dlm
239 reply that is received:                           243 reply that is received:
240                                                   244 
241 ======   =====================================    245 ======   =======================================
242 status   The status of the dlm request            246 status   The status of the dlm request
243 flags    The dlm request flags                    247 flags    The dlm request flags
244 tdiff    The time taken by this specific reque    248 tdiff    The time taken by this specific request
245 ======   =====================================    249 ======   =======================================
246                                                   250 
247 (remaining fields as per above list)              251 (remaining fields as per above list)
248                                                   252 
249                                                   253 
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php