linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC v2 00/14] md: introduce a new lockless bitmap
@ 2025-03-28  6:08 Yu Kuai
  2025-03-28  6:08 ` [PATCH RFC v2 01/14] block: factor out a helper bdev_file_alloc() Yu Kuai
                   ` (15 more replies)
  0 siblings, 16 replies; 27+ messages in thread
From: Yu Kuai @ 2025-03-28  6:08 UTC (permalink / raw)
  To: hch, xni, colyli, axboe, agk, snitzer, mpatocka, song, yukuai3
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, yukuai1,
	yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

#### Background

Redundant data is used to enhance data fault tolerance, and the storage
method for redundant data vary depending on the RAID levels. And it's
important to maintain the consistency of redundant data.

Bitmap is used to record which data blocks have been synchronized and which
ones need to be resynchronized or recovered. Each bit in the bitmap
represents a segment of data in the array. When a bit is set, it indicates
that the multiple redundant copies of that data segment may not be
consistent. Data synchronization can be performed based on the bitmap after
power failure or readding a disk. If there is no bitmap, a full disk
synchronization is required.

#### Key Concept

##### State Machine

Each bit is one byte, contain 6 difference state, see llbitmap_state. And
there are total 8 differenct actions, see llbitmap_action, can change state:

llbitmap state machine: transitions between states

|           | Startwrite | Startsync | Endsync | Abortsync| Reload   | Daemon | Discard   | Stale     |
| --------- | ---------- | --------- | ------- | -------  | -------- | ------ | --------- | --------- |
| Unwritten | Dirty      | x         | x       | x        | x        | x      | x         | x         |
| Clean     | Dirty      | x         | x       | x        | x        | x      | Unwritten | NeedSync  |
| Dirty     | x          | x         | x       | x        | NeedSync | Clean  | Unwritten | NeedSync  |
| NeedSync  | x          | Syncing   | x       | x        | x        | x      | Unwritten | x         |
| Syncing   | x          | Syncing   | Dirty   | NeedSync | NeedSync | x      | Unwritten | NeedSync  |

special illustration:
- Unwritten is special state, which means user never write data, hence there
  is no need to resync/recover data. This is safe if user create filesystems
  for the array, filesystem will make sure user will get zero data for
  unwritten blocks.
- After resync is done, change state from Syncing to Dirty first, in case
  Startwrite happen before the state is Clean.

##### Bitmap IO

A hidden disk, named mdxxx_bitmap, is created for bitmap, see details in
llbitmap_add_disk(). And a file is created as well to manage bitmap IO for
this disk, see details in llbitmap_open_disk(). Read/write bitmap is
converted to buffer IO to this file.

IO fast path will set bits to dirty, and those dirty bits will be cleared
by daemon after IO is done. llbitmap_barrier is used to syncronize between
IO path and daemon;

Test result: to be added

Noted:
1) user must apply the following mdadm patch, and then llbitmap can be
enabled by --bitmap=lockless
https://lore.kernel.org/all/20250327134853.1069356-1-yukuai1@huaweicloud.com/
2) this set is cooked on the top of my other set:
https://lore.kernel.org/all/20250219083456.941760-1-yukuai1@huaweicloud.com/

Yu Kuai (14):
  block: factor out a helper bdev_file_alloc()
  md/md-bitmap: pass discard information to bitmap_{start, end}write
  md/md-bitmap: remove parameter slot from bitmap_create()
  md: add a new sysfs api bitmap_version
  md: delay registeration of bitmap_ops until creating bitmap
  md/md-llbitmap: implement bit state machine
  md/md-llbitmap: implement hidden disk to manage bitmap IO
  md/md-llbitmap: implement APIs for page level dirty bits
    synchronization
  md/md-llbitmap: implement APIs to mange bitmap lifetime
  md/md-llbitmap: implement APIs to dirty bits and clear bits
  md/md-llbitmap: implement APIs for sync_thread
  md/md-llbitmap: implement all bitmap operations
  md/md-llbitmap: implement sysfs APIs
  md/md-llbitmap: add Kconfig

 block/bdev.c             |   21 +-
 drivers/md/Kconfig       |   12 +
 drivers/md/Makefile      |    1 +
 drivers/md/md-bitmap.c   |   10 +-
 drivers/md/md-bitmap.h   |   21 +-
 drivers/md/md-llbitmap.c | 1410 ++++++++++++++++++++++++++++++++++++++
 drivers/md/md.c          |  180 ++++-
 drivers/md/md.h          |    3 +
 include/linux/blkdev.h   |    1 +
 9 files changed, 1614 insertions(+), 45 deletions(-)
 create mode 100644 drivers/md/md-llbitmap.c

-- 
2.39.2


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

end of thread, other threads:[~2025-04-21  7:39 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-28  6:08 [PATCH RFC v2 00/14] md: introduce a new lockless bitmap Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 01/14] block: factor out a helper bdev_file_alloc() Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 02/14] md/md-bitmap: pass discard information to bitmap_{start, end}write Yu Kuai
2025-04-04  9:29   ` Christoph Hellwig
2025-04-07  1:19     ` Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 03/14] md/md-bitmap: remove parameter slot from bitmap_create() Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 04/14] md: add a new sysfs api bitmap_version Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 05/14] md: delay registeration of bitmap_ops until creating bitmap Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 06/14] md/md-llbitmap: implement bit state machine Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 07/14] md/md-llbitmap: implement hidden disk to manage bitmap IO Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 08/14] md/md-llbitmap: implement APIs for page level dirty bits synchronization Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 09/14] md/md-llbitmap: implement APIs to mange bitmap lifetime Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 10/14] md/md-llbitmap: implement APIs to dirty bits and clear bits Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 11/14] md/md-llbitmap: implement APIs for sync_thread Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 12/14] md/md-llbitmap: implement all bitmap operations Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 13/14] md/md-llbitmap: implement sysfs APIs Yu Kuai
2025-03-28  6:08 ` [PATCH RFC v2 14/14] md/md-llbitmap: add Kconfig Yu Kuai
2025-03-28 11:06 ` [PATCH RFC v2 00/14] md: introduce a new lockless bitmap Christoph Hellwig
2025-03-29  1:11   ` Yu Kuai
2025-04-09  8:32     ` Christoph Hellwig
2025-04-09  9:27       ` Yu Kuai
2025-04-09  9:40         ` Christoph Hellwig
2025-04-11  1:36           ` Yu Kuai
2025-04-19  8:46             ` Yu Kuai
2025-04-21  7:39               ` Christoph Hellwig
2025-04-04  9:27 ` Christoph Hellwig
2025-04-07  1:09   ` Yu Kuai

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