linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.com>
To: Ted Tso <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org,
	Ross Zwisler <ross.zwisler@linux.intel.com>,
	dan.j.williams@intel.com, Jan Kara <jack@suse.com>
Subject: [PATCH 5/9] ext4: Document lock ordering
Date: Wed,  4 Nov 2015 17:18:36 +0100	[thread overview]
Message-ID: <1446653920-23127-6-git-send-email-jack@suse.com> (raw)
In-Reply-To: <1446653920-23127-1-git-send-email-jack@suse.com>

We have enough locks that it's probably worth documenting the lock
ordering rules we have in ext4.

Signed-off-by: Jan Kara <jack@suse.com>
---
 fs/ext4/super.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 61fad9e33bb9..152f719a0c62 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -85,6 +85,36 @@ static void ext4_unregister_li_request(struct super_block *sb);
 static void ext4_clear_request_list(void);
 static int ext4_reserve_clusters(struct ext4_sb_info *, ext4_fsblk_t);
 
+/*
+ * Lock ordering
+ *
+ * Note the difference between i_mmap_sem (EXT4_I(inode)->i_mmap_sem) and
+ * i_mmap_rwsem (inode->i_mmap_rwsem)!
+ *
+ * page fault path:
+ * mmap_sem -> sb_start_pagefault -> i_mmap_sem (r) -> transaction start ->
+ *   page lock -> i_data_sem (rw)
+ *
+ * buffered write path:
+ * sb_start_write -> i_mutex -> mmap_sem
+ * sb_start_write -> i_mutex -> transaction start -> page lock ->
+ *   i_data_sem (rw)
+ *
+ * truncate:
+ * sb_start_write -> i_mutex -> EXT4_STATE_DIOREAD_LOCK (w) -> i_mmap_sem (w) ->
+ *   i_mmap_rwsem (w) -> page lock
+ * sb_start_write -> i_mutex -> EXT4_STATE_DIOREAD_LOCK (w) -> i_mmap_sem (w) ->
+ *   transaction start -> i_data_sem (rw)
+ *
+ * direct IO:
+ * sb_start_write -> i_mutex -> EXT4_STATE_DIOREAD_LOCK (r) -> mmap_sem
+ * sb_start_write -> i_mutex -> EXT4_STATE_DIOREAD_LOCK (r) ->
+ *   transaction start -> i_data_sem (rw)
+ *
+ * writepages:
+ * transaction start -> page lock(s) -> i_data_sem (rw)
+ */
+
 #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT2)
 static struct file_system_type ext2_fs_type = {
 	.owner		= THIS_MODULE,
-- 
2.1.4


  parent reply	other threads:[~2015-11-04 16:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-04 16:18 [PATCH 0/9 v3] ext4: Punch hole and DAX fixes Jan Kara
2015-11-04 16:18 ` [PATCH 1/9] ext4: Fix races between page faults and hole punching Jan Kara
2015-11-04 16:18 ` [PATCH 2/9] ext4: Move unlocked dio protection from ext4_alloc_file_blocks() Jan Kara
2015-11-04 16:18 ` [PATCH 3/9] ext4: Fix races between buffered IO and collapse / insert range Jan Kara
2015-11-04 16:18 ` [PATCH 4/9] ext4: Fix races of writeback with punch hole and zero range Jan Kara
2015-11-04 16:18 ` Jan Kara [this message]
2015-11-04 16:18 ` [PATCH 6/9] ext4: Get rid of EXT4_GET_BLOCKS_NO_LOCK flag Jan Kara
2015-11-04 16:18 ` [PATCH 7/9] ext4: Provide ext4_issue_zeroout() Jan Kara
2015-11-04 16:18 ` [PATCH 8/9] ext4: Implement allocation of pre-zeroed blocks Jan Kara
2015-11-04 16:18 ` [PATCH 9/9] ext4: Use pre-zeroed blocks for DAX page faults Jan Kara
2015-11-04 18:51 ` [PATCH 0/9 v3] ext4: Punch hole and DAX fixes Ross Zwisler
2015-11-06 17:57 ` Boylston, Brian
2015-11-06 22:17   ` Dave Chinner
2015-11-09 16:22   ` Jan Kara
2015-11-09 16:51     ` Jan Kara
2015-11-10  0:00       ` Dave Chinner
2015-11-10 10:02         ` Jan Kara
2015-11-10 22:31           ` Dave Chinner
2015-11-11 15:25             ` Jan Kara
  -- strict thread matches above, loose matches on Subject: below --
2015-11-10 19:50 [PATCH 0/9 v4] " Jan Kara
2015-11-10 19:50 ` [PATCH 5/9] ext4: Document lock ordering Jan Kara
2015-10-22  8:15 [PATCH 0/9 v2] ext4: Punch hole and DAX fixes Jan Kara
2015-10-22  8:15 ` [PATCH 5/9] ext4: Document lock ordering Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446653920-23127-6-git-send-email-jack@suse.com \
    --to=jack@suse.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ross.zwisler@linux.intel.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).