From: "Zhou Jifeng" <zhoujifeng@kylinos.com.cn>
To: 周继峰 <zhoujifeng@kylinos.com.cn>, "Coly Li" <colyli@kernel.org>
Cc: "kent.overstreet" <kent.overstreet@linux.dev>,
linux-bcache <linux-bcache@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re:[PATCH v2] bcache: enhancing the security of dirty data writeback
Date: Wed, 13 Aug 2025 15:11:48 +0800 [thread overview]
Message-ID: <tencent_09D8A9E34CEA74AC70E3901C@qq.com> (raw)
In-Reply-To: <20250813021236.30133-1-zhoujifeng@kylinos.com.cn>
On Wed, 13 Aug 2025 at 10:14, Zhou Jifeng <zhoujifeng@kylinos.com.cn> wrote:
>
> There is a potential data consistency risk in bcache's writeback mode:when
> the application calls fsync, bcache returns success after completing the
> log write, persisting the cache disk data, and persisting the HDD internal
> cache. However, at this point, the actual application data may still be in
> a dirty state and remain stuck in the cache disk. when these data are
> subsequently written back to the HDD asynchronously through REQ_OP_WRITE,
> there is no forced refresh mechanism to ensure physical placement on the
> disk, and there may be no power-off protection measures, which poses a risk
> of data loss. This mechanism may cause the application to misjudge that the
> data has been persisted, which is different from the actual storage state,
> and also violates the semantic agreement that fsync should ensure data
> persistence.
>
> This patch aims to enhance the reliability of dirty data writeback through
> PREFLUSH, ensuring that the dirty data mark in the cache device is cleared
> only after the dirty data is written to the disk. Double triggering
> conditions for PREFLUSH:
> 1、When the cumulative number of dirty bkeys written back reaches the
> threshold(Dynamic control parameters:/sys/block/bcache0/bcache/
> flush_interval, the default value is 20000. by increasing the value of this
> parameter, the impact of flush on performance can be reduced.)
> 2、When the interval since the last refresh exceeds 30 seconds
> If any of the conditions are met, the system will send a PREFLUSH command
> to the backend HDD, and clear the corresponding dirty bkey mark only after
> confirming that the PREFLUSH is executed successfully.
>
> Signed-off-by: Zhou Jifeng <zhoujifeng@kylinos.com.cn>
> ---
> v1 -> v2: Make revisions according to the review comments.
>
>
> [snipped]
>
>
> diff --git a/drivers/md/bcache/bcache_ondisk.h b/drivers/md/bcache/bcache_ondisk.h
> index 6620a7f8fffc..df5800838e40 100644
> --- a/drivers/md/bcache/bcache_ondisk.h
> +++ b/drivers/md/bcache/bcache_ondisk.h
> @@ -294,6 +294,10 @@ BITMASK(BDEV_CACHE_MODE, struct cache_sb, flags, 0, 4);
> #define CACHE_MODE_WRITEBACK 1U
> #define CACHE_MODE_WRITEAROUND 2U
> #define CACHE_MODE_NONE 3U
> +BITMASK(BDEV_WRITEBACK_FLUSH, struct cache_sb, flags, 4, 1);
> +#define WRITEBACK_FLUSH_OFF 0U
> +#define WRITEBACK_FLUSH_ON 1U
> +
> BITMASK(BDEV_STATE, struct cache_sb, flags, 61, 2);
> #define BDEV_STATE_NONE 0U
> #define BDEV_STATE_CLEAN 1U
Sorry, the inspection was not thorough enough. This is an invalid code. It was left over
from the past and was forgotten to be deleted.
prev parent reply other threads:[~2025-08-13 7:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 6:21 [PATCH] " Zhou Jifeng
2025-07-31 15:49 ` Kent Overstreet
2025-08-01 2:27 ` Zhou Jifeng
2025-08-01 2:37 ` Kent Overstreet
2025-08-01 3:30 ` Zhou Jifeng
2025-08-01 3:41 ` Kent Overstreet
2025-08-01 6:10 ` Zhou Jifeng
2025-08-02 17:29 ` Coly Li
2025-08-02 18:49 ` Kent Overstreet
2025-08-04 3:47 ` Zhou Jifeng
2025-08-04 4:17 ` Kent Overstreet
2025-08-04 15:31 ` Coly Li
2025-08-04 16:07 ` Kent Overstreet
2025-08-05 1:17 ` Zhou Jifeng
2025-08-05 1:31 ` Kent Overstreet
2025-08-05 3:31 ` Coly Li
2025-08-05 3:34 ` Kent Overstreet
2025-08-05 4:57 ` Coly Li
2025-08-05 9:37 ` Zhou Jifeng
2025-08-05 16:29 ` Coly Li
2025-08-06 11:19 ` Zhou Jifeng
2025-08-06 16:10 ` Coly Li
2025-08-07 2:01 ` Zhou Jifeng
2025-08-13 2:12 ` [PATCH v2] " Zhou Jifeng
2025-08-13 7:11 ` Zhou Jifeng [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=tencent_09D8A9E34CEA74AC70E3901C@qq.com \
--to=zhoujifeng@kylinos.com.cn \
--cc=colyli@kernel.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcache@vger.kernel.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®