Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp606599imm; Fri, 31 Aug 2018 08:32:05 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaSz6BiZvZ/cVFxm5bI3WMr2wBJmu1BW9KHb9/iIcjdTY96jg/5LNrldFNgUZXmy/bEpg5q X-Received: by 2002:a65:650f:: with SMTP id x15-v6mr15169826pgv.127.1535729525467; Fri, 31 Aug 2018 08:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535729525; cv=none; d=google.com; s=arc-20160816; b=VC3QHoKEWCjJeUz8wL16cfnAClVqW8Jovi1EW+3E9J5LPHuj2y1AP6wHHCFVPUFehk mVBbS5hNUCLQw2ucdKg4iPCWtBEXmJzOdEJdseko8yml3500EHfv4CCkF2s72U1icGhR mRR5/AFv7YFbBXbpixbVIw7SW7ZNu2fJdmw6E/GjEzqwKKp/THuxWjk11bW7oN1aTHNl 0u6AYiDsZ3AIB1UpU3tyK1jO+7h81l+4uhW5cLKvZ22pfAXMNY+EewkvYcbv3cSz8wZq dGn7BbpHs4k8YzC5X0DkQfYzsafrG4ykHLYYMOmq0r65mNLXJ7dz3fY4g8KeWQe2Lua+ yacQ== 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:arc-authentication-results; bh=r4xlJrCOyIDs6oSO9a8eot+HhJ0UKStNZvu7TqaUHHI=; b=M8tKAMor2KTTfgdapEAfFqnKTgfPCqCWPwmtGm0oJ8ViSgGZ9s2ZhQXaycpZAEft0Q JWr5efy2qPtvgOpMJLteXtBG7G89aAKfaM87THIHKQZcYRwgTioSaUtxgFlMU6vtPe2A mwlL7eCi5SmF54xAf2L3xdlwSs+N3vbHblt+xhZemSJdFl+oN8egNWVM5VWJ/L4zOmyC y4X9dTfLepnGSJonB5KJZ4ljBiVx9KR8QSXoP0RP7q2BaKQxgoqaqLTOj2EMDPbWlxP/ +nOzKzumWWKCqWVIrCDBUi0kwwXONygTFkhFFu7N3YUbt6FAune909ImufQ+fyYXMitU aG3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=eUtCchfL; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q8-v6si8599483pls.482.2018.08.31.08.31.50; Fri, 31 Aug 2018 08:32:05 -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=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=eUtCchfL; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729063AbeHaTiM (ORCPT + 99 others); Fri, 31 Aug 2018 15:38:12 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:36619 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727286AbeHaTiM (ORCPT ); Fri, 31 Aug 2018 15:38:12 -0400 Received: by mail-qk1-f195.google.com with SMTP id 93-v6so1641783qks.3 for ; Fri, 31 Aug 2018 08:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=r4xlJrCOyIDs6oSO9a8eot+HhJ0UKStNZvu7TqaUHHI=; b=eUtCchfLR28qwPaFKR1o0VGLHzliYbHEoXgYVmNPog1b8I6I5HpHcSkIiC1JmRF7NN /paBfy4M1KgUCcznVTxR7/0yA2vw0H+sp3z9ql4ZvtkejTzpf6CTIrS0sdUHAKZ5+UcO l2R++nsfrw672Ef2svHQ4IoLEaGxTzO7VLGdCNsnxk0uU0+iyI11/JZ+o8c4mVpMOHg5 iRUnG/hgXArTezrHSAZVk5zPPe35b88NxVHNTEgbHPGAQPQzF4cycysMjuvJDbdq0LKF sPLkLn0GFDHnYe2jdXeVtYwV4gHZm6xCgpK5/E/1yRbLBFYMgcqUtMyWc/Y8uygNX5+k 5cQg== 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=r4xlJrCOyIDs6oSO9a8eot+HhJ0UKStNZvu7TqaUHHI=; b=VZOndENu7zlBwYRcBiwqE9PUI4UWyL7/iLTqWu2YDo69/2jWfLTUJp8gcGS6FlkEDm U3yl60bB68X4MTyQ3KXSCynD8EVsVhZ+o5o92DAbk4LET3bxPU9zUONyFDkd3MEHgGZO isudQvDBbEb0N64X67luNnnomCqlhD9QJizuMLMOzedxesVlSVwL2uu7qVaK+Hyx6uLN eubNLTpdvQQCrn9L+iIen1ER8VXhWk1FwQVlzrAxlcg2r3ghxoxbMfNsK5qLov4s7Mfj QnWMHyJY+lJKC3YxHXv6jG4BxfQdCH+J+b5VSHzKZoxkK+zRmt4oqQyMj/TofyP2XI3Y 83rA== X-Gm-Message-State: APzg51C7JlOyqoloS/Qr7zSTftH5fdzsydgIDqpROdYEIPE/1xKxnd/m xkLga9qva9Y0+2iqYVVXISz9QQ== X-Received: by 2002:a37:6c87:: with SMTP id h129-v6mr15341104qkc.280.1535729410313; Fri, 31 Aug 2018 08:30:10 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id j10-v6sm7246576qka.94.2018.08.31.08.30.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 08:30:09 -0700 (PDT) Date: Fri, 31 Aug 2018 11:30:08 -0400 From: Josef Bacik To: Dennis Zhou Cc: Jens Axboe , Tejun Heo , Johannes Weiner , Josef Bacik , kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Jiufei Xue , Joseph Qi Subject: Re: [PATCH 03/15] blkcg: use tryget logic when associating a blkg with a bio Message-ID: <20180831153007.nybnuyx43adn76rm@destiny> References: <20180831015356.69796-1-dennisszhou@gmail.com> <20180831015356.69796-4-dennisszhou@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180831015356.69796-4-dennisszhou@gmail.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 30, 2018 at 09:53:44PM -0400, Dennis Zhou wrote: > From: "Dennis Zhou (Facebook)" > > There is a very small change a bio gets caught up in a really > unfortunate race between a task migration, cgroup exiting, and itself > trying to associate with a blkg. This is due to css offlining being > performed after the css->refcnt is killed which triggers removal of > blkgs that reach their blkg->refcnt of 0. > > To avoid this, association with a blkg should use tryget and fallback to > using the root_blkg. > > Fixes: 08e18eab0c579 ("block: add bi_blkg to the bio for cgroups") > Signed-off-by: Dennis Zhou > Cc: Jiufei Xue > Cc: Joseph Qi > Cc: Tejun Heo > Cc: Josef Bacik > Cc: Jens Axboe > --- > block/bio.c | 3 ++- > block/blk-throttle.c | 5 +++-- > 2 files changed, 5 insertions(+), 3 deletions(-) > > diff --git a/block/bio.c b/block/bio.c > index 04969b392c72..4473ccd22987 100644 > --- a/block/bio.c > +++ b/block/bio.c > @@ -1987,7 +1987,8 @@ int bio_associate_blkg(struct bio *bio, struct blkcg_gq *blkg) > { > if (unlikely(bio->bi_blkg)) > return -EBUSY; > - blkg_get(blkg); > + if (!blkg_try_get(blkg)) > + return -ENODEV; > bio->bi_blkg = blkg; > return 0; > } > diff --git a/block/blk-throttle.c b/block/blk-throttle.c > index a3eede00d302..c626e1f7cdcd 100644 > --- a/block/blk-throttle.c > +++ b/block/blk-throttle.c > @@ -2129,8 +2129,9 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td) > static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio) > { > #ifdef CONFIG_BLK_DEV_THROTTLING_LOW > - if (bio->bi_css) > - bio_associate_blkg(bio, tg_to_blkg(tg)); > + /* fallback to root_blkg if we fail to get a blkg ref */ > + if (bio->bi_css && bio_associate_blkg(bio, tg_to_blkg(tg))) > + bio_associate_blkg(bio, bio->bi_disk->queue->root_blkg); Except if we've already assocated a blkg this is just extra, can we do if (bio->bi_css && (bio_associate_blkg(bio, tg_to_blkg(tg)) == -ENODEV)) to make it clear that we're only attaching it to the root if we failed to attach a blkg at all? Thanks, Josef