From: Bart Van Assche <bvanassche@acm.org>
To: Yang Yang <yang.yang@vivo.com>,
Andrew Morton <akpm@linux-foundation.org>,
Jens Axboe <axboe@kernel.dk>, Ming Lei <ming.lei@redhat.com>,
Omar Sandoval <osandov@fb.com>,
linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH v7] sbitmap: fix io hung due to race on sbitmap_word::cleared
Date: Mon, 15 Jul 2024 10:26:03 -0700 [thread overview]
Message-ID: <263282cd-dadc-43f7-be8f-892248bc3318@acm.org> (raw)
In-Reply-To: <20240715091125.36381-1-yang.yang@vivo.com>
On 7/15/24 2:11 AM, Yang Yang wrote:
> +
> + /**
> + * @swap_lock: serializes simultaneous updates of ->word and ->cleared
> + */
> + spinlock_t swap_lock;
> } ____cacheline_aligned_in_smp;
Thank you for having updated this comment.
> -static inline bool sbitmap_deferred_clear(struct sbitmap_word *map)
> +static inline bool sbitmap_deferred_clear(struct sbitmap_word *map,
> + unsigned int depth, unsigned int alloc_hint, bool wrap)
> {
> - unsigned long mask;
> + unsigned long mask, word_mask;
> + bool ret = false;
>
> - if (!READ_ONCE(map->cleared))
> - return false;
> + guard(spinlock_irqsave)(&map->swap_lock);
> +
> + if (!map->cleared) {
> + if (depth > 0) {
> + word_mask = (~0UL) >> (BITS_PER_LONG - depth);
> + /*
> + * The current behavior is to always retry after moving
> + * ->cleared to word, and we change it to retry in case
> + * of any free bits. To avoid an infinite loop, we need
> + * to take wrap & alloc_hint into account, otherwise a
> + * soft lockup may occur.
> + */
> + if (!wrap && alloc_hint)
> + word_mask &= ~((1UL << alloc_hint) - 1);
> +
> + if ((READ_ONCE(map->word) & word_mask) == word_mask)
> + ret = false;
> + else
> + ret = true;
> + }
> +
> + return ret;
> + }
Now that guard()() is being used, the local variable 'ret' can be
eliminated. The if (READ_ONCE() ...) statement can be changed into the
following: return (READ_ONCE(map->word) & word_mask) != word_mask;
and "return ret;" can be changed into "return false;". Additionally,
the indentation depth can be reduced by changing "if (depth > 0) {" ...
into "if (depth == 0) return false;".
Otherwise this patch looks good to me.
Thanks,
Bart.
next prev parent reply other threads:[~2024-07-15 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-15 9:11 Yang Yang
2024-07-15 17:26 ` Bart Van Assche [this message]
2024-07-16 3:48 ` YangYang
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=263282cd-dadc-43f7-be8f-892248bc3318@acm.org \
--to=bvanassche@acm.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=osandov@fb.com \
--cc=yang.yang@vivo.com \
/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®