* [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations
@ 2024-08-10 2:08 Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations Yu Kuai
` (26 more replies)
0 siblings, 27 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
The background is that currently bitmap is using a global spin_lock,
cauing lock contention and huge IO performance degration for all raid
levels.
However, it's impossible to implement a new lock free bitmap with
current situation that md-bitmap exposes the internal implementation
with lots of exported apis. Hence bitmap_operations is invented, to
describe bitmap core implementation, and a new bitmap can be introduced
with a new bitmap_operations, we only need to switch to the new one
during initialization.
And with this we can build bitmap as kernel module, but that's not
our concern for now.
Noted I just compile this patchset, not tested yet.
Yu Kuai (26):
md/md-bitmap: introduce struct bitmap_operations
md/md-bitmap: merge md_bitmap_create() into bitmap_operations
md/md-bitmap: merge md_bitmap_load() into bitmap_operations
md/md-bitmap: merge md_bitmap_destroy() into bitmap_operations
md/md-bitmap: merge md_bitmap_flush() into bitmap_operations
md/md-bitmap: don't expose md_bitmap_print_sb()
md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations
md/md-bitmap: merge md_bitmap_status() into bitmap_operations
md/md-bitmap: remove md_bitmap_setallbits()
md/md-bitmap: merge bitmap_write_all() into bitmap_operations
md/md-bitmap: merge md_bitmap_dirty_bits() into bitmap_operations
md/md-bitmap: merge md_bitmap_startwrite() into bitmap_operations
md/md-bitmap: merge md_bitmap_endwrite() into bitmap_operations
md/md-bitmap: merge md_bitmap_start_sync() into bitmap_operations
md/md-bitmap: merge md_bitmap_end_sync() into bitmap_operations
md/md-bitmap: merge md_bitmap_close_sync() into bitmap_operations
md/md-bitmap: mrege md_bitmap_cond_end_sync() into bitmap_operations
md/md-bitmap: merge bitmap_sync_with_cluster() into bitmap_operations
md/md-bitmap: merge md_bitmap_resize() into bitmap_operations
md/md-bitmap: merge get_bitmap_from_slot() into bitmap_operations
md/md-bitmap: merge md_bitmap_copy_from_slot() into bitmap_operations
md/md-bitmap: merge md_bitmap_free() into bitmap_operations
md/md-bitmap: merge md_bitmap_wait_behind_writes() into
bitmap_operations
md/md-bitmap: merge md_bitmap_daemon_work() into bitmap_operations
md/md-bitmap: merge md_bitmap_unplug() and md_bitmap_unplug_async()
md/md-bitmap: merge bitmap_unplug() into bitmap_operations
drivers/md/dm-raid.c | 2 +-
drivers/md/md-bitmap.c | 216 +++++++++++++++++---------------
drivers/md/md-bitmap.h | 259 ++++++++++++++++++++++++++++++++++-----
drivers/md/md-cluster.c | 21 ++--
drivers/md/md.c | 13 +-
drivers/md/md.h | 1 +
drivers/md/raid1-10.c | 7 +-
drivers/md/raid1.c | 22 ++--
drivers/md/raid10.c | 32 +++--
drivers/md/raid5-cache.c | 2 +-
drivers/md/raid5.c | 25 ++--
11 files changed, 401 insertions(+), 199 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 35+ messages in thread
* [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-13 6:58 ` Mariusz Tkaczyk
2024-08-10 2:08 ` [PATCH RFC -next 02/26] md/md-bitmap: merge md_bitmap_create() into bitmap_operations Yu Kuai
` (25 subsequent siblings)
26 siblings, 1 reply; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
The structure is empty for now, and will be used in later patches to
merge in bitmap operations, prepare to implement a new lock free
bitmap in the fulture.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 8 ++++++++
drivers/md/md-bitmap.h | 4 ++++
drivers/md/md.c | 1 +
drivers/md/md.h | 1 +
4 files changed, 14 insertions(+)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 08232d8dc815..d9838fbcc9d7 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2707,3 +2707,11 @@ const struct attribute_group md_bitmap_group = {
.name = "bitmap",
.attrs = md_bitmap_attrs,
};
+
+static struct bitmap_operations bitmap_ops = {
+};
+
+void mddev_set_bitmap_ops(struct mddev *mddev)
+{
+ mddev->bitmap_ops = &bitmap_ops;
+}
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index bb9eb418780a..992feaf66d47 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -234,7 +234,11 @@ struct bitmap {
int cluster_slot; /* Slot offset for clustered env */
};
+struct bitmap_operations {
+};
+
/* the bitmap API */
+void mddev_set_bitmap_ops(struct mddev *mddev);
/* these are used only by md/bitmap */
struct bitmap *md_bitmap_create(struct mddev *mddev, int slot);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index d3a837506a36..f23138dd96a7 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -772,6 +772,7 @@ int mddev_init(struct mddev *mddev)
mddev->resync_min = 0;
mddev->resync_max = MaxSector;
mddev->level = LEVEL_NONE;
+ mddev_set_bitmap_ops(mddev);
INIT_WORK(&mddev->sync_work, md_start_sync);
INIT_WORK(&mddev->del_work, mddev_delayed_delete);
diff --git a/drivers/md/md.h b/drivers/md/md.h
index a0d6827dced9..e56193f71ab4 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -536,6 +536,7 @@ struct mddev {
int sync_checkers; /* # of threads checking writes_pending */
struct bitmap *bitmap; /* the bitmap for the device */
+ struct bitmap_operations *bitmap_ops;
struct {
struct file *file; /* the bitmap file */
loff_t offset; /* offset from superblock of
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 02/26] md/md-bitmap: merge md_bitmap_create() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() " Yu Kuai
` (24 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 7 ++++---
drivers/md/md-bitmap.h | 10 +++++++++-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index d9838fbcc9d7..d731f7d4bbbb 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1878,7 +1878,7 @@ void md_bitmap_destroy(struct mddev *mddev)
* if this returns an error, bitmap_destroy must be called to do clean up
* once mddev->bitmap is set
*/
-struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
+static struct bitmap *bitmap_create(struct mddev *mddev, int slot)
{
struct bitmap *bitmap;
sector_t blocks = mddev->resync_max_sectors;
@@ -2029,7 +2029,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
int rv = 0;
struct bitmap *bitmap;
- bitmap = md_bitmap_create(mddev, slot);
+ bitmap = bitmap_create(mddev, slot);
if (IS_ERR(bitmap)) {
rv = PTR_ERR(bitmap);
return ERR_PTR(rv);
@@ -2404,7 +2404,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
}
mddev->bitmap_info.offset = offset;
- bitmap = md_bitmap_create(mddev, -1);
+ bitmap = bitmap_create(mddev, -1);
if (IS_ERR(bitmap)) {
rv = PTR_ERR(bitmap);
goto out;
@@ -2709,6 +2709,7 @@ const struct attribute_group md_bitmap_group = {
};
static struct bitmap_operations bitmap_ops = {
+ .create = bitmap_create,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 992feaf66d47..a7cbf0c692fc 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -235,13 +235,21 @@ struct bitmap {
};
struct bitmap_operations {
+ struct bitmap* (*create)(struct mddev *mddev, int slot);
};
/* the bitmap API */
void mddev_set_bitmap_ops(struct mddev *mddev);
/* these are used only by md/bitmap */
-struct bitmap *md_bitmap_create(struct mddev *mddev, int slot);
+static inline struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
+{
+ if (!mddev->bitmap_ops->create)
+ return ERR_PTR(-EOPNOTSUPP);
+
+ return mddev->bitmap_ops->create(mddev, slot);
+}
+
int md_bitmap_load(struct mddev *mddev);
void md_bitmap_flush(struct mddev *mddev);
void md_bitmap_destroy(struct mddev *mddev);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 02/26] md/md-bitmap: merge md_bitmap_create() into bitmap_operations Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-13 7:07 ` Mariusz Tkaczyk
2024-08-10 2:08 ` [PATCH RFC -next 04/26] md/md-bitmap: merge md_bitmap_destroy() " Yu Kuai
` (23 subsequent siblings)
26 siblings, 1 reply; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 6 +++---
drivers/md/md-bitmap.h | 10 +++++++++-
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index d731f7d4bbbb..9a9f0fe3ebd0 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1965,7 +1965,7 @@ static struct bitmap *bitmap_create(struct mddev *mddev, int slot)
return ERR_PTR(err);
}
-int md_bitmap_load(struct mddev *mddev)
+static int bitmap_load(struct mddev *mddev)
{
int err = 0;
sector_t start = 0;
@@ -2021,7 +2021,6 @@ int md_bitmap_load(struct mddev *mddev)
out:
return err;
}
-EXPORT_SYMBOL_GPL(md_bitmap_load);
/* caller need to free returned bitmap with md_bitmap_free() */
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
@@ -2411,7 +2410,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
}
mddev->bitmap = bitmap;
- rv = md_bitmap_load(mddev);
+ rv = bitmap_load(mddev);
if (rv) {
mddev->bitmap_info.offset = 0;
md_bitmap_destroy(mddev);
@@ -2710,6 +2709,7 @@ const struct attribute_group md_bitmap_group = {
static struct bitmap_operations bitmap_ops = {
.create = bitmap_create,
+ .load = bitmap_load,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index a7cbf0c692fc..de7fbe5903dd 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -236,6 +236,7 @@ struct bitmap {
struct bitmap_operations {
struct bitmap* (*create)(struct mddev *mddev, int slot);
+ int (*load)(struct mddev *mddev);
};
/* the bitmap API */
@@ -250,7 +251,14 @@ static inline struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
return mddev->bitmap_ops->create(mddev, slot);
}
-int md_bitmap_load(struct mddev *mddev);
+static inline int md_bitmap_load(struct mddev *mddev)
+{
+ if (!mddev->bitmap_ops->load)
+ return -EOPNOTSUPP;
+
+ return mddev->bitmap_ops->load(mddev);
+}
+
void md_bitmap_flush(struct mddev *mddev);
void md_bitmap_destroy(struct mddev *mddev);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 04/26] md/md-bitmap: merge md_bitmap_destroy() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (2 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 05/26] md/md-bitmap: merge md_bitmap_flush() " Yu Kuai
` (22 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 7 ++++---
drivers/md/md-bitmap.h | 10 +++++++++-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 9a9f0fe3ebd0..8aaf0491bf5d 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1852,7 +1852,7 @@ void md_bitmap_wait_behind_writes(struct mddev *mddev)
}
}
-void md_bitmap_destroy(struct mddev *mddev)
+static void bitmap_destroy(struct mddev *mddev)
{
struct bitmap *bitmap = mddev->bitmap;
@@ -2366,7 +2366,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
goto out;
}
- md_bitmap_destroy(mddev);
+ bitmap_destroy(mddev);
mddev->bitmap_info.offset = 0;
if (mddev->bitmap_info.file) {
struct file *f = mddev->bitmap_info.file;
@@ -2413,7 +2413,7 @@ location_store(struct mddev *mddev, const char *buf, size_t len)
rv = bitmap_load(mddev);
if (rv) {
mddev->bitmap_info.offset = 0;
- md_bitmap_destroy(mddev);
+ bitmap_destroy(mddev);
goto out;
}
}
@@ -2710,6 +2710,7 @@ const struct attribute_group md_bitmap_group = {
static struct bitmap_operations bitmap_ops = {
.create = bitmap_create,
.load = bitmap_load,
+ .destroy = bitmap_destroy,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index de7fbe5903dd..46db4d8199d8 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -237,6 +237,7 @@ struct bitmap {
struct bitmap_operations {
struct bitmap* (*create)(struct mddev *mddev, int slot);
int (*load)(struct mddev *mddev);
+ void (*destroy)(struct mddev *mddev);
};
/* the bitmap API */
@@ -259,8 +260,15 @@ static inline int md_bitmap_load(struct mddev *mddev)
return mddev->bitmap_ops->load(mddev);
}
+static inline void md_bitmap_destroy(struct mddev *mddev)
+{
+ if (!mddev->bitmap_ops->destroy)
+ return;
+
+ mddev->bitmap_ops->destroy(mddev);
+}
+
void md_bitmap_flush(struct mddev *mddev);
-void md_bitmap_destroy(struct mddev *mddev);
void md_bitmap_print_sb(struct bitmap *bitmap);
void md_bitmap_update_sb(struct bitmap *bitmap);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 05/26] md/md-bitmap: merge md_bitmap_flush() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (3 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 04/26] md/md-bitmap: merge md_bitmap_destroy() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 06/26] md/md-bitmap: don't expose md_bitmap_print_sb() Yu Kuai
` (21 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 3 ++-
drivers/md/md-bitmap.h | 9 ++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 8aaf0491bf5d..33bcae5594e2 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1776,7 +1776,7 @@ void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long
/*
* flush out any pending updates
*/
-void md_bitmap_flush(struct mddev *mddev)
+static void bitmap_flush(struct mddev *mddev)
{
struct bitmap *bitmap = mddev->bitmap;
long sleep;
@@ -2711,6 +2711,7 @@ static struct bitmap_operations bitmap_ops = {
.create = bitmap_create,
.load = bitmap_load,
.destroy = bitmap_destroy,
+ .flush = bitmap_flush,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 46db4d8199d8..749351db04d3 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -238,6 +238,7 @@ struct bitmap_operations {
struct bitmap* (*create)(struct mddev *mddev, int slot);
int (*load)(struct mddev *mddev);
void (*destroy)(struct mddev *mddev);
+ void (*flush)(struct mddev *mddev);
};
/* the bitmap API */
@@ -268,7 +269,13 @@ static inline void md_bitmap_destroy(struct mddev *mddev)
mddev->bitmap_ops->destroy(mddev);
}
-void md_bitmap_flush(struct mddev *mddev);
+static inline void md_bitmap_flush(struct mddev *mddev)
+{
+ if (!mddev->bitmap_ops->flush)
+ return;
+
+ mddev->bitmap_ops->flush(mddev);
+}
void md_bitmap_print_sb(struct bitmap *bitmap);
void md_bitmap_update_sb(struct bitmap *bitmap);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 06/26] md/md-bitmap: don't expose md_bitmap_print_sb()
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (4 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 05/26] md/md-bitmap: merge md_bitmap_flush() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations Yu Kuai
` (20 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
md_bitmap_print_sb() is only used inside md-bitmap.c, hence make it
static, and also rename it to bitmap_print_sb().
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 4 ++--
drivers/md/md-bitmap.h | 1 -
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 33bcae5594e2..0ff733756043 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -513,7 +513,7 @@ void md_bitmap_update_sb(struct bitmap *bitmap)
EXPORT_SYMBOL(md_bitmap_update_sb);
/* print out the bitmap file superblock */
-void md_bitmap_print_sb(struct bitmap *bitmap)
+static void bitmap_print_sb(struct bitmap *bitmap)
{
bitmap_super_t *sb;
@@ -760,7 +760,7 @@ static int md_bitmap_read_sb(struct bitmap *bitmap)
bitmap->mddev->bitmap_info.space > sectors_reserved)
bitmap->mddev->bitmap_info.space = sectors_reserved;
} else {
- md_bitmap_print_sb(bitmap);
+ bitmap_print_sb(bitmap);
if (bitmap->cluster_slot < 0)
md_cluster_stop(bitmap->mddev);
}
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 749351db04d3..935c5dc45b89 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -277,7 +277,6 @@ static inline void md_bitmap_flush(struct mddev *mddev)
mddev->bitmap_ops->flush(mddev);
}
-void md_bitmap_print_sb(struct bitmap *bitmap);
void md_bitmap_update_sb(struct bitmap *bitmap);
void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (5 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 06/26] md/md-bitmap: don't expose md_bitmap_print_sb() Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-13 7:17 ` Mariusz Tkaczyk
2024-08-10 2:08 ` [PATCH RFC -next 08/26] md/md-bitmap: merge md_bitmap_status() " Yu Kuai
` (19 subsequent siblings)
26 siblings, 1 reply; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 15 ++++++++-------
drivers/md/md-bitmap.h | 11 ++++++++++-
drivers/md/md-cluster.c | 3 ++-
drivers/md/md.c | 4 ++--
4 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 0ff733756043..b34f13aa2697 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -472,7 +472,7 @@ static void md_bitmap_wait_writes(struct bitmap *bitmap)
/* update the event counter and sync the superblock to disk */
-void md_bitmap_update_sb(struct bitmap *bitmap)
+static void bitmap_update_sb(struct bitmap *bitmap)
{
bitmap_super_t *sb;
@@ -510,7 +510,6 @@ void md_bitmap_update_sb(struct bitmap *bitmap)
write_sb_page(bitmap, bitmap->storage.sb_index,
bitmap->storage.sb_page, 1);
}
-EXPORT_SYMBOL(md_bitmap_update_sb);
/* print out the bitmap file superblock */
static void bitmap_print_sb(struct bitmap *bitmap)
@@ -893,7 +892,7 @@ static void md_bitmap_file_unmap(struct bitmap_storage *store)
static void md_bitmap_file_kick(struct bitmap *bitmap)
{
if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) {
- md_bitmap_update_sb(bitmap);
+ bitmap_update_sb(bitmap);
if (bitmap->storage.file) {
pr_warn("%s: kicking failed bitmap file %pD4 from array!\n",
@@ -1796,7 +1795,7 @@ static void bitmap_flush(struct mddev *mddev)
md_bitmap_daemon_work(mddev);
if (mddev->bitmap_info.external)
md_super_wait(mddev);
- md_bitmap_update_sb(bitmap);
+ bitmap_update_sb(bitmap);
}
/*
@@ -2014,7 +2013,7 @@ static int bitmap_load(struct mddev *mddev)
mddev_set_timeout(mddev, mddev->bitmap_info.daemon_sleep, true);
md_wakeup_thread(mddev->thread);
- md_bitmap_update_sb(bitmap);
+ bitmap_update_sb(bitmap);
if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
err = -EIO;
@@ -2075,7 +2074,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
}
if (clear_bits) {
- md_bitmap_update_sb(bitmap);
+ bitmap_update_sb(bitmap);
/* BITMAP_PAGE_PENDING is set, but bitmap_unplug needs
* BITMAP_PAGE_DIRTY or _NEEDWRITE to write ... */
for (i = 0; i < bitmap->storage.file_pages; i++)
@@ -2568,7 +2567,7 @@ backlog_store(struct mddev *mddev, const char *buf, size_t len)
mddev_create_serial_pool(mddev, rdev);
}
if (old_mwb != backlog)
- md_bitmap_update_sb(mddev->bitmap);
+ bitmap_update_sb(mddev->bitmap);
mddev_unlock_and_resume(mddev);
return len;
@@ -2712,6 +2711,8 @@ static struct bitmap_operations bitmap_ops = {
.load = bitmap_load,
.destroy = bitmap_destroy,
.flush = bitmap_flush,
+
+ .update_sb = bitmap_update_sb,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 935c5dc45b89..29c217630ae5 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -239,6 +239,8 @@ struct bitmap_operations {
int (*load)(struct mddev *mddev);
void (*destroy)(struct mddev *mddev);
void (*flush)(struct mddev *mddev);
+
+ void (*update_sb)(struct bitmap *bitmap);
};
/* the bitmap API */
@@ -277,7 +279,14 @@ static inline void md_bitmap_flush(struct mddev *mddev)
mddev->bitmap_ops->flush(mddev);
}
-void md_bitmap_update_sb(struct bitmap *bitmap);
+static inline void md_bitmap_update_sb(struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->update_sb)
+ return;
+
+ mddev->bitmap_ops->update_sb(mddev->bitmap);
+}
+
void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap);
int md_bitmap_setallbits(struct bitmap *bitmap);
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 1d0db62f0351..79e67393fee0 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1244,7 +1244,8 @@ static int cluster_check_sync_size(struct mddev *mddev)
bm_lockres->flags |= DLM_LKF_NOQUEUE;
rv = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
if (!rv)
- md_bitmap_update_sb(bitmap);
+ mddev->bitmap_ops->update_sb(bitmap);
+
lockres_free(bm_lockres);
sb = kmap_atomic(bitmap->storage.sb_page);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index f23138dd96a7..e749e24e12de 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2821,7 +2821,7 @@ void md_update_sb(struct mddev *mddev, int force_change)
mddev_add_trace_msg(mddev, "md md_update_sb");
rewrite:
- md_bitmap_update_sb(mddev->bitmap);
+ md_bitmap_update_sb(mddev);
rdev_for_each(rdev, mddev) {
if (rdev->sb_loaded != 1)
continue; /* no noise on spare devices */
@@ -9966,7 +9966,7 @@ static void check_sb_changes(struct mddev *mddev, struct md_rdev *rdev)
if (ret)
pr_info("md-cluster: resize failed\n");
else
- md_bitmap_update_sb(mddev->bitmap);
+ md_bitmap_update_sb(mddev);
}
/* Check for change of roles in the active devices */
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 08/26] md/md-bitmap: merge md_bitmap_status() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (6 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 09/26] md/md-bitmap: remove md_bitmap_setallbits() Yu Kuai
` (18 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 3 ++-
drivers/md/md-bitmap.h | 11 +++++++++--
drivers/md/md.c | 2 +-
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b34f13aa2697..9a21123a3b8b 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2092,7 +2092,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
EXPORT_SYMBOL_GPL(md_bitmap_copy_from_slot);
-void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
+static void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
{
unsigned long chunk_kb;
struct bitmap_counts *counts;
@@ -2711,6 +2711,7 @@ static struct bitmap_operations bitmap_ops = {
.load = bitmap_load,
.destroy = bitmap_destroy,
.flush = bitmap_flush,
+ .status = bitmap_status,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 29c217630ae5..c60b6a9f6163 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -239,6 +239,7 @@ struct bitmap_operations {
int (*load)(struct mddev *mddev);
void (*destroy)(struct mddev *mddev);
void (*flush)(struct mddev *mddev);
+ void (*status)(struct seq_file *seq, struct bitmap *bitmap);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -279,6 +280,14 @@ static inline void md_bitmap_flush(struct mddev *mddev)
mddev->bitmap_ops->flush(mddev);
}
+static inline void md_bitmap_status(struct seq_file *seq, struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->status)
+ return;
+
+ mddev->bitmap_ops->status(seq, mddev->bitmap);
+}
+
static inline void md_bitmap_update_sb(struct mddev *mddev)
{
if (!mddev->bitmap || !mddev->bitmap_ops->update_sb)
@@ -287,8 +296,6 @@ static inline void md_bitmap_update_sb(struct mddev *mddev)
mddev->bitmap_ops->update_sb(mddev->bitmap);
}
-void md_bitmap_status(struct seq_file *seq, struct bitmap *bitmap);
-
int md_bitmap_setallbits(struct bitmap *bitmap);
void md_bitmap_write_all(struct bitmap *bitmap);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index e749e24e12de..033ea06f6abe 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -8454,7 +8454,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
} else
seq_printf(seq, "\n ");
- md_bitmap_status(seq, mddev->bitmap);
+ md_bitmap_status(seq, mddev);
seq_printf(seq, "\n");
}
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 09/26] md/md-bitmap: remove md_bitmap_setallbits()
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (7 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 08/26] md/md-bitmap: merge md_bitmap_status() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 10/26] md/md-bitmap: merge bitmap_write_all() into bitmap_operations Yu Kuai
` (17 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
md_bitmap_setallbits() is not used, hence can be removed.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index c60b6a9f6163..3fd2e5a7ba9c 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -296,7 +296,6 @@ static inline void md_bitmap_update_sb(struct mddev *mddev)
mddev->bitmap_ops->update_sb(mddev->bitmap);
}
-int md_bitmap_setallbits(struct bitmap *bitmap);
void md_bitmap_write_all(struct bitmap *bitmap);
void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 10/26] md/md-bitmap: merge bitmap_write_all() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (8 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 09/26] md/md-bitmap: remove md_bitmap_setallbits() Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 11/26] md/md-bitmap: merge md_bitmap_dirty_bits() " Yu Kuai
` (16 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 3 ++-
drivers/md/md-bitmap.h | 9 ++++++++-
drivers/md/md.c | 2 +-
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 9a21123a3b8b..aab7bb5418f7 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1225,7 +1225,7 @@ static int md_bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
return ret;
}
-void md_bitmap_write_all(struct bitmap *bitmap)
+static void bitmap_write_all(struct bitmap *bitmap)
{
/* We don't actually write all bitmap blocks here,
* just flag them as needing to be written
@@ -2712,6 +2712,7 @@ static struct bitmap_operations bitmap_ops = {
.destroy = bitmap_destroy,
.flush = bitmap_flush,
.status = bitmap_status,
+ .write_all = bitmap_write_all,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 3fd2e5a7ba9c..9df0c1d5f7ee 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -240,6 +240,7 @@ struct bitmap_operations {
void (*destroy)(struct mddev *mddev);
void (*flush)(struct mddev *mddev);
void (*status)(struct seq_file *seq, struct bitmap *bitmap);
+ void (*write_all)(struct bitmap *bitmap);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -296,7 +297,13 @@ static inline void md_bitmap_update_sb(struct mddev *mddev)
mddev->bitmap_ops->update_sb(mddev->bitmap);
}
-void md_bitmap_write_all(struct bitmap *bitmap);
+static inline void md_bitmap_write_all(struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->write_all)
+ return;
+
+ mddev->bitmap_ops->write_all(mddev->bitmap);
+}
void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 033ea06f6abe..2260540dd458 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9507,7 +9507,7 @@ static void md_start_sync(struct work_struct *ws)
* stored on all devices. So make sure all bitmap pages get written.
*/
if (spares)
- md_bitmap_write_all(mddev->bitmap);
+ md_bitmap_write_all(mddev);
name = test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) ?
"reshape" : "resync";
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 11/26] md/md-bitmap: merge md_bitmap_dirty_bits() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (9 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 10/26] md/md-bitmap: merge bitmap_write_all() into bitmap_operations Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 12/26] md/md-bitmap: merge md_bitmap_startwrite() " Yu Kuai
` (15 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 4 +++-
drivers/md/md-bitmap.h | 10 +++++++++-
drivers/md/md.c | 2 +-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index aab7bb5418f7..b85ae1bf2b7d 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1755,7 +1755,8 @@ static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, in
}
/* dirty the memory and file bits for bitmap chunks "s" to "e" */
-void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e)
+static void bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s,
+ unsigned long e)
{
unsigned long chunk;
@@ -2713,6 +2714,7 @@ static struct bitmap_operations bitmap_ops = {
.flush = bitmap_flush,
.status = bitmap_status,
.write_all = bitmap_write_all,
+ .dirty_bits = bitmap_dirty_bits,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 9df0c1d5f7ee..b708a25bd6f4 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -241,6 +241,7 @@ struct bitmap_operations {
void (*flush)(struct mddev *mddev);
void (*status)(struct seq_file *seq, struct bitmap *bitmap);
void (*write_all)(struct bitmap *bitmap);
+ void (*dirty_bits)(struct bitmap *bitmap, unsigned long s, unsigned long e);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -305,7 +306,14 @@ static inline void md_bitmap_write_all(struct mddev *mddev)
mddev->bitmap_ops->write_all(mddev->bitmap);
}
-void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long e);
+static inline void md_bitmap_dirty_bits(struct mddev *mddev, unsigned long s,
+ unsigned long e)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->dirty_bits)
+ return;
+
+ mddev->bitmap_ops->dirty_bits(mddev->bitmap, s, e);
+}
/* these are exported */
int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 2260540dd458..841539a0be1b 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4688,7 +4688,7 @@ bitmap_store(struct mddev *mddev, const char *buf, size_t len)
if (buf == end) break;
}
if (*end && !isspace(*end)) break;
- md_bitmap_dirty_bits(mddev->bitmap, chunk, end_chunk);
+ md_bitmap_dirty_bits(mddev, chunk, end_chunk);
buf = skip_spaces(end);
}
md_bitmap_unplug(mddev->bitmap); /* flush the bits to disk */
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 12/26] md/md-bitmap: merge md_bitmap_startwrite() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (10 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 11/26] md/md-bitmap: merge md_bitmap_dirty_bits() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 13/26] md/md-bitmap: merge md_bitmap_endwrite() " Yu Kuai
` (14 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 6 ++++--
drivers/md/md-bitmap.h | 15 +++++++++++++--
drivers/md/raid1.c | 3 ++-
drivers/md/raid10.c | 2 +-
drivers/md/raid5.c | 5 ++---
5 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b85ae1bf2b7d..75e87073e3bc 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1460,7 +1460,8 @@ __acquires(bitmap->lock)
&(bitmap->bp[page].map[pageoff]);
}
-int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind)
+static int bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
+ unsigned long sectors, int behind)
{
if (!bitmap)
return 0;
@@ -1522,7 +1523,6 @@ int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long s
}
return 0;
}
-EXPORT_SYMBOL(md_bitmap_startwrite);
void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
unsigned long sectors, int success, int behind)
@@ -2716,6 +2716,8 @@ static struct bitmap_operations bitmap_ops = {
.write_all = bitmap_write_all,
.dirty_bits = bitmap_dirty_bits,
+ .startwrite = bitmap_startwrite,
+
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index b708a25bd6f4..166cc2a44909 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -243,6 +243,9 @@ struct bitmap_operations {
void (*write_all)(struct bitmap *bitmap);
void (*dirty_bits)(struct bitmap *bitmap, unsigned long s, unsigned long e);
+ int (*startwrite)(struct bitmap *bitmap, sector_t offset,
+ unsigned long sectors, int behind);
+
void (*update_sb)(struct bitmap *bitmap);
};
@@ -316,8 +319,16 @@ static inline void md_bitmap_dirty_bits(struct mddev *mddev, unsigned long s,
}
/* these are exported */
-int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
- unsigned long sectors, int behind);
+static inline int md_bitmap_startwrite(struct mddev *mddev, sector_t offset,
+ unsigned long sectors, int behind)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->startwrite)
+ return -EOPNOTSUPP;
+
+ return mddev->bitmap_ops->startwrite(mddev->bitmap, offset, sectors,
+ behind);
+}
+
void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
unsigned long sectors, int success, int behind);
int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded);
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 7acfe7c9dc8d..16e741bde382 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1617,7 +1617,8 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
alloc_behind_master_bio(r1_bio, bio);
}
- md_bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors,
+ md_bitmap_startwrite(mddev, r1_bio->sector,
+ r1_bio->sectors,
test_bit(R1BIO_BehindIO, &r1_bio->state));
first_clone = 0;
}
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 2a9c4ee982e0..34948fef1339 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1492,7 +1492,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
md_account_bio(mddev, &bio);
r10_bio->master_bio = bio;
atomic_set(&r10_bio->remaining, 1);
- md_bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0);
+ md_bitmap_startwrite(mddev, r10_bio->sector, r10_bio->sectors, 0);
for (i = 0; i < conf->copies; i++) {
if (r10_bio->devs[i].bio)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index c14cf2410365..127e4b4c6c20 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -3563,7 +3563,7 @@ static void __add_stripe_bio(struct stripe_head *sh, struct bio *bi,
*/
set_bit(STRIPE_BITMAP_PENDING, &sh->state);
spin_unlock_irq(&sh->stripe_lock);
- md_bitmap_startwrite(conf->mddev->bitmap, sh->sector,
+ md_bitmap_startwrite(conf->mddev, sh->sector,
RAID5_STRIPE_SECTORS(conf), 0);
spin_lock_irq(&sh->stripe_lock);
clear_bit(STRIPE_BITMAP_PENDING, &sh->state);
@@ -5791,8 +5791,7 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
for (d = 0;
d < conf->raid_disks - conf->max_degraded;
d++)
- md_bitmap_startwrite(mddev->bitmap,
- sh->sector,
+ md_bitmap_startwrite(mddev, sh->sector,
RAID5_STRIPE_SECTORS(conf),
0);
sh->bm_seq = conf->seq_flush + 1;
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 13/26] md/md-bitmap: merge md_bitmap_endwrite() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (11 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 12/26] md/md-bitmap: merge md_bitmap_startwrite() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 14/26] md/md-bitmap: merge md_bitmap_start_sync() " Yu Kuai
` (13 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 6 +++---
drivers/md/md-bitmap.h | 15 +++++++++++++--
drivers/md/raid1.c | 3 +--
drivers/md/raid10.c | 3 +--
drivers/md/raid5-cache.c | 2 +-
drivers/md/raid5.c | 6 +++---
6 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 75e87073e3bc..d726e571406d 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1524,8 +1524,8 @@ static int bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
return 0;
}
-void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
- unsigned long sectors, int success, int behind)
+static void bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
+ unsigned long sectors, int success, int behind)
{
if (!bitmap)
return;
@@ -1575,7 +1575,6 @@ void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
sectors = 0;
}
}
-EXPORT_SYMBOL(md_bitmap_endwrite);
static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks,
int degraded)
@@ -2717,6 +2716,7 @@ static struct bitmap_operations bitmap_ops = {
.dirty_bits = bitmap_dirty_bits,
.startwrite = bitmap_startwrite,
+ .endwrite = bitmap_endwrite,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 166cc2a44909..3a8be496d9b2 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -245,6 +245,8 @@ struct bitmap_operations {
int (*startwrite)(struct bitmap *bitmap, sector_t offset,
unsigned long sectors, int behind);
+ void (*endwrite)(struct bitmap *bitmap, sector_t offset,
+ unsigned long sectors, int success, int behind);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -329,8 +331,17 @@ static inline int md_bitmap_startwrite(struct mddev *mddev, sector_t offset,
behind);
}
-void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
- unsigned long sectors, int success, int behind);
+static inline void md_bitmap_endwrite(struct mddev *mddev, sector_t offset,
+ unsigned long sectors, int success,
+ int behind)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->endwrite)
+ return;
+
+ mddev->bitmap_ops->endwrite(mddev->bitmap, offset, sectors, success,
+ behind);
+}
+
int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded);
void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
void md_bitmap_close_sync(struct bitmap *bitmap);
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 16e741bde382..670ed59d3453 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -418,8 +418,7 @@ static void close_write(struct r1bio *r1_bio)
r1_bio->behind_master_bio = NULL;
}
/* clear the bitmap if all writes complete successfully */
- md_bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
- r1_bio->sectors,
+ md_bitmap_endwrite(r1_bio->mddev, r1_bio->sector, r1_bio->sectors,
!test_bit(R1BIO_Degraded, &r1_bio->state),
test_bit(R1BIO_BehindIO, &r1_bio->state));
md_write_end(r1_bio->mddev);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 34948fef1339..2876686a9bf2 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -427,8 +427,7 @@ static void raid10_end_read_request(struct bio *bio)
static void close_write(struct r10bio *r10_bio)
{
/* clear the bitmap if all writes complete successfully */
- md_bitmap_endwrite(r10_bio->mddev->bitmap, r10_bio->sector,
- r10_bio->sectors,
+ md_bitmap_endwrite(r10_bio->mddev, r10_bio->sector, r10_bio->sectors,
!test_bit(R10BIO_Degraded, &r10_bio->state),
0);
md_write_end(r10_bio->mddev);
diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
index 874874fe4fa1..1b007276371c 100644
--- a/drivers/md/raid5-cache.c
+++ b/drivers/md/raid5-cache.c
@@ -313,7 +313,7 @@ void r5c_handle_cached_data_endio(struct r5conf *conf,
if (sh->dev[i].written) {
set_bit(R5_UPTODATE, &sh->dev[i].flags);
r5c_return_dev_pending_writes(conf, &sh->dev[i]);
- md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
+ md_bitmap_endwrite(conf->mddev, sh->sector,
RAID5_STRIPE_SECTORS(conf),
!test_bit(STRIPE_DEGRADED, &sh->state),
0);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 127e4b4c6c20..2e54115da719 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -3663,7 +3663,7 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
bi = nextbi;
}
if (bitmap_end)
- md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
+ md_bitmap_endwrite(conf->mddev, sh->sector,
RAID5_STRIPE_SECTORS(conf), 0, 0);
bitmap_end = 0;
/* and fail all 'written' */
@@ -3709,7 +3709,7 @@ handle_failed_stripe(struct r5conf *conf, struct stripe_head *sh,
}
}
if (bitmap_end)
- md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
+ md_bitmap_endwrite(conf->mddev, sh->sector,
RAID5_STRIPE_SECTORS(conf), 0, 0);
/* If we were in the middle of a write the parity block might
* still be locked - so just clear all R5_LOCKED flags
@@ -4059,7 +4059,7 @@ static void handle_stripe_clean_event(struct r5conf *conf,
bio_endio(wbi);
wbi = wbi2;
}
- md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
+ md_bitmap_endwrite(conf->mddev, sh->sector,
RAID5_STRIPE_SECTORS(conf),
!test_bit(STRIPE_DEGRADED, &sh->state),
0);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 14/26] md/md-bitmap: merge md_bitmap_start_sync() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (12 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 13/26] md/md-bitmap: merge md_bitmap_endwrite() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 15/26] md/md-bitmap: merge md_bitmap_end_sync() " Yu Kuai
` (12 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 10 +++++-----
drivers/md/md-bitmap.h | 13 ++++++++++++-
drivers/md/raid1.c | 4 ++--
drivers/md/raid10.c | 6 +++---
drivers/md/raid5.c | 4 ++--
5 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index d726e571406d..b20b6585fc44 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1604,8 +1604,8 @@ static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t
return rv;
}
-int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks,
- int degraded)
+static int bitmap_start_sync(struct bitmap *bitmap, sector_t offset,
+ sector_t *blocks, int degraded)
{
/* bitmap_start_sync must always report on multiples of whole
* pages, otherwise resync (which is very PAGE_SIZE based) will
@@ -1626,7 +1626,6 @@ int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *block
}
return rv;
}
-EXPORT_SYMBOL(md_bitmap_start_sync);
void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted)
{
@@ -1720,7 +1719,7 @@ void md_bitmap_sync_with_cluster(struct mddev *mddev,
WARN((blocks > new_lo) && old_lo, "alignment is not correct for lo\n");
for (sector = old_hi; sector < new_hi; ) {
- md_bitmap_start_sync(bitmap, sector, &blocks, 0);
+ bitmap_start_sync(bitmap, sector, &blocks, 0);
sector += blocks;
}
WARN((blocks > new_hi) && old_hi, "alignment is not correct for hi\n");
@@ -1988,7 +1987,7 @@ static int bitmap_load(struct mddev *mddev)
*/
while (sector < mddev->resync_max_sectors) {
sector_t blocks;
- md_bitmap_start_sync(bitmap, sector, &blocks, 0);
+ bitmap_start_sync(bitmap, sector, &blocks, 0);
sector += blocks;
}
md_bitmap_close_sync(bitmap);
@@ -2717,6 +2716,7 @@ static struct bitmap_operations bitmap_ops = {
.startwrite = bitmap_startwrite,
.endwrite = bitmap_endwrite,
+ .start_sync = bitmap_start_sync,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 3a8be496d9b2..118141b6caeb 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -247,6 +247,8 @@ struct bitmap_operations {
unsigned long sectors, int behind);
void (*endwrite)(struct bitmap *bitmap, sector_t offset,
unsigned long sectors, int success, int behind);
+ int (*start_sync)(struct bitmap *bitmap, sector_t offset,
+ sector_t *blocks, int degraded);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -342,7 +344,16 @@ static inline void md_bitmap_endwrite(struct mddev *mddev, sector_t offset,
behind);
}
-int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded);
+static inline int md_bitmap_start_sync(struct mddev *mddev, sector_t offset,
+ sector_t *blocks, int degraded)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->start_sync)
+ return -EOPNOTSUPP;
+
+ return mddev->bitmap_ops->start_sync(mddev->bitmap, offset, blocks,
+ degraded);
+}
+
void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
void md_bitmap_close_sync(struct bitmap *bitmap);
void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force);
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 670ed59d3453..e86cf05f9870 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2807,7 +2807,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
/* before building a request, check if we can skip these blocks..
* This call the bitmap_start_sync doesn't actually record anything
*/
- if (!md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
+ if (!md_bitmap_start_sync(mddev, sector_nr, &sync_blocks, 1) &&
!conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) {
/* We can skip this block, and probably several more */
*skipped = 1;
@@ -2982,7 +2982,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
if (len == 0)
break;
if (sync_blocks == 0) {
- if (!md_bitmap_start_sync(mddev->bitmap, sector_nr,
+ if (!md_bitmap_start_sync(mddev, sector_nr,
&sync_blocks, still_degraded) &&
!conf->fullsync &&
!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 2876686a9bf2..20c0ccf28ef5 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3319,7 +3319,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
* we only need to recover the block if it is set in
* the bitmap
*/
- must_sync = md_bitmap_start_sync(mddev->bitmap, sect,
+ must_sync = md_bitmap_start_sync(mddev, sect,
&sync_blocks, 1);
if (sync_blocks < max_sync)
max_sync = sync_blocks;
@@ -3363,7 +3363,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
}
}
- must_sync = md_bitmap_start_sync(mddev->bitmap, sect,
+ must_sync = md_bitmap_start_sync(mddev, sect,
&sync_blocks, still_degraded);
any_working = 0;
@@ -3541,7 +3541,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
mddev_is_clustered(mddev) &&
(sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high));
- if (!md_bitmap_start_sync(mddev->bitmap, sector_nr,
+ if (!md_bitmap_start_sync(mddev, sector_nr,
&sync_blocks, mddev->degraded) &&
!conf->fullsync && !test_bit(MD_RECOVERY_REQUESTED,
&mddev->recovery)) {
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 2e54115da719..a2688987a2d0 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6530,7 +6530,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
}
if (!test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery) &&
!conf->fullsync &&
- !md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, 1) &&
+ !md_bitmap_start_sync(mddev, sector_nr, &sync_blocks, 1) &&
sync_blocks >= RAID5_STRIPE_SECTORS(conf)) {
/* we can skip this block, and probably more */
do_div(sync_blocks, RAID5_STRIPE_SECTORS(conf));
@@ -6561,7 +6561,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
still_degraded = 1;
}
- md_bitmap_start_sync(mddev->bitmap, sector_nr, &sync_blocks, still_degraded);
+ md_bitmap_start_sync(mddev, sector_nr, &sync_blocks, still_degraded);
set_bit(STRIPE_SYNC_REQUESTED, &sh->state);
set_bit(STRIPE_HANDLE, &sh->state);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 15/26] md/md-bitmap: merge md_bitmap_end_sync() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (13 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 14/26] md/md-bitmap: merge md_bitmap_start_sync() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 16/26] md/md-bitmap: merge md_bitmap_close_sync() " Yu Kuai
` (11 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 15 ++++++---------
drivers/md/md-bitmap.h | 14 +++++++++++++-
drivers/md/raid1.c | 4 ++--
drivers/md/raid10.c | 5 ++---
drivers/md/raid5.c | 2 +-
5 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b20b6585fc44..d0163533da14 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1627,15 +1627,12 @@ static int bitmap_start_sync(struct bitmap *bitmap, sector_t offset,
return rv;
}
-void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted)
+static void bitmap_end_sync(struct bitmap *bitmap, sector_t offset,
+ sector_t *blocks, int aborted)
{
bitmap_counter_t *bmc;
unsigned long flags;
- if (bitmap == NULL) {
- *blocks = 1024;
- return;
- }
spin_lock_irqsave(&bitmap->counts.lock, flags);
bmc = md_bitmap_get_counter(&bitmap->counts, offset, blocks, 0);
if (bmc == NULL)
@@ -1656,7 +1653,6 @@ void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks
unlock:
spin_unlock_irqrestore(&bitmap->counts.lock, flags);
}
-EXPORT_SYMBOL(md_bitmap_end_sync);
void md_bitmap_close_sync(struct bitmap *bitmap)
{
@@ -1669,7 +1665,7 @@ void md_bitmap_close_sync(struct bitmap *bitmap)
if (!bitmap)
return;
while (sector < bitmap->mddev->resync_max_sectors) {
- md_bitmap_end_sync(bitmap, sector, &blocks, 0);
+ bitmap_end_sync(bitmap, sector, &blocks, 0);
sector += blocks;
}
}
@@ -1697,7 +1693,7 @@ void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force)
sector &= ~((1ULL << bitmap->counts.chunkshift) - 1);
s = 0;
while (s < sector && s < bitmap->mddev->resync_max_sectors) {
- md_bitmap_end_sync(bitmap, s, &blocks, 0);
+ bitmap_end_sync(bitmap, s, &blocks, 0);
s += blocks;
}
bitmap->last_end_sync = jiffies;
@@ -1713,7 +1709,7 @@ void md_bitmap_sync_with_cluster(struct mddev *mddev,
sector_t sector, blocks = 0;
for (sector = old_lo; sector < new_lo; ) {
- md_bitmap_end_sync(bitmap, sector, &blocks, 0);
+ bitmap_end_sync(bitmap, sector, &blocks, 0);
sector += blocks;
}
WARN((blocks > new_lo) && old_lo, "alignment is not correct for lo\n");
@@ -2717,6 +2713,7 @@ static struct bitmap_operations bitmap_ops = {
.startwrite = bitmap_startwrite,
.endwrite = bitmap_endwrite,
.start_sync = bitmap_start_sync,
+ .end_sync = bitmap_end_sync,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 118141b6caeb..58c114246a2d 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -249,6 +249,8 @@ struct bitmap_operations {
unsigned long sectors, int success, int behind);
int (*start_sync)(struct bitmap *bitmap, sector_t offset,
sector_t *blocks, int degraded);
+ void (*end_sync)(struct bitmap *bitmap, sector_t offset,
+ sector_t *blocks, int aborted);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -354,7 +356,17 @@ static inline int md_bitmap_start_sync(struct mddev *mddev, sector_t offset,
degraded);
}
-void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
+static inline void md_bitmap_end_sync(struct mddev *mddev, sector_t offset,
+ sector_t *blocks, int aborted)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->end_sync) {
+ *blocks = 1024;
+ return;
+ }
+
+ mddev->bitmap_ops->end_sync(mddev->bitmap, offset, blocks, aborted);
+}
+
void md_bitmap_close_sync(struct bitmap *bitmap);
void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force);
void md_bitmap_sync_with_cluster(struct mddev *mddev,
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index e86cf05f9870..cf787ead3d0d 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2036,7 +2036,7 @@ static void abort_sync_write(struct mddev *mddev, struct r1bio *r1_bio)
/* make sure these bits don't get cleared. */
do {
- md_bitmap_end_sync(mddev->bitmap, s, &sync_blocks, 1);
+ md_bitmap_end_sync(mddev, s, &sync_blocks, 1);
s += sync_blocks;
sectors_to_go -= sync_blocks;
} while (sectors_to_go > 0);
@@ -2782,7 +2782,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
* We can find the current addess in mddev->curr_resync
*/
if (mddev->curr_resync < max_sector) /* aborted */
- md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
+ md_bitmap_end_sync(mddev, mddev->curr_resync,
&sync_blocks, 1);
else /* completed sync */
conf->fullsync = 0;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 20c0ccf28ef5..3746692f5f1c 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3191,13 +3191,12 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
if (mddev->curr_resync < max_sector) { /* aborted */
if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery))
- md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
+ md_bitmap_end_sync(mddev, mddev->curr_resync,
&sync_blocks, 1);
else for (i = 0; i < conf->geo.raid_disks; i++) {
sector_t sect =
raid10_find_virt(conf, mddev->curr_resync, i);
- md_bitmap_end_sync(mddev->bitmap, sect,
- &sync_blocks, 1);
+ md_bitmap_end_sync(mddev, sect, &sync_blocks, 1);
}
} else {
/* completed sync */
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index a2688987a2d0..c566fcc6fd46 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6497,7 +6497,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
}
if (mddev->curr_resync < max_sector) /* aborted */
- md_bitmap_end_sync(mddev->bitmap, mddev->curr_resync,
+ md_bitmap_end_sync(mddev, mddev->curr_resync,
&sync_blocks, 1);
else /* completed sync */
conf->fullsync = 0;
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 16/26] md/md-bitmap: merge md_bitmap_close_sync() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (14 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 15/26] md/md-bitmap: merge md_bitmap_end_sync() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 17/26] md/md-bitmap: mrege md_bitmap_cond_end_sync() " Yu Kuai
` (10 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 9 ++++-----
drivers/md/md-bitmap.h | 10 +++++++++-
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 2 +-
drivers/md/raid5.c | 2 +-
5 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index d0163533da14..100551868484 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1654,7 +1654,7 @@ static void bitmap_end_sync(struct bitmap *bitmap, sector_t offset,
spin_unlock_irqrestore(&bitmap->counts.lock, flags);
}
-void md_bitmap_close_sync(struct bitmap *bitmap)
+static void bitmap_close_sync(struct bitmap *bitmap)
{
/* Sync has finished, and any bitmap chunks that weren't synced
* properly have been aborted. It remains to us to clear the
@@ -1662,14 +1662,12 @@ void md_bitmap_close_sync(struct bitmap *bitmap)
*/
sector_t sector = 0;
sector_t blocks;
- if (!bitmap)
- return;
+
while (sector < bitmap->mddev->resync_max_sectors) {
bitmap_end_sync(bitmap, sector, &blocks, 0);
sector += blocks;
}
}
-EXPORT_SYMBOL(md_bitmap_close_sync);
void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force)
{
@@ -1986,7 +1984,7 @@ static int bitmap_load(struct mddev *mddev)
bitmap_start_sync(bitmap, sector, &blocks, 0);
sector += blocks;
}
- md_bitmap_close_sync(bitmap);
+ bitmap_close_sync(bitmap);
if (mddev->degraded == 0
|| bitmap->events_cleared == mddev->events)
@@ -2714,6 +2712,7 @@ static struct bitmap_operations bitmap_ops = {
.endwrite = bitmap_endwrite,
.start_sync = bitmap_start_sync,
.end_sync = bitmap_end_sync,
+ .close_sync = bitmap_close_sync,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 58c114246a2d..56ede16ce5fe 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -251,6 +251,7 @@ struct bitmap_operations {
sector_t *blocks, int degraded);
void (*end_sync)(struct bitmap *bitmap, sector_t offset,
sector_t *blocks, int aborted);
+ void (*close_sync)(struct bitmap *bitmap);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -367,7 +368,14 @@ static inline void md_bitmap_end_sync(struct mddev *mddev, sector_t offset,
mddev->bitmap_ops->end_sync(mddev->bitmap, offset, blocks, aborted);
}
-void md_bitmap_close_sync(struct bitmap *bitmap);
+static inline void md_bitmap_close_sync(struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->close_sync)
+ return;
+
+ mddev->bitmap_ops->close_sync(mddev->bitmap);
+}
+
void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force);
void md_bitmap_sync_with_cluster(struct mddev *mddev,
sector_t old_lo, sector_t old_hi,
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index cf787ead3d0d..8f5beba4184c 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2787,7 +2787,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
else /* completed sync */
conf->fullsync = 0;
- md_bitmap_close_sync(mddev->bitmap);
+ md_bitmap_close_sync(mddev);
close_sync(conf);
if (mddev_is_clustered(mddev)) {
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 3746692f5f1c..19035e9950f1 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3216,7 +3216,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
}
conf->fullsync = 0;
}
- md_bitmap_close_sync(mddev->bitmap);
+ md_bitmap_close_sync(mddev);
close_sync(conf);
*skipped = 1;
return sectors_skipped;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index c566fcc6fd46..06f8a4a55b2b 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6501,7 +6501,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
&sync_blocks, 1);
else /* completed sync */
conf->fullsync = 0;
- md_bitmap_close_sync(mddev->bitmap);
+ md_bitmap_close_sync(mddev);
return 0;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 17/26] md/md-bitmap: mrege md_bitmap_cond_end_sync() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (15 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 16/26] md/md-bitmap: merge md_bitmap_close_sync() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 18/26] md/md-bitmap: merge bitmap_sync_with_cluster() " Yu Kuai
` (9 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 7 +++----
drivers/md/md-bitmap.h | 11 ++++++++++-
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 2 +-
drivers/md/raid5.c | 2 +-
5 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 100551868484..3c09de471634 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1669,13 +1669,12 @@ static void bitmap_close_sync(struct bitmap *bitmap)
}
}
-void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force)
+static void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector,
+ bool force)
{
sector_t s = 0;
sector_t blocks;
- if (!bitmap)
- return;
if (sector == 0) {
bitmap->last_end_sync = jiffies;
return;
@@ -1697,7 +1696,6 @@ void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force)
bitmap->last_end_sync = jiffies;
sysfs_notify_dirent_safe(bitmap->mddev->sysfs_completed);
}
-EXPORT_SYMBOL(md_bitmap_cond_end_sync);
void md_bitmap_sync_with_cluster(struct mddev *mddev,
sector_t old_lo, sector_t old_hi,
@@ -2713,6 +2711,7 @@ static struct bitmap_operations bitmap_ops = {
.start_sync = bitmap_start_sync,
.end_sync = bitmap_end_sync,
.close_sync = bitmap_close_sync,
+ .cond_end_sync = bitmap_cond_end_sync,
.update_sb = bitmap_update_sb,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 56ede16ce5fe..71c3610dca7b 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -252,6 +252,7 @@ struct bitmap_operations {
void (*end_sync)(struct bitmap *bitmap, sector_t offset,
sector_t *blocks, int aborted);
void (*close_sync)(struct bitmap *bitmap);
+ void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
void (*update_sb)(struct bitmap *bitmap);
};
@@ -376,7 +377,15 @@ static inline void md_bitmap_close_sync(struct mddev *mddev)
mddev->bitmap_ops->close_sync(mddev->bitmap);
}
-void md_bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector, bool force);
+static inline void md_bitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
+ bool force)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->cond_end_sync)
+ return;
+
+ mddev->bitmap_ops->cond_end_sync(mddev->bitmap, sector, force);
+}
+
void md_bitmap_sync_with_cluster(struct mddev *mddev,
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi);
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 8f5beba4184c..c8cd6036441b 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -2825,7 +2825,7 @@ static sector_t raid1_sync_request(struct mddev *mddev, sector_t sector_nr,
* sector_nr + two times RESYNC_SECTORS
*/
- md_bitmap_cond_end_sync(mddev->bitmap, sector_nr,
+ md_bitmap_cond_end_sync(mddev, sector_nr,
mddev_is_clustered(mddev) && (sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high));
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 19035e9950f1..1ea9b4117b08 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3536,7 +3536,7 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr,
* safety reason, which ensures curr_resync_completed is
* updated in bitmap_cond_end_sync.
*/
- md_bitmap_cond_end_sync(mddev->bitmap, sector_nr,
+ md_bitmap_cond_end_sync(mddev, sector_nr,
mddev_is_clustered(mddev) &&
(sector_nr + 2 * RESYNC_SECTORS > conf->cluster_sync_high));
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 06f8a4a55b2b..8f0de56c0b23 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6539,7 +6539,7 @@ static inline sector_t raid5_sync_request(struct mddev *mddev, sector_t sector_n
return sync_blocks * RAID5_STRIPE_SECTORS(conf);
}
- md_bitmap_cond_end_sync(mddev->bitmap, sector_nr, false);
+ md_bitmap_cond_end_sync(mddev, sector_nr, false);
sh = raid5_get_active_stripe(conf, NULL, sector_nr,
R5_GAS_NOBLOCK);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 18/26] md/md-bitmap: merge bitmap_sync_with_cluster() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (16 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 17/26] md/md-bitmap: mrege md_bitmap_cond_end_sync() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 19/26] md/md-bitmap: merge md_bitmap_resize() " Yu Kuai
` (8 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 9 ++++-----
drivers/md/md-bitmap.h | 16 +++++++++++++---
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 3c09de471634..8828175ad442 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1697,11 +1697,10 @@ static void bitmap_cond_end_sync(struct bitmap *bitmap, sector_t sector,
sysfs_notify_dirent_safe(bitmap->mddev->sysfs_completed);
}
-void md_bitmap_sync_with_cluster(struct mddev *mddev,
- sector_t old_lo, sector_t old_hi,
- sector_t new_lo, sector_t new_hi)
+static void bitmap_sync_with_cluster(struct bitmap *bitmap,
+ sector_t old_lo, sector_t old_hi,
+ sector_t new_lo, sector_t new_hi)
{
- struct bitmap *bitmap = mddev->bitmap;
sector_t sector, blocks = 0;
for (sector = old_lo; sector < new_lo; ) {
@@ -1716,7 +1715,6 @@ void md_bitmap_sync_with_cluster(struct mddev *mddev,
}
WARN((blocks > new_hi) && old_hi, "alignment is not correct for hi\n");
}
-EXPORT_SYMBOL(md_bitmap_sync_with_cluster);
static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed)
{
@@ -2714,6 +2712,7 @@ static struct bitmap_operations bitmap_ops = {
.cond_end_sync = bitmap_cond_end_sync,
.update_sb = bitmap_update_sb,
+ .sync_with_cluster = bitmap_sync_with_cluster,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 71c3610dca7b..5a77b6d8358b 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -255,6 +255,9 @@ struct bitmap_operations {
void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
void (*update_sb)(struct bitmap *bitmap);
+ void (*sync_with_cluster)(struct bitmap *bitmap,
+ sector_t old_lo, sector_t old_hi,
+ sector_t new_lo, sector_t new_hi);
};
/* the bitmap API */
@@ -386,9 +389,16 @@ static inline void md_bitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
mddev->bitmap_ops->cond_end_sync(mddev->bitmap, sector, force);
}
-void md_bitmap_sync_with_cluster(struct mddev *mddev,
- sector_t old_lo, sector_t old_hi,
- sector_t new_lo, sector_t new_hi);
+static inline void md_bitmap_sync_with_cluster(struct mddev *mddev,
+ sector_t old_lo, sector_t old_hi,
+ sector_t new_lo, sector_t new_hi)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->sync_with_cluster)
+ return;
+
+ mddev->bitmap_ops->sync_with_cluster(mddev->bitmap, old_lo, old_hi,
+ new_lo, new_hi);
+}
void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 19/26] md/md-bitmap: merge md_bitmap_resize() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (17 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 18/26] md/md-bitmap: merge bitmap_sync_with_cluster() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 20/26] md/md-bitmap: merge get_bitmap_from_slot() " Yu Kuai
` (7 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/dm-raid.c | 2 +-
drivers/md/md-bitmap.c | 11 +++++++----
drivers/md/md-bitmap.h | 13 +++++++++++--
drivers/md/md-cluster.c | 4 ++--
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 8 ++++----
drivers/md/raid5.c | 2 +-
7 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 0c3323e0adb2..6342775c79dd 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -4066,7 +4066,7 @@ static int raid_preresume(struct dm_target *ti)
mddev->bitmap_info.chunksize != to_bytes(rs->requested_bitmap_chunk_sectors)))) {
int chunksize = to_bytes(rs->requested_bitmap_chunk_sectors) ?: mddev->bitmap_info.chunksize;
- r = md_bitmap_resize(mddev->bitmap, mddev->dev_sectors, chunksize, 0);
+ r = md_bitmap_resize(mddev, mddev->dev_sectors, chunksize, 0);
if (r)
DMERR("Failed to resize bitmap");
}
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 8828175ad442..ed43139b52f4 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -32,6 +32,9 @@
#include "md.h"
#include "md-bitmap.h"
+static int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
+ int chunksize, int init);
+
static inline char *bmname(struct bitmap *bitmap)
{
return bitmap->mddev ? mdname(bitmap->mddev) : "mdX";
@@ -1936,7 +1939,7 @@ static struct bitmap *bitmap_create(struct mddev *mddev, int slot)
goto error;
bitmap->daemon_lastrun = jiffies;
- err = md_bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1);
+ err = bitmap_resize(bitmap, blocks, mddev->bitmap_info.chunksize, 1);
if (err)
goto error;
@@ -2108,8 +2111,8 @@ static void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
seq_printf(seq, "\n");
}
-int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
- int chunksize, int init)
+static int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
+ int chunksize, int init)
{
/* If chunk_size is 0, choose an appropriate chunk size.
* Then possibly allocate new storage space.
@@ -2314,7 +2317,6 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
err:
return ret;
}
-EXPORT_SYMBOL_GPL(md_bitmap_resize);
static ssize_t
location_show(struct mddev *mddev, char *page)
@@ -2712,6 +2714,7 @@ static struct bitmap_operations bitmap_ops = {
.cond_end_sync = bitmap_cond_end_sync,
.update_sb = bitmap_update_sb,
+ .resize = bitmap_resize,
.sync_with_cluster = bitmap_sync_with_cluster,
};
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 5a77b6d8358b..37edf8626a60 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -255,6 +255,8 @@ struct bitmap_operations {
void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
void (*update_sb)(struct bitmap *bitmap);
+ int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
+ int init);
void (*sync_with_cluster)(struct bitmap *bitmap,
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi);
@@ -389,6 +391,15 @@ static inline void md_bitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
mddev->bitmap_ops->cond_end_sync(mddev->bitmap, sector, force);
}
+static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
+ int chunksize, int init)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->resize)
+ return -EOPNOTSUPP;
+
+ return mddev->bitmap_ops->resize(mddev->bitmap, blocks, chunksize, init);
+}
+
static inline void md_bitmap_sync_with_cluster(struct mddev *mddev,
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi)
@@ -404,8 +415,6 @@ void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
void md_bitmap_daemon_work(struct mddev *mddev);
-int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
- int chunksize, int init);
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot);
int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
sector_t *lo, sector_t *hi, bool clear_bits);
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index 79e67393fee0..d843ea190e7b 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -628,8 +628,8 @@ static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
break;
case BITMAP_RESIZE:
if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0))
- ret = md_bitmap_resize(mddev->bitmap,
- le64_to_cpu(msg->high), 0, 0);
+ ret = md_bitmap_resize(mddev, le64_to_cpu(msg->high), 0,
+ 0);
break;
default:
ret = -1;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index c8cd6036441b..fef69fce586c 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -3311,7 +3311,7 @@ static int raid1_resize(struct mddev *mddev, sector_t sectors)
mddev->array_sectors > newsize)
return -EINVAL;
if (mddev->bitmap) {
- int ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
+ int ret = md_bitmap_resize(mddev, newsize, 0, 0);
if (ret)
return ret;
}
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1ea9b4117b08..a8a14cda8446 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -4201,7 +4201,7 @@ static int raid10_resize(struct mddev *mddev, sector_t sectors)
mddev->array_sectors > size)
return -EINVAL;
if (mddev->bitmap) {
- int ret = md_bitmap_resize(mddev->bitmap, size, 0, 0);
+ int ret = md_bitmap_resize(mddev, size, 0, 0);
if (ret)
return ret;
}
@@ -4470,7 +4470,7 @@ static int raid10_start_reshape(struct mddev *mddev)
newsize = raid10_size(mddev, 0, conf->geo.raid_disks);
if (!mddev_is_clustered(mddev)) {
- ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
+ ret = md_bitmap_resize(mddev, newsize, 0, 0);
if (ret)
goto abort;
else
@@ -4492,13 +4492,13 @@ static int raid10_start_reshape(struct mddev *mddev)
MD_FEATURE_RESHAPE_ACTIVE)) || (oldsize == newsize))
goto out;
- ret = md_bitmap_resize(mddev->bitmap, newsize, 0, 0);
+ ret = md_bitmap_resize(mddev, newsize, 0, 0);
if (ret)
goto abort;
ret = md_cluster_ops->resize_bitmaps(mddev, newsize, oldsize);
if (ret) {
- md_bitmap_resize(mddev->bitmap, oldsize, 0, 0);
+ md_bitmap_resize(mddev, oldsize, 0, 0);
goto abort;
}
}
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 8f0de56c0b23..8b1e2157a798 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -8320,7 +8320,7 @@ static int raid5_resize(struct mddev *mddev, sector_t sectors)
mddev->array_sectors > newsize)
return -EINVAL;
if (mddev->bitmap) {
- int ret = md_bitmap_resize(mddev->bitmap, sectors, 0, 0);
+ int ret = md_bitmap_resize(mddev, sectors, 0, 0);
if (ret)
return ret;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 20/26] md/md-bitmap: merge get_bitmap_from_slot() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (18 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 19/26] md/md-bitmap: merge md_bitmap_resize() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 21/26] md/md-bitmap: merge md_bitmap_copy_from_slot() " Yu Kuai
` (6 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Also rename it to md_bitmap_get_from_slot().
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 6 +++---
drivers/md/md-bitmap.h | 11 ++++++++++-
drivers/md/md-cluster.c | 4 ++--
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index ed43139b52f4..f6c0334708ee 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2014,7 +2014,7 @@ static int bitmap_load(struct mddev *mddev)
}
/* caller need to free returned bitmap with md_bitmap_free() */
-struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
+static struct bitmap *bitmap_get_from_slot(struct mddev *mddev, int slot)
{
int rv = 0;
struct bitmap *bitmap;
@@ -2033,7 +2033,6 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
return bitmap;
}
-EXPORT_SYMBOL(get_bitmap_from_slot);
/* Loads the bitmap associated with slot and copies the resync information
* to our bitmap
@@ -2046,7 +2045,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
struct bitmap_counts *counts;
struct bitmap *bitmap;
- bitmap = get_bitmap_from_slot(mddev, slot);
+ bitmap = bitmap_get_from_slot(mddev, slot);
if (IS_ERR(bitmap)) {
pr_err("%s can't get bitmap from slot %d\n", __func__, slot);
return -1;
@@ -2716,6 +2715,7 @@ static struct bitmap_operations bitmap_ops = {
.update_sb = bitmap_update_sb,
.resize = bitmap_resize,
.sync_with_cluster = bitmap_sync_with_cluster,
+ .get_from_slot = bitmap_get_from_slot,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 37edf8626a60..199fb961b11f 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -260,6 +260,7 @@ struct bitmap_operations {
void (*sync_with_cluster)(struct bitmap *bitmap,
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi);
+ struct bitmap* (*get_from_slot)(struct mddev *mddev, int slot);
};
/* the bitmap API */
@@ -411,11 +412,19 @@ static inline void md_bitmap_sync_with_cluster(struct mddev *mddev,
new_lo, new_hi);
}
+static inline struct bitmap *md_bitmap_get_from_slot(struct mddev *mddev,
+ int slot)
+{
+ if (!mddev->bitmap_ops->get_from_slot)
+ return ERR_PTR(-EOPNOTSUPP);
+
+ return mddev->bitmap_ops->get_from_slot(mddev, slot);
+}
+
void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
void md_bitmap_daemon_work(struct mddev *mddev);
-struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot);
int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
sector_t *lo, sector_t *hi, bool clear_bits);
void md_bitmap_free(struct bitmap *bitmap);
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index d843ea190e7b..d608535fc06a 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1162,7 +1162,7 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
if (i == md_cluster_ops->slot_number(mddev))
continue;
- bitmap = get_bitmap_from_slot(mddev, i);
+ bitmap = md_bitmap_get_from_slot(mddev, i);
if (IS_ERR(bitmap)) {
pr_err("can't get bitmap from slot %d\n", i);
bitmap = NULL;
@@ -1224,7 +1224,7 @@ static int cluster_check_sync_size(struct mddev *mddev)
if (i == current_slot)
continue;
- bitmap = get_bitmap_from_slot(mddev, i);
+ bitmap = md_bitmap_get_from_slot(mddev, i);
if (IS_ERR(bitmap)) {
pr_err("can't get bitmap from slot %d\n", i);
return -1;
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 21/26] md/md-bitmap: merge md_bitmap_copy_from_slot() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (19 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 20/26] md/md-bitmap: merge get_bitmap_from_slot() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 22/26] md/md-bitmap: merge md_bitmap_free() " Yu Kuai
` (5 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 7 +++----
drivers/md/md-bitmap.h | 14 ++++++++++++--
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index f6c0334708ee..199bd6757543 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2037,8 +2037,8 @@ static struct bitmap *bitmap_get_from_slot(struct mddev *mddev, int slot)
/* Loads the bitmap associated with slot and copies the resync information
* to our bitmap
*/
-int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
- sector_t *low, sector_t *high, bool clear_bits)
+static int bitmap_copy_from_slot(struct mddev *mddev, int slot, sector_t *low,
+ sector_t *high, bool clear_bits)
{
int rv = 0, i, j;
sector_t block, lo = 0, hi = 0;
@@ -2080,8 +2080,6 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
return rv;
}
-EXPORT_SYMBOL_GPL(md_bitmap_copy_from_slot);
-
static void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
{
@@ -2716,6 +2714,7 @@ static struct bitmap_operations bitmap_ops = {
.resize = bitmap_resize,
.sync_with_cluster = bitmap_sync_with_cluster,
.get_from_slot = bitmap_get_from_slot,
+ .copy_from_slot = bitmap_copy_from_slot,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 199fb961b11f..acd868e2ef5e 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -261,6 +261,8 @@ struct bitmap_operations {
sector_t old_lo, sector_t old_hi,
sector_t new_lo, sector_t new_hi);
struct bitmap* (*get_from_slot)(struct mddev *mddev, int slot);
+ int (*copy_from_slot)(struct mddev *mddev, int slot,
+ sector_t *lo, sector_t *hi, bool clear_bits);
};
/* the bitmap API */
@@ -421,12 +423,20 @@ static inline struct bitmap *md_bitmap_get_from_slot(struct mddev *mddev,
return mddev->bitmap_ops->get_from_slot(mddev, slot);
}
+static inline int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
+ sector_t *lo, sector_t *hi,
+ bool clear_bits)
+{
+ if (!mddev->bitmap_ops->copy_from_slot)
+ return -EOPNOTSUPP;
+
+ return mddev->bitmap_ops->copy_from_slot(mddev, slot, lo, hi, clear_bits);
+}
+
void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
void md_bitmap_daemon_work(struct mddev *mddev);
-int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
- sector_t *lo, sector_t *hi, bool clear_bits);
void md_bitmap_free(struct bitmap *bitmap);
void md_bitmap_wait_behind_writes(struct mddev *mddev);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 22/26] md/md-bitmap: merge md_bitmap_free() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (20 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 21/26] md/md-bitmap: merge md_bitmap_copy_from_slot() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 23/26] md/md-bitmap: merge md_bitmap_wait_behind_writes() " Yu Kuai
` (4 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 17 +++++++----------
drivers/md/md-bitmap.h | 10 +++++++++-
drivers/md/md-cluster.c | 10 +++++-----
3 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 199bd6757543..99c496a32e94 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1790,10 +1790,7 @@ static void bitmap_flush(struct mddev *mddev)
bitmap_update_sb(bitmap);
}
-/*
- * free memory that was allocated
- */
-void md_bitmap_free(struct bitmap *bitmap)
+static void __bitmap_free(struct bitmap *bitmap)
{
unsigned long k, pages;
struct bitmap_page *bp;
@@ -1827,7 +1824,6 @@ void md_bitmap_free(struct bitmap *bitmap)
kfree(bp);
kfree(bitmap);
}
-EXPORT_SYMBOL(md_bitmap_free);
void md_bitmap_wait_behind_writes(struct mddev *mddev)
{
@@ -1861,7 +1857,7 @@ static void bitmap_destroy(struct mddev *mddev)
mutex_unlock(&mddev->bitmap_info.mutex);
mddev_set_timeout(mddev, MAX_SCHEDULE_TIMEOUT, true);
- md_bitmap_free(bitmap);
+ __bitmap_free(bitmap);
}
/*
@@ -1952,7 +1948,7 @@ static struct bitmap *bitmap_create(struct mddev *mddev, int slot)
return bitmap;
error:
- md_bitmap_free(bitmap);
+ __bitmap_free(bitmap);
return ERR_PTR(err);
}
@@ -2013,7 +2009,7 @@ static int bitmap_load(struct mddev *mddev)
return err;
}
-/* caller need to free returned bitmap with md_bitmap_free() */
+/* caller need to free returned bitmap with __bitmap_free() */
static struct bitmap *bitmap_get_from_slot(struct mddev *mddev, int slot)
{
int rv = 0;
@@ -2027,7 +2023,7 @@ static struct bitmap *bitmap_get_from_slot(struct mddev *mddev, int slot)
rv = md_bitmap_init_from_disk(bitmap, 0);
if (rv) {
- md_bitmap_free(bitmap);
+ __bitmap_free(bitmap);
return ERR_PTR(rv);
}
@@ -2076,7 +2072,7 @@ static int bitmap_copy_from_slot(struct mddev *mddev, int slot, sector_t *low,
md_bitmap_unplug(mddev->bitmap);
*low = lo;
*high = hi;
- md_bitmap_free(bitmap);
+ __bitmap_free(bitmap);
return rv;
}
@@ -2715,6 +2711,7 @@ static struct bitmap_operations bitmap_ops = {
.sync_with_cluster = bitmap_sync_with_cluster,
.get_from_slot = bitmap_get_from_slot,
.copy_from_slot = bitmap_copy_from_slot,
+ .free = __bitmap_free,
};
void mddev_set_bitmap_ops(struct mddev *mddev)
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index acd868e2ef5e..b5836e5ff1e3 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -263,6 +263,7 @@ struct bitmap_operations {
struct bitmap* (*get_from_slot)(struct mddev *mddev, int slot);
int (*copy_from_slot)(struct mddev *mddev, int slot,
sector_t *lo, sector_t *hi, bool clear_bits);
+ void (*free)(struct bitmap *bitmap);
};
/* the bitmap API */
@@ -433,11 +434,18 @@ static inline int md_bitmap_copy_from_slot(struct mddev *mddev, int slot,
return mddev->bitmap_ops->copy_from_slot(mddev, slot, lo, hi, clear_bits);
}
+static inline void md_bitmap_free(struct mddev *mddev, struct bitmap *bitmap)
+{
+ if (!mddev->bitmap_ops->free)
+ return;
+
+ return mddev->bitmap_ops->free(bitmap);
+}
+
void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
void md_bitmap_daemon_work(struct mddev *mddev);
-void md_bitmap_free(struct bitmap *bitmap);
void md_bitmap_wait_behind_writes(struct mddev *mddev);
static inline bool md_bitmap_enabled(struct bitmap *bitmap)
diff --git a/drivers/md/md-cluster.c b/drivers/md/md-cluster.c
index d608535fc06a..9e3c579703f6 100644
--- a/drivers/md/md-cluster.c
+++ b/drivers/md/md-cluster.c
@@ -1192,12 +1192,12 @@ static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsiz
* can't resize bitmap
*/
goto out;
- md_bitmap_free(bitmap);
+ md_bitmap_free(mddev, bitmap);
}
return 0;
out:
- md_bitmap_free(bitmap);
+ md_bitmap_free(mddev, bitmap);
update_bitmap_size(mddev, oldsize);
return -1;
}
@@ -1238,7 +1238,7 @@ static int cluster_check_sync_size(struct mddev *mddev)
bm_lockres = lockres_init(mddev, str, NULL, 1);
if (!bm_lockres) {
pr_err("md-cluster: Cannot initialize %s\n", str);
- md_bitmap_free(bitmap);
+ md_bitmap_free(mddev, bitmap);
return -1;
}
bm_lockres->flags |= DLM_LKF_NOQUEUE;
@@ -1253,11 +1253,11 @@ static int cluster_check_sync_size(struct mddev *mddev)
sync_size = sb->sync_size;
else if (sync_size != sb->sync_size) {
kunmap_atomic(sb);
- md_bitmap_free(bitmap);
+ md_bitmap_free(mddev, bitmap);
return -1;
}
kunmap_atomic(sb);
- md_bitmap_free(bitmap);
+ md_bitmap_free(mddev, bitmap);
}
return (my_sync_size == sync_size) ? 0 : -1;
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 23/26] md/md-bitmap: merge md_bitmap_wait_behind_writes() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (21 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 22/26] md/md-bitmap: merge md_bitmap_free() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 24/26] md/md-bitmap: merge md_bitmap_daemon_work() " Yu Kuai
` (3 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 11 +++++------
drivers/md/md-bitmap.h | 11 +++++++++--
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 99c496a32e94..87e192d172fb 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1825,14 +1825,12 @@ static void __bitmap_free(struct bitmap *bitmap)
kfree(bitmap);
}
-void md_bitmap_wait_behind_writes(struct mddev *mddev)
+static void bitmap_wait_behind_writes(struct bitmap *bitmap)
{
- struct bitmap *bitmap = mddev->bitmap;
-
/* wait for behind writes to complete */
- if (bitmap && atomic_read(&bitmap->behind_writes) > 0) {
+ if (atomic_read(&bitmap->behind_writes) > 0) {
pr_debug("md:%s: behind writes in progress - waiting to stop.\n",
- mdname(mddev));
+ mdname(bitmap->mddev));
/* need to kick something here to make sure I/O goes? */
wait_event(bitmap->behind_wait,
atomic_read(&bitmap->behind_writes) == 0);
@@ -1846,7 +1844,7 @@ static void bitmap_destroy(struct mddev *mddev)
if (!bitmap) /* there was no bitmap */
return;
- md_bitmap_wait_behind_writes(mddev);
+ bitmap_wait_behind_writes(bitmap);
if (!mddev->serialize_policy)
mddev_destroy_serial_pool(mddev, NULL);
@@ -2705,6 +2703,7 @@ static struct bitmap_operations bitmap_ops = {
.end_sync = bitmap_end_sync,
.close_sync = bitmap_close_sync,
.cond_end_sync = bitmap_cond_end_sync,
+ .wait_behind_writes = bitmap_wait_behind_writes,
.update_sb = bitmap_update_sb,
.resize = bitmap_resize,
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index b5836e5ff1e3..090d4f11f3cd 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -253,6 +253,7 @@ struct bitmap_operations {
sector_t *blocks, int aborted);
void (*close_sync)(struct bitmap *bitmap);
void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
+ void (*wait_behind_writes)(struct bitmap *bitmap);
void (*update_sb)(struct bitmap *bitmap);
int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
@@ -395,6 +396,14 @@ static inline void md_bitmap_cond_end_sync(struct mddev *mddev, sector_t sector,
mddev->bitmap_ops->cond_end_sync(mddev->bitmap, sector, force);
}
+static inline void md_bitmap_wait_behind_writes(struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->wait_behind_writes)
+ return;
+
+ mddev->bitmap_ops->wait_behind_writes(mddev->bitmap);
+}
+
static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
int chunksize, int init)
{
@@ -446,8 +455,6 @@ void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
void md_bitmap_daemon_work(struct mddev *mddev);
-void md_bitmap_wait_behind_writes(struct mddev *mddev);
-
static inline bool md_bitmap_enabled(struct bitmap *bitmap)
{
return bitmap && bitmap->storage.filemap &&
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 24/26] md/md-bitmap: merge md_bitmap_daemon_work() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (22 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 23/26] md/md-bitmap: merge md_bitmap_wait_behind_writes() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 25/26] md/md-bitmap: merge md_bitmap_unplug() and md_bitmap_unplug_async() Yu Kuai
` (2 subsequent siblings)
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 19 +++++++------------
drivers/md/md-bitmap.h | 10 +++++++++-
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 87e192d172fb..4f3ea6e51572 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1292,9 +1292,9 @@ static void mddev_set_timeout(struct mddev *mddev, unsigned long timeout,
* bitmap daemon -- periodically wakes up to clean bits and flush pages
* out to disk
*/
-void md_bitmap_daemon_work(struct mddev *mddev)
+static void bitmap_daemon_work(struct bitmap *bitmap)
{
- struct bitmap *bitmap;
+ struct mddev *mddev = bitmap->mddev;
unsigned long j;
unsigned long nextpage;
sector_t blocks;
@@ -1304,13 +1304,8 @@ void md_bitmap_daemon_work(struct mddev *mddev)
* bitmap_destroy.
*/
mutex_lock(&mddev->bitmap_info.mutex);
- bitmap = mddev->bitmap;
- if (bitmap == NULL) {
- mutex_unlock(&mddev->bitmap_info.mutex);
- return;
- }
- if (time_before(jiffies, bitmap->daemon_lastrun
- + mddev->bitmap_info.daemon_sleep))
+ if (time_before(jiffies, bitmap->daemon_lastrun +
+ mddev->bitmap_info.daemon_sleep))
goto done;
bitmap->daemon_lastrun = jiffies;
@@ -1780,11 +1775,11 @@ static void bitmap_flush(struct mddev *mddev)
*/
sleep = mddev->bitmap_info.daemon_sleep * 2;
bitmap->daemon_lastrun -= sleep;
- md_bitmap_daemon_work(mddev);
+ bitmap_daemon_work(bitmap);
bitmap->daemon_lastrun -= sleep;
- md_bitmap_daemon_work(mddev);
+ bitmap_daemon_work(bitmap);
bitmap->daemon_lastrun -= sleep;
- md_bitmap_daemon_work(mddev);
+ bitmap_daemon_work(bitmap);
if (mddev->bitmap_info.external)
md_super_wait(mddev);
bitmap_update_sb(bitmap);
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 090d4f11f3cd..f67e030139cd 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -254,6 +254,7 @@ struct bitmap_operations {
void (*close_sync)(struct bitmap *bitmap);
void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
void (*wait_behind_writes)(struct bitmap *bitmap);
+ void (*daemon_work)(struct bitmap *bitmap);
void (*update_sb)(struct bitmap *bitmap);
int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
@@ -404,6 +405,14 @@ static inline void md_bitmap_wait_behind_writes(struct mddev *mddev)
mddev->bitmap_ops->wait_behind_writes(mddev->bitmap);
}
+static inline void md_bitmap_daemon_work(struct mddev *mddev)
+{
+ if (!mddev->bitmap || !mddev->bitmap_ops->daemon_work)
+ return;
+
+ mddev->bitmap_ops->daemon_work(mddev->bitmap);
+}
+
static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
int chunksize, int init)
{
@@ -453,7 +462,6 @@ static inline void md_bitmap_free(struct mddev *mddev, struct bitmap *bitmap)
void md_bitmap_unplug(struct bitmap *bitmap);
void md_bitmap_unplug_async(struct bitmap *bitmap);
-void md_bitmap_daemon_work(struct mddev *mddev);
static inline bool md_bitmap_enabled(struct bitmap *bitmap)
{
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 25/26] md/md-bitmap: merge md_bitmap_unplug() and md_bitmap_unplug_async()
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (23 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 24/26] md/md-bitmap: merge md_bitmap_daemon_work() " Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 26/26] md/md-bitmap: merge bitmap_unplug() into bitmap_operations Yu Kuai
2024-08-13 7:21 ` [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Christoph Hellwig
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
Add a new paramater "bool sync" for md_bitmap_unplug(), and remove the
exported md_bitmap_unplug_async(). Hence bitmap_operations only need one
op to cover them.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 23 +++++++++++++++--------
drivers/md/md-bitmap.h | 3 +--
drivers/md/md.c | 2 +-
drivers/md/raid1-10.c | 5 +----
drivers/md/raid5.c | 2 +-
5 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 4f3ea6e51572..b08476746350 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1030,7 +1030,7 @@ static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block)
/* this gets called when the md device is ready to unplug its underlying
* (slave) device queues -- before we let any writes go down, we need to
* sync the dirty pages of the bitmap file to disk */
-void md_bitmap_unplug(struct bitmap *bitmap)
+static void bitmap_unplug(struct bitmap *bitmap)
{
unsigned long i;
int dirty, need_write;
@@ -1062,7 +1062,6 @@ void md_bitmap_unplug(struct bitmap *bitmap)
if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
md_bitmap_file_kick(bitmap);
}
-EXPORT_SYMBOL(md_bitmap_unplug);
struct bitmap_unplug_work {
struct work_struct work;
@@ -1075,11 +1074,11 @@ static void md_bitmap_unplug_fn(struct work_struct *work)
struct bitmap_unplug_work *unplug_work =
container_of(work, struct bitmap_unplug_work, work);
- md_bitmap_unplug(unplug_work->bitmap);
+ bitmap_unplug(unplug_work->bitmap);
complete(unplug_work->done);
}
-void md_bitmap_unplug_async(struct bitmap *bitmap)
+static void bitmap_unplug_async(struct bitmap *bitmap)
{
DECLARE_COMPLETION_ONSTACK(done);
struct bitmap_unplug_work unplug_work;
@@ -1091,7 +1090,15 @@ void md_bitmap_unplug_async(struct bitmap *bitmap)
queue_work(md_bitmap_wq, &unplug_work.work);
wait_for_completion(&done);
}
-EXPORT_SYMBOL(md_bitmap_unplug_async);
+
+void md_bitmap_unplug(struct bitmap *bitmap, bool sync)
+{
+ if (sync)
+ bitmap_unplug(bitmap);
+ else
+ bitmap_unplug_async(bitmap);
+}
+EXPORT_SYMBOL(md_bitmap_unplug);
static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
@@ -2060,9 +2067,9 @@ static int bitmap_copy_from_slot(struct mddev *mddev, int slot, sector_t *low,
for (i = 0; i < bitmap->storage.file_pages; i++)
if (test_page_attr(bitmap, i, BITMAP_PAGE_PENDING))
set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE);
- md_bitmap_unplug(bitmap);
+ bitmap_unplug(bitmap);
}
- md_bitmap_unplug(mddev->bitmap);
+ bitmap_unplug(mddev->bitmap);
*low = lo;
*high = hi;
__bitmap_free(bitmap);
@@ -2296,7 +2303,7 @@ static int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
spin_unlock_irq(&bitmap->counts.lock);
if (!init) {
- md_bitmap_unplug(bitmap);
+ bitmap_unplug(bitmap);
bitmap->mddev->pers->quiesce(bitmap->mddev, 0);
}
ret = 0;
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index f67e030139cd..054e85c4a704 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -460,8 +460,7 @@ static inline void md_bitmap_free(struct mddev *mddev, struct bitmap *bitmap)
return mddev->bitmap_ops->free(bitmap);
}
-void md_bitmap_unplug(struct bitmap *bitmap);
-void md_bitmap_unplug_async(struct bitmap *bitmap);
+void md_bitmap_unplug(struct bitmap *bitmap, bool sync);
static inline bool md_bitmap_enabled(struct bitmap *bitmap)
{
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 841539a0be1b..2e6270c47317 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4691,7 +4691,7 @@ bitmap_store(struct mddev *mddev, const char *buf, size_t len)
md_bitmap_dirty_bits(mddev, chunk, end_chunk);
buf = skip_spaces(end);
}
- md_bitmap_unplug(mddev->bitmap); /* flush the bits to disk */
+ md_bitmap_unplug(mddev->bitmap, true); /* flush the bits to disk */
out:
mddev_unlock(mddev);
return len;
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index 2ea1710a3b70..e8410d0cc96f 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -168,10 +168,7 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
*/
static inline void raid1_prepare_flush_writes(struct bitmap *bitmap)
{
- if (current->bio_list)
- md_bitmap_unplug_async(bitmap);
- else
- md_bitmap_unplug(bitmap);
+ md_bitmap_unplug(bitmap, current->bio_list == NULL);
}
/*
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 8b1e2157a798..99332649bac3 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6766,7 +6766,7 @@ static void raid5d(struct md_thread *thread)
/* Now is a good time to flush some bitmap updates */
conf->seq_flush++;
spin_unlock_irq(&conf->device_lock);
- md_bitmap_unplug(mddev->bitmap);
+ md_bitmap_unplug(mddev->bitmap, true);
spin_lock_irq(&conf->device_lock);
conf->seq_write = conf->seq_flush;
activate_bit_delay(conf, conf->temp_inactive_list);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [PATCH RFC -next 26/26] md/md-bitmap: merge bitmap_unplug() into bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (24 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 25/26] md/md-bitmap: merge md_bitmap_unplug() and md_bitmap_unplug_async() Yu Kuai
@ 2024-08-10 2:08 ` Yu Kuai
2024-08-13 7:21 ` [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Christoph Hellwig
26 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-10 2:08 UTC (permalink / raw)
To: song; +Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun
From: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/md/md-bitmap.c | 16 ++++++++--------
drivers/md/md-bitmap.h | 11 +++++++++--
drivers/md/md.c | 2 +-
drivers/md/raid1-10.c | 4 ++--
drivers/md/raid1.c | 2 +-
drivers/md/raid10.c | 4 ++--
drivers/md/raid5.c | 2 +-
7 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index b08476746350..449556124d0e 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1030,7 +1030,7 @@ static int md_bitmap_file_test_bit(struct bitmap *bitmap, sector_t block)
/* this gets called when the md device is ready to unplug its underlying
* (slave) device queues -- before we let any writes go down, we need to
* sync the dirty pages of the bitmap file to disk */
-static void bitmap_unplug(struct bitmap *bitmap)
+static void __bitmap_unplug(struct bitmap *bitmap)
{
unsigned long i;
int dirty, need_write;
@@ -1074,7 +1074,7 @@ static void md_bitmap_unplug_fn(struct work_struct *work)
struct bitmap_unplug_work *unplug_work =
container_of(work, struct bitmap_unplug_work, work);
- bitmap_unplug(unplug_work->bitmap);
+ __bitmap_unplug(unplug_work->bitmap);
complete(unplug_work->done);
}
@@ -1091,14 +1091,13 @@ static void bitmap_unplug_async(struct bitmap *bitmap)
wait_for_completion(&done);
}
-void md_bitmap_unplug(struct bitmap *bitmap, bool sync)
+static void bitmap_unplug(struct bitmap *bitmap, bool sync)
{
if (sync)
- bitmap_unplug(bitmap);
+ __bitmap_unplug(bitmap);
else
bitmap_unplug_async(bitmap);
}
-EXPORT_SYMBOL(md_bitmap_unplug);
static void md_bitmap_set_memory_bits(struct bitmap *bitmap, sector_t offset, int needed);
@@ -2067,9 +2066,9 @@ static int bitmap_copy_from_slot(struct mddev *mddev, int slot, sector_t *low,
for (i = 0; i < bitmap->storage.file_pages; i++)
if (test_page_attr(bitmap, i, BITMAP_PAGE_PENDING))
set_page_attr(bitmap, i, BITMAP_PAGE_NEEDWRITE);
- bitmap_unplug(bitmap);
+ __bitmap_unplug(bitmap);
}
- bitmap_unplug(mddev->bitmap);
+ __bitmap_unplug(mddev->bitmap);
*low = lo;
*high = hi;
__bitmap_free(bitmap);
@@ -2303,7 +2302,7 @@ static int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
spin_unlock_irq(&bitmap->counts.lock);
if (!init) {
- bitmap_unplug(bitmap);
+ __bitmap_unplug(bitmap);
bitmap->mddev->pers->quiesce(bitmap->mddev, 0);
}
ret = 0;
@@ -2706,6 +2705,7 @@ static struct bitmap_operations bitmap_ops = {
.close_sync = bitmap_close_sync,
.cond_end_sync = bitmap_cond_end_sync,
.wait_behind_writes = bitmap_wait_behind_writes,
+ .unplug = bitmap_unplug,
.update_sb = bitmap_update_sb,
.resize = bitmap_resize,
diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
index 054e85c4a704..9e9e328d675c 100644
--- a/drivers/md/md-bitmap.h
+++ b/drivers/md/md-bitmap.h
@@ -255,6 +255,7 @@ struct bitmap_operations {
void (*cond_end_sync)(struct bitmap *bitmap, sector_t sector, bool force);
void (*wait_behind_writes)(struct bitmap *bitmap);
void (*daemon_work)(struct bitmap *bitmap);
+ void (*unplug)(struct bitmap *bitmap, bool sync);
void (*update_sb)(struct bitmap *bitmap);
int (*resize)(struct bitmap *bitmap, sector_t blocks, int chunksize,
@@ -413,6 +414,14 @@ static inline void md_bitmap_daemon_work(struct mddev *mddev)
mddev->bitmap_ops->daemon_work(mddev->bitmap);
}
+static inline void md_bitmap_unplug(struct mddev *mddev, bool sync)
+{
+ if (!mddev->bitmap && !mddev->bitmap_ops->unplug)
+ return;
+
+ mddev->bitmap_ops->unplug(mddev->bitmap, sync);
+}
+
static inline int md_bitmap_resize(struct mddev *mddev, sector_t blocks,
int chunksize, int init)
{
@@ -460,8 +469,6 @@ static inline void md_bitmap_free(struct mddev *mddev, struct bitmap *bitmap)
return mddev->bitmap_ops->free(bitmap);
}
-void md_bitmap_unplug(struct bitmap *bitmap, bool sync);
-
static inline bool md_bitmap_enabled(struct bitmap *bitmap)
{
return bitmap && bitmap->storage.filemap &&
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 2e6270c47317..8610b6fec263 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4691,7 +4691,7 @@ bitmap_store(struct mddev *mddev, const char *buf, size_t len)
md_bitmap_dirty_bits(mddev, chunk, end_chunk);
buf = skip_spaces(end);
}
- md_bitmap_unplug(mddev->bitmap, true); /* flush the bits to disk */
+ md_bitmap_unplug(mddev, true); /* flush the bits to disk */
out:
mddev_unlock(mddev);
return len;
diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c
index e8410d0cc96f..45b30f08f3a5 100644
--- a/drivers/md/raid1-10.c
+++ b/drivers/md/raid1-10.c
@@ -166,9 +166,9 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
* while current io submission must wait for bitmap io to be done. In order to
* avoid such deadlock, submit bitmap io asynchronously.
*/
-static inline void raid1_prepare_flush_writes(struct bitmap *bitmap)
+static inline void raid1_prepare_flush_writes(struct mddev *mddev)
{
- md_bitmap_unplug(bitmap, current->bio_list == NULL);
+ md_bitmap_unplug(mddev, current->bio_list == NULL);
}
/*
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index fef69fce586c..4e8dd032a453 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -893,7 +893,7 @@ static void wake_up_barrier(struct r1conf *conf)
static void flush_bio_list(struct r1conf *conf, struct bio *bio)
{
/* flush any pending bitmap writes to disk before proceeding w/ I/O */
- raid1_prepare_flush_writes(conf->mddev->bitmap);
+ raid1_prepare_flush_writes(conf->mddev);
wake_up_barrier(conf);
while (bio) { /* submit pending writes */
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index a8a14cda8446..13f61e07d513 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -883,7 +883,7 @@ static void flush_pending_writes(struct r10conf *conf)
__set_current_state(TASK_RUNNING);
blk_start_plug(&plug);
- raid1_prepare_flush_writes(conf->mddev->bitmap);
+ raid1_prepare_flush_writes(conf->mddev);
wake_up(&conf->wait_barrier);
while (bio) { /* submit pending writes */
@@ -1099,7 +1099,7 @@ static void raid10_unplug(struct blk_plug_cb *cb, bool from_schedule)
/* we aren't scheduling, so we can do the write-out directly. */
bio = bio_list_get(&plug->pending);
- raid1_prepare_flush_writes(mddev->bitmap);
+ raid1_prepare_flush_writes(mddev);
wake_up_barrier(conf);
while (bio) { /* submit pending writes */
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 99332649bac3..0bb3608dd3c8 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -6766,7 +6766,7 @@ static void raid5d(struct md_thread *thread)
/* Now is a good time to flush some bitmap updates */
conf->seq_flush++;
spin_unlock_irq(&conf->device_lock);
- md_bitmap_unplug(mddev->bitmap, true);
+ md_bitmap_unplug(mddev, true);
spin_lock_irq(&conf->device_lock);
conf->seq_write = conf->seq_flush;
activate_bit_delay(conf, conf->temp_inactive_list);
--
2.39.2
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations
2024-08-10 2:08 ` [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations Yu Kuai
@ 2024-08-13 6:58 ` Mariusz Tkaczyk
2024-08-13 7:25 ` Yu Kuai
0 siblings, 1 reply; 35+ messages in thread
From: Mariusz Tkaczyk @ 2024-08-13 6:58 UTC (permalink / raw)
To: Yu Kuai; +Cc: song, linux-kernel, linux-raid, yukuai3, yi.zhang, yangerkun
On Sat, 10 Aug 2024 10:08:29 +0800
Yu Kuai <yukuai1@huaweicloud.com> wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> The structure is empty for now, and will be used in later patches to
> merge in bitmap operations, prepare to implement a new lock free
> bitmap in the fulture.
HI Kuai,
typo: future
I think that as "later" you meant next patches in this patchset, right? If yes,
Please you "next" instead.
At this point bringing "lock free implementation in the future" looks like
totally unnecessary. It may happen or may not. Eventually, You can mention it in
cover letter. What we have now is the most important.
This is just a code rework. The main goal of this (as you mentioned in second
patch):
"So that the implementation won't be exposed, and it'll be possible
to invent a new bitmap by replacing bitmap_operations."
but please mention that you are not going to implement second mechanism to not
confuse reader. You need it to improve code maintainability mainly I think.
I would mention something about common "struct _ops" pattern (the special
structure to keep related operations together) that it is going to follow now.
For me, this one can be easy merged with the patch 2, so we will got struct +
usage in one patch.
Anyway, LGTM.
Thanks,
Mariusz
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() into bitmap_operations
2024-08-10 2:08 ` [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() " Yu Kuai
@ 2024-08-13 7:07 ` Mariusz Tkaczyk
2024-08-13 7:30 ` Yu Kuai
0 siblings, 1 reply; 35+ messages in thread
From: Mariusz Tkaczyk @ 2024-08-13 7:07 UTC (permalink / raw)
To: Yu Kuai; +Cc: song, linux-kernel, linux-raid, yukuai3, yi.zhang, yangerkun
On Sat, 10 Aug 2024 10:08:31 +0800
Yu Kuai <yukuai1@huaweicloud.com> wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> So that the implementation won't be exposed, and it'll be possible
> to invent a new bitmap by replacing bitmap_operations.
I don't like repeating same commit message for few patches.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/md/md-bitmap.c | 6 +++---
> drivers/md/md-bitmap.h | 10 +++++++++-
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index d731f7d4bbbb..9a9f0fe3ebd0 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -1965,7 +1965,7 @@ static struct bitmap *bitmap_create(struct mddev
> *mddev, int slot) return ERR_PTR(err);
> }
>
> -int md_bitmap_load(struct mddev *mddev)
> +static int bitmap_load(struct mddev *mddev)
> {
> int err = 0;
> sector_t start = 0;
> @@ -2021,7 +2021,6 @@ int md_bitmap_load(struct mddev *mddev)
> out:
> return err;
> }
> -EXPORT_SYMBOL_GPL(md_bitmap_load);
>
> /* caller need to free returned bitmap with md_bitmap_free() */
> struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
> @@ -2411,7 +2410,7 @@ location_store(struct mddev *mddev, const char *buf,
> size_t len) }
>
> mddev->bitmap = bitmap;
> - rv = md_bitmap_load(mddev);
> + rv = bitmap_load(mddev);
> if (rv) {
> mddev->bitmap_info.offset = 0;
> md_bitmap_destroy(mddev);
> @@ -2710,6 +2709,7 @@ const struct attribute_group md_bitmap_group = {
>
> static struct bitmap_operations bitmap_ops = {
> .create = bitmap_create,
> + .load = bitmap_load,
> };
>
> void mddev_set_bitmap_ops(struct mddev *mddev)
> diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
> index a7cbf0c692fc..de7fbe5903dd 100644
> --- a/drivers/md/md-bitmap.h
> +++ b/drivers/md/md-bitmap.h
> @@ -236,6 +236,7 @@ struct bitmap {
>
> struct bitmap_operations {
> struct bitmap* (*create)(struct mddev *mddev, int slot);
> + int (*load)(struct mddev *mddev);
> };
>
> /* the bitmap API */
> @@ -250,7 +251,14 @@ static inline struct bitmap *md_bitmap_create(struct
> mddev *mddev, int slot) return mddev->bitmap_ops->create(mddev, slot);
> }
>
> -int md_bitmap_load(struct mddev *mddev);
> +static inline int md_bitmap_load(struct mddev *mddev)
> +{
> + if (!mddev->bitmap_ops->load)
> + return -EOPNOTSUPP;
> +
> + return mddev->bitmap_ops->load(mddev);
> +}
At this point we have only on bitmpa op (at that probably won't change), so if
we we have bitmap_ops assigned (mddev->bitmap_ops != NULL) then ->load is must
have, hence I don't see a need for this wrapper.
you probably made this to avoid changes across code. If yes, please mention it
in commit message but I still would prefer to replace them all by calls to
mddev->bitmap_ops->load().
Mariusz
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations
2024-08-10 2:08 ` [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations Yu Kuai
@ 2024-08-13 7:17 ` Mariusz Tkaczyk
2024-08-13 7:33 ` Yu Kuai
0 siblings, 1 reply; 35+ messages in thread
From: Mariusz Tkaczyk @ 2024-08-13 7:17 UTC (permalink / raw)
To: Yu Kuai; +Cc: song, linux-kernel, linux-raid, yukuai3, yi.zhang, yangerkun
On Sat, 10 Aug 2024 10:08:35 +0800
Yu Kuai <yukuai1@huaweicloud.com> wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> So that the implementation won't be exposed, and it'll be possible
> to invent a new bitmap by replacing bitmap_operations.
Please update commit message.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> drivers/md/md-bitmap.c | 15 ++++++++-------
> drivers/md/md-bitmap.h | 11 ++++++++++-
> drivers/md/md-cluster.c | 3 ++-
> drivers/md/md.c | 4 ++--
> 4 files changed, 22 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index 0ff733756043..b34f13aa2697 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -472,7 +472,7 @@ static void md_bitmap_wait_writes(struct bitmap *bitmap)
>
>
> /* update the event counter and sync the superblock to disk */
> -void md_bitmap_update_sb(struct bitmap *bitmap)
> +static void bitmap_update_sb(struct bitmap *bitmap)
> {
> bitmap_super_t *sb;
>
> @@ -510,7 +510,6 @@ void md_bitmap_update_sb(struct bitmap *bitmap)
> write_sb_page(bitmap, bitmap->storage.sb_index,
> bitmap->storage.sb_page, 1);
> }
> -EXPORT_SYMBOL(md_bitmap_update_sb);
>
> /* print out the bitmap file superblock */
> static void bitmap_print_sb(struct bitmap *bitmap)
> @@ -893,7 +892,7 @@ static void md_bitmap_file_unmap(struct bitmap_storage
> *store) static void md_bitmap_file_kick(struct bitmap *bitmap)
> {
> if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) {
> - md_bitmap_update_sb(bitmap);
> + bitmap_update_sb(bitmap);
>
> if (bitmap->storage.file) {
> pr_warn("%s: kicking failed bitmap file %pD4 from
> array!\n", @@ -1796,7 +1795,7 @@ static void bitmap_flush(struct mddev *mddev)
> md_bitmap_daemon_work(mddev);
> if (mddev->bitmap_info.external)
> md_super_wait(mddev);
> - md_bitmap_update_sb(bitmap);
> + bitmap_update_sb(bitmap);
> }
>
> /*
> @@ -2014,7 +2013,7 @@ static int bitmap_load(struct mddev *mddev)
> mddev_set_timeout(mddev, mddev->bitmap_info.daemon_sleep, true);
> md_wakeup_thread(mddev->thread);
>
> - md_bitmap_update_sb(bitmap);
> + bitmap_update_sb(bitmap);
You changed function name here and it is harmful for git blame. What is the
reason behind that? it must be described in commit message to help Song making
the decision if it is worthy merging or not.
>
> if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
> err = -EIO;
> @@ -2075,7 +2074,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int
> slot, }
>
> if (clear_bits) {
> - md_bitmap_update_sb(bitmap);
> + bitmap_update_sb(bitmap);
> /* BITMAP_PAGE_PENDING is set, but bitmap_unplug needs
> * BITMAP_PAGE_DIRTY or _NEEDWRITE to write ... */
> for (i = 0; i < bitmap->storage.file_pages; i++)
> @@ -2568,7 +2567,7 @@ backlog_store(struct mddev *mddev, const char *buf,
> size_t len) mddev_create_serial_pool(mddev, rdev);
> }
> if (old_mwb != backlog)
> - md_bitmap_update_sb(mddev->bitmap);
> + bitmap_update_sb(mddev->bitmap);
>
> mddev_unlock_and_resume(mddev);
> return len;
> @@ -2712,6 +2711,8 @@ static struct bitmap_operations bitmap_ops = {
> .load = bitmap_load,
> .destroy = bitmap_destroy,
> .flush = bitmap_flush,
> +
> + .update_sb = bitmap_update_sb,
> };
>
> void mddev_set_bitmap_ops(struct mddev *mddev)
> diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
> index 935c5dc45b89..29c217630ae5 100644
> --- a/drivers/md/md-bitmap.h
> +++ b/drivers/md/md-bitmap.h
> @@ -239,6 +239,8 @@ struct bitmap_operations {
> int (*load)(struct mddev *mddev);
> void (*destroy)(struct mddev *mddev);
> void (*flush)(struct mddev *mddev);
> +
> + void (*update_sb)(struct bitmap *bitmap);
> };
>
> /* the bitmap API */
> @@ -277,7 +279,14 @@ static inline void md_bitmap_flush(struct mddev *mddev)
> mddev->bitmap_ops->flush(mddev);
> }
>
> -void md_bitmap_update_sb(struct bitmap *bitmap);
> +static inline void md_bitmap_update_sb(struct mddev *mddev)
> +{
> + if (!mddev->bitmap || !mddev->bitmap_ops->update_sb)
> + return;
I would like to avoid dead code here. !mddev->bitmap is probably not an option
an this point in code. !mddev->bitmap_ops->update_sb i not an option because we
have only one bitmap op. Do I miss something?
I will stop here for today now to give you a chance to reply, to be sure that
we are on same page. I see that my comments are similar so it may not be worthy
to go one by one and repeat same comment. I may miss something important.
Thanks
Mariusz
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
` (25 preceding siblings ...)
2024-08-10 2:08 ` [PATCH RFC -next 26/26] md/md-bitmap: merge bitmap_unplug() into bitmap_operations Yu Kuai
@ 2024-08-13 7:21 ` Christoph Hellwig
2024-08-13 7:36 ` Yu Kuai
26 siblings, 1 reply; 35+ messages in thread
From: Christoph Hellwig @ 2024-08-13 7:21 UTC (permalink / raw)
To: Yu Kuai; +Cc: song, linux-kernel, linux-raid, yukuai3, yi.zhang, yangerkun
On Sat, Aug 10, 2024 at 10:08:28AM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> The background is that currently bitmap is using a global spin_lock,
> cauing lock contention and huge IO performance degration for all raid
> levels.
>
> However, it's impossible to implement a new lock free bitmap with
> current situation that md-bitmap exposes the internal implementation
> with lots of exported apis. Hence bitmap_operations is invented, to
> describe bitmap core implementation, and a new bitmap can be introduced
> with a new bitmap_operations, we only need to switch to the new one
> during initialization.
>
> And with this we can build bitmap as kernel module, but that's not
> our concern for now.
>
> Noted I just compile this patchset, not tested yet.
Refactoring the bitmap code to be modular seems like a good idea.
But I'd just turn this into plain function calls and maybe a hidden
data structure if you feel really fancy. No need to introduce expensive
indirect calls and a separate module.
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations
2024-08-13 6:58 ` Mariusz Tkaczyk
@ 2024-08-13 7:25 ` Yu Kuai
0 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-13 7:25 UTC (permalink / raw)
To: Mariusz Tkaczyk, Yu Kuai
Cc: song, linux-kernel, linux-raid, yi.zhang, yangerkun, yukuai (C)
Hi,
在 2024/08/13 14:58, Mariusz Tkaczyk 写道:
> On Sat, 10 Aug 2024 10:08:29 +0800
> Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> The structure is empty for now, and will be used in later patches to
>> merge in bitmap operations, prepare to implement a new lock free
>> bitmap in the fulture.
>
>
> HI Kuai,
>
> typo: future
>
> I think that as "later" you meant next patches in this patchset, right? If yes,
> Please you "next" instead.
>
> At this point bringing "lock free implementation in the future" looks like
> totally unnecessary. It may happen or may not. Eventually, You can mention it in
> cover letter. What we have now is the most important.
>
> This is just a code rework. The main goal of this (as you mentioned in second
> patch):
>
> "So that the implementation won't be exposed, and it'll be possible
> to invent a new bitmap by replacing bitmap_operations."
>
> but please mention that you are not going to implement second mechanism to not
> confuse reader. You need it to improve code maintainability mainly I think.
>
> I would mention something about common "struct _ops" pattern (the special
> structure to keep related operations together) that it is going to follow now.
>
> For me, this one can be easy merged with the patch 2, so we will got struct +
> usage in one patch.
Thanks for the review. Got it.
BTW, v2 will look totally different with v1. You can leave v1 for now. :)
Kuai
>
> Anyway, LGTM.
>
> Thanks,
> Mariusz
>
> .
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() into bitmap_operations
2024-08-13 7:07 ` Mariusz Tkaczyk
@ 2024-08-13 7:30 ` Yu Kuai
0 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-13 7:30 UTC (permalink / raw)
To: Mariusz Tkaczyk, Yu Kuai
Cc: song, linux-kernel, linux-raid, yi.zhang, yangerkun, yukuai (C)
Hi,
在 2024/08/13 15:07, Mariusz Tkaczyk 写道:
> On Sat, 10 Aug 2024 10:08:31 +0800
> Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> So that the implementation won't be exposed, and it'll be possible
>> to invent a new bitmap by replacing bitmap_operations.
>
> I don't like repeating same commit message for few patches.
>
>>
>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>> ---
>> drivers/md/md-bitmap.c | 6 +++---
>> drivers/md/md-bitmap.h | 10 +++++++++-
>> 2 files changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
>> index d731f7d4bbbb..9a9f0fe3ebd0 100644
>> --- a/drivers/md/md-bitmap.c
>> +++ b/drivers/md/md-bitmap.c
>> @@ -1965,7 +1965,7 @@ static struct bitmap *bitmap_create(struct mddev
>> *mddev, int slot) return ERR_PTR(err);
>> }
>>
>> -int md_bitmap_load(struct mddev *mddev)
>> +static int bitmap_load(struct mddev *mddev)
>> {
>> int err = 0;
>> sector_t start = 0;
>> @@ -2021,7 +2021,6 @@ int md_bitmap_load(struct mddev *mddev)
>> out:
>> return err;
>> }
>> -EXPORT_SYMBOL_GPL(md_bitmap_load);
>>
>> /* caller need to free returned bitmap with md_bitmap_free() */
>> struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
>> @@ -2411,7 +2410,7 @@ location_store(struct mddev *mddev, const char *buf,
>> size_t len) }
>>
>> mddev->bitmap = bitmap;
>> - rv = md_bitmap_load(mddev);
>> + rv = bitmap_load(mddev);
>> if (rv) {
>> mddev->bitmap_info.offset = 0;
>> md_bitmap_destroy(mddev);
>> @@ -2710,6 +2709,7 @@ const struct attribute_group md_bitmap_group = {
>>
>> static struct bitmap_operations bitmap_ops = {
>> .create = bitmap_create,
>> + .load = bitmap_load,
>> };
>>
>> void mddev_set_bitmap_ops(struct mddev *mddev)
>> diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
>> index a7cbf0c692fc..de7fbe5903dd 100644
>> --- a/drivers/md/md-bitmap.h
>> +++ b/drivers/md/md-bitmap.h
>> @@ -236,6 +236,7 @@ struct bitmap {
>>
>> struct bitmap_operations {
>> struct bitmap* (*create)(struct mddev *mddev, int slot);
>> + int (*load)(struct mddev *mddev);
>> };
>>
>> /* the bitmap API */
>> @@ -250,7 +251,14 @@ static inline struct bitmap *md_bitmap_create(struct
>> mddev *mddev, int slot) return mddev->bitmap_ops->create(mddev, slot);
>> }
>>
>> -int md_bitmap_load(struct mddev *mddev);
>> +static inline int md_bitmap_load(struct mddev *mddev)
>> +{
>> + if (!mddev->bitmap_ops->load)
>> + return -EOPNOTSUPP;
>> +
>> + return mddev->bitmap_ops->load(mddev);
>> +}
>
> At this point we have only on bitmpa op (at that probably won't change), so if
> we we have bitmap_ops assigned (mddev->bitmap_ops != NULL) then ->load is must
> have, hence I don't see a need for this wrapper.
Yes, we must define the load op otherwise the bitmap_ops is meaningless.
>
> you probably made this to avoid changes across code. If yes, please mention it
> in commit message but I still would prefer to replace them all by calls to
> mddev->bitmap_ops->load().
I'll replace to use mddev->bitmap_ops->load() directly, and other
places. And I'll keep this inline helper for some ops that is used for
md-cluster, because I'm not planning to support md-cluster for the new
bitmap first.
Thanks,
Kuai
>
> Mariusz
>
>
> .
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations
2024-08-13 7:17 ` Mariusz Tkaczyk
@ 2024-08-13 7:33 ` Yu Kuai
0 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-13 7:33 UTC (permalink / raw)
To: Mariusz Tkaczyk, Yu Kuai
Cc: song, linux-kernel, linux-raid, yi.zhang, yangerkun, yukuai (C)
Hi,
在 2024/08/13 15:17, Mariusz Tkaczyk 写道:
> On Sat, 10 Aug 2024 10:08:35 +0800
> Yu Kuai <yukuai1@huaweicloud.com> wrote:
>
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> So that the implementation won't be exposed, and it'll be possible
>> to invent a new bitmap by replacing bitmap_operations.
>
> Please update commit message.
>
>>
>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>> ---
>> drivers/md/md-bitmap.c | 15 ++++++++-------
>> drivers/md/md-bitmap.h | 11 ++++++++++-
>> drivers/md/md-cluster.c | 3 ++-
>> drivers/md/md.c | 4 ++--
>> 4 files changed, 22 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
>> index 0ff733756043..b34f13aa2697 100644
>> --- a/drivers/md/md-bitmap.c
>> +++ b/drivers/md/md-bitmap.c
>> @@ -472,7 +472,7 @@ static void md_bitmap_wait_writes(struct bitmap *bitmap)
>>
>>
>> /* update the event counter and sync the superblock to disk */
>> -void md_bitmap_update_sb(struct bitmap *bitmap)
>> +static void bitmap_update_sb(struct bitmap *bitmap)
>> {
>> bitmap_super_t *sb;
>>
>> @@ -510,7 +510,6 @@ void md_bitmap_update_sb(struct bitmap *bitmap)
>> write_sb_page(bitmap, bitmap->storage.sb_index,
>> bitmap->storage.sb_page, 1);
>> }
>> -EXPORT_SYMBOL(md_bitmap_update_sb);
>>
>> /* print out the bitmap file superblock */
>> static void bitmap_print_sb(struct bitmap *bitmap)
>> @@ -893,7 +892,7 @@ static void md_bitmap_file_unmap(struct bitmap_storage
>> *store) static void md_bitmap_file_kick(struct bitmap *bitmap)
>> {
>> if (!test_and_set_bit(BITMAP_STALE, &bitmap->flags)) {
>> - md_bitmap_update_sb(bitmap);
>> + bitmap_update_sb(bitmap);
>>
>> if (bitmap->storage.file) {
>> pr_warn("%s: kicking failed bitmap file %pD4 from
>> array!\n", @@ -1796,7 +1795,7 @@ static void bitmap_flush(struct mddev *mddev)
>> md_bitmap_daemon_work(mddev);
>> if (mddev->bitmap_info.external)
>> md_super_wait(mddev);
>> - md_bitmap_update_sb(bitmap);
>> + bitmap_update_sb(bitmap);
>> }
>>
>> /*
>> @@ -2014,7 +2013,7 @@ static int bitmap_load(struct mddev *mddev)
>> mddev_set_timeout(mddev, mddev->bitmap_info.daemon_sleep, true);
>> md_wakeup_thread(mddev->thread);
>>
>> - md_bitmap_update_sb(bitmap);
>> + bitmap_update_sb(bitmap);
>
> You changed function name here and it is harmful for git blame. What is the
> reason behind that? it must be described in commit message to help Song making
> the decision if it is worthy merging or not.
>
>>
>> if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
>> err = -EIO;
>> @@ -2075,7 +2074,7 @@ int md_bitmap_copy_from_slot(struct mddev *mddev, int
>> slot, }
>>
>> if (clear_bits) {
>> - md_bitmap_update_sb(bitmap);
>> + bitmap_update_sb(bitmap);
>> /* BITMAP_PAGE_PENDING is set, but bitmap_unplug needs
>> * BITMAP_PAGE_DIRTY or _NEEDWRITE to write ... */
>> for (i = 0; i < bitmap->storage.file_pages; i++)
>> @@ -2568,7 +2567,7 @@ backlog_store(struct mddev *mddev, const char *buf,
>> size_t len) mddev_create_serial_pool(mddev, rdev);
>> }
>> if (old_mwb != backlog)
>> - md_bitmap_update_sb(mddev->bitmap);
>> + bitmap_update_sb(mddev->bitmap);
>>
>> mddev_unlock_and_resume(mddev);
>> return len;
>> @@ -2712,6 +2711,8 @@ static struct bitmap_operations bitmap_ops = {
>> .load = bitmap_load,
>> .destroy = bitmap_destroy,
>> .flush = bitmap_flush,
>> +
>> + .update_sb = bitmap_update_sb,
>> };
>>
>> void mddev_set_bitmap_ops(struct mddev *mddev)
>> diff --git a/drivers/md/md-bitmap.h b/drivers/md/md-bitmap.h
>> index 935c5dc45b89..29c217630ae5 100644
>> --- a/drivers/md/md-bitmap.h
>> +++ b/drivers/md/md-bitmap.h
>> @@ -239,6 +239,8 @@ struct bitmap_operations {
>> int (*load)(struct mddev *mddev);
>> void (*destroy)(struct mddev *mddev);
>> void (*flush)(struct mddev *mddev);
>> +
>> + void (*update_sb)(struct bitmap *bitmap);
>> };
>>
>> /* the bitmap API */
>> @@ -277,7 +279,14 @@ static inline void md_bitmap_flush(struct mddev *mddev)
>> mddev->bitmap_ops->flush(mddev);
>> }
>>
>> -void md_bitmap_update_sb(struct bitmap *bitmap);
>> +static inline void md_bitmap_update_sb(struct mddev *mddev)
>> +{
>> + if (!mddev->bitmap || !mddev->bitmap_ops->update_sb)
>> + return;
>
> I would like to avoid dead code here. !mddev->bitmap is probably not an option
> an this point in code. !mddev->bitmap_ops->update_sb i not an option because we
> have only one bitmap op. Do I miss something?
mddev->bitmap will be an option for the array with bitmap=none. However,
!mddev->bitmap_ops->update_sb is indeed not an option.
>
> I will stop here for today now to give you a chance to reply, to be sure that
> we are on same page. I see that my comments are similar so it may not be worthy
> to go one by one and repeat same comment. I may miss something important.
Yes, but for the similiar commit message, I'm not sure how to improve
this for now. We don't want a large patch to merge all the ops at once.
Thanks,
Kuai
>
> Thanks
> Mariusz
>
>
> .
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations
2024-08-13 7:21 ` [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Christoph Hellwig
@ 2024-08-13 7:36 ` Yu Kuai
0 siblings, 0 replies; 35+ messages in thread
From: Yu Kuai @ 2024-08-13 7:36 UTC (permalink / raw)
To: Christoph Hellwig, Yu Kuai
Cc: song, linux-kernel, linux-raid, yi.zhang, yangerkun, yukuai (C)
在 2024/08/13 15:21, Christoph Hellwig 写道:
> On Sat, Aug 10, 2024 at 10:08:28AM +0800, Yu Kuai wrote:
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> The background is that currently bitmap is using a global spin_lock,
>> cauing lock contention and huge IO performance degration for all raid
>> levels.
>>
>> However, it's impossible to implement a new lock free bitmap with
>> current situation that md-bitmap exposes the internal implementation
>> with lots of exported apis. Hence bitmap_operations is invented, to
>> describe bitmap core implementation, and a new bitmap can be introduced
>> with a new bitmap_operations, we only need to switch to the new one
>> during initialization.
>>
>> And with this we can build bitmap as kernel module, but that's not
>> our concern for now.
>>
>> Noted I just compile this patchset, not tested yet.
>
> Refactoring the bitmap code to be modular seems like a good idea.
>
> But I'd just turn this into plain function calls and maybe a hidden
> data structure if you feel really fancy. No need to introduce expensive
> indirect calls and a separate module.
Got it, and will make the struct bitmap a hidden structure in the next
version. This is exactly what I'm doing now locally, get rid of bitmap
direct dereference :).
Thanks for the review!
Kuai
>
> .
>
^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2024-08-13 7:36 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-10 2:08 [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 01/26] md/md-bitmap: introduce struct bitmap_operations Yu Kuai
2024-08-13 6:58 ` Mariusz Tkaczyk
2024-08-13 7:25 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 02/26] md/md-bitmap: merge md_bitmap_create() into bitmap_operations Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 03/26] md/md-bitmap: merge md_bitmap_load() " Yu Kuai
2024-08-13 7:07 ` Mariusz Tkaczyk
2024-08-13 7:30 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 04/26] md/md-bitmap: merge md_bitmap_destroy() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 05/26] md/md-bitmap: merge md_bitmap_flush() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 06/26] md/md-bitmap: don't expose md_bitmap_print_sb() Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 07/26] md/md-bitmap: merge md_bitmap_update_sb() into bitmap_operations Yu Kuai
2024-08-13 7:17 ` Mariusz Tkaczyk
2024-08-13 7:33 ` Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 08/26] md/md-bitmap: merge md_bitmap_status() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 09/26] md/md-bitmap: remove md_bitmap_setallbits() Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 10/26] md/md-bitmap: merge bitmap_write_all() into bitmap_operations Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 11/26] md/md-bitmap: merge md_bitmap_dirty_bits() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 12/26] md/md-bitmap: merge md_bitmap_startwrite() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 13/26] md/md-bitmap: merge md_bitmap_endwrite() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 14/26] md/md-bitmap: merge md_bitmap_start_sync() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 15/26] md/md-bitmap: merge md_bitmap_end_sync() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 16/26] md/md-bitmap: merge md_bitmap_close_sync() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 17/26] md/md-bitmap: mrege md_bitmap_cond_end_sync() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 18/26] md/md-bitmap: merge bitmap_sync_with_cluster() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 19/26] md/md-bitmap: merge md_bitmap_resize() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 20/26] md/md-bitmap: merge get_bitmap_from_slot() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 21/26] md/md-bitmap: merge md_bitmap_copy_from_slot() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 22/26] md/md-bitmap: merge md_bitmap_free() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 23/26] md/md-bitmap: merge md_bitmap_wait_behind_writes() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 24/26] md/md-bitmap: merge md_bitmap_daemon_work() " Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 25/26] md/md-bitmap: merge md_bitmap_unplug() and md_bitmap_unplug_async() Yu Kuai
2024-08-10 2:08 ` [PATCH RFC -next 26/26] md/md-bitmap: merge bitmap_unplug() into bitmap_operations Yu Kuai
2024-08-13 7:21 ` [PATCH RFC -next 00/26] md/md-bitmap: introduce bitmap_operations Christoph Hellwig
2024-08-13 7:36 ` 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).