mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: David Howells <dhowells@redhat.com>, Hou Tao <houtao@huaweicloud.com>
Cc: linux-cachefs@redhat.com, Jeff Layton <jlayton@kernel.org>,
	linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org,
	houtao1@huawei.com
Subject: Re: [PATCH v2 1/2] fscache: Use wait_on_bit() to wait for the freeing of relinquished volume
Date: Thu, 12 Jan 2023 11:58:27 +0800	[thread overview]
Message-ID: <6acd0aea-2e7b-e30e-214f-81f4c3766ead@linux.alibaba.com> (raw)
In-Reply-To: <2431838.1673453170@warthog.procyon.org.uk>



On 1/12/23 12:06 AM, David Howells wrote:
> Hou Tao <houtao@huaweicloud.com> wrote:
> 
>>  			clear_bit(FSCACHE_VOLUME_ACQUIRE_PENDING, &cursor->flags);
>> +			/*
>> +			 * Paired with barrier in wait_on_bit(). Check
>> +			 * wake_up_bit() and waitqueue_active() for details.
>> +			 */
>> +			smp_mb__after_atomic();
>>  			wake_up_bit(&cursor->flags, FSCACHE_VOLUME_ACQUIRE_PENDING);
> 
> What two values are you applying a partial ordering to?

Yeah Hou Tao has explained that a full barrier is needed here to avoid
the potential reordering at the waker side.

As I was also researching on this these days, I'd like to share my
thought on this, hopefully if it could give some insight :)

Without the barrier at the waker side, it may suffer from the following
race:

```
CPU0 - waker                    CPU1 - waiter

if (waitqueue_active(wq_head)) <-- find no wq_entry in wq_head list
    wake_up(wq_head);

                                for (;;) {
                                   prepare_to_wait(...);
                                        # add wq_entry into wq_head list

                                    if (@cond)  <-- @cond is false
                                        break;
                                    schedule(); <-- wq_entry still in
                                                    wq_head list,
                                                    wait for next wakeup
                                 }
                                 finish_wait(&wq_head, &wait);

@cond = true;
```

in which case the waiter misses the wakeup for one time.

-- 
Thanks,
Jingbo

  parent reply	other threads:[~2023-01-12  3:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-26 10:33 [PATCH v2 0/2] Fixes for fscache volume operations Hou Tao
2022-12-26 10:33 ` [PATCH v2 1/2] fscache: Use wait_on_bit() to wait for the freeing of relinquished volume Hou Tao
2023-01-12  3:47   ` Jingbo Xu
2023-01-12  6:14     ` Hou Tao
2022-12-26 10:33 ` [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit() Hou Tao
2023-01-12  4:34   ` Jingbo Xu
2023-01-12  6:17     ` Hou Tao
2023-01-11  4:03 ` [PATCH v2 0/2] Fixes for fscache volume operations Hou Tao
2023-01-11 16:06 ` [PATCH v2 1/2] fscache: Use wait_on_bit() to wait for the freeing of relinquished volume David Howells
2023-01-12  1:05   ` Hou Tao
2023-01-12  3:58   ` Jingbo Xu [this message]
2023-01-12  6:12     ` Hou Tao
2023-01-11 16:09 ` [PATCH v2 2/2] fscache: Add the missing smp_mb__after_atomic() before wake_up_bit() David Howells
2023-01-12  1:07   ` Hou Tao
2023-01-11 16:24 ` David Howells

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=6acd0aea-2e7b-e30e-214f-81f4c3766ead@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=dhowells@redhat.com \
    --cc=houtao1@huawei.com \
    --cc=houtao@huaweicloud.com \
    --cc=jlayton@kernel.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®