gfs2: Only set PageChecked if we have a transaction
authorBob Peterson <rpeterso@redhat.com>
Wed, 19 Aug 2020 13:55:18 +0000 (08:55 -0500)
committerAndreas Gruenbacher <agruenba@redhat.com>
Thu, 15 Oct 2020 12:29:03 +0000 (14:29 +0200)
With jdata writes, we frequently got into situations where gfs2 deadlocked
because of this calling sequence:

gfs2_ail1_start
   gfs2_ail1_flush - for every tr on the sd_ail1_list:
      gfs2_ail1_start_one - for every bd on the tr's tr_ail1_list:
         generic_writepages
    write_cache_pages passing __writepage()
       calls clear_page_dirty_for_io which calls set_page_dirty:
          which calls jdata_set_page_dirty which sets PageChecked.
       __writepage() calls
          mapping->a_ops->writepage AKA gfs2_jdata_writepage

However, gfs2_jdata_writepage checks if PageChecked is set, and if so, it
ignores the write and redirties the page. The problem is that write_cache_pages
calls clear_page_dirty_for_io, which often calls set_page_dirty(). See comments
in page-writeback.c starting with "Yes, Virginia". If it's jdata,
set_page_dirty will call jdata_set_page_dirty which will set PageChecked.
That causes a conflict because it makes it look like the page has been
redirtied by another writer, in which case we need to skip writing it and
redirty the page. That ends up in a deadlock because it isn't a "real" writer
and nothing will ever clear PageChecked.

If we do have a real writer, it will have started a transaction. So this
patch checks if a transaction is in use, and if not, it skips setting
PageChecked. That way, the page will be dirtied, cleaned, and written
appropriately.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/aops.c

index 1e7ab51..9cd2eca 100644 (file)
@@ -623,7 +623,8 @@ out:
  
 static int jdata_set_page_dirty(struct page *page)
 {
-       SetPageChecked(page);
+       if (current->journal_info)
+               SetPageChecked(page);
        return __set_page_dirty_buffers(page);
 }