aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/filesystems
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2013-06-21 08:58:15 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-06-29 04:57:42 -0400
commit1c8c601a8c0dc59fe64907dcd9d512a3d181ddc7 (patch)
tree1a9c91de460a7c2f9fd6ad77060be484456e49b9 /Documentation/filesystems
parent889746917193ab3007a779d65231510715b20fb6 (diff)
locks: protect most of the file_lock handling with i_lock
Having a global lock that protects all of this code is a clear scalability problem. Instead of doing that, move most of the code to be protected by the i_lock instead. The exceptions are the global lists that the ->fl_link sits on, and the ->fl_block list. ->fl_link is what connects these structures to the global lists, so we must ensure that we hold those locks when iterating over or updating these lists. Furthermore, sound deadlock detection requires that we hold the blocked_list state steady while checking for loops. We also must ensure that the search and update to the list are atomic. For the checking and insertion side of the blocked_list, push the acquisition of the global lock into __posix_lock_file and ensure that checking and update of the blocked_list is done without dropping the lock in between. On the removal side, when waking up blocked lock waiters, take the global lock before walking the blocked list and dequeue the waiters from the global list prior to removal from the fl_block list. With this, deadlock detection should be race free while we minimize excessive file_lock_lock thrashing. Finally, in order to avoid a lock inversion problem when handling /proc/locks output we must ensure that manipulations of the fl_block list are also protected by the file_lock_lock. Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'Documentation/filesystems')
-rw-r--r--Documentation/filesystems/Locking21
1 files changed, 14 insertions, 7 deletions
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking
index f94a362f408e..c2963a74fbc3 100644
--- a/Documentation/filesystems/Locking
+++ b/Documentation/filesystems/Locking
@@ -342,7 +342,7 @@ prototypes:
342 342
343 343
344locking rules: 344locking rules:
345 file_lock_lock may block 345 inode->i_lock may block
346fl_copy_lock: yes no 346fl_copy_lock: yes no
347fl_release_private: maybe no 347fl_release_private: maybe no
348 348
@@ -355,12 +355,19 @@ prototypes:
355 int (*lm_change)(struct file_lock **, int); 355 int (*lm_change)(struct file_lock **, int);
356 356
357locking rules: 357locking rules:
358 file_lock_lock may block 358
359lm_compare_owner: yes no 359 inode->i_lock file_lock_lock may block
360lm_notify: yes no 360lm_compare_owner: yes[1] maybe no
361lm_grant: no no 361lm_notify: yes yes no
362lm_break: yes no 362lm_grant: no no no
363lm_change yes no 363lm_break: yes no no
364lm_change yes no no
365
366[1]: ->lm_compare_owner is generally called with *an* inode->i_lock held. It
367may not be the i_lock of the inode for either file_lock being compared! This is
368the case with deadlock detection, since the code has to chase down the owners
369of locks that may be entirely unrelated to the one on which the lock is being
370acquired. When doing a search for deadlocks, the file_lock_lock is also held.
364 371
365--------------------------- buffer_head ----------------------------------- 372--------------------------- buffer_head -----------------------------------
366prototypes: 373prototypes: