Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp791163imm; Fri, 31 Aug 2018 13:24:58 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaUfN7cj3YpIzUdWbehJ2hv5+UOrx74mY1UoqnMFukCFMrEFYyFF99QROu4gMo9tAPoG/0V X-Received: by 2002:a62:8704:: with SMTP id i4-v6mr17537472pfe.62.1535747097984; Fri, 31 Aug 2018 13:24:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535747097; cv=none; d=google.com; s=arc-20160816; b=LUfpi1J2ty5uAccRIIEIdJtTneOvYOcRe66AfO6ov/6VqlZwG7qBtv9LWIKZuIHrC0 4PqBvMOoakx+6apOsZCsdE+pvoVu8ARQ4wD4uopkx5OnGfJptoTSKh9mqe3L0vWhoaVv hqazWeYycvtqVaoP5t1nl8WnaN3bM0u/8STC7VEu+7lCKSeAbjZT+F62e3FMQig/9/IF 6VaXZyTtx4inhEFIFfnWTfPL03Hn79zOZ2imdO9piXHbJHAtsNPxEAFL5KcuLCoPpD9U zM6dBcxD3QlXz94mImxbkDoBa3fNwqfp6ecfDXZAwp/opv4dMUJSMhC6eAi2DUBicEMq RA9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4ycn/g7fw8SqfXjt7f6eHXQQdDKhRrTOaowx1xDnWeg=; b=HcDr7aU3T4aA7C5CX4DVInNbqyC/+/hrIK5JJm7v8r54KQJoLbbDKgWoCxj0XE8w/T 0AAUoj+kkTCQrPWKMl4Z2vdC2S193ihpPTlyXNw8z+lNSPw9ntDjiXQ9Tucmn8mc2DWy iUkqxbj0GJSpJ8RxxptOFRbeLIyQwvzlsu0UjIVnkSRaKd3ACnUu+tSQSGn5+4BDWn+z 6yJ499q/rqNcRddF95m74VaD+/BWWnSYFp5G4JXlwg0buWjJbZdq9Y+Z9cQ9QS7IMkGM GbF6SXTjXvCRK57sOXCezY1lucNJiNBbOTVUVA8ydC2cIaWPV+9v2/jI5DOp9lQ+S4Qx pJDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bZuVkyCU; 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 v1-v6si11268863plb.387.2018.08.31.13.24.41; Fri, 31 Aug 2018 13:24:57 -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=bZuVkyCU; 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 S1727730AbeIAAch (ORCPT + 99 others); Fri, 31 Aug 2018 20:32:37 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:36669 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727318AbeIAAcg (ORCPT ); Fri, 31 Aug 2018 20:32:36 -0400 Received: by mail-yw1-f66.google.com with SMTP id w202-v6so5504365yww.3; Fri, 31 Aug 2018 13:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4ycn/g7fw8SqfXjt7f6eHXQQdDKhRrTOaowx1xDnWeg=; b=bZuVkyCU1I70NNU/Nt6qA+o76T3OmFM2XGSQlTC/lPJT7C5jA/ts+UF53fAXi4g3tG 0Q2vQwCwAOE53QDwEOSFpaV0duuAdctBWbjH9Z+cZK5/PkbO2nqkAnO2Zz5Hj6REO2B2 Q771+5202p1QLs/shU8sZyELGxXPSy33lvsMWYvYk9LLDCwyJdcJDjgR432TelMGTm4n 2wcf8pmAJUalwtdh61M77DtcLaXCGL0/saDQ++CaWXD67LXH+uu58ycs24LQgz+/5fEy 1D3UR5eGeoKR8zwFnozt+gSTc0I6HMXMVho2482Fx0l6F8WBILRUmnmUpUJUODnwdPfn pG0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4ycn/g7fw8SqfXjt7f6eHXQQdDKhRrTOaowx1xDnWeg=; b=BoA2xCGsil8YwmvnYgetz0IuLSFxemh0G2J+nYQDjVLeSCaGVBdraI39HmC/a79wwb 2FnYd6hEZBHSHTo24vdixwmFYib5cY+GQReA8qGA0/nQ+KUFhXhd9EP2jNoClKoZ+MlZ +vitm/qRKJOGgWKIaq+r737VIv1WXsei0VkPsCGUmkWAoGzMB0vwEB4Fk693PrFASH0d Eykly9EfTnXMxPMWcKgzuu7C1GyOwJY0jSPGv/KOSLWGZBl58cx4BTYb5jadw+KK/VRq 2HmAhTF2WNkXMJi8Mtxtizp8AGG9MRQpYaG9B4iQQOynJW17fhMWYji8uVJiUt/UAGhy UAgA== X-Gm-Message-State: APzg51BEhgsOZJl9rHEurOGNfBd9NF/zGq2oyOjmBnAq0S1NUzf88XXF cF+Ojogbk36jBQ3MyLHba5o= X-Received: by 2002:a81:1151:: with SMTP id 78-v6mr9772760ywr.138.1535747009349; Fri, 31 Aug 2018 13:23:29 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([199.201.65.129]) by smtp.gmail.com with ESMTPSA id u8-v6sm3978961ywl.59.2018.08.31.13.23.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Aug 2018 13:23:28 -0700 (PDT) From: Dennis Zhou To: Jens Axboe , Tejun Heo , Johannes Weiner , Josef Bacik Cc: kernel-team@fb.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, "Dennis Zhou (Facebook)" , Jiufei Xue , Joseph Qi Subject: [PATCH 3/3] blkcg: use tryget logic when associating a blkg with a bio Date: Fri, 31 Aug 2018 16:22:44 -0400 Message-Id: <20180831202244.21678-4-dennisszhou@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180831202244.21678-1-dennisszhou@gmail.com> References: <20180831202244.21678-1-dennisszhou@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. v2: - In blk-throttle, be explicit that we only associate with the root_blkg if tryget failed. 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..01d0620a4e4a 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)) == -ENODEV)) + bio_associate_blkg(bio, bio->bi_disk->queue->root_blkg); bio_issue_init(&bio->bi_issue, bio_sectors(bio)); #endif } -- 2.17.1