All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Subject: [PATCH] block: fix -EAGAIN IOPOLL task/vm accounting
Date: Sat, 29 Aug 2020 10:51:11 -0600	[thread overview]
Message-ID: <d27ff6f0-9347-e880-fa9d-514e993014dc@kernel.dk> (raw)

We currently increment the task/vm counts when we first attempt to queue a
bio. But this isn't necessarily correct - if the request allocation fails
with -EAGAIN, for example, and the caller retries, then we'll over-account
by as many retries as are done.

This can happen for polled IO, where we cannot wait for requests. Hence
retries can get aggressive, if we're running out of requests. If this
happens, then watching the IO rates in vmstat are incorrect as they count
every issue attempt as successful and hence the stats are inflated by
quite a lot potentially.

Add a bio flag to know if we've done accounting or not. This prevents
the same bio from being accounted potentially many times, when retried.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/block/blk-core.c b/block/blk-core.c
index d9d632639bd1..ff562a8cd9c9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1236,7 +1236,7 @@ blk_qc_t submit_bio(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) && !bio_flagged(bio, BIO_ACCOUNTED)) {
 		unsigned int count;
 
 		if (unlikely(bio_op(bio) == REQ_OP_WRITE_SAME))
@@ -1259,6 +1259,7 @@ blk_qc_t submit_bio(struct bio *bio)
 				(unsigned long long)bio->bi_iter.bi_sector,
 				bio_devname(bio, b), count);
 		}
+		bio_set_flag(bio, BIO_ACCOUNTED);
 	}
 
 	/*
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 63a39e47fc60..39bcc9326c7a 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -266,6 +266,7 @@ enum {
 				 * of this bio. */
 	BIO_CGROUP_ACCT,	/* has been accounted to a cgroup */
 	BIO_TRACKED,		/* set if bio goes through the rq_qos path */
+	BIO_ACCOUNTED,		/* task/vm stats have been done */
 	BIO_FLAG_LAST
 };
 
-- 
Jens Axboe


             reply	other threads:[~2020-08-29 16:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-29 16:51 Jens Axboe [this message]
2020-08-30  6:26 ` [PATCH] block: fix -EAGAIN IOPOLL task/vm accounting Christoph Hellwig
2020-08-30 15:09   ` Jens Axboe
2020-08-30 15:28     ` Christoph Hellwig
2020-08-31  3:12       ` Ming Lei
2020-08-31 14:02       ` Jens Axboe
2020-08-31 14:12         ` Christoph Hellwig
2020-08-31 14:18           ` Jens Axboe
2020-09-01  5:42             ` Christoph Hellwig
2020-09-01 14:01               ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d27ff6f0-9347-e880-fa9d-514e993014dc@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.