1- Glock internal locking rules
2- ------------------------------
1+ .. SPDX-License-Identifier: GPL-2.0
2+
3+ ============================
4+ Glock internal locking rules
5+ ============================
36
47This documents the basic principles of the glock state machine
58internals. Each glock (struct gfs2_glock in fs/gfs2/incore.h)
@@ -24,46 +27,52 @@ There are three lock states that users of the glock layer can request,
2427namely shared (SH), deferred (DF) and exclusive (EX). Those translate
2528to the following DLM lock modes:
2629
27- Glock mode | DLM lock mode
28- ------------------------------
29- UN | IV/NL Unlocked (no DLM lock associated with glock) or NL
30- SH | PR (Protected read)
31- DF | CW (Concurrent write)
32- EX | EX (Exclusive)
30+ ========== ====== =====================================================
31+ Glock mode DLM lock mode
32+ ========== ====== =====================================================
33+ UN IV/NL Unlocked (no DLM lock associated with glock) or NL
34+ SH PR (Protected read)
35+ DF CW (Concurrent write)
36+ EX EX (Exclusive)
37+ ========== ====== =====================================================
3338
3439Thus DF is basically a shared mode which is incompatible with the "normal"
3540shared lock mode, SH. In GFS2 the DF mode is used exclusively for direct I/O
3641operations. The glocks are basically a lock plus some routines which deal
3742with cache management. The following rules apply for the cache:
3843
39- Glock mode | Cache data | Cache Metadata | Dirty Data | Dirty Metadata
40- --------------------------------------------------------------------------
41- UN | No | No | No | No
42- SH | Yes | Yes | No | No
43- DF | No | Yes | No | No
44- EX | Yes | Yes | Yes | Yes
44+ ========== ========== ============== ========== ==============
45+ Glock mode Cache data Cache Metadata Dirty Data Dirty Metadata
46+ ========== ========== ============== ========== ==============
47+ UN No No No No
48+ SH Yes Yes No No
49+ DF No Yes No No
50+ EX Yes Yes Yes Yes
51+ ========== ========== ============== ========== ==============
4552
4653These rules are implemented using the various glock operations which
4754are defined for each type of glock. Not all types of glocks use
4855all the modes. Only inode glocks use the DF mode for example.
4956
5057Table of glock operations and per type constants:
5158
52- Field | Purpose
53- ----------------------------------------------------------------------------
54- go_xmote_th | Called before remote state change (e.g. to sync dirty data)
55- go_xmote_bh | Called after remote state change (e.g. to refill cache)
56- go_inval | Called if remote state change requires invalidating the cache
57- go_demote_ok | Returns boolean value of whether its ok to demote a glock
58- | (e.g. checks timeout, and that there is no cached data)
59- go_lock | Called for the first local holder of a lock
60- go_unlock | Called on the final local unlock of a lock
61- go_dump | Called to print content of object for debugfs file, or on
62- | error to dump glock to the log.
63- go_type | The type of the glock, LM_TYPE_.....
64- go_callback | Called if the DLM sends a callback to drop this lock
65- go_flags | GLOF_ASPACE is set, if the glock has an address space
66- | associated with it
59+ ============= =============================================================
60+ Field Purpose
61+ ============= =============================================================
62+ go_xmote_th Called before remote state change (e.g. to sync dirty data)
63+ go_xmote_bh Called after remote state change (e.g. to refill cache)
64+ go_inval Called if remote state change requires invalidating the cache
65+ go_demote_ok Returns boolean value of whether its ok to demote a glock
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
69+ go_dump Called to print content of object for debugfs file, or on
70+ error to dump glock to the log.
71+ go_type The type of the glock, ``LM_TYPE_* ``
72+ go_callback Called if the DLM sends a callback to drop this lock
73+ go_flags GLOF_ASPACE is set, if the glock has an address space
74+ associated with it
75+ ============= =============================================================
6776
6877The minimum hold time for each lock is the time after a remote lock
6978grant for which we ignore remote demote requests. This is in order to
@@ -82,29 +91,33 @@ rather than via the glock.
8291
8392Locking rules for glock operations:
8493
85- Operation | GLF_LOCK bit lock held | gl_lockref.lock spinlock held
86- -------------------------------------------------------------------------
87- go_xmote_th | Yes | No
88- go_xmote_bh | Yes | No
89- go_inval | Yes | No
90- go_demote_ok | Sometimes | Yes
91- go_lock | Yes | No
92- go_unlock | Yes | No
93- go_dump | Sometimes | Yes
94- go_callback | Sometimes (N/A) | Yes
95-
96- N.B. Operations must not drop either the bit lock or the spinlock
97- if its held on entry. go_dump and do_demote_ok must never block.
98- Note that go_dump will only be called if the glock's state
99- indicates that it is caching uptodate data.
94+ ============= ====================== =============================
95+ Operation GLF_LOCK bit lock held gl_lockref.lock spinlock held
96+ ============= ====================== =============================
97+ go_xmote_th Yes No
98+ go_xmote_bh Yes No
99+ go_inval Yes No
100+ go_demote_ok Sometimes Yes
101+ go_lock Yes No
102+ go_unlock Yes No
103+ go_dump Sometimes Yes
104+ go_callback Sometimes (N/A) Yes
105+ ============= ====================== =============================
106+
107+ .. Note ::
108+
109+ Operations must not drop either the bit lock or the spinlock
110+ if its held on entry. go_dump and do_demote_ok must never block.
111+ Note that go_dump will only be called if the glock's state
112+ indicates that it is caching uptodate data.
100113
101114Glock locking order within GFS2:
102115
103116 1. i_rwsem (if required)
104117 2. Rename glock (for rename only)
105118 3. Inode glock(s)
106119 (Parents before children, inodes at "same level" with same parent in
107- lock number order)
120+ lock number order)
108121 4. Rgrp glock(s) (for (de)allocation operations)
109122 5. Transaction glock (via gfs2_trans_begin) for non-read operations
110123 6. i_rw_mutex (if required)
@@ -117,8 +130,8 @@ determine the lifetime of the inode in question. Locking of inodes
117130is on a per-inode basis. Locking of rgrps is on a per rgrp basis.
118131In general we prefer to lock local locks prior to cluster locks.
119132
120- Glock Statistics
121- -- ----------------
133+ Glock Statistics
134+ ----------------
122135
123136The stats are divided into two sets: those relating to the
124137super block and those relating to an individual glock. The
@@ -173,8 +186,8 @@ we'd like to get a better idea of these timings:
1731861. To be able to better set the glock "min hold time"
1741872. To spot performance issues more easily
1751883. To improve the algorithm for selecting resource groups for
176- allocation (to base it on lock wait time, rather than blindly
177- using a "try lock")
189+ allocation (to base it on lock wait time, rather than blindly
190+ using a "try lock")
178191
179192Due to the smoothing action of the updates, a step change in
180193some input quantity being sampled will only fully be taken
@@ -195,25 +208,30 @@ as possible. There are always inaccuracies in any
195208measuring system, but I hope this is as accurate as we
196209can reasonably make it.
197210
198- Per sb stats can be found here:
199- /sys/kernel/debug/gfs2/<fsname>/sbstats
200- Per glock stats can be found here:
201- /sys/kernel/debug/gfs2/<fsname>/glstats
211+ Per sb stats can be found here::
212+
213+ /sys/kernel/debug/gfs2/<fsname>/sbstats
214+
215+ Per glock stats can be found here::
216+
217+ /sys/kernel/debug/gfs2/<fsname>/glstats
202218
203219Assuming that debugfs is mounted on /sys/kernel/debug and also
204220that <fsname> is replaced with the name of the gfs2 filesystem
205221in question.
206222
207223The abbreviations used in the output as are follows:
208224
209- srtt - Smoothed round trip time for non-blocking dlm requests
210- srttvar - Variance estimate for srtt
211- srttb - Smoothed round trip time for (potentially) blocking dlm requests
212- srttvarb - Variance estimate for srttb
213- sirt - Smoothed inter-request time (for dlm requests)
214- sirtvar - Variance estimate for sirt
215- dlm - Number of dlm requests made (dcnt in glstats file)
216- queue - Number of glock requests queued (qcnt in glstats file)
225+ ========= ================================================================
226+ srtt Smoothed round trip time for non blocking dlm requests
227+ srttvar Variance estimate for srtt
228+ srttb Smoothed round trip time for (potentially) blocking dlm requests
229+ srttvarb Variance estimate for srttb
230+ sirt Smoothed inter request time (for dlm requests)
231+ sirtvar Variance estimate for sirt
232+ dlm Number of dlm requests made (dcnt in glstats file)
233+ queue Number of glock requests queued (qcnt in glstats file)
234+ ========= ================================================================
217235
218236The sbstats file contains a set of these stats for each glock type (so 8 lines
219237for each type) and for each cpu (one column per cpu). The glstats file contains
@@ -224,9 +242,12 @@ The gfs2_glock_lock_time tracepoint prints out the current values of the stats
224242for the glock in question, along with some addition information on each dlm
225243reply that is received:
226244
227- status - The status of the dlm request
228- flags - The dlm request flags
229- tdiff - The time taken by this specific request
245+ ====== =======================================
246+ status The status of the dlm request
247+ flags The dlm request flags
248+ tdiff The time taken by this specific request
249+ ====== =======================================
250+
230251(remaining fields as per above list)
231252
232253
0 commit comments