History

Merge tag 'for-5.6/drivers-2020-01-27' of git://git.kernel.dk/linux-block

Pull block driver updates from Jens Axboe: "Like the core side, not a lot of changes here, just two main items: - Series of patches (via Coly) with fixes for bcache (Coly, Christoph) - MD pull request from Song" * tag 'for-5.6/drivers-2020-01-27' of git://git.kernel.dk/linux-block: (31 commits) bcache: reap from tail of c->btree_cache in bch_mca_scan() bcache: reap c->btree_cache_freeable from the tail in bch_mca_scan() bcache: remove member accessed from struct btree bcache: print written and keys in trace_bcache_btree_write bcache: avoid unnecessary btree nodes flushing in btree_flush_write() bcache: add code comments for state->pool in __btree_sort() lib: crc64: include <linux/crc64.h> for 'crc64_be' bcache: use read_cache_page_gfp to read the superblock bcache: store a pointer to the on-disk sb in the cache and cached_dev structures bcache: return a pointer to the on-disk sb from read_super bcache: transfer the sb_page reference to register_{bdev,cache} bcache: fix use-after-free in register_bcache() bcache: properly initialize 'path' and 'err' in register_bcache() bcache: rework error unwinding in register_bcache bcache: use a separate data structure for the on-disk super block bcache: cached_dev_free needs to put the sb page md/raid1: introduce wait_for_serialization md/raid1: use bucket based mechanism for IO serialization md: introduce a new struct for IO serialization md: don't destroy serial_info_pool if serialize_policy is true ...

Linus Torvalds committed 6 years ago

Commit 22a8f392 parents 48b4b4f e3de04417 files · +571 −262Browse files

Unified · Split

17 files
  1. drivers/md/bcache/bcache.h +2 −0
  2. drivers/md/bcache/bset.c +5 −0
  3. drivers/md/bcache/btree.c +10 −14
  4. drivers/md/bcache/btree.h +0 −2
  5. drivers/md/bcache/journal.c +75 −5
  6. drivers/md/bcache/super.c +71 −65
  7. drivers/md/md-bitmap.c +12 −13
  8. drivers/md/md.c +199 −55
  9. drivers/md/md.h +27 −18
  10. drivers/md/raid1.c +61 −50
  11. drivers/md/raid5.c +7 −14
  12. include/linux/raid/pq.h +6 −1
  13. include/trace/events/bcache.h +2 −1
  14. include/uapi/linux/bcache.h +52 −0
  15. lib/crc64.c +1 −0
  16. lib/raid6/algos.c +40 −23
  17. lib/raid6/mktables.c +1 −1
drivers/md/bcache/bcache.h+2−0
@@ -301,6 +301,7 @@ struct cached_dev { · 300 unmodified lines
301301 struct block_device *bdev;
302302
303303 struct cache_sb sb;
304+ struct cache_sb_disk *sb_disk;
304305 struct bio sb_bio;
305306 struct bio_vec sb_bv[1];
306307 struct closure sb_write;
@@ -403,6 +404,7 @@ enum alloc_reserve { · 96 unmodified lines
403404 struct cache {
404405 struct cache_set *set;
405406 struct cache_sb sb;
407+ struct cache_sb_disk *sb_disk;
406408 struct bio sb_bio;
407409 struct bio_vec sb_bv[1];
408410
drivers/md/bcache/bset.c+5−0
@@ -1257,6 +1257,11 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter, · 1256 unmodified lines
12571257 * Our temporary buffer is the same size as the btree node's
12581258 * buffer, we can just swap buffers instead of doing a big
12591259 * memcpy()
1260+ *
1261+ * Don't worry event 'out' is allocated from mempool, it can
1262+ * still be swapped here. Because state->pool is a page mempool
1263+ * creaated by by mempool_init_page_pool(), which allocates
1264+ * pages by alloc_pages() indeed.
12601265 */
12611266
12621267 out->magic = b->set->data->magic;
drivers/md/bcache/btree.c+10−14
@@ -734,34 +734,32 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, · 733 unmodified lines
734734
735735 i = 0;
736736 btree_cache_used = c->btree_cache_used;
737− list_for_each_entry_safe(b, t, &c->btree_cache_freeable, list) {
737+ list_for_each_entry_safe_reverse(b, t, &c->btree_cache_freeable, list) {
738738 if (nr <= 0)
739739 goto out;
740740
741− if (++i > 3 &&
742− !mca_reap(b, 0, false)) {
741+ if (!mca_reap(b, 0, false)) {
743742 mca_data_free(b);
744743 rw_unlock(true, b);
745744 freed++;
746745 }
747746 nr--;
747+ i++;
748748 }
749749
750− for (; (nr--) && i < btree_cache_used; i++) {
751− if (list_empty(&c->btree_cache))
750+ list_for_each_entry_safe_reverse(b, t, &c->btree_cache, list) {
751+ if (nr <= 0 || i >= btree_cache_used)
752752 goto out;
753753
754− b = list_first_entry(&c->btree_cache, struct btree, list);
755− list_rotate_left(&c->btree_cache);
756−
757− if (!b->accessed &&
758− !mca_reap(b, 0, false)) {
754+ if (!mca_reap(b, 0, false)) {
759755 mca_bucket_free(b);
760756 mca_data_free(b);
761757 rw_unlock(true, b);
762758 freed++;
763− } else
764− b->accessed = 0;
759+ }
760+
761+ nr--;
762+ i++;
765763 }
766764 out:
767765 mutex_unlock(&c->bucket_lock);
@@ -1069,7 +1067,6 @@ retry: · 301 unmodified lines
10691067 BUG_ON(!b->written);
10701068
10711069 b->parent = parent;
1072− b->accessed = 1;
10731070
10741071 for (; i <= b->keys.nsets && b->keys.set[i].size; i++) {
10751072 prefetch(b->keys.set[i].tree);
@@ -1160,7 +1157,6 @@ retry: · 84 unmodified lines
11601157 goto retry;
11611158 }
11621159
1163− b->accessed = 1;
11641160 b->parent = parent;
11651161 bch_bset_init_next(&b->keys, b->keys.set->data, bset_magic(&b->c->sb));
11661162
drivers/md/bcache/btree.h+0−2
@@ -121,8 +121,6 @@ struct btree { · 120 unmodified lines
121121 /* Key/pointer for this btree node */
122122 BKEY_PADDED(key);
123123
124− /* Single bit - set when accessed, cleared by shrinker */
125− unsigned long accessed;
126124 unsigned long seq;
127125 struct rw_semaphore lock;
128126 struct cache_set *c;
drivers/md/bcache/journal.c+75−5
@@ -417,10 +417,14 @@ err: · 416 unmodified lines
417417
418418 /* Journalling */
419419
420+#define nr_to_fifo_front(p, front_p, mask) (((p) - (front_p)) & (mask))
421+
420422 static void btree_flush_write(struct cache_set *c)
421423 {
422424 struct btree *b, *t, *btree_nodes[BTREE_FLUSH_NR];
423− unsigned int i, n;
425+ unsigned int i, nr, ref_nr;
426+ atomic_t *fifo_front_p, *now_fifo_front_p;
427+ size_t mask;
424428
425429 if (c->journal.btree_flushing)
426430 return;
@@ -433,12 +437,50 @@ static void btree_flush_write(struct cache_set *c) · 6 unmodified lines
433437 c->journal.btree_flushing = true;
434438 spin_unlock(&c->journal.flush_write_lock);
435439
440+ /* get the oldest journal entry and check its refcount */
441+ spin_lock(&c->journal.lock);
442+ fifo_front_p = &fifo_front(&c->journal.pin);
443+ ref_nr = atomic_read(fifo_front_p);
444+ if (ref_nr <= 0) {
445+ /*
446+ * do nothing if no btree node references
447+ * the oldest journal entry
448+ */
449+ spin_unlock(&c->journal.lock);
450+ goto out;
451+ }
452+ spin_unlock(&c->journal.lock);
453+
454+ mask = c->journal.pin.mask;
455+ nr = 0;
436456 atomic_long_inc(&c->flush_write);
437457 memset(btree_nodes, 0, sizeof(btree_nodes));
438− n = 0;
439458
440459 mutex_lock(&c->bucket_lock);
441460 list_for_each_entry_safe_reverse(b, t, &c->btree_cache, list) {
461+ /*
462+ * It is safe to get now_fifo_front_p without holding
463+ * c->journal.lock here, because we don't need to know
464+ * the exactly accurate value, just check whether the
465+ * front pointer of c->journal.pin is changed.
466+ */
467+ now_fifo_front_p = &fifo_front(&c->journal.pin);
468+ /*
469+ * If the oldest journal entry is reclaimed and front
470+ * pointer of c->journal.pin changes, it is unnecessary
471+ * to scan c->btree_cache anymore, just quit the loop and
472+ * flush out what we have already.
473+ */
474+ if (now_fifo_front_p != fifo_front_p)
475+ break;
476+ /*
477+ * quit this loop if all matching btree nodes are
478+ * scanned and record in btree_nodes[] already.
479+ */
480+ ref_nr = atomic_read(fifo_front_p);
481+ if (nr >= ref_nr)
482+ break;
483+
442484 if (btree_node_journal_flush(b))
443485 pr_err("BUG: flush_write bit should not be set here!");
444486
@@ -454,17 +496,44 @@ static void btree_flush_write(struct cache_set *c) · 9 unmodified lines
454496 continue;
455497 }
456498
499+ /*
500+ * Only select the btree node which exactly references
501+ * the oldest journal entry.
502+ *
503+ * If the journal entry pointed by fifo_front_p is
504+ * reclaimed in parallel, don't worry:
505+ * - the list_for_each_xxx loop will quit when checking
506+ * next now_fifo_front_p.
507+ * - If there are matched nodes recorded in btree_nodes[],
508+ * they are clean now (this is why and how the oldest
509+ * journal entry can be reclaimed). These selected nodes
510+ * will be ignored and skipped in the folowing for-loop.
511+ */
512+ if (nr_to_fifo_front(btree_current_write(b)->journal,
513+ fifo_front_p,
514+ mask) != 0) {
515+ mutex_unlock(&b->write_lock);
516+ continue;
517+ }
518+
457519 set_btree_node_journal_flush(b);
458520
459521 mutex_unlock(&b->write_lock);
460522
461− btree_nodes[n++] = b;
462− if (n == BTREE_FLUSH_NR)
523+ btree_nodes[nr++] = b;
524+ /*
525+ * To avoid holding c->bucket_lock too long time,
526+ * only scan for BTREE_FLUSH_NR matched btree nodes
527+ * at most. If there are more btree nodes reference
528+ * the oldest journal entry, try to flush them next
529+ * time when btree_flush_write() is called.
530+ */
531+ if (nr == BTREE_FLUSH_NR)
463532 break;
464533 }
465534 mutex_unlock(&c->bucket_lock);
466535
467− for (i = 0; i < n; i++) {
536+ for (i = 0; i < nr; i++) {
468537 b = btree_nodes[i];
469538 if (!b) {
470539 pr_err("BUG: btree_nodes[%d] is NULL", i);
@@ -497,6 +566,7 @@ static void btree_flush_write(struct cache_set *c) · 26 unmodified lines
497566 mutex_unlock(&b->write_lock);
498567 }
499568
569+out:
500570 spin_lock(&c->journal.flush_write_lock);
501571 c->journal.btree_flushing = false;
502572 spin_unlock(&c->journal.flush_write_lock);
drivers/md/bcache/super.c+71−65
@@ -15,7 +15,6 @@ · 14 unmodified lines
1515 #include "writeback.h"
1616
1717 #include <linux/blkdev.h>
18−#include <linux/buffer_head.h>
1918 #include <linux/debugfs.h>
2019 #include <linux/genhd.h>
2120 #include <linux/idr.h>
@@ -60,17 +59,18 @@ struct workqueue_struct *bch_journal_wq; · 38 unmodified lines
6059 /* Superblock */
6160
6261 static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
63− struct page **res)
62+ struct cache_sb_disk **res)
6463 {
6564 const char *err;
66− struct cache_sb *s;
67− struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);
65+ struct cache_sb_disk *s;
66+ struct page *page;
6867 unsigned int i;
6968
70− if (!bh)
69+ page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
70+ SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL);
71+ if (IS_ERR(page))
7172 return "IO error";
72−
73− s = (struct cache_sb *) bh->b_data;
73+ s = page_address(page) + offset_in_page(SB_OFFSET);
7474
7575 sb->offset = le64_to_cpu(s->offset);
7676 sb->version = le64_to_cpu(s->version);
@@ -188,12 +188,10 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev, · 111 unmodified lines
188188 }
189189
190190 sb->last_mount = (u32)ktime_get_real_seconds();
191− err = NULL;
192−
193− get_page(bh->b_page);
194− *res = bh->b_page;
191+ *res = s;
192+ return NULL;
195193 err:
196− put_bh(bh);
194+ put_page(page);
197195 return err;
198196 }
199197
@@ -207,15 +205,15 @@ static void write_bdev_super_endio(struct bio *bio) · 7 unmodified lines
207205 closure_put(&dc->sb_write);
208206 }
209207
210−static void __write_super(struct cache_sb *sb, struct bio *bio)
208+static void __write_super(struct cache_sb *sb, struct cache_sb_disk *out,
209+ struct bio *bio)
211210 {
212− struct cache_sb *out = page_address(bio_first_page_all(bio));
213211 unsigned int i;
214212
213+ bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_META;
215214 bio->bi_iter.bi_sector = SB_SECTOR;
216− bio->bi_iter.bi_size = SB_SIZE;
217− bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_SYNC|REQ_META);
218− bch_bio_map(bio, NULL);
215+ __bio_add_page(bio, virt_to_page(out), SB_SIZE,
216+ offset_in_page(out));
219217
220218 out->offset = cpu_to_le64(sb->offset);
221219 out->version = cpu_to_le64(sb->version);
@@ -257,14 +255,14 @@ void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent) · 35 unmodified lines
257255 down(&dc->sb_write_mutex);
258256 closure_init(cl, parent);
259257
260− bio_reset(bio);
258+ bio_init(bio, dc->sb_bv, 1);
261259 bio_set_dev(bio, dc->bdev);
262260 bio->bi_end_io = write_bdev_super_endio;
263261 bio->bi_private = dc;
264262
265263 closure_get(cl);
266264 /* I/O request sent to backing device */
267− __write_super(&dc->sb, bio);
265+ __write_super(&dc->sb, dc->sb_disk, bio);
268266
269267 closure_return_with_destructor(cl, bch_write_bdev_super_unlock);
270268 }
@@ -306,13 +304,13 @@ void bcache_write_super(struct cache_set *c) · 35 unmodified lines
306304
307305 SET_CACHE_SYNC(&ca->sb, CACHE_SYNC(&c->sb));
308306
309− bio_reset(bio);
307+ bio_init(bio, ca->sb_bv, 1);
310308 bio_set_dev(bio, ca->bdev);
311309 bio->bi_end_io = write_super_endio;
312310 bio->bi_private = ca;
313311
314312 closure_get(cl);
315− __write_super(&ca->sb, bio);
313+ __write_super(&ca->sb, ca->sb_disk, bio);
316314 }
317315
318316 closure_return_with_destructor(cl, bcache_write_super_unlock);
@@ -1275,6 +1273,9 @@ static void cached_dev_free(struct closure *cl) · 956 unmodified lines
12751273
12761274 mutex_unlock(&bch_register_lock);
12771275
1276+ if (dc->sb_disk)
1277+ put_page(virt_to_page(dc->sb_disk));
1278+
12781279 if (!IS_ERR_OR_NULL(dc->bdev))
12791280 blkdev_put(dc->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
12801281
@@ -1350,7 +1351,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size) · 69 unmodified lines
13501351
13511352 /* Cached device - bcache superblock */
13521353
1353−static int register_bdev(struct cache_sb *sb, struct page *sb_page,
1354+static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
13541355 struct block_device *bdev,
13551356 struct cached_dev *dc)
13561357 {
@@ -1362,11 +1363,7 @@ static int register_bdev(struct cache_sb *sb, struct page *sb_page, · 5 unmodified lines
13621363 memcpy(&dc->sb, sb, sizeof(struct cache_sb));
13631364 dc->bdev = bdev;
13641365 dc->bdev->bd_holder = dc;
1365−
1366− bio_init(&dc->sb_bio, dc->sb_bio.bi_inline_vecs, 1);
1367− bio_first_bvec_all(&dc->sb_bio)->bv_page = sb_page;
1368− get_page(sb_page);
1369−
1366+ dc->sb_disk = sb_disk;
13701367
13711368 if (cached_dev_init(dc, sb->block_size << 9))
13721369 goto err;
@@ -2136,8 +2133,8 @@ void bch_cache_release(struct kobject *kobj) · 763 unmodified lines
21362133 for (i = 0; i < RESERVE_NR; i++)
21372134 free_fifo(&ca->free[i]);
21382135
2139− if (ca->sb_bio.bi_inline_vecs[0].bv_page)
2140− put_page(bio_first_page_all(&ca->sb_bio));
2136+ if (ca->sb_disk)
2137+ put_page(virt_to_page(ca->sb_disk));
21412138
21422139 if (!IS_ERR_OR_NULL(ca->bdev))
21432140 blkdev_put(ca->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
@@ -2259,7 +2256,7 @@ err_free: · 115 unmodified lines
22592256 return ret;
22602257 }
22612258
2262−static int register_cache(struct cache_sb *sb, struct page *sb_page,
2259+static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
22632260 struct block_device *bdev, struct cache *ca)
22642261 {
22652262 const char *err = NULL; /* must be set for any error case */
@@ -2269,10 +2266,7 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page, · 3 unmodified lines
22692266 memcpy(&ca->sb, sb, sizeof(struct cache_sb));
22702267 ca->bdev = bdev;
22712268 ca->bdev->bd_holder = ca;
2272−
2273− bio_init(&ca->sb_bio, ca->sb_bio.bi_inline_vecs, 1);
2274− bio_first_bvec_all(&ca->sb_bio)->bv_page = sb_page;
2275− get_page(sb_page);
2269+ ca->sb_disk = sb_disk;
22762270
22772271 if (blk_queue_discard(bdev_get_queue(bdev)))
22782272 ca->discard = CACHE_DISCARD(&ca->sb);
@@ -2372,29 +2366,35 @@ static bool bch_is_open(struct block_device *bdev) · 93 unmodified lines
23722366 static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
23732367 const char *buffer, size_t size)
23742368 {
2375− ssize_t ret = -EINVAL;
2376− const char *err = "cannot allocate memory";
2369+ const char *err;
23772370 char *path = NULL;
2378− struct cache_sb *sb = NULL;
2379− struct block_device *bdev = NULL;
2380− struct page *sb_page = NULL;
2371+ struct cache_sb *sb;
2372+ struct cache_sb_disk *sb_disk;
2373+ struct block_device *bdev;
2374+ ssize_t ret;
23812375
2376+ ret = -EBUSY;
2377+ err = "failed to reference bcache module";
23822378 if (!try_module_get(THIS_MODULE))
2383− return -EBUSY;
2379+ goto out;
23842380
23852381 /* For latest state of bcache_is_reboot */
23862382 smp_mb();
2383+ err = "bcache is in reboot";
23872384 if (bcache_is_reboot)
2388− return -EBUSY;
2385+ goto out_module_put;
23892386
2387+ ret = -ENOMEM;
2388+ err = "cannot allocate memory";
23902389 path = kstrndup(buffer, size, GFP_KERNEL);
23912390 if (!path)
2392− goto err;
2391+ goto out_module_put;
23932392
23942393 sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL);
23952394 if (!sb)
2396− goto err;
2395+ goto out_free_path;
23972396
2397+ ret = -EINVAL;
23982398 err = "failed to open device";
23992399 bdev = blkdev_get_by_path(strim(path),
24002400 FMODE_READ|FMODE_WRITE|FMODE_EXCL,
@@ -2411,57 +2411,63 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, · 10 unmodified lines
24112411 if (!IS_ERR(bdev))
24122412 bdput(bdev);
24132413 if (attr == &ksysfs_register_quiet)
2414− goto quiet_out;
2414+ goto done;
24152415 }
2416− goto err;
2416+ goto out_free_sb;
24172417 }
24182418
24192419 err = "failed to set blocksize";
24202420 if (set_blocksize(bdev, 4096))
2421− goto err_close;
2421+ goto out_blkdev_put;
24222422
2423− err = read_super(sb, bdev, &sb_page);
2423+ err = read_super(sb, bdev, &sb_disk);
24242424 if (err)
2425− goto err_close;
2425+ goto out_blkdev_put;
24262426
24272427 err = "failed to register device";
24282428 if (SB_IS_BDEV(sb)) {
24292429 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL);
24302430
24312431 if (!dc)
2432− goto err_close;
2432+ goto out_put_sb_page;
24332433
24342434 mutex_lock(&bch_register_lock);
2435− ret = register_bdev(sb, sb_page, bdev, dc);
2435+ ret = register_bdev(sb, sb_disk, bdev, dc);
24362436 mutex_unlock(&bch_register_lock);
24372437 /* blkdev_put() will be called in cached_dev_free() */
24382438 if (ret < 0)
2439− goto err;
2439+ goto out_free_sb;
24402440 } else {
24412441 struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
24422442
24432443 if (!ca)
2444− goto err_close;
2444+ goto out_put_sb_page;
24452445
24462446 /* blkdev_put() will be called in bch_cache_release() */
2447− if (register_cache(sb, sb_page, bdev, ca) != 0)
2448− goto err;
2447+ if (register_cache(sb, sb_disk, bdev, ca) != 0)
2448+ goto out_free_sb;
24492449 }
2450−quiet_out:
2451− ret = size;
2452−out:
2453− if (sb_page)
2454− put_page(sb_page);
2450+
2451+done:
24552452 kfree(sb);
24562453 kfree(path);
24572454 module_put(THIS_MODULE);
2458− return ret;
2455+ return size;
24592456
2460−err_close:
2461− blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
2462−err:
2463− pr_info("error %s: %s", path, err);
2464− goto out;
2457+out_put_sb_page:
2458+ put_page(virt_to_page(sb_disk));
2459+out_blkdev_put:
2460+ blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
2461+out_free_sb:
2462+ kfree(sb);
2463+out_free_path:
2464+ kfree(path);
2465+ path = NULL;
2466+out_module_put:
2467+ module_put(THIS_MODULE);
2468+out:
2469+ pr_info("error %s: %s", path?path:"", err);
2470+ return ret;
24652471 }
24662472
24672473
drivers/md/md-bitmap.c+12−13
@@ -1019,8 +1019,6 @@ void md_bitmap_unplug(struct bitmap *bitmap) · 1018 unmodified lines
10191019 /* look at each page to see if there are any set bits that need to be
10201020 * flushed out to disk */
10211021 for (i = 0; i < bitmap->storage.file_pages; i++) {
1022− if (!bitmap->storage.filemap)
1023− return;
10241022 dirty = test_and_clear_page_attr(bitmap, i, BITMAP_PAGE_DIRTY);
10251023 need_write = test_and_clear_page_attr(bitmap, i,
10261024 BITMAP_PAGE_NEEDWRITE);
@@ -1338,7 +1336,8 @@ void md_bitmap_daemon_work(struct mddev *mddev) · 311 unmodified lines
13381336 BITMAP_PAGE_DIRTY))
13391337 /* bitmap_unplug will handle the rest */
13401338 break;
1341− if (test_and_clear_page_attr(bitmap, j,
1339+ if (bitmap->storage.filemap &&
1340+ test_and_clear_page_attr(bitmap, j,
13421341 BITMAP_PAGE_NEEDWRITE)) {
13431342 write_page(bitmap, bitmap->storage.filemap[j], 0);
13441343 }
@@ -1790,8 +1789,8 @@ void md_bitmap_destroy(struct mddev *mddev) · 445 unmodified lines
17901789 return;
17911790
17921791 md_bitmap_wait_behind_writes(mddev);
1793− mempool_destroy(mddev->wb_info_pool);
1794− mddev->wb_info_pool = NULL;
1792+ if (!mddev->serialize_policy)
1793+ mddev_destroy_serial_pool(mddev, NULL, true);
17951794
17961795 mutex_lock(&mddev->bitmap_info.mutex);
17971796 spin_lock(&mddev->lock);
@@ -1908,7 +1907,7 @@ int md_bitmap_load(struct mddev *mddev) · 110 unmodified lines
19081907 goto out;
19091908
19101909 rdev_for_each(rdev, mddev)
1911− mddev_create_wb_pool(mddev, rdev, true);
1910+ mddev_create_serial_pool(mddev, rdev, true);
19121911
19131912 if (mddev_is_clustered(mddev))
19141913 md_cluster_ops->load_bitmaps(mddev, mddev->bitmap_info.nodes);
@@ -2475,16 +2474,16 @@ backlog_store(struct mddev *mddev, const char *buf, size_t len) · 560 unmodified lines
24752474 if (backlog > COUNTER_MAX)
24762475 return -EINVAL;
24772476 mddev->bitmap_info.max_write_behind = backlog;
2478− if (!backlog && mddev->wb_info_pool) {
2479− /* wb_info_pool is not needed if backlog is zero */
2480− mempool_destroy(mddev->wb_info_pool);
2481− mddev->wb_info_pool = NULL;
2482− } else if (backlog && !mddev->wb_info_pool) {
2483− /* wb_info_pool is needed since backlog is not zero */
2477+ if (!backlog && mddev->serial_info_pool) {
2478+ /* serial_info_pool is not needed if backlog is zero */
2479+ if (!mddev->serialize_policy)
2480+ mddev_destroy_serial_pool(mddev, NULL, false);
2481+ } else if (backlog && !mddev->serial_info_pool) {
2482+ /* serial_info_pool is needed since backlog is not zero */
24842483 struct md_rdev *rdev;
24852484
24862485 rdev_for_each(rdev, mddev)
2487− mddev_create_wb_pool(mddev, rdev, false);
2486+ mddev_create_serial_pool(mddev, rdev, false);
24882487 }
24892488 if (old_mwb != backlog)
24902489 md_bitmap_update_sb(mddev->bitmap);
drivers/md/md.c+199−55
@@ -125,74 +125,165 @@ static inline int speed_max(struct mddev *mddev) · 124 unmodified lines
125125 mddev->sync_speed_max : sysctl_speed_limit_max;
126126 }
127127
128−static int rdev_init_wb(struct md_rdev *rdev)
128+static void rdev_uninit_serial(struct md_rdev *rdev)
129129 {
130− if (rdev->bdev->bd_queue->nr_hw_queues == 1)
130+ if (!test_and_clear_bit(CollisionCheck, &rdev->flags))
131+ return;
132+
133+ kvfree(rdev->serial);
134+ rdev->serial = NULL;
135+}
136+
137+static void rdevs_uninit_serial(struct mddev *mddev)
138+{
139+ struct md_rdev *rdev;
140+
141+ rdev_for_each(rdev, mddev)
142+ rdev_uninit_serial(rdev);
143+}
144+
145+static int rdev_init_serial(struct md_rdev *rdev)
146+{
147+ /* serial_nums equals with BARRIER_BUCKETS_NR */
148+ int i, serial_nums = 1 << ((PAGE_SHIFT - ilog2(sizeof(atomic_t))));
149+ struct serial_in_rdev *serial = NULL;
150+
151+ if (test_bit(CollisionCheck, &rdev->flags))
131152 return 0;
132153
133− spin_lock_init(&rdev->wb_list_lock);
134− INIT_LIST_HEAD(&rdev->wb_list);
135− init_waitqueue_head(&rdev->wb_io_wait);
136− set_bit(WBCollisionCheck, &rdev->flags);
154+ serial = kvmalloc(sizeof(struct serial_in_rdev) * serial_nums,
155+ GFP_KERNEL);
156+ if (!serial)
157+ return -ENOMEM;
137158
138− return 1;
159+ for (i = 0; i < serial_nums; i++) {
160+ struct serial_in_rdev *serial_tmp = &serial[i];
161+
162+ spin_lock_init(&serial_tmp->serial_lock);
163+ serial_tmp->serial_rb = RB_ROOT_CACHED;
164+ init_waitqueue_head(&serial_tmp->serial_io_wait);
165+ }
166+
167+ rdev->serial = serial;
168+ set_bit(CollisionCheck, &rdev->flags);
169+
170+ return 0;
171+}
172+
173+static int rdevs_init_serial(struct mddev *mddev)
174+{
175+ struct md_rdev *rdev;
176+ int ret = 0;
177+
178+ rdev_for_each(rdev, mddev) {
179+ ret = rdev_init_serial(rdev);
180+ if (ret)
181+ break;
182+ }
183+
184+ /* Free all resources if pool is not existed */
185+ if (ret && !mddev->serial_info_pool)
186+ rdevs_uninit_serial(mddev);
187+
188+ return ret;
139189 }
140190
141191 /*
142− * Create wb_info_pool if rdev is the first multi-queue device flaged
143− * with writemostly, also write-behind mode is enabled.
192+ * rdev needs to enable serial stuffs if it meets the conditions:
193+ * 1. it is multi-queue device flaged with writemostly.
194+ * 2. the write-behind mode is enabled.
144195 */
145−void mddev_create_wb_pool(struct mddev *mddev, struct md_rdev *rdev,
146− bool is_suspend)
196+static int rdev_need_serial(struct md_rdev *rdev)
147197 {
148− if (mddev->bitmap_info.max_write_behind == 0)
149− return;
198+ return (rdev && rdev->mddev->bitmap_info.max_write_behind > 0 &&
199+ rdev->bdev->bd_queue->nr_hw_queues != 1 &&
200+ test_bit(WriteMostly, &rdev->flags));
201+}
202+
203+/*
204+ * Init resource for rdev(s), then create serial_info_pool if:
205+ * 1. rdev is the first device which return true from rdev_enable_serial.
206+ * 2. rdev is NULL, means we want to enable serialization for all rdevs.
207+ */
208+void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
209+ bool is_suspend)
210+{
211+ int ret = 0;
150212
151− if (!test_bit(WriteMostly, &rdev->flags) || !rdev_init_wb(rdev))
213+ if (rdev && !rdev_need_serial(rdev) &&
214+ !test_bit(CollisionCheck, &rdev->flags))
152215 return;
153216
154− if (mddev->wb_info_pool == NULL) {
217+ if (!is_suspend)
218+ mddev_suspend(mddev);
219+
220+ if (!rdev)
221+ ret = rdevs_init_serial(mddev);
222+ else
223+ ret = rdev_init_serial(rdev);
224+ if (ret)
225+ goto abort;
226+
227+ if (mddev->serial_info_pool == NULL) {
155228 unsigned int noio_flag;
156229
157− if (!is_suspend)
158− mddev_suspend(mddev);
159230 noio_flag = memalloc_noio_save();
160− mddev->wb_info_pool = mempool_create_kmalloc_pool(NR_WB_INFOS,
161− sizeof(struct wb_info));
231+ mddev->serial_info_pool =
232+ mempool_create_kmalloc_pool(NR_SERIAL_INFOS,
233+ sizeof(struct serial_info));
162234 memalloc_noio_restore(noio_flag);
163− if (!mddev->wb_info_pool)
164− pr_err("can't alloc memory pool for writemostly\n");
165− if (!is_suspend)
166− mddev_resume(mddev);
235+ if (!mddev->serial_info_pool) {
236+ rdevs_uninit_serial(mddev);
237+ pr_err("can't alloc memory pool for serialization\n");
238+ }
167239 }
240+
241+abort:
242+ if (!is_suspend)
243+ mddev_resume(mddev);
168244 }
169−EXPORT_SYMBOL_GPL(mddev_create_wb_pool);
170245
171246 /*
172− * destroy wb_info_pool if rdev is the last device flaged with WBCollisionCheck.
247+ * Free resource from rdev(s), and destroy serial_info_pool under conditions:
248+ * 1. rdev is the last device flaged with CollisionCheck.
249+ * 2. when bitmap is destroyed while policy is not enabled.
250+ * 3. for disable policy, the pool is destroyed only when no rdev needs it.
173251 */
174−static void mddev_destroy_wb_pool(struct mddev *mddev, struct md_rdev *rdev)
252+void mddev_destroy_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
253+ bool is_suspend)
175254 {
176− if (!test_and_clear_bit(WBCollisionCheck, &rdev->flags))
255+ if (rdev && !test_bit(CollisionCheck, &rdev->flags))
177256 return;
178257
179− if (mddev->wb_info_pool) {
258+ if (mddev->serial_info_pool) {
180259 struct md_rdev *temp;
181− int num = 0;
260+ int num = 0; /* used to track if other rdevs need the pool */
182261
183− /*
184− * Check if other rdevs need wb_info_pool.
185− */
186− rdev_for_each(temp, mddev)
187− if (temp != rdev &&
188− test_bit(WBCollisionCheck, &temp->flags))
262+ if (!is_suspend)
263+ mddev_suspend(mddev);
264+ rdev_for_each(temp, mddev) {
265+ if (!rdev) {
266+ if (!mddev->serialize_policy ||
267+ !rdev_need_serial(temp))
268+ rdev_uninit_serial(temp);
269+ else
270+ num++;
271+ } else if (temp != rdev &&
272+ test_bit(CollisionCheck, &temp->flags))
189273 num++;
190− if (!num) {
191− mddev_suspend(rdev->mddev);
192− mempool_destroy(mddev->wb_info_pool);
193− mddev->wb_info_pool = NULL;
194− mddev_resume(rdev->mddev);
195274 }
275+
276+ if (rdev)
277+ rdev_uninit_serial(rdev);
278+
279+ if (num)
280+ pr_info("The mempool could be used by other devices\n");
281+ else {
282+ mempool_destroy(mddev->serial_info_pool);
283+ mddev->serial_info_pool = NULL;
284+ }
285+ if (!is_suspend)
286+ mddev_resume(mddev);
196287 }
197288 }
198289
@@ -2337,7 +2428,7 @@ static int bind_rdev_to_array(struct md_rdev *rdev, struct mddev *mddev) · 2138 unmodified lines
23372428 pr_debug("md: bind<%s>\n", b);
23382429
23392430 if (mddev->raid_disks)
2340− mddev_create_wb_pool(mddev, rdev, false);
2431+ mddev_create_serial_pool(mddev, rdev, false);
23412432
23422433 if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
23432434 goto fail;
@@ -2375,7 +2466,7 @@ static void unbind_rdev_from_array(struct md_rdev *rdev) · 31 unmodified lines
23752466 bd_unlink_disk_holder(rdev->bdev, rdev->mddev->gendisk);
23762467 list_del_rcu(&rdev->same_set);
23772468 pr_debug("md: unbind<%s>\n", bdevname(rdev->bdev,b));
2378− mddev_destroy_wb_pool(rdev->mddev, rdev);
2469+ mddev_destroy_serial_pool(rdev->mddev, rdev, false);
23792470 rdev->mddev = NULL;
23802471 sysfs_remove_link(&rdev->kobj, "block");
23812472 sysfs_put(rdev->sysfs_state);
@@ -2888,10 +2979,10 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) · 506 unmodified lines
28882979 }
28892980 } else if (cmd_match(buf, "writemostly")) {
28902981 set_bit(WriteMostly, &rdev->flags);
2891− mddev_create_wb_pool(rdev->mddev, rdev, false);
2982+ mddev_create_serial_pool(rdev->mddev, rdev, false);
28922983 err = 0;
28932984 } else if (cmd_match(buf, "-writemostly")) {
2894− mddev_destroy_wb_pool(rdev->mddev, rdev);
2985+ mddev_destroy_serial_pool(rdev->mddev, rdev, false);
28952986 clear_bit(WriteMostly, &rdev->flags);
28962987 err = 0;
28972988 } else if (cmd_match(buf, "blocked")) {
@@ -5277,6 +5368,57 @@ static struct md_sysfs_entry md_fail_last_dev = · 2379 unmodified lines
52775368 __ATTR(fail_last_dev, S_IRUGO | S_IWUSR, fail_last_dev_show,
52785369 fail_last_dev_store);
52795370
5371+static ssize_t serialize_policy_show(struct mddev *mddev, char *page)
5372+{
5373+ if (mddev->pers == NULL || (mddev->pers->level != 1))
5374+ return sprintf(page, "n/a\n");
5375+ else
5376+ return sprintf(page, "%d\n", mddev->serialize_policy);
5377+}
5378+
5379+/*
5380+ * Setting serialize_policy to true to enforce write IO is not reordered
5381+ * for raid1.
5382+ */
5383+static ssize_t
5384+serialize_policy_store(struct mddev *mddev, const char *buf, size_t len)
5385+{
5386+ int err;
5387+ bool value;
5388+
5389+ err = kstrtobool(buf, &value);
5390+ if (err)
5391+ return err;
5392+
5393+ if (value == mddev->serialize_policy)
5394+ return len;
5395+
5396+ err = mddev_lock(mddev);
5397+ if (err)
5398+ return err;
5399+ if (mddev->pers == NULL || (mddev->pers->level != 1)) {
5400+ pr_err("md: serialize_policy is only effective for raid1\n");
5401+ err = -EINVAL;
5402+ goto unlock;
5403+ }
5404+
5405+ mddev_suspend(mddev);
5406+ if (value)
5407+ mddev_create_serial_pool(mddev, NULL, true);
5408+ else
5409+ mddev_destroy_serial_pool(mddev, NULL, true);
5410+ mddev->serialize_policy = value;
5411+ mddev_resume(mddev);
5412+unlock:
5413+ mddev_unlock(mddev);
5414+ return err ?: len;
5415+}
5416+
5417+static struct md_sysfs_entry md_serialize_policy =
5418+__ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show,
5419+ serialize_policy_store);
5420+
5421+
52805422 static struct attribute *md_default_attrs[] = {
52815423 &md_level.attr,
52825424 &md_layout.attr,
@@ -5294,6 +5436,7 @@ static struct attribute *md_default_attrs[] = { · 11 unmodified lines
52945436 &max_corr_read_errors.attr,
52955437 &md_consistency_policy.attr,
52965438 &md_fail_last_dev.attr,
5439+ &md_serialize_policy.attr,
52975440 NULL,
52985441 };
52995442
@@ -5769,18 +5912,18 @@ int md_run(struct mddev *mddev) · 469 unmodified lines
57695912 goto bitmap_abort;
57705913
57715914 if (mddev->bitmap_info.max_write_behind > 0) {
5772− bool creat_pool = false;
5915+ bool create_pool = false;
57735916
57745917 rdev_for_each(rdev, mddev) {
57755918 if (test_bit(WriteMostly, &rdev->flags) &&
5776− rdev_init_wb(rdev))
5777− creat_pool = true;
5778− }
5779− if (creat_pool && mddev->wb_info_pool == NULL) {
5780− mddev->wb_info_pool =
5781− mempool_create_kmalloc_pool(NR_WB_INFOS,
5782− sizeof(struct wb_info));
5783− if (!mddev->wb_info_pool) {
5919+ rdev_init_serial(rdev))
5920+ create_pool = true;
5921+ }
5922+ if (create_pool && mddev->serial_info_pool == NULL) {
5923+ mddev->serial_info_pool =
5924+ mempool_create_kmalloc_pool(NR_SERIAL_INFOS,
5925+ sizeof(struct serial_info));
5926+ if (!mddev->serial_info_pool) {
57845927 err = -ENOMEM;
57855928 goto bitmap_abort;
57865929 }
@@ -6025,8 +6168,9 @@ static void __md_stop_writes(struct mddev *mddev) · 238 unmodified lines
60256168 mddev->in_sync = 1;
60266169 md_update_sb(mddev, 1);
60276170 }
6028− mempool_destroy(mddev->wb_info_pool);
6029− mddev->wb_info_pool = NULL;
6171+ /* disable policy to guarantee rdevs free resources for serialization */
6172+ mddev->serialize_policy = 0;
6173+ mddev_destroy_serial_pool(mddev, NULL, true);
60306174 }
60316175
60326176 void md_stop_writes(struct mddev *mddev)
drivers/md/md.h+27−18
@@ -32,6 +32,16 @@ · 31 unmodified lines
3232 * be retried.
3333 */
3434 #define MD_FAILFAST (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT)
35+
36+/*
37+ * The struct embedded in rdev is used to serialize IO.
38+ */
39+struct serial_in_rdev {
40+ struct rb_root_cached serial_rb;
41+ spinlock_t serial_lock;
42+ wait_queue_head_t serial_io_wait;
43+};
44+
3545 /*
3646 * MD's 'extended' device
3747 */
@@ -110,12 +120,7 @@ struct md_rdev { · 72 unmodified lines
110120 * in superblock.
111121 */
112122
113− /*
114− * The members for check collision of write behind IOs.
115− */
116− struct list_head wb_list;
117− spinlock_t wb_list_lock;
118− wait_queue_head_t wb_io_wait;
123+ struct serial_in_rdev *serial; /* used for raid1 io serialization */
119124
120125 struct work_struct del_work; /* used for delayed sysfs removal */
121126
@@ -201,9 +206,9 @@ enum flag_bits { · 79 unmodified lines
201206 * it didn't fail, so don't use FailFast
202207 * any more for metadata
203208 */
204− WBCollisionCheck, /*
205− * multiqueue device should check if there
206− * is collision between write behind bios.
209+ CollisionCheck, /*
210+ * check if there is collision between raid1
211+ * serial bios.
207212 */
208213 };
209214
@@ -263,12 +268,13 @@ enum mddev_sb_flags { · 53 unmodified lines
263268 MD_SB_NEED_REWRITE, /* metadata write needs to be repeated */
264269 };
265270
266−#define NR_WB_INFOS 8
267−/* record current range of write behind IOs */
268−struct wb_info {
269− sector_t lo;
270− sector_t hi;
271− struct list_head list;
271+#define NR_SERIAL_INFOS 8
272+/* record current range of serialize IOs */
273+struct serial_info {
274+ struct rb_node node;
275+ sector_t start; /* start sector of rb node */
276+ sector_t last; /* end sector of rb node */
277+ sector_t _subtree_last; /* highest sector in subtree of rb node */
272278 };
273279
274280 struct mddev {
@@ -487,13 +493,14 @@ struct mddev { · 212 unmodified lines
487493 */
488494 struct work_struct flush_work;
489495 struct work_struct event_work; /* used by dm to report failure event */
490− mempool_t *wb_info_pool;
496+ mempool_t *serial_info_pool;
491497 void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
492498 struct md_cluster_info *cluster_info;
493499 unsigned int good_device_nr; /* good device num within cluster raid */
494500
495501 bool has_superblocks:1;
496502 bool fail_last_dev:1;
503+ bool serialize_policy:1;
497504 };
498505
499506 enum recovery_flags {
@@ -737,8 +744,10 @@ extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs, · 237 unmodified lines
737744 extern void md_reload_sb(struct mddev *mddev, int raid_disk);
738745 extern void md_update_sb(struct mddev *mddev, int force);
739746 extern void md_kick_rdev_from_array(struct md_rdev * rdev);
740−extern void mddev_create_wb_pool(struct mddev *mddev, struct md_rdev *rdev,
741− bool is_suspend);
747+extern void mddev_create_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
748+ bool is_suspend);
749+extern void mddev_destroy_serial_pool(struct mddev *mddev, struct md_rdev *rdev,
750+ bool is_suspend);
742751 struct md_rdev *md_find_rdev_nr_rcu(struct mddev *mddev, int nr);
743752 struct md_rdev *md_find_rdev_rcu(struct mddev *mddev, dev_t dev);
744753
drivers/md/raid1.c+61−50
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #include <linux/module.h>
3030 #include <linux/seq_file.h>
3131 #include <linux/ratelimit.h>
32+#include <linux/interval_tree_generic.h>
3233
3334 #include <trace/events/block.h>
3435
@@ -50,55 +51,71 @@ static void lower_barrier(struct r1conf *conf, sector_t sector_nr); · 15 unmodified lines
5051
5152 #include "raid1-10.c"
5253
53−static int check_and_add_wb(struct md_rdev *rdev, sector_t lo, sector_t hi)
54+#define START(node) ((node)->start)
55+#define LAST(node) ((node)->last)
56+INTERVAL_TREE_DEFINE(struct serial_info, node, sector_t, _subtree_last,
57+ START, LAST, static inline, raid1_rb);
58+
59+static int check_and_add_serial(struct md_rdev *rdev, struct r1bio *r1_bio,
60+ struct serial_info *si, int idx)
5461 {
55− struct wb_info *wi, *temp_wi;
5662 unsigned long flags;
5763 int ret = 0;
58− struct mddev *mddev = rdev->mddev;
59−
60− wi = mempool_alloc(mddev->wb_info_pool, GFP_NOIO);
61−
62− spin_lock_irqsave(&rdev->wb_list_lock, flags);
63− list_for_each_entry(temp_wi, &rdev->wb_list, list) {
64− /* collision happened */
65− if (hi > temp_wi->lo && lo < temp_wi->hi) {
66− ret = -EBUSY;
67− break;
68− }
64+ sector_t lo = r1_bio->sector;
65+ sector_t hi = lo + r1_bio->sectors;
66+ struct serial_in_rdev *serial = &rdev->serial[idx];
67+
68+ spin_lock_irqsave(&serial->serial_lock, flags);
69+ /* collision happened */
70+ if (raid1_rb_iter_first(&serial->serial_rb, lo, hi))
71+ ret = -EBUSY;
72+ else {
73+ si->start = lo;
74+ si->last = hi;
75+ raid1_rb_insert(si, &serial->serial_rb);
6976 }
70−
71− if (!ret) {
72− wi->lo = lo;
73− wi->hi = hi;
74− list_add(&wi->list, &rdev->wb_list);
75− } else
76− mempool_free(wi, mddev->wb_info_pool);
77− spin_unlock_irqrestore(&rdev->wb_list_lock, flags);
77+ spin_unlock_irqrestore(&serial->serial_lock, flags);
7878
7979 return ret;
8080 }
8181
82−static void remove_wb(struct md_rdev *rdev, sector_t lo, sector_t hi)
82+static void wait_for_serialization(struct md_rdev *rdev, struct r1bio *r1_bio)
83+{
84+ struct mddev *mddev = rdev->mddev;
85+ struct serial_info *si;
86+ int idx = sector_to_idx(r1_bio->sector);
87+ struct serial_in_rdev *serial = &rdev->serial[idx];
88+
89+ if (WARN_ON(!mddev->serial_info_pool))
90+ return;
91+ si = mempool_alloc(mddev->serial_info_pool, GFP_NOIO);
92+ wait_event(serial->serial_io_wait,
93+ check_and_add_serial(rdev, r1_bio, si, idx) == 0);
94+}
95+
96+static void remove_serial(struct md_rdev *rdev, sector_t lo, sector_t hi)
8397 {
84− struct wb_info *wi;
98+ struct serial_info *si;
8599 unsigned long flags;
86100 int found = 0;
87101 struct mddev *mddev = rdev->mddev;
88−
89− spin_lock_irqsave(&rdev->wb_list_lock, flags);
90− list_for_each_entry(wi, &rdev->wb_list, list)
91− if (hi == wi->hi && lo == wi->lo) {
92− list_del(&wi->list);
93− mempool_free(wi, mddev->wb_info_pool);
102+ int idx = sector_to_idx(lo);
103+ struct serial_in_rdev *serial = &rdev->serial[idx];
104+
105+ spin_lock_irqsave(&serial->serial_lock, flags);
106+ for (si = raid1_rb_iter_first(&serial->serial_rb, lo, hi);
107+ si; si = raid1_rb_iter_next(si, lo, hi)) {
108+ if (si->start == lo && si->last == hi) {
109+ raid1_rb_remove(si, &serial->serial_rb);
110+ mempool_free(si, mddev->serial_info_pool);
94111 found = 1;
95112 break;
96113 }
97−
114+ }
98115 if (!found)
99− WARN(1, "The write behind IO is not recorded\n");
100− spin_unlock_irqrestore(&rdev->wb_list_lock, flags);
101− wake_up(&rdev->wb_io_wait);
116+ WARN(1, "The write IO is not recorded for serialization\n");
117+ spin_unlock_irqrestore(&serial->serial_lock, flags);
118+ wake_up(&serial->serial_io_wait);
102119 }
103120
104121 /*
@@ -430,6 +447,8 @@ static void raid1_end_write_request(struct bio *bio) · 325 unmodified lines
430447 int mirror = find_bio_disk(r1_bio, bio);
431448 struct md_rdev *rdev = conf->mirrors[mirror].rdev;
432449 bool discard_error;
450+ sector_t lo = r1_bio->sector;
451+ sector_t hi = r1_bio->sector + r1_bio->sectors;
433452
434453 discard_error = bio->bi_status && bio_op(bio) == REQ_OP_DISCARD;
435454
@@ -499,12 +518,8 @@ static void raid1_end_write_request(struct bio *bio) · 63 unmodified lines
499518 }
500519
501520 if (behind) {
502− if (test_bit(WBCollisionCheck, &rdev->flags)) {
503− sector_t lo = r1_bio->sector;
504− sector_t hi = r1_bio->sector + r1_bio->sectors;
505−
506− remove_wb(rdev, lo, hi);
507− }
521+ if (test_bit(CollisionCheck, &rdev->flags))
522+ remove_serial(rdev, lo, hi);
508523 if (test_bit(WriteMostly, &rdev->flags))
509524 atomic_dec(&r1_bio->behind_remaining);
510525
@@ -527,7 +542,8 @@ static void raid1_end_write_request(struct bio *bio) · 16 unmodified lines
527542 call_bio_endio(r1_bio);
528543 }
529544 }
530− }
545+ } else if (rdev->mddev->serialize_policy)
546+ remove_serial(rdev, lo, hi);
531547 if (r1_bio->bios[mirror] == NULL)
532548 rdev_dec_pending(rdev, conf->mddev);
533549
@@ -1479,6 +1495,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, · 945 unmodified lines
14791495
14801496 for (i = 0; i < disks; i++) {
14811497 struct bio *mbio = NULL;
1498+ struct md_rdev *rdev = conf->mirrors[i].rdev;
14821499 if (!r1_bio->bios[i])
14831500 continue;
14841501
@@ -1506,18 +1523,12 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, · 21 unmodified lines
15061523 mbio = bio_clone_fast(bio, GFP_NOIO, &mddev->bio_set);
15071524
15081525 if (r1_bio->behind_master_bio) {
1509− struct md_rdev *rdev = conf->mirrors[i].rdev;
1510−
1511− if (test_bit(WBCollisionCheck, &rdev->flags)) {
1512− sector_t lo = r1_bio->sector;
1513− sector_t hi = r1_bio->sector + r1_bio->sectors;
1514−
1515− wait_event(rdev->wb_io_wait,
1516− check_and_add_wb(rdev, lo, hi) == 0);
1517− }
1526+ if (test_bit(CollisionCheck, &rdev->flags))
1527+ wait_for_serialization(rdev, r1_bio);
15181528 if (test_bit(WriteMostly, &rdev->flags))
15191529 atomic_inc(&r1_bio->behind_remaining);
1520− }
1530+ } else if (mddev->serialize_policy)
1531+ wait_for_serialization(rdev, r1_bio);
15211532
15221533 r1_bio->bios[i] = mbio;
15231534
drivers/md/raid5.c+7−14
@@ -6598,7 +6598,6 @@ raid5_show_group_thread_cnt(struct mddev *mddev, char *page) · 6597 unmodified lines
65986598
65996599 static int alloc_thread_groups(struct r5conf *conf, int cnt,
66006600 int *group_cnt,
6601− int *worker_cnt_per_group,
66026601 struct r5worker_group **worker_groups);
66036602 static ssize_t
66046603 raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len)
@@ -6607,7 +6606,7 @@ raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) · 2 unmodified lines
66076606 unsigned int new;
66086607 int err;
66096608 struct r5worker_group *new_groups, *old_groups;
6610− int group_cnt, worker_cnt_per_group;
6609+ int group_cnt;
66116610
66126611 if (len >= PAGE_SIZE)
66136612 return -EINVAL;
@@ -6630,13 +6629,11 @@ raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len) · 16 unmodified lines
66306629 if (old_groups)
66316630 flush_workqueue(raid5_wq);
66326631
6633− err = alloc_thread_groups(conf, new,
6634− &group_cnt, &worker_cnt_per_group,
6635− &new_groups);
6632+ err = alloc_thread_groups(conf, new, &group_cnt, &new_groups);
66366633 if (!err) {
66376634 spin_lock_irq(&conf->device_lock);
66386635 conf->group_cnt = group_cnt;
6639− conf->worker_cnt_per_group = worker_cnt_per_group;
6636+ conf->worker_cnt_per_group = new;
66406637 conf->worker_groups = new_groups;
66416638 spin_unlock_irq(&conf->device_lock);
66426639
@@ -6672,16 +6669,13 @@ static struct attribute_group raid5_attrs_group = { · 29 unmodified lines
66726669 .attrs = raid5_attrs,
66736670 };
66746671
6675−static int alloc_thread_groups(struct r5conf *conf, int cnt,
6676− int *group_cnt,
6677− int *worker_cnt_per_group,
6672+static int alloc_thread_groups(struct r5conf *conf, int cnt, int *group_cnt,
66786673 struct r5worker_group **worker_groups)
66796674 {
66806675 int i, j, k;
66816676 ssize_t size;
66826677 struct r5worker *workers;
66836678
6684− *worker_cnt_per_group = cnt;
66856679 if (cnt == 0) {
66866680 *group_cnt = 0;
66876681 *worker_groups = NULL;
@@ -6882,7 +6876,7 @@ static struct r5conf *setup_conf(struct mddev *mddev) · 194 unmodified lines
68826876 struct disk_info *disk;
68836877 char pers_name[6];
68846878 int i;
6885− int group_cnt, worker_cnt_per_group;
6879+ int group_cnt;
68866880 struct r5worker_group *new_group;
68876881 int ret;
68886882
@@ -6928,10 +6922,9 @@ static struct r5conf *setup_conf(struct mddev *mddev) · 39 unmodified lines
69286922 for (i = 0; i < PENDING_IO_MAX; i++)
69296923 list_add(&conf->pending_data[i].sibling, &conf->free_list);
69306924 /* Don't enable multi-threading by default*/
6931− if (!alloc_thread_groups(conf, 0, &group_cnt, &worker_cnt_per_group,
6932− &new_group)) {
6925+ if (!alloc_thread_groups(conf, 0, &group_cnt, &new_group)) {
69336926 conf->group_cnt = group_cnt;
6934− conf->worker_cnt_per_group = worker_cnt_per_group;
6927+ conf->worker_cnt_per_group = 0;
69356928 conf->worker_groups = new_group;
69366929 } else
69376930 goto abort;
include/linux/raid/pq.h+6−1
@@ -27,8 +27,8 @@ extern const char raid6_empty_zero_page[PAGE_SIZE]; · 26 unmodified lines
2727
2828 #include <errno.h>
2929 #include <inttypes.h>
30−#include <limits.h>
3130 #include <stddef.h>
31+#include <string.h>
3232 #include <sys/mman.h>
3333 #include <sys/time.h>
3434 #include <sys/types.h>
@@ -44,6 +44,9 @@ typedef uint64_t u64; · 9 unmodified lines
4444 #ifndef PAGE_SIZE
4545 # define PAGE_SIZE 4096
4646 #endif
47+#ifndef PAGE_SHIFT
48+# define PAGE_SHIFT 12
49+#endif
4750 extern const char raid6_empty_zero_page[PAGE_SIZE];
4851
4952 #define __init
@@ -59,7 +62,9 @@ extern const char raid6_empty_zero_page[PAGE_SIZE]; · 9 unmodified lines
5962 #define enable_kernel_altivec()
6063 #define disable_kernel_altivec()
6164
65+#undef EXPORT_SYMBOL
6266 #define EXPORT_SYMBOL(sym)
67+#undef EXPORT_SYMBOL_GPL
6368 #define EXPORT_SYMBOL_GPL(sym)
6469 #define MODULE_LICENSE(licence)
6570 #define MODULE_DESCRIPTION(desc)
include/trace/events/bcache.h+2−1
@@ -275,7 +275,8 @@ TRACE_EVENT(bcache_btree_write, · 274 unmodified lines
275275 __entry->keys = b->keys.set[b->keys.nsets].data->keys;
276276 ),
277277
278− TP_printk("bucket %zu", __entry->bucket)
278+ TP_printk("bucket %zu written block %u + %u",
279+ __entry->bucket, __entry->block, __entry->keys)
279280 );
280281
281282 DEFINE_EVENT(btree_node, bcache_btree_node_alloc,
include/uapi/linux/bcache.h+52−0
@@ -148,6 +148,7 @@ static inline struct bkey *bkey_idx(const struct bkey *k, unsigned int nr_keys) · 147 unmodified lines
148148 #define BCACHE_SB_MAX_VERSION 4
149149
150150 #define SB_SECTOR 8
151+#define SB_OFFSET (SB_SECTOR << SECTOR_SHIFT)
151152 #define SB_SIZE 4096
152153 #define SB_LABEL_SIZE 32
153154 #define SB_JOURNAL_BUCKETS 256U
@@ -156,6 +157,57 @@ static inline struct bkey *bkey_idx(const struct bkey *k, unsigned int nr_keys) · 2 unmodified lines
156157
157158 #define BDEV_DATA_START_DEFAULT 16 /* sectors */
158159
160+struct cache_sb_disk {
161+ __le64 csum;
162+ __le64 offset; /* sector where this sb was written */
163+ __le64 version;
164+
165+ __u8 magic[16];
166+
167+ __u8 uuid[16];
168+ union {
169+ __u8 set_uuid[16];
170+ __le64 set_magic;
171+ };
172+ __u8 label[SB_LABEL_SIZE];
173+
174+ __le64 flags;
175+ __le64 seq;
176+ __le64 pad[8];
177+
178+ union {
179+ struct {
180+ /* Cache devices */
181+ __le64 nbuckets; /* device size */
182+
183+ __le16 block_size; /* sectors */
184+ __le16 bucket_size; /* sectors */
185+
186+ __le16 nr_in_set;
187+ __le16 nr_this_dev;
188+ };
189+ struct {
190+ /* Backing devices */
191+ __le64 data_offset;
192+
193+ /*
194+ * block_size from the cache device section is still used by
195+ * backing devices, so don't add anything here until we fix
196+ * things to not need it for backing devices anymore
197+ */
198+ };
199+ };
200+
201+ __le32 last_mount; /* time overflow in y2106 */
202+
203+ __le16 first_bucket;
204+ union {
205+ __le16 njournal_buckets;
206+ __le16 keys;
207+ };
208+ __le64 d[SB_JOURNAL_BUCKETS]; /* journal buckets */
209+};
210+
159211 struct cache_sb {
160212 __u64 csum;
161213 __u64 offset; /* sector where this sb was written */
lib/crc64.c+1−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828
2929 #include <linux/module.h>
3030 #include <linux/types.h>
31+#include <linux/crc64.h>
3132 #include "crc64table.h"
3233
3334 MODULE_DESCRIPTION("CRC64 calculations");
lib/raid6/algos.c+40−23
@@ -124,6 +124,9 @@ const struct raid6_recov_calls *const raid6_recov_algos[] = { · 123 unmodified lines
124124 #define time_before(x, y) ((x) < (y))
125125 #endif
126126
127+#define RAID6_TEST_DISKS 8
128+#define RAID6_TEST_DISKS_ORDER 3
129+
127130 static inline const struct raid6_recov_calls *raid6_choose_recov(void)
128131 {
129132 const struct raid6_recov_calls *const *algo;
@@ -146,7 +149,7 @@ static inline const struct raid6_recov_calls *raid6_choose_recov(void) · 16 unmodified lines
146149 }
147150
148151 static inline const struct raid6_calls *raid6_choose_gen(
149− void *(*const dptrs)[(65536/PAGE_SIZE)+2], const int disks)
152+ void *(*const dptrs)[RAID6_TEST_DISKS], const int disks)
150153 {
151154 unsigned long perf, bestgenperf, bestxorperf, j0, j1;
152155 int start = (disks>>1)-1, stop = disks-3; /* work on the second half of the disks */
@@ -181,7 +184,8 @@ static inline const struct raid6_calls *raid6_choose_gen( · 28 unmodified lines
181184 best = *algo;
182185 }
183186 pr_info("raid6: %-8s gen() %5ld MB/s\n", (*algo)->name,
184− (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2));
187+ (perf * HZ * (disks-2)) >>
188+ (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2));
185189
186190 if (!(*algo)->xor_syndrome)
187191 continue;
@@ -204,17 +208,24 @@ static inline const struct raid6_calls *raid6_choose_gen( · 16 unmodified lines
204208 bestxorperf = perf;
205209
206210 pr_info("raid6: %-8s xor() %5ld MB/s\n", (*algo)->name,
207− (perf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2+1));
211+ (perf * HZ * (disks-2)) >>
212+ (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1));
208213 }
209214 }
210215
211216 if (best) {
212− pr_info("raid6: using algorithm %s gen() %ld MB/s\n",
213− best->name,
214− (bestgenperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2));
215− if (best->xor_syndrome)
216− pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n",
217− (bestxorperf*HZ) >> (20-16+RAID6_TIME_JIFFIES_LG2+1));
217+ if (IS_ENABLED(CONFIG_RAID6_PQ_BENCHMARK)) {
218+ pr_info("raid6: using algorithm %s gen() %ld MB/s\n",
219+ best->name,
220+ (bestgenperf * HZ * (disks-2)) >>
221+ (20 - PAGE_SHIFT+RAID6_TIME_JIFFIES_LG2));
222+ if (best->xor_syndrome)
223+ pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n",
224+ (bestxorperf * HZ * (disks-2)) >>
225+ (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1));
226+ } else
227+ pr_info("raid6: skip pq benchmark and using algorithm %s\n",
228+ best->name);
218229 raid6_call = *best;
219230 } else
220231 pr_err("raid6: Yikes! No algorithm found!\n");
@@ -228,27 +239,33 @@ static inline const struct raid6_calls *raid6_choose_gen( · 7 unmodified lines
228239
229240 int __init raid6_select_algo(void)
230241 {
231− const int disks = (65536/PAGE_SIZE)+2;
242+ const int disks = RAID6_TEST_DISKS;
232243
233244 const struct raid6_calls *gen_best;
234245 const struct raid6_recov_calls *rec_best;
235− char *syndromes;
236− void *dptrs[(65536/PAGE_SIZE)+2];
237− int i;
238−
239− for (i = 0; i < disks-2; i++)
240− dptrs[i] = ((char *)raid6_gfmul) + PAGE_SIZE*i;
241−
242− /* Normal code - use a 2-page allocation to avoid D$ conflict */
243− syndromes = (void *) __get_free_pages(GFP_KERNEL, 1);
246+ char *disk_ptr, *p;
247+ void *dptrs[RAID6_TEST_DISKS];
248+ int i, cycle;
244249
245− if (!syndromes) {
250+ /* prepare the buffer and fill it circularly with gfmul table */
251+ disk_ptr = (char *)__get_free_pages(GFP_KERNEL, RAID6_TEST_DISKS_ORDER);
252+ if (!disk_ptr) {
246253 pr_err("raid6: Yikes! No memory available.\n");
247254 return -ENOMEM;
248255 }
249256
250− dptrs[disks-2] = syndromes;
251− dptrs[disks-1] = syndromes + PAGE_SIZE;
257+ p = disk_ptr;
258+ for (i = 0; i < disks; i++)
259+ dptrs[i] = p + PAGE_SIZE * i;
260+
261+ cycle = ((disks - 2) * PAGE_SIZE) / 65536;
262+ for (i = 0; i < cycle; i++) {
263+ memcpy(p, raid6_gfmul, 65536);
264+ p += 65536;
265+ }
266+
267+ if ((disks - 2) * PAGE_SIZE % 65536)
268+ memcpy(p, raid6_gfmul, (disks - 2) * PAGE_SIZE % 65536);
252269
253270 /* select raid gen_syndrome function */
254271 gen_best = raid6_choose_gen(&dptrs, disks);
@@ -256,7 +273,7 @@ int __init raid6_select_algo(void) · 1 unmodified line
256273 /* select raid recover functions */
257274 rec_best = raid6_choose_recov();
258275
259− free_pages((unsigned long)syndromes, 1);
276+ free_pages((unsigned long)disk_ptr, RAID6_TEST_DISKS_ORDER);
260277
261278 return gen_best && rec_best ? 0 : -EINVAL;
262279 }
lib/raid6/mktables.c+1−1
@@ -56,8 +56,8 @@ int main(int argc, char *argv[]) · 55 unmodified lines
5656 uint8_t v;
5757 uint8_t exptbl[256], invtbl[256];
5858
59− printf("#include <linux/raid/pq.h>\n");
6059 printf("#include <linux/export.h>\n");
60+ printf("#include <linux/raid/pq.h>\n");
6161
6262 /* Compute multiplication table */
6363 printf("\nconst u8 __attribute__((aligned(256)))\n"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t