From: Ming Lei <ming.lei@redhat.com>
To: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-scsi@vger.kernel.org, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH V2 05/13] block: only account passthrough IO from userspace
Date: Sat, 22 Jan 2022 19:10:46 +0800 [thread overview]
Message-ID: <20220122111054.1126146-6-ming.lei@redhat.com> (raw)
In-Reply-To: <20220122111054.1126146-1-ming.lei@redhat.com>
Passthrough request from userspace has one active block_device/disk
associated, so they can be accounted via rq->q->disk. For other
passthrough request, there may not be disk/block_device for the queue,
since either the queue has not a disk or the disk may be deleted
already.
Add flag of BLK_MQ_REQ_USER_IO for only accounting passthrough request
from userspace.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-mq.c | 13 ++++++++++++-
drivers/nvme/host/ioctl.c | 2 +-
drivers/scsi/scsi_ioctl.c | 3 ++-
include/linux/blk-mq.h | 2 ++
4 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a6d4780580fc..0d25cc5778c9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -336,6 +336,17 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
}
EXPORT_SYMBOL(blk_rq_init);
+static inline bool blk_mq_io_may_account(struct blk_mq_alloc_data *data)
+{
+ if (!blk_op_is_passthrough(data->cmd_flags))
+ return true;
+
+ if (data->flags & BLK_MQ_REQ_USER_IO)
+ return true;
+
+ return false;
+}
+
static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
struct blk_mq_tags *tags, unsigned int tag, u64 alloc_time_ns)
{
@@ -351,7 +362,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
if (data->flags & BLK_MQ_REQ_PM)
data->rq_flags |= RQF_PM;
- if (blk_queue_io_stat(q))
+ if (blk_queue_io_stat(q) && blk_mq_io_may_account(data))
data->rq_flags |= RQF_IO_STAT;
rq->rq_flags = data->rq_flags;
diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 22314962842d..f94afc38a6e3 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -66,7 +66,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
void *meta = NULL;
int ret;
- req = nvme_alloc_request(q, cmd, 0);
+ req = nvme_alloc_request(q, cmd, BLK_MQ_REQ_USER_IO);
if (IS_ERR(req))
return PTR_ERR(req);
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index e13fd380deb6..b262fe06dacc 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -440,7 +440,8 @@ static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr, fmode_t mode)
ret = -ENOMEM;
rq = scsi_alloc_request(sdev->request_queue, writing ?
- REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
+ REQ_OP_DRV_OUT : REQ_OP_DRV_IN,
+ BLK_MQ_REQ_USER_IO);
if (IS_ERR(rq))
return PTR_ERR(rq);
req = scsi_req(rq);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index d319ffa59354..d2ad2ed11723 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -709,6 +709,8 @@ enum {
BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 << 1),
/* set RQF_PM */
BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 2),
+ /* user IO request */
+ BLK_MQ_REQ_USER_IO = (__force blk_mq_req_flags_t)(1 << 3),
};
struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
--
2.31.1
next prev parent reply other threads:[~2022-01-22 11:12 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-22 11:10 [PATCH V2 00/13] block: don't drain file system I/O on del_gendisk Ming Lei
2022-01-22 11:10 ` [PATCH V2 01/13] block: declare blkcg_[init|exit]_queue in private header Ming Lei
2022-01-24 12:59 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 02/13] block: move initialization of q->blkg_list into blkcg_init_queue Ming Lei
2022-01-24 13:00 ` Christoph Hellwig
2022-01-24 18:32 ` Bart Van Assche
2022-01-22 11:10 ` [PATCH V2 03/13] block: move blkcg initialization/destroy into disk allocation/release handler Ming Lei
2022-01-24 13:02 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 04/13] block/wbt: fix negative inflight counter when remove scsi device Ming Lei
2022-02-17 7:45 ` Christoph Hellwig
2022-02-17 14:53 ` Jens Axboe
2022-01-22 11:10 ` Ming Lei [this message]
2022-01-24 13:05 ` [PATCH V2 05/13] block: only account passthrough IO from userspace Christoph Hellwig
2022-01-24 23:09 ` Ming Lei
2022-01-25 6:16 ` Christoph Hellwig
2022-01-25 7:19 ` Christoph Hellwig
2022-01-25 8:35 ` Ming Lei
2022-01-25 9:09 ` Ming Lei
2022-01-26 5:50 ` Christoph Hellwig
2022-01-26 7:21 ` Ming Lei
2022-01-26 8:10 ` Christoph Hellwig
2022-01-26 8:33 ` Ming Lei
2022-01-26 8:49 ` Christoph Hellwig
2022-01-26 9:59 ` Ming Lei
2022-01-26 16:37 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 06/13] block: don't remove hctx debugfs dir from blk_mq_exit_queue Ming Lei
2022-01-24 13:06 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 07/13] block: move q_usage_counter release into blk_queue_release Ming Lei
2022-01-24 13:09 ` Christoph Hellwig
2022-01-24 19:06 ` Bart Van Assche
2022-01-22 11:10 ` [PATCH V2 08/13] block: export __blk_mq_unfreeze_queue Ming Lei
2022-01-24 13:11 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 09/13] scsi: force unfreezing queue into atomic mode Ming Lei
2022-01-24 13:15 ` Christoph Hellwig
2022-01-24 23:21 ` Ming Lei
2022-01-25 7:27 ` Christoph Hellwig
2022-01-25 8:54 ` Ming Lei
2022-01-26 8:15 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 10/13] block: add helper of disk_release_queue for release queue data for disk Ming Lei
2022-01-24 13:16 ` Christoph Hellwig
2022-01-24 23:27 ` Ming Lei
2022-01-25 6:17 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 11/13] block: move blk_exit_queue into disk_release Ming Lei
2022-01-24 13:22 ` Christoph Hellwig
2022-01-24 23:38 ` Ming Lei
2022-01-22 11:10 ` [PATCH V2 12/13] block: move rq_qos_exit() into disk_release() Ming Lei
2022-01-24 13:28 ` Christoph Hellwig
2022-01-22 11:10 ` [PATCH V2 13/13] block: don't drain file system I/O on del_gendisk Ming Lei
2022-01-24 13:39 ` Christoph Hellwig
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=20220122111054.1126146-6-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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 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).