Commit 9e444768 authored by Shaohua Li's avatar Shaohua Li Committed by NeilBrown

MD: raid5 avoid unnecessary zero page for trim

We want to avoid zero discarded dev page, because it's useless for discard.
But if we don't zero it, another read/write hit such page in the cache and will
get inconsistent data.

To avoid zero the page, we don't set R5_UPTODATE flag after construction is
done. In this way, discard write request is still issued and finished, but read
will not hit the page. If the stripe gets accessed soon, we need reread the
stripe, but since the chance is low, the reread isn't a big deal.
Signed-off-by: default avatarShaohua Li <shli@fusionio.com>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent 620125f2
...@@ -547,7 +547,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s) ...@@ -547,7 +547,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
rw = WRITE_FUA; rw = WRITE_FUA;
else else
rw = WRITE; rw = WRITE;
if (test_and_clear_bit(R5_Discard, &sh->dev[i].flags)) if (test_bit(R5_Discard, &sh->dev[i].flags))
rw |= REQ_DISCARD; rw |= REQ_DISCARD;
} else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags)) } else if (test_and_clear_bit(R5_Wantread, &sh->dev[i].flags))
rw = READ; rw = READ;
...@@ -1172,11 +1172,9 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx) ...@@ -1172,11 +1172,9 @@ ops_run_biodrain(struct stripe_head *sh, struct dma_async_tx_descriptor *tx)
set_bit(R5_WantFUA, &dev->flags); set_bit(R5_WantFUA, &dev->flags);
if (wbi->bi_rw & REQ_SYNC) if (wbi->bi_rw & REQ_SYNC)
set_bit(R5_SyncIO, &dev->flags); set_bit(R5_SyncIO, &dev->flags);
if (wbi->bi_rw & REQ_DISCARD) { if (wbi->bi_rw & REQ_DISCARD)
memset(page_address(dev->page), 0,
STRIPE_SECTORS << 9);
set_bit(R5_Discard, &dev->flags); set_bit(R5_Discard, &dev->flags);
} else else
tx = async_copy_data(1, wbi, dev->page, tx = async_copy_data(1, wbi, dev->page,
dev->sector, tx); dev->sector, tx);
wbi = r5_next_bio(wbi, dev->sector); wbi = r5_next_bio(wbi, dev->sector);
...@@ -1194,7 +1192,7 @@ static void ops_complete_reconstruct(void *stripe_head_ref) ...@@ -1194,7 +1192,7 @@ static void ops_complete_reconstruct(void *stripe_head_ref)
int pd_idx = sh->pd_idx; int pd_idx = sh->pd_idx;
int qd_idx = sh->qd_idx; int qd_idx = sh->qd_idx;
int i; int i;
bool fua = false, sync = false; bool fua = false, sync = false, discard = false;
pr_debug("%s: stripe %llu\n", __func__, pr_debug("%s: stripe %llu\n", __func__,
(unsigned long long)sh->sector); (unsigned long long)sh->sector);
...@@ -1202,13 +1200,15 @@ static void ops_complete_reconstruct(void *stripe_head_ref) ...@@ -1202,13 +1200,15 @@ static void ops_complete_reconstruct(void *stripe_head_ref)
for (i = disks; i--; ) { for (i = disks; i--; ) {
fua |= test_bit(R5_WantFUA, &sh->dev[i].flags); fua |= test_bit(R5_WantFUA, &sh->dev[i].flags);
sync |= test_bit(R5_SyncIO, &sh->dev[i].flags); sync |= test_bit(R5_SyncIO, &sh->dev[i].flags);
discard |= test_bit(R5_Discard, &sh->dev[i].flags);
} }
for (i = disks; i--; ) { for (i = disks; i--; ) {
struct r5dev *dev = &sh->dev[i]; struct r5dev *dev = &sh->dev[i];
if (dev->written || i == pd_idx || i == qd_idx) { if (dev->written || i == pd_idx || i == qd_idx) {
set_bit(R5_UPTODATE, &dev->flags); if (!discard)
set_bit(R5_UPTODATE, &dev->flags);
if (fua) if (fua)
set_bit(R5_WantFUA, &dev->flags); set_bit(R5_WantFUA, &dev->flags);
if (sync) if (sync)
...@@ -1252,8 +1252,6 @@ ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu, ...@@ -1252,8 +1252,6 @@ ops_run_reconstruct5(struct stripe_head *sh, struct raid5_percpu *percpu,
} }
if (i >= sh->disks) { if (i >= sh->disks) {
atomic_inc(&sh->count); atomic_inc(&sh->count);
memset(page_address(sh->dev[pd_idx].page), 0,
STRIPE_SECTORS << 9);
set_bit(R5_Discard, &sh->dev[pd_idx].flags); set_bit(R5_Discard, &sh->dev[pd_idx].flags);
ops_complete_reconstruct(sh); ops_complete_reconstruct(sh);
return; return;
...@@ -1314,10 +1312,6 @@ ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu, ...@@ -1314,10 +1312,6 @@ ops_run_reconstruct6(struct stripe_head *sh, struct raid5_percpu *percpu,
} }
if (i >= sh->disks) { if (i >= sh->disks) {
atomic_inc(&sh->count); atomic_inc(&sh->count);
memset(page_address(sh->dev[sh->pd_idx].page), 0,
STRIPE_SECTORS << 9);
memset(page_address(sh->dev[sh->qd_idx].page), 0,
STRIPE_SECTORS << 9);
set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags); set_bit(R5_Discard, &sh->dev[sh->pd_idx].flags);
set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags); set_bit(R5_Discard, &sh->dev[sh->qd_idx].flags);
ops_complete_reconstruct(sh); ops_complete_reconstruct(sh);
...@@ -2775,7 +2769,8 @@ static void handle_stripe_clean_event(struct r5conf *conf, ...@@ -2775,7 +2769,8 @@ static void handle_stripe_clean_event(struct r5conf *conf,
if (sh->dev[i].written) { if (sh->dev[i].written) {
dev = &sh->dev[i]; dev = &sh->dev[i];
if (!test_bit(R5_LOCKED, &dev->flags) && if (!test_bit(R5_LOCKED, &dev->flags) &&
test_bit(R5_UPTODATE, &dev->flags)) { (test_bit(R5_UPTODATE, &dev->flags) ||
test_and_clear_bit(R5_Discard, &dev->flags))) {
/* We can return any write requests */ /* We can return any write requests */
struct bio *wbi, *wbi2; struct bio *wbi, *wbi2;
pr_debug("Return write for disc %d\n", i); pr_debug("Return write for disc %d\n", i);
...@@ -3493,10 +3488,12 @@ static void handle_stripe(struct stripe_head *sh) ...@@ -3493,10 +3488,12 @@ static void handle_stripe(struct stripe_head *sh)
if (s.written && if (s.written &&
(s.p_failed || ((test_bit(R5_Insync, &pdev->flags) (s.p_failed || ((test_bit(R5_Insync, &pdev->flags)
&& !test_bit(R5_LOCKED, &pdev->flags) && !test_bit(R5_LOCKED, &pdev->flags)
&& test_bit(R5_UPTODATE, &pdev->flags)))) && && (test_bit(R5_UPTODATE, &pdev->flags) ||
test_bit(R5_Discard, &pdev->flags))))) &&
(s.q_failed || ((test_bit(R5_Insync, &qdev->flags) (s.q_failed || ((test_bit(R5_Insync, &qdev->flags)
&& !test_bit(R5_LOCKED, &qdev->flags) && !test_bit(R5_LOCKED, &qdev->flags)
&& test_bit(R5_UPTODATE, &qdev->flags))))) && (test_bit(R5_UPTODATE, &qdev->flags) ||
test_bit(R5_Discard, &qdev->flags))))))
handle_stripe_clean_event(conf, sh, disks, &s.return_bi); handle_stripe_clean_event(conf, sh, disks, &s.return_bi);
/* Now we might consider reading some blocks, either to check/generate /* Now we might consider reading some blocks, either to check/generate
...@@ -3523,9 +3520,11 @@ static void handle_stripe(struct stripe_head *sh) ...@@ -3523,9 +3520,11 @@ static void handle_stripe(struct stripe_head *sh)
/* All the 'written' buffers and the parity block are ready to /* All the 'written' buffers and the parity block are ready to
* be written back to disk * be written back to disk
*/ */
BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags)); BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[sh->pd_idx].flags) &&
!test_bit(R5_Discard, &sh->dev[sh->pd_idx].flags));
BUG_ON(sh->qd_idx >= 0 && BUG_ON(sh->qd_idx >= 0 &&
!test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags)); !test_bit(R5_UPTODATE, &sh->dev[sh->qd_idx].flags) &&
!test_bit(R5_Discard, &sh->dev[sh->qd_idx].flags));
for (i = disks; i--; ) { for (i = disks; i--; ) {
struct r5dev *dev = &sh->dev[i]; struct r5dev *dev = &sh->dev[i];
if (test_bit(R5_LOCKED, &dev->flags) && if (test_bit(R5_LOCKED, &dev->flags) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment