Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp672969imm; Thu, 6 Sep 2018 08:23:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZGK6Wdc5XYHLsPrSn2c/mJM3yc5+pSSqkffofYulVbkIuFJ4AhqhrYCtI898LleKiVoKE4 X-Received: by 2002:a62:3545:: with SMTP id c66-v6mr3353202pfa.63.1536247425476; Thu, 06 Sep 2018 08:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536247425; cv=none; d=google.com; s=arc-20160816; b=o6nIy0RSuB5PQty/Ny8rPiurD8t+tk+WfnabqHHGrTLIhb0lu2fc78/4XhPpo8O2mj woKuyXCUvmQMSbixXEF4dpSvzH1ymCh/sqhocItk3DQioIRBXtmgSDQfy59Ndi4Pz9us pWknuTngxyvSNA5+NIFtNYAW2AqBZZ7LtPas51ebQCSRDF6hxmwcd5dvC4VeXu0+2To7 AhasUcSUuhpPm4ZjXMi5KgJXYmcInyFxnncqNJN1H70WBeiTY9uPNvoo/ckIQLgRjToN ZtzULq7SrM5CiLaM2KwRq/+doPyCL+7nGKLbRt817/qnJKvRtftgayRqyc0rP3B0rr/6 VNUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=zb2t7fnEFpTNY92P+q79KIuwpqsi0lHQ8yrY3sayUYo=; b=K5fzzRnBv+qylaZrVZ1DpyEn+u5rsCJMdssFYfT9Ufh4IEsSnCx5OciSeZ+a09fZmE GxzN3EtiSwyALiv/D6QzCjgOlPWaP6ZolIUM9sIqBpwdTvytnaLuhpBY7X43eY+nRGrS sHYUnMBanbDcG9X10uF2fzj78vTs8KLj2nyb3kB2bfGnWsTfnm7k+uXAj2tko8aw5iaE XjP260Q5CYPvJDUr6TLN11Z9IqY3Q5HCiy+53cKiXe0xdGJLotu0bC4Tzt7qLwTpKPo3 DXL42GzlEUMYS+COVHokKOhpUrsSPHq7yPVFPMZ8AAZW+G7oQsEekRZYZygK7xmWKJiE WB5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dfEQPOBa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x25-v6si5550721pfi.138.2018.09.06.08.23.28; Thu, 06 Sep 2018 08:23:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dfEQPOBa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730196AbeIFT5u (ORCPT + 99 others); Thu, 6 Sep 2018 15:57:50 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:45815 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727501AbeIFT5u (ORCPT ); Thu, 6 Sep 2018 15:57:50 -0400 Received: by mail-yw1-f65.google.com with SMTP id p206-v6so4196217ywg.12; Thu, 06 Sep 2018 08:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zb2t7fnEFpTNY92P+q79KIuwpqsi0lHQ8yrY3sayUYo=; b=dfEQPOBaSRiw1xlv2rsfYhgg1AgZjEGmxweeotaQt76RJ6rsw/kynSjJNQADcdre/b NYQx1xIVWWgu377YSlkvCTuowzC+Gw0ZvNfCj7ksqNwcJI3i3w+TRlnPQSDiNboj3Umx 1uQi7QV3qgALw9D2eBzNZDS37Ts1bl6LMwuopKKkbAXs7O4cg9SFL5KXiEwLJ/V3DIij JvGDaWcltZF1RajrLj8e0RclKnPd2WS7a1b4QVebhg+ncuz3p4FlXQtNnGyMVu6S74db ckmszjeTLQimwH3zk/fUWEGEc7pYVoUA6GydO5kUOjtlip80CRpOwxOJvgJTCsCexgb4 0pOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zb2t7fnEFpTNY92P+q79KIuwpqsi0lHQ8yrY3sayUYo=; b=j5DeDRhf/43RwJrVXV6aQ6vnzWZb1J4oQMqVKt0TZWvP0STj2GDc0lVW7SLSAgw6Gp shLqm6aaQ537vQiTJOVNFxT3B6jo0XdNTBmRilcJkq5/+kagSxCjan8taCrUCO1wz3pq pprm2a5AHqyPrdD8IVheySguyI5PIEgvLb3vRFarvN4jPlVe5z1sIf45nQuGG3iM7vFd NQSLQIoNaKlw35d4cM076Rs5i5PfhAM7o61479mQcat8iB/yW+2nMPpNZ+t1JAlm2Z6l VWjbVnwprCUhCcE+sOpSest9Kh2ptPbocwRIlkRTsXk+n9FzYtnVX9PsC36BpRW88K2w Z6gQ== X-Gm-Message-State: APzg51B/iqIYDPSqGt0OWBj3FnRU8b5H1xlQPKUW2ZlKVl0Ac9Jjqwdg tce9gHQp+Oiec6gGiEmDnV8= X-Received: by 2002:a81:453:: with SMTP id 80-v6mr1715599ywe.203.1536247309343; Thu, 06 Sep 2018 08:21:49 -0700 (PDT) Received: from dennisz-mbp.dhcp.thefacebook.com ([2620:10d:c091:180::1:ad69]) by smtp.gmail.com with ESMTPSA id j186-v6sm1882153ywd.88.2018.09.06.08.21.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 08:21:48 -0700 (PDT) Date: Thu, 6 Sep 2018 11:21:23 -0400 From: Dennis Zhou To: Josef Bacik Cc: Jens Axboe , Tejun Heo , Johannes Weiner , kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 04/15] blkcg: fix ref count issue with bio_blkcg using task_css Message-ID: <20180906152120.GA5055@dennisz-mbp.dhcp.thefacebook.com> References: <20180831015356.69796-1-dennisszhou@gmail.com> <20180831015356.69796-5-dennisszhou@gmail.com> <20180831153538.brzgcm3rgmwfy3rg@destiny> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180831153538.brzgcm3rgmwfy3rg@destiny> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 11:35:39AM -0400, Josef Bacik wrote: > On Thu, Aug 30, 2018 at 09:53:45PM -0400, Dennis Zhou wrote: > > From: "Dennis Zhou (Facebook)" > > +/** > > + * blkcg_get_css - find and get a reference to the css > > + * > > + * Find the css associated with either the kthread or the current task. > > + */ > > +static inline struct cgroup_subsys_state *blkcg_get_css(void) > > +{ > > + struct cgroup_subsys_state *css; > > + > > + rcu_read_lock(); > > + > > + css = kthread_blkcg(); > > + if (css) { > > + css_get(css); > > + } else { > > + while (true) { > > + css = task_css(current, io_cgrp_id); > > + if (likely(css_tryget(css))) > > + break; > > + cpu_relax(); > > Does this work? I'm ignorant of what cpu_relax() does, but it seems if we're > rcu_read_lock()'ed here we aren't going to queisce so if we fail to get the css > here we just simply aren't going to get it unless we go to sleep right? An > honest question, because this is all magic to me, I'd like to understand how > this isn't going to infinite loop on us if css_tryget(css) fails. > Tejun replied earlier with an indepth answer. Thanks Tejun! I'll make sure to add a comment detailing what's going on. > > +/** > > + * bio_blkcg - grab the blkcg associated with a bio > > + * @bio: target bio > > + * > > + * This returns the blkcg associated with a bio, NULL if not associated. > > + * Callers are expected to either handle NULL or know association has been > > + * done prior to calling this. > > + */ > > static inline struct blkcg *bio_blkcg(struct bio *bio) > > { > > - struct cgroup_subsys_state *css; > > - > > if (bio && bio->bi_css) > > return css_to_blkcg(bio->bi_css); > > - css = kthread_blkcg(); > > - if (css) > > - return css_to_blkcg(css); > > - return css_to_blkcg(task_css(current, io_cgrp_id)); > > + return NULL; > > } > > > > So this is fine per se, but I know recently I was doing a bio_blkcg(NULL) to get > whatever the blkcg was for the current task. I threw that work away so I'm not > worried about me, but have you made sure nobody else is doing something similar? > Initially I thought the BFQ and CFQ stuff only interacted with bios which should already be associated. Turns out during init, they rely on that bio_blkcg to read from current and then do the wrong thing of hard associating with it (_get vs _tryget). I've created a __bio_blkcg which is identical to the old function with notes to not use it. Making changes to BFQ and CFQ would take a good bit more work to make sure I'm not breaking what they're expecting to do, so I leave that to future work. > > static inline bool blk_cgroup_congested(void) > > @@ -519,6 +549,11 @@ static inline struct request_list *blk_get_rl(struct request_queue *q, > > rcu_read_lock(); > > > > blkcg = bio_blkcg(bio); > > + if (blkcg) { > > + css_get(&blkcg->css); > > + } else { > > + blkcg = css_to_blkcg(blkcg_get_css()); > > + } > > Kill these extra braces please. Thanks, Done. Thanks, Dennis