archive mirror
 help / color / mirror / Atom feed
From: Vivek Goyal <>
Subject: [PATCH v4 3/3] dax: Wake up all waiters after invalidating dax entry
Date: Fri, 23 Apr 2021 09:07:23 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

I am seeing missed wakeups which ultimately lead to a deadlock when I am
using virtiofs with DAX enabled and running "make -j". I had to mount
virtiofs as rootfs and also reduce to dax window size to 256M to reproduce
the problem consistently.

So here is the problem. put_unlocked_entry() wakes up waiters only
if entry is not null as well as !dax_is_conflict(entry). But if I
call multiple instances of invalidate_inode_pages2() in parallel,
then I can run into a situation where there are waiters on
this index but nobody will wake these waiters.

        __dax_invalidate_entry() {
                entry = get_unlocked_entry(&xas, 0);
                dax_disassociate_entry(entry, mapping, trunc);
                xas_store(&xas, NULL);
                put_unlocked_entry(&xas, entry);

Say a fault in in progress and it has locked entry at offset say "0x1c".
Now say three instances of invalidate_inode_pages2() are in progress
(A, B, C) and they all try to invalidate entry at offset "0x1c". Given
dax entry is locked, all tree instances A, B, C will wait in wait queue.

When dax fault finishes, say A is woken up. It will store NULL entry
at index "0x1c" and wake up B. When B comes along it will find "entry=0"
at page offset 0x1c and it will call put_unlocked_entry(&xas, 0). And
this means put_unlocked_entry() will not wake up next waiter, given
the current code. And that means C continues to wait and is not woken

This patch fixes the issue by waking up all waiters when a dax entry
has been invalidated. This seems to fix the deadlock I am facing
and I can make forward progress.

Reported-by: Sergio Lopez <>
Fixes: ac401cc78242 ("dax: New fault locking")
Reviewed-by: Jan Kara <>
Suggested-by: Dan Williams <>
Signed-off-by: Vivek Goyal <>
 fs/dax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/dax.c b/fs/dax.c
index 96e896de8f18..83daa57d37d3 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -675,7 +675,7 @@ static int __dax_invalidate_entry(struct address_space *mapping,
 	ret = 1;
-	put_unlocked_entry(&xas, entry, WAKE_NEXT);
+	put_unlocked_entry(&xas, entry, WAKE_ALL);
 	return ret;

  parent reply	other threads:[~2021-04-23 13:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 13:07 [PATCH v4 0/3] dax: Fix missed wakeup in put_unlocked_entry() Vivek Goyal
2021-04-23 13:07 ` [PATCH v4 1/3] dax: Add an enum for specifying dax wakup mode Vivek Goyal
2021-04-26 13:46   ` Matthew Wilcox
2021-04-26 17:52     ` Vivek Goyal
2021-04-26 18:02       ` Matthew Wilcox
2021-04-26 18:08         ` Vivek Goyal
2021-04-23 13:07 ` [PATCH v4 2/3] dax: Add a wakeup mode parameter to put_unlocked_entry() Vivek Goyal
2021-04-23 13:07 ` Vivek Goyal [this message]
2021-04-23 20:38 ` [PATCH v4 0/3] dax: Fix missed wakeup in put_unlocked_entry() Dan Williams

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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \

* 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).