title: how metadata journal stalls write system call?
body: <p>I am using CentOS 7.1.1503 with kernel linux 3.10.0-229.el7.x86_64, ext4 file system with ordered journal mode, and delalloc enabled.</p>
  
  <p>When my app writes logs to a file continually (about 6M/s), I can find the write system call stalled for 100-700 ms occasionally, When I disable ext4's journal feature, or set the journal mode to writeback, or disable delay allocate, the stalling disappears. When I set linux's writeback more frequent, dirty page expire time shorter, the problem reduced. </p>
  
  <p>I printed the process's stack when stalling happends, I got this:</p>
  
  <pre><code>[&lt;ffffffff812e31f4&gt;] call_rwsem_down_read_failed+0x14/0x30
  [&lt;ffffffffa0195854&gt;] ext4_da_get_block_prep+0x1a4/0x4b0 [ext4]
  [&lt;ffffffff811fbe17&gt;] __block_write_begin+0x1a7/0x490
  [&lt;ffffffffa019b71c&gt;] ext4_da_write_begin+0x15c/0x340 [ext4]
  [&lt;ffffffff8115685e&gt;] generic_file_buffered_write+0x11e/0x290
  [&lt;ffffffff811589c5&gt;] __generic_file_aio_write+0x1d5/0x3e0
  [&lt;ffffffff81158c2d&gt;] generic_file_aio_write+0x5d/0xc0
  [&lt;ffffffffa0190b75&gt;] ext4_file_write+0xb5/0x460 [ext4]
  [&lt;ffffffff811c64cd&gt;] do_sync_write+0x8d/0xd0
  [&lt;ffffffff811c6c6d&gt;] vfs_write+0xbd/0x1e0
  [&lt;ffffffff811c76b8&gt;] SyS_write+0x58/0xb0
  [&lt;ffffffff81614a29&gt;] system_call_fastpath+0x16/0x1b
  [&lt;ffffffffffffffff&gt;] 0xffffffffffffffff
  </code></pre>
  
  <p>I read the source code of linux kernel, and found that call_rwsem_down_read_failed will call rwsem_down_read_failed which will keep waiting for rw_semaphore.</p>
  
  <p>I think the reason is that metadata journal flushing must wait for related dirty pages flushed, when dirty pages flushing took long time, the journal blocked, and journal commit has this inode's rw_semaphore, write system call to this inode is stalled.</p>
  
  <p>I really hope I can find evidence to prove it.</p>