linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dax: Use non-exclusive wait in wait_entry_unlocked()
@ 2018-12-21 19:38 Dan Williams
  2019-01-02 15:35 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Williams @ 2018-12-21 19:38 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: Jan Kara, Matthew Wilcox, Linus Torvalds, linux-nvdimm

get_unlocked_entry() uses an exclusive wait because it is guaranteed to
eventually obtain the lock and follow on with an unlock+wakeup cycle.
The wait_entry_unlocked() path does not have the same guarantee. Rather
than open-code an extra wakeup, just switch to a non-exclusive wait.

Cc: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox <willy@infradead.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 fs/dax.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/dax.c b/fs/dax.c
index 48132eca3761..042d3b31b413 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -246,18 +246,16 @@ static void wait_entry_unlocked(struct xa_state *xas, void *entry)
 	ewait.wait.func = wake_exceptional_entry_func;
 
 	wq = dax_entry_waitqueue(xas, entry, &ewait.key);
-	prepare_to_wait_exclusive(wq, &ewait.wait, TASK_UNINTERRUPTIBLE);
+	/*
+	 * Unlike get_unlocked_entry() there is no guarantee that this
+	 * path ever successfully retrieves an unlocked entry before an
+	 * inode dies. Perform a non-exclusive wait in case this path
+	 * never successfully performs its own wake up.
+	 */
+	prepare_to_wait(wq, &ewait.wait, TASK_UNINTERRUPTIBLE);
 	xas_unlock_irq(xas);
 	schedule();
 	finish_wait(wq, &ewait.wait);
-
-	/*
-	 * Entry lock waits are exclusive. Wake up the next waiter since
-	 * we aren't sure we will acquire the entry lock and thus wake
-	 * the next waiter up on unlock.
-	 */
-	if (waitqueue_active(wq))
-		__wake_up(wq, TASK_NORMAL, 1, &ewait.key);
 }
 
 static void put_unlocked_entry(struct xa_state *xas, void *entry)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] dax: Use non-exclusive wait in wait_entry_unlocked()
  2018-12-21 19:38 [PATCH] dax: Use non-exclusive wait in wait_entry_unlocked() Dan Williams
@ 2019-01-02 15:35 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2019-01-02 15:35 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-fsdevel, Jan Kara, Matthew Wilcox, Linus Torvalds, linux-nvdimm

On Fri 21-12-18 11:38:04, Dan Williams wrote:
> get_unlocked_entry() uses an exclusive wait because it is guaranteed to
> eventually obtain the lock and follow on with an unlock+wakeup cycle.
> The wait_entry_unlocked() path does not have the same guarantee. Rather
> than open-code an extra wakeup, just switch to a non-exclusive wait.
> 
> Cc: Jan Kara <jack@suse.cz>
> Cc: Matthew Wilcox <willy@infradead.org>
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  fs/dax.c |   16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)

Thanks for cleaning this up! The patch looks good to me. You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> 
> diff --git a/fs/dax.c b/fs/dax.c
> index 48132eca3761..042d3b31b413 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -246,18 +246,16 @@ static void wait_entry_unlocked(struct xa_state *xas, void *entry)
>  	ewait.wait.func = wake_exceptional_entry_func;
>  
>  	wq = dax_entry_waitqueue(xas, entry, &ewait.key);
> -	prepare_to_wait_exclusive(wq, &ewait.wait, TASK_UNINTERRUPTIBLE);
> +	/*
> +	 * Unlike get_unlocked_entry() there is no guarantee that this
> +	 * path ever successfully retrieves an unlocked entry before an
> +	 * inode dies. Perform a non-exclusive wait in case this path
> +	 * never successfully performs its own wake up.
> +	 */
> +	prepare_to_wait(wq, &ewait.wait, TASK_UNINTERRUPTIBLE);
>  	xas_unlock_irq(xas);
>  	schedule();
>  	finish_wait(wq, &ewait.wait);
> -
> -	/*
> -	 * Entry lock waits are exclusive. Wake up the next waiter since
> -	 * we aren't sure we will acquire the entry lock and thus wake
> -	 * the next waiter up on unlock.
> -	 */
> -	if (waitqueue_active(wq))
> -		__wake_up(wq, TASK_NORMAL, 1, &ewait.key);
>  }
>  
>  static void put_unlocked_entry(struct xa_state *xas, void *entry)
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-02 15:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-21 19:38 [PATCH] dax: Use non-exclusive wait in wait_entry_unlocked() Dan Williams
2019-01-02 15:35 ` Jan Kara

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