Skip to content

Commit 5ab829f

Browse files
committed
md/md-llbitmap: introduce new lockless bitmap
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. Due to known performance issues with md-bitmap and the unreasonable implementations: - self-managed IO submitting like filemap_write_page(); - global spin_lock I have decided not to continue optimizing based on the current bitmap implementation, this new bitmap is invented without locking from IO fast path and can be used with fast disks. For designs and details, see the comments in drivers/md-llbitmap.c. Link: https://lore.kernel.org/linux-raid/20250829080426.1441678-12-yukuai1@huaweicloud.com Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Li Nan <linan122@huawei.com>
1 parent 66be318 commit 5ab829f

8 files changed

Lines changed: 1696 additions & 12 deletions

File tree

Documentation/admin-guide/md.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ All md devices contain:
387387
No bitmap
388388
bitmap
389389
The default internal bitmap
390+
llbitmap
391+
The lockless internal bitmap
390392

391393
If bitmap_type is not none, then additional bitmap attributes bitmap/xxx or
392394
llbitmap/xxx will be created after md device KOBJ_CHANGE event.
@@ -447,6 +449,24 @@ If bitmap_type is bitmap, then the md device will also contain:
447449
once the array becomes non-degraded, and this fact has been
448450
recorded in the metadata.
449451

452+
If bitmap_type is llbitmap, then the md device will also contain:
453+
454+
llbitmap/bits
455+
This is read-only, show status of bitmap bits, the number of each
456+
value.
457+
458+
llbitmap/metadata
459+
This is read-only, show bitmap metadata, include chunksize, chunkshift,
460+
chunks, offset and daemon_sleep.
461+
462+
llbitmap/daemon_sleep
463+
This is read-write, time in seconds that daemon function will be
464+
triggered to clear dirty bits.
465+
466+
llbitmap/barrier_idle
467+
This is read-write, time in seconds that page barrier will be idled,
468+
means dirty bits in the page will be cleared.
469+
450470
As component devices are added to an md array, they appear in the ``md``
451471
directory as new directories named::
452472

drivers/md/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ config MD_BITMAP
5252

5353
If unsure, say Y.
5454

55+
config MD_LLBITMAP
56+
bool "MD RAID lockless bitmap support"
57+
depends on BLK_DEV_MD
58+
help
59+
If you say Y here, support for the lockless write intent bitmap will
60+
be enabled.
61+
62+
Note, this is an experimental feature.
63+
64+
If unsure, say N.
65+
5566
config MD_AUTODETECT
5667
bool "Autodetect RAID arrays during kernel boot"
5768
depends on BLK_DEV_MD=y

drivers/md/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dm-zoned-y += dm-zoned-target.o dm-zoned-metadata.o dm-zoned-reclaim.o
2929

3030
md-mod-y += md.o
3131
md-mod-$(CONFIG_MD_BITMAP) += md-bitmap.o
32+
md-mod-$(CONFIG_MD_LLBITMAP) += md-llbitmap.o
3233
raid456-y += raid5.o raid5-cache.o raid5-ppl.o
3334
linear-y += md-linear.o
3435

drivers/md/md-bitmap.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@
3434
#include "md-bitmap.h"
3535
#include "md-cluster.h"
3636

37-
#define BITMAP_MAJOR_LO 3
38-
/* version 4 insists the bitmap is in little-endian order
39-
* with version 3, it is host-endian which is non-portable
40-
* Version 5 is currently set only for clustered devices
41-
*/
42-
#define BITMAP_MAJOR_HI 4
43-
#define BITMAP_MAJOR_CLUSTERED 5
44-
#define BITMAP_MAJOR_HOSTENDIAN 3
45-
4637
/*
4738
* in-memory bitmap:
4839
*

drivers/md/md-bitmap.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,26 @@
99

1010
#define BITMAP_MAGIC 0x6d746962
1111

12+
/*
13+
* version 3 is host-endian order, this is deprecated and not used for new
14+
* array
15+
*/
16+
#define BITMAP_MAJOR_LO 3
17+
#define BITMAP_MAJOR_HOSTENDIAN 3
18+
/* version 4 is little-endian order, the default value */
19+
#define BITMAP_MAJOR_HI 4
20+
/* version 5 is only used for cluster */
21+
#define BITMAP_MAJOR_CLUSTERED 5
22+
/* version 6 is only used for lockless bitmap */
23+
#define BITMAP_MAJOR_LOCKLESS 6
24+
1225
/* use these for bitmap->flags and bitmap->sb->state bit-fields */
1326
enum bitmap_state {
14-
BITMAP_STALE = 1, /* the bitmap file is out of date or had -EIO */
27+
BITMAP_STALE = 1, /* the bitmap file is out of date or had -EIO */
1528
BITMAP_WRITE_ERROR = 2, /* A write error has occurred */
29+
BITMAP_FIRST_USE = 3, /* llbitmap is just created */
30+
BITMAP_CLEAN = 4, /* llbitmap is created with assume_clean */
31+
BITMAP_DAEMON_BUSY = 5, /* llbitmap daemon is not finished after daemon_sleep */
1632
BITMAP_HOSTENDIAN =15,
1733
};
1834

@@ -166,4 +182,17 @@ static inline void md_bitmap_exit(void)
166182
}
167183
#endif
168184

185+
#ifdef CONFIG_MD_LLBITMAP
186+
int md_llbitmap_init(void);
187+
void md_llbitmap_exit(void);
188+
#else
189+
static inline int md_llbitmap_init(void)
190+
{
191+
return 0;
192+
}
193+
static inline void md_llbitmap_exit(void)
194+
{
195+
}
196+
#endif
197+
169198
#endif

0 commit comments

Comments
 (0)