From: Johannes Weiner <hannes@cmpxchg.org>
To: Dan Schatzberg <dschatzberg@fb.com>
Cc: Jens Axboe <axboe@kernel.dk>, Tejun Heo <tj@kernel.org>,
Li Zefan <lizefan@huawei.com>, Michal Hocko <mhocko@kernel.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>,
"open list:BLOCK LAYER" <linux-block@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
"open list:CONTROL GROUP (CGROUP)" <cgroups@vger.kernel.org>,
"open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)"
<linux-mm@kvack.org>
Subject: Re: [PATCH 2/2] loop: charge i/o per cgroup
Date: Thu, 6 Feb 2020 10:46:24 -0500 [thread overview]
Message-ID: <20200206154624.GB24735@cmpxchg.org> (raw)
In-Reply-To: <20200205223348.880610-3-dschatzberg@fb.com>
Hello Dan,
On Wed, Feb 05, 2020 at 02:33:48PM -0800, Dan Schatzberg wrote:
> @@ -1925,14 +1990,13 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
> }
>
> /* always use the first bio's css */
> + cmd->blk_css = NULL;
> #ifdef CONFIG_BLK_CGROUP
> - if (cmd->use_aio && rq->bio && rq->bio->bi_blkg) {
> - cmd->css = &bio_blkcg(rq->bio)->css;
> - css_get(cmd->css);
> - } else
> + if (rq->bio && rq->bio->bi_blkg)
> + cmd->blk_css = &bio_blkcg(rq->bio)->css;
> #endif
> - cmd->css = NULL;
> - kthread_queue_work(&lo->worker, &cmd->work);
> +
> + loop_queue_work(lo, cmd);
>
> return BLK_STS_OK;
> }
> @@ -1942,6 +2006,9 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
> struct request *rq = blk_mq_rq_from_pdu(cmd);
> const bool write = op_is_write(req_op(rq));
> struct loop_device *lo = rq->q->queuedata;
> +#ifdef CONFIG_MEMCG
> + struct cgroup_subsys_state *mem_css;
> +#endif
> int ret = 0;
>
> if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY)) {
> @@ -1949,8 +2016,24 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
> goto failed;
> }
>
> + if (cmd->blk_css) {
> +#ifdef CONFIG_MEMCG
> + mem_css = cgroup_get_e_css(cmd->blk_css->cgroup,
> + &memory_cgrp_subsys);
> + memalloc_use_memcg(mem_cgroup_from_css(mem_css));
> +#endif
> + kthread_associate_blkcg(cmd->blk_css);
> + }
> +
> ret = do_req_filebacked(lo, rq);
> - failed:
> +
> + if (cmd->blk_css) {
> + kthread_associate_blkcg(NULL);
> +#ifdef CONFIG_MEMCG
> + memalloc_unuse_memcg();
> +#endif
cgroup_get_e_css() acquires a reference, it looks like you're missing
a css_put() here.
I also wonder why you look up blk_css and mem_css in separate
places. Since you already renamed cmd->css to cmd->blk_css, can you
also add cmd->mem_css and pair up their lookup and refcounting?
This should make loop_handle_cmd() a bit more straight-forward:
if (cmd->blk_css)
kthread_associate_blkcg(cmd->blk_css);
if (cmd->mem_css)
memalloc_use_memcg(mem_cgroup_from_css(mem_css));
ret = do_req_filebacked(lo, rq);
memalloc_unuse_memcg();
kthread_associate_blkcg(NULL);
All these functions have dummy implementations for !CONFIG_BLK_CGROUP,
!CONFIG_MEMCG etc., so it shouldn't require any additional ifdefs.
next prev parent reply other threads:[~2020-02-06 15:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200205223348.880610-1-dschatzberg@fb.com>
[not found] ` <20200205223348.880610-2-dschatzberg@fb.com>
2020-02-06 15:27 ` [PATCH 1/2] mm: Charge current memcg when no mm is set Johannes Weiner
2020-02-12 23:06 ` Tejun Heo
[not found] ` <20200205223348.880610-3-dschatzberg@fb.com>
2020-02-06 15:46 ` Johannes Weiner [this message]
2020-02-13 0:07 ` [PATCH 2/2] loop: charge i/o per cgroup Tejun Heo
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=20200206154624.GB24735@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=dschatzberg@fb.com \
--cc=hughd@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan@huawei.com \
--cc=mhocko@kernel.org \
--cc=tj@kernel.org \
--cc=vdavydov.dev@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;
as well as URLs for NNTP newsgroup(s).