From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, "Christoph Hellwig" <hch@lst.de>,
"Ming Lei" <ming.lei@redhat.com>,
"Michal Koutný" <mkoutny@suse.com>,
"Dan Schatzberg" <schatzberg.dan@gmail.com>
Subject: [PATCH 1/6] loop: clean up blkcg association
Date: Mon, 5 Jul 2021 18:26:02 +0800 [thread overview]
Message-ID: <20210705102607.127810-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20210705102607.127810-1-ming.lei@redhat.com>
Each loop_worker is responsible for running requests originated from
same blkcg, so:
1) associate with kthread in the entry of loop_process_work(), and
disassociate in the end of this function, then we can avoid to do
both for each request.
2) remove ->blkcg_css and ->memcg_css from 'loop_cmd' since both are
per loop_worker.
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Dan Schatzberg <schatzberg.dan@gmail.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/block/loop.c | 67 ++++++++++++++++++++------------------------
drivers/block/loop.h | 2 --
2 files changed, 30 insertions(+), 39 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 02509bc54242..8378b8455f7c 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -949,10 +949,17 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
struct loop_worker *cur_worker, *worker = NULL;
struct work_struct *work;
struct list_head *cmd_list;
+ struct cgroup_subsys_state *blkcg_css = NULL;
+#ifdef CONFIG_BLK_CGROUP
+ struct request *rq = blk_mq_rq_from_pdu(cmd);
+
+ if (rq->bio && rq->bio->bi_blkg)
+ blkcg_css = &bio_blkcg(rq->bio)->css;
+#endif
spin_lock_irq(&lo->lo_work_lock);
- if (queue_on_root_worker(cmd->blkcg_css))
+ if (queue_on_root_worker(blkcg_css))
goto queue_work;
node = &lo->worker_tree.rb_node;
@@ -960,10 +967,10 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
while (*node) {
parent = *node;
cur_worker = container_of(*node, struct loop_worker, rb_node);
- if (cur_worker->blkcg_css == cmd->blkcg_css) {
+ if (cur_worker->blkcg_css == blkcg_css) {
worker = cur_worker;
break;
- } else if ((long)cur_worker->blkcg_css < (long)cmd->blkcg_css) {
+ } else if ((long)cur_worker->blkcg_css < (long)blkcg_css) {
node = &(*node)->rb_left;
} else {
node = &(*node)->rb_right;
@@ -977,15 +984,10 @@ static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
* In the event we cannot allocate a worker, just queue on the
* rootcg worker and issue the I/O as the rootcg
*/
- if (!worker) {
- cmd->blkcg_css = NULL;
- if (cmd->memcg_css)
- css_put(cmd->memcg_css);
- cmd->memcg_css = NULL;
+ if (!worker)
goto queue_work;
- }
- worker->blkcg_css = cmd->blkcg_css;
+ worker->blkcg_css = blkcg_css;
css_get(worker->blkcg_css);
INIT_WORK(&worker->work, loop_workfn);
INIT_LIST_HEAD(&worker->cmd_list);
@@ -2100,19 +2102,6 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
break;
}
- /* always use the first bio's css */
- cmd->blkcg_css = NULL;
- cmd->memcg_css = NULL;
-#ifdef CONFIG_BLK_CGROUP
- if (rq->bio && rq->bio->bi_blkg) {
- cmd->blkcg_css = &bio_blkcg(rq->bio)->css;
-#ifdef CONFIG_MEMCG
- cmd->memcg_css =
- cgroup_get_e_css(cmd->blkcg_css->cgroup,
- &memory_cgrp_subsys);
-#endif
- }
-#endif
loop_queue_work(lo, cmd);
return BLK_STS_OK;
@@ -2124,28 +2113,14 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
const bool write = op_is_write(req_op(rq));
struct loop_device *lo = rq->q->queuedata;
int ret = 0;
- struct mem_cgroup *old_memcg = NULL;
if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY)) {
ret = -EIO;
goto failed;
}
- if (cmd->blkcg_css)
- kthread_associate_blkcg(cmd->blkcg_css);
- if (cmd->memcg_css)
- old_memcg = set_active_memcg(
- mem_cgroup_from_css(cmd->memcg_css));
-
ret = do_req_filebacked(lo, rq);
- if (cmd->blkcg_css)
- kthread_associate_blkcg(NULL);
-
- if (cmd->memcg_css) {
- set_active_memcg(old_memcg);
- css_put(cmd->memcg_css);
- }
failed:
/* complete non-aio request */
if (!cmd->use_aio || ret) {
@@ -2201,7 +2176,25 @@ static void loop_workfn(struct work_struct *work)
{
struct loop_worker *worker =
container_of(work, struct loop_worker, work);
+ struct mem_cgroup *old_memcg = NULL;
+ struct cgroup_subsys_state *memcg_css = NULL;
+
+ kthread_associate_blkcg(worker->blkcg_css);
+#ifdef CONFIG_MEMCG
+ memcg_css = cgroup_get_e_css(worker->blkcg_css->cgroup,
+ &memory_cgrp_subsys);
+#endif
+ if (memcg_css)
+ old_memcg = set_active_memcg(
+ mem_cgroup_from_css(memcg_css));
+
loop_process_work(worker, &worker->cmd_list, worker->lo);
+
+ kthread_associate_blkcg(NULL);
+ if (memcg_css) {
+ set_active_memcg(old_memcg);
+ css_put(memcg_css);
+ }
}
static void loop_rootcg_workfn(struct work_struct *work)
diff --git a/drivers/block/loop.h b/drivers/block/loop.h
index 1988899db63a..a52a3fd89457 100644
--- a/drivers/block/loop.h
+++ b/drivers/block/loop.h
@@ -77,8 +77,6 @@ struct loop_cmd {
long ret;
struct kiocb iocb;
struct bio_vec *bvec;
- struct cgroup_subsys_state *blkcg_css;
- struct cgroup_subsys_state *memcg_css;
};
/* Support for loadable transfer modules */
--
2.31.1
next prev parent reply other threads:[~2021-07-05 10:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-05 10:26 [PATCH 0/6] loop: cleanup charging io to mem/blkcg Ming Lei
2021-07-05 10:26 ` Ming Lei [this message]
2021-07-06 5:51 ` [PATCH 1/6] loop: clean up blkcg association Christoph Hellwig
2021-07-08 7:20 ` Ming Lei
2021-07-05 10:26 ` [PATCH 2/6] loop: conver timer for monitoring idle worker into dwork Ming Lei
2021-07-06 5:52 ` Christoph Hellwig
2021-07-08 7:23 ` Ming Lei
2021-07-05 10:26 ` [PATCH 3/6] loop: add __loop_free_idle_workers() for covering freeing workers in clearing FD Ming Lei
2021-07-05 10:26 ` [PATCH 4/6] loop: improve loop_process_work Ming Lei
2021-07-06 5:54 ` Christoph Hellwig
2021-07-05 10:26 ` [PATCH 5/6] loop: use xarray to store workers Ming Lei
2021-07-05 10:26 ` [PATCH 6/6] loop: don't add worker into idle list Ming Lei
2021-07-06 13:55 ` Dan Schatzberg
2021-07-07 3:19 ` Ming Lei
2021-07-07 13:55 ` Dan Schatzberg
2021-07-08 6:58 ` Ming Lei
2021-07-08 14:16 ` Dan Schatzberg
2021-07-08 15:01 ` Ming Lei
2021-07-08 15:15 ` Dan Schatzberg
2021-07-09 0:49 ` Ming Lei
2021-07-09 13:47 ` Dan Schatzberg
2021-07-08 14:41 ` Dan Schatzberg
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=20210705102607.127810-2-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=schatzberg.dan@gmail.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