From: Yu Kuai <yukuai1@huaweicloud.com>
To: Hannes Reinecke <hare@suse.de>, Yu Kuai <yukuai@kernel.org>,
hch@lst.de, xni@redhat.com, axboe@kernel.dk,
linux-raid@vger.kernel.org, song@kernel.org
Cc: yangerkun@huawei.com, yi.zhang@huawei.com,
johnny.chenyi@huawei.com, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v2 11/11] md/md-llbitmap: introduce new lockless bitmap
Date: Mon, 14 Jul 2025 09:41:19 +0800 [thread overview]
Message-ID: <9f86f347-97ee-130b-2dce-9c8465d7baa9@huaweicloud.com> (raw)
In-Reply-To: <a0ae5ea4-513e-40f0-9421-2bec57e1ee89@suse.de>
Hi, Hannes!
在 2025/07/08 15:47, Hannes Reinecke 写道:
[...]
>> + case BitUnwritten:
>> + pctl->state[pos] = level_456 ? BitNeedSync : BitDirty;
>
> This really looks as if we should use WRITE_ONCE() ...
Sorry for the late reply, we're just writing one byte here, either old
value or new value with be read concurrently, I think we don't need
WRITE_ONCE() here, and READ_ONCE() on the reader side to prevent reading
strange value.
[...]
>> + if (!test_bit(LLPageDirty, &pctl->flags))
>> + set_bit(LLPageDirty, &pctl->flags);
>> +
>
> test_and_set_bit?
We don't need to guarantee atomicity here, so perhaps test_bit() and
set_bit() will have less overhead?
[...]
>> + for (pos = bit * io_size; pos < (bit + 1) * io_size; pos++) {
>> + if (pos == offset)
>> + continue;
>> + if (pctl->state[pos] == BitDirty ||
>> + pctl->state[pos] == BitNeedSync) {
>> + llbitmap_infect_dirty_bits(llbitmap, pctl, bit, offset);
>> + return;
>
> Hmm. That looks _so_ inefficient. A loop within a loop... Wouldn't it be
> possible to use XOR or something to flip several bits at once?
This is a good question. I was thinking this will only be executed once
for every daemon_sleep seconds, and the additional overhead is fine, and
perf results do confirm that.
For XOR, we'll have to convert the enum type llbitmap_stage to one state
per bit, and there are total 7 states already and not good for future
expansion.
[...]
>> +static void llbitmap_pending_timer_fn(struct timer_list *t)
>> +{
>> + struct llbitmap *llbitmap = from_timer(llbitmap, t, pending_timer);
>> +
>> + if (work_busy(&llbitmap->daemon_work)) {
>> + pr_warn("daemon_work not finished\n");
>> + set_bit(BITMAP_DAEMON_BUSY, &llbitmap->flags);
>> + return;
>> + }
>> +
>
> Do you really need to check this?
> Wouldn't it be easier to just run the daemon, which should devolve in a
> no-op if no work is to be done?
This is the same reason as below, if the daemon get stuck and doesn't
finish in the last daemon_sleep seconds, just print a warning message
for now, and the BITMAP_DAEMON_BUSY is used for debuging perpose.
[...]
>> + llbitmap_suspend(llbitmap, idx);
>> + llbitmap_state_machine(llbitmap, start, end,
>> BitmapActionDaemon);
>
> How do you ensure that the daemon doesn't get stuck trying to write/read
> individual pages? Shouldn't there be some sort of 'emergency exit'?
Perhaps llbitmap_suspend_timeout() and give up clearing dirty bits if
failed? If inflight writes get stuck, suspend will forbit all new
writers to be issued.
Thanks,
Kuai
prev parent reply other threads:[~2025-07-14 1:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-07 16:51 [PATCH v2 00/11] md/llbitmap: md/md-llbitmap: introduce a new lockless bitmap Yu Kuai
2025-07-07 16:51 ` [PATCH v2 01/11] md: add a new parameter 'offset' to md_super_write() Yu Kuai
2025-07-07 16:51 ` [PATCH v2 02/11] md: factor out a helper raid_is_456() Yu Kuai
2025-07-07 16:51 ` [PATCH v2 03/11] md/md-bitmap: support discard for bitmap ops Yu Kuai
2025-07-08 6:21 ` Hannes Reinecke
2025-07-07 16:51 ` [PATCH v2 04/11] md: add a new mddev field 'bitmap_id' Yu Kuai
2025-07-08 6:23 ` Hannes Reinecke
2025-07-07 16:51 ` [PATCH v2 05/11] md/md-bitmap: add a new sysfs api bitmap_type Yu Kuai
2025-07-08 6:24 ` Hannes Reinecke
2025-07-07 16:51 ` [PATCH v2 06/11] md/md-bitmap: delay registration of bitmap_ops until creating bitmap Yu Kuai
2025-07-08 6:29 ` Hannes Reinecke
[not found] ` <CAHW3DrjVM-yb-U==ZfR3k9ZS7qSpqY4ASch7qqhP2zquTdSS2w@mail.gmail.com>
2025-07-08 11:57 ` Hannes Reinecke
2025-07-09 6:44 ` 余快
2025-07-09 9:11 ` Hannes Reinecke
2025-07-07 16:51 ` [PATCH v2 07/11] md/md-bitmap: add a new method skip_sync_blocks() in bitmap_operations Yu Kuai
2025-07-07 16:51 ` [PATCH v2 08/11] md/md-bitmap: add a new method blocks_synced() " Yu Kuai
2025-07-07 16:52 ` [PATCH v2 09/11] md: add a new recovery_flag MD_RECOVERY_LAZY_RECOVER Yu Kuai
2025-07-08 6:29 ` Hannes Reinecke
2025-07-07 16:52 ` [PATCH v2 10/11] md/md-bitmap: make method bitmap_ops->daemon_work optional Yu Kuai
2025-07-07 16:52 ` [PATCH v2 11/11] md/md-llbitmap: introduce new lockless bitmap Yu Kuai
2025-07-08 7:47 ` Hannes Reinecke
2025-07-14 1:41 ` Yu Kuai [this message]
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=9f86f347-97ee-130b-2dce-9c8465d7baa9@huaweicloud.com \
--to=yukuai1@huaweicloud.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=johnny.chenyi@huawei.com \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
--cc=xni@redhat.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
--cc=yukuai3@huawei.com \
--cc=yukuai@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;
as well as URLs for NNTP newsgroup(s).