From: Mauricio Faria de Oliveira <mfo@canonical.com>
To: linux-ext4@vger.kernel.org, "Theodore Y. Ts'o" <tytso@mit.edu>
Cc: dann frazier <dann.frazier@canonical.com>,
Andreas Dilger <adilger@dilger.ca>, Jan Kara <jack@suse.com>
Subject: [RFC PATCH 05/11] ext4: data=journal: prevent journalled writeback deadlock in __ext4_journalled_writepage()
Date: Thu, 23 Apr 2020 20:36:59 -0300 [thread overview]
Message-ID: <20200423233705.5878-6-mfo@canonical.com> (raw)
In-Reply-To: <20200423233705.5878-1-mfo@canonical.com>
This patch checks for and prevents the deadlock with a page in
journalled writeback in __ext4_journalled_writepage().
It turns out that __ext4_journalled_writepage() may race with itself
in another task (e.g., two tasks set the same mmap'ed page dirty and
called msync(), one after the other), so we have to check/handle it.
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
---
fs/ext4/inode.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 574a062b8bcd..401313be8a5b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1910,6 +1910,7 @@ static noinline int __ext4_journalled_writepage(struct page *page,
*/
ejwp = kmem_cache_alloc(ext4_journalled_wb_page_cachep, GFP_KERNEL);
+retry_journal:
handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE,
ext4_writepage_trans_blocks(inode));
if (IS_ERR(handle)) {
@@ -1948,7 +1949,20 @@ static noinline int __ext4_journalled_writepage(struct page *page,
goto out;
}
- /* Data integrity writeback; have to wait and do it. */
+ /*
+ * Data integrity writeback; have to wait and do it.
+ *
+ * Check for deadlock with page in journalled writeback
+ * (i.e. another task running/ran this function as well)
+ */
+ if (ext4_check_journalled_writeback(handle, page)) {
+ get_page(page);
+ unlock_page(page);
+ ext4_journal_stop(handle);
+ ext4_start_commit_datasync(inode);
+ wait_on_page_writeback(page);
+ goto retry_journal;
+ }
wait_on_page_writeback(page);
}
--
2.20.1
next prev parent reply other threads:[~2020-04-23 23:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-23 23:36 [RFC PATCH 00/11] ext4: data=journal: writeback mmap'ed pagecache Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 01/11] ext4: data=journal: introduce struct/kmem_cache ext4_journalled_wb_page/_cachep Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 02/11] ext4: data=journal: handle page writeback in __ext4_journalled_writepage() Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 03/11] ext4: data=journal: call ext4_force_commit() in ext4_writepages() for msync() Mauricio Faria de Oliveira
2020-04-23 23:36 ` [RFC PATCH 04/11] ext4: data=journal: introduce helpers for journalled writeback deadlock Mauricio Faria de Oliveira
2020-04-23 23:36 ` Mauricio Faria de Oliveira [this message]
2020-04-23 23:37 ` [RFC PATCH 06/11] ext4: data=journal: prevent journalled writeback deadlock in ext4_write_begin() Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 07/11] ext4: grab page before starting transaction handle in ext4_convert_inline_data_to_extent() Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 08/11] ext4: data=journal: prevent journalled writeback deadlock " Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 09/11] ext4: grab page before starting transaction handle in ext4_try_to_write_inline_data() Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 10/11] ext4: deduplicate code with error legs " Mauricio Faria de Oliveira
2020-04-23 23:37 ` [RFC PATCH 11/11] ext4: data=journal: prevent journalled writeback deadlock " Mauricio Faria de Oliveira
2020-05-15 18:39 ` [RFC PATCH 00/11] ext4: data=journal: writeback mmap'ed pagecache Mauricio Faria de Oliveira
2020-05-17 7:40 ` Andreas Dilger
2020-06-10 13:21 ` Jan Kara
2020-06-10 15:15 ` Mauricio Faria de Oliveira
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=20200423233705.5878-6-mfo@canonical.com \
--to=mfo@canonical.com \
--cc=adilger@dilger.ca \
--cc=dann.frazier@canonical.com \
--cc=jack@suse.com \
--cc=linux-ext4@vger.kernel.org \
--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).