2010-06-23 03:26:18

by Tao Ma

[permalink] [raw]
Subject: [PATCH] block: Don't count_vm_events for discard bio in submit_bio.

In submit_bio, we count vm events by check READ/WRITE.
But actually DISCARD_NOBARRIER also has the WRITE flag set.
It looks as if in blkdev_issue_discard, we also add a
page as the payload and the bio_has_data check isn't enough.
So add another check for discard bio.

Cc: Jens Axboe <[email protected]>
Signed-off-by: Tao Ma <[email protected]>
---
block/blk-core.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index f84cce4..a725602 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1586,7 +1586,7 @@ void submit_bio(int rw, struct bio *bio)
* If it's a regular read/write or a barrier with data attached,
* go through the normal accounting stuff before submission.
*/
- if (bio_has_data(bio)) {
+ if (bio_has_data(bio) && !(rw & BIO_RW_DISCARD)) {
if (rw & WRITE) {
count_vm_events(PGPGOUT, count);
} else {
--
1.5.5


2010-06-23 19:41:14

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] block: Don't count_vm_events for discard bio in submit_bio.

On Wed, 23 Jun 2010 11:24:51 +0800
Tao Ma <[email protected]> wrote:

> In submit_bio, we count vm events by check READ/WRITE.
> But actually DISCARD_NOBARRIER also has the WRITE flag set.
> It looks as if in blkdev_issue_discard, we also add a
> page as the payload and the bio_has_data check isn't enough.
> So add another check for discard bio.
>
> Cc: Jens Axboe <[email protected]>
> Signed-off-by: Tao Ma <[email protected]>
> ---
> block/blk-core.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/block/blk-core.c b/block/blk-core.c
> index f84cce4..a725602 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -1586,7 +1586,7 @@ void submit_bio(int rw, struct bio *bio)
> * If it's a regular read/write or a barrier with data attached,
> * go through the normal accounting stuff before submission.
> */
> - if (bio_has_data(bio)) {
> + if (bio_has_data(bio) && !(rw & BIO_RW_DISCARD)) {
> if (rw & WRITE) {
> count_vm_events(PGPGOUT, count);
> } else {

Yes, that's a buglet.

Note that Christoph's "[PATCH, RFC] block: don't allocate a payload for
discard request" will fix it in a better way. That patch is in
linux-next now, but I expect it will be taken out again (quickly,
please) because Mike has found a number of problems with it.

Your patch looks like a decent temporary fix for mainline, and a
permanent one for -stable.

2010-06-23 20:41:53

by Mike Snitzer

[permalink] [raw]
Subject: Re: block: Don't count_vm_events for discard bio in submit_bio.

On Wed, Jun 23 2010 at 3:40pm -0400,
Andrew Morton <[email protected]> wrote:

> On Wed, 23 Jun 2010 11:24:51 +0800
> Tao Ma <[email protected]> wrote:
>
> > In submit_bio, we count vm events by check READ/WRITE.
> > But actually DISCARD_NOBARRIER also has the WRITE flag set.
> > It looks as if in blkdev_issue_discard, we also add a
> > page as the payload and the bio_has_data check isn't enough.
> > So add another check for discard bio.
> >
> > Cc: Jens Axboe <[email protected]>
> > Signed-off-by: Tao Ma <[email protected]>
> > ---
> > block/blk-core.c | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/block/blk-core.c b/block/blk-core.c
> > index f84cce4..a725602 100644
> > --- a/block/blk-core.c
> > +++ b/block/blk-core.c
> > @@ -1586,7 +1586,7 @@ void submit_bio(int rw, struct bio *bio)
> > * If it's a regular read/write or a barrier with data attached,
> > * go through the normal accounting stuff before submission.
> > */
> > - if (bio_has_data(bio)) {
> > + if (bio_has_data(bio) && !(rw & BIO_RW_DISCARD)) {
> > if (rw & WRITE) {
> > count_vm_events(PGPGOUT, count);
> > } else {
>
> Yes, that's a buglet.
>
> Note that Christoph's "[PATCH, RFC] block: don't allocate a payload for
> discard request" will fix it in a better way.

Oddly, even with Christoph's patch, bio_has_data() is still true once
the discard bio gets to DM.

Figuring out why is on my near-term TODO.

Mike

2010-06-24 00:30:19

by Tao Ma

[permalink] [raw]
Subject: [PATCH v2] block: Don't count_vm_events for discard bio in submit_bio.

Hi Andrew,
> Yes, that's a buglet.
>
> Note that Christoph's "[PATCH, RFC] block: don't allocate a payload for
> discard request" will fix it in a better way. That patch is in
> linux-next now, but I expect it will be taken out again (quickly,
> please) because Mike has found a number of problems with it.
ok, I haven't noticed that. thanks for the info.
>
> Your patch looks like a decent temporary fix for mainline, and a
> permanent one for -stable.
I am sorry, but I made a mistake. BIO_RW_DISCARD is a enum for bit offset.
So the right check should be rw & (1 << BIO_RW_DISCARD).
I have regenerated the patch. Sorry for the inconvenience.

Regards,
Tao

>From 060630d842a987a518c648ff65160639100c9a1b Mon Sep 17 00:00:00 2001
From: Tao Ma <[email protected]>
Date: Thu, 24 Jun 2010 07:43:57 +0800
Subject: [PATCH v2] block: Don't count_vm_events for discard bio in submit_bio.

In submit_bio, we count vm events by check READ/WRITE.
But actually DISCARD_NOBARRIER also has the WRITE flag set.
It looks as if in blkdev_issue_discard, we also add a
page as the payload and the bio_has_data check isn't enough.
So add another check for discard bio.

Signed-off-by: Tao Ma <[email protected]>
---
block/blk-core.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index f84cce4..26aa542 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1586,7 +1586,7 @@ void submit_bio(int rw, struct bio *bio)
* If it's a regular read/write or a barrier with data attached,
* go through the normal accounting stuff before submission.
*/
- if (bio_has_data(bio)) {
+ if (bio_has_data(bio) && !(rw & (1 << BIO_RW_DISCARD))) {
if (rw & WRITE) {
count_vm_events(PGPGOUT, count);
} else {
--
1.5.5

2010-06-24 06:14:43

by Jens Axboe

[permalink] [raw]
Subject: Re: [PATCH v2] block: Don't count_vm_events for discard bio in submit_bio.

On 2010-06-24 02:28, Tao Ma wrote:
> Hi Andrew,
>> Yes, that's a buglet.
>>
>> Note that Christoph's "[PATCH, RFC] block: don't allocate a payload for
>> discard request" will fix it in a better way. That patch is in
>> linux-next now, but I expect it will be taken out again (quickly,
>> please) because Mike has found a number of problems with it.
> ok, I haven't noticed that. thanks for the info.
>>
>> Your patch looks like a decent temporary fix for mainline, and a
>> permanent one for -stable.
> I am sorry, but I made a mistake. BIO_RW_DISCARD is a enum for bit offset.
> So the right check should be rw & (1 << BIO_RW_DISCARD).
> I have regenerated the patch. Sorry for the inconvenience.

Thanks, this one looks good. Applied.

--
Jens Axboe