• Changwei Ge's avatar
    ocfs2: try to reuse extent block in dealloc without meta_alloc · 71a36944
    Changwei Ge authored
    A crash issue was reported by John Lightsey with a call trace as follows:
    
      ocfs2_split_extent+0x1ad3/0x1b40 [ocfs2]
      ocfs2_change_extent_flag+0x33a/0x470 [ocfs2]
      ocfs2_mark_extent_written+0x172/0x220 [ocfs2]
      ocfs2_dio_end_io+0x62d/0x910 [ocfs2]
      dio_complete+0x19a/0x1a0
      do_blockdev_direct_IO+0x19dd/0x1eb0
      __blockdev_direct_IO+0x43/0x50
      ocfs2_direct_IO+0x8f/0xa0 [ocfs2]
      generic_file_direct_write+0xb2/0x170
      __generic_file_write_iter+0xc3/0x1b0
      ocfs2_file_write_iter+0x4bb/0xca0 [ocfs2]
      __vfs_write+0xae/0xf0
      vfs_write+0xb8/0x1b0
      SyS_write+0x4f/0xb0
      system_call_fastpath+0x16/0x75
    
    The BUG code told that extent tree wants to grow but no metadata was
    reserved ahead of time.  From my investigation into this issue, the root
    cause it that although enough metadata is not reserved, there should be
    enough for following use.  Rightmost extent is merged into its left one
    due to a certain times of marking extent written.  Because during
    marking extent written, we got many physically continuous extents.  At
    last, an empty extent showed up and the rightmost path is removed from
    extent tree.
    
    Add a new mechanism to reuse extent block cached in dealloc which were
    just unlinked from extent tree to solve this crash issue.
    
    Criteria is that during marking extents *written*, if extent rotation
    and merging results in unlinking extent with growing extent tree later
    without any metadata reserved ahead of time, try to reuse those extents
    in dealloc in which deleted extents are cached.
    
    Also, this patch addresses the issue John reported that ::dw_zero_count
    is not calculated properly.
    
    After applying this patch, the issue John reported was gone.  Thanks for
    the reproducer provided by John.  And this patch has passed
    ocfs2-test(29 cases) suite running by New H3C Group.
    
    [ge.changwei@h3c.com: fix static checker warnning]
      Link: http://lkml.kernel.org/r/63ADC13FD55D6546B7DECE290D39E373F29196AE@H3CMLB12-EX.srv.huawei-3com.com
    [akpm@linux-foundation.org: brelse(NULL) is legal]
    Link: http://lkml.kernel.org/r/1515479070-32653-2-git-send-email-ge.changwei@h3c.comSigned-off-by: default avatarChangwei Ge <ge.changwei@h3c.com>
    Reported-by: default avatarJohn Lightsey <john@nixnuts.net>
    Tested-by: default avatarJohn Lightsey <john@nixnuts.net>
    Cc: Joel Becker <jlbec@evilplan.org>
    Cc: Joseph Qi <jiangqi903@gmail.com>
    Cc: Junxiao Bi <junxiao.bi@oracle.com>
    Cc: Dan Carpenter <dan.carpenter@oracle.com>
    Cc: Mark Fasheh <mfasheh@versity.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    71a36944
alloc.h 11.9 KB