From patchwork Wed Jan 30 05:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 157024 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5512735jaa; Tue, 29 Jan 2019 21:23:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN6AktnR08M2IE5c2LcTbgWVuKkvr43aYjleEKRkfKIgNR5jDB1WPvWH0HAAcD/Wb23dN/Sa X-Received: by 2002:a63:2406:: with SMTP id k6mr25385450pgk.229.1548825788505; Tue, 29 Jan 2019 21:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548825788; cv=none; d=google.com; s=arc-20160816; b=lhe3Te8u734xXvhn/H1B8njpaZxcv4YP/vXloSAEVzuOg3HDPo9UMklHBuHu7BSTBA tLkOsinHuMd+MvjEc9oJlBhuHT87PXpdWOr00ZS9pymgKFRuq9fHz7eKT6x36if+M4w7 zdStAQbYuzDXZzZHECe9l31Uv+pUGtkqATs45W4eFwjZmYWGdWP3OHb4tHPeMDuwvt7h Qn12sG6MOPRY/vm4zaguNwxQcWjcCNoNR1uMtKy6p5NLYwl2KsA7WXT4pbtUcVg7eJuo 79aICsLsf68pKCbMLXRSqe/ICuz+tbAsk/QgkEsSBThMZADbcKlJwVhCXvwM5YDXsSJV GuHQ== 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; bh=06OAt3prsZG+l6s8Qp99Ip2RXja0vs/0PYt5i3Pia90=; b=VzF86I/PLQMqfinNmH+Om5VLHj0lepL5PdtbxIo2PNLQtVasYiBpDXryEllHV11AW7 EEovq7RxmUIC7pfjQCpZo/x+PJMIitwOq+eapZ9jTrprepHGnO9HVC2rC0LThjdkfgcq dqRK8ob5K9gEfTrR4Pd5hdbhUbH6KkU5UD4hVZcjXxUCnGW/hkX6N50ajIQwfeVmqkvv GdEE3oMPPwlOQWU5CGEQodjGd1fXRE6rhGJjIyJInrQopq6B1VSdSdNcSm1NYgs0+CX4 2nBDjSY3cX3tGGPgE7fS+jtGc77ipw/S7O7kqi6W9MoM+TJjOLq+QWMh8nbT65rDYFOh BIOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c2DSpdQm; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y7si538687plk.275.2019.01.29.21.23.08; Tue, 29 Jan 2019 21:23:08 -0800 (PST) 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=@linaro.org header.s=google header.b=c2DSpdQm; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726494AbfA3FXG (ORCPT + 31 others); Wed, 30 Jan 2019 00:23:06 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37687 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725806AbfA3FXF (ORCPT ); Wed, 30 Jan 2019 00:23:05 -0500 Received: by mail-wm1-f68.google.com with SMTP id g67so20151331wmd.2 for ; Tue, 29 Jan 2019 21:23:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=06OAt3prsZG+l6s8Qp99Ip2RXja0vs/0PYt5i3Pia90=; b=c2DSpdQmUlLR81QkXCFHNXdgRPMSjz81amSQYYD8St+ys1TXQCgXTgUUlntRvJ0TD0 a6haEOcV89f+0tWif/MIO6fFcUXP5EmaopZUlaSjGMaAdZkgOUVq08TbQKaRIbcjtfwW XhtKUlXF9HMaiXkWWFKP3W6VhfKICfDT/myqE= 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=06OAt3prsZG+l6s8Qp99Ip2RXja0vs/0PYt5i3Pia90=; b=WW0dQkwGFmmMvQuhucheDbLaPDfJndlHUKpCOehbJ5UETNofcAAQLj+B9Kci/24pCl 6cd243tsY/PFLJ4de/w5tXU9QJ7KdIu3rWBUOLc3IwhT2K41yUvRy3yxFOBSfArO/TnO 1JbWBVQiYg2z7TTVhi+yjOsXFSGg19rGBzfAI34AeiYjGXTGeRXfDbiSGx+Kp5E4AMoh Ozs7QCqVArgC3d95Nak9EIn0dfN3EQM+GSC61vVxq9ffSAfL9rHBrO6ADtwunKTrUBnV rggpfc5fFHLsi8PloilPIDEuPuugIoyu/IfnTo9Bm4wZ9NUqWHeiz+zlmzwUALdl1VIX ouFA== X-Gm-Message-State: AJcUukcWJH/Iv4QJ7C7ZrybHvuAsTBflmpXy0uNJwW4yy9bev02FgG+0 Bt/v3SLAN8NS6SMVR2RoqK7ttorLzZmHaw== X-Received: by 2002:a1c:8484:: with SMTP id g126mr24823375wmd.117.1548825782794; Tue, 29 Jan 2019 21:23:02 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:a13d:e482:c90f:2b78]) by smtp.gmail.com with ESMTPSA id c21sm731809wre.71.2019.01.29.21.23.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Jan 2019 21:23:01 -0800 (PST) From: Vincent Guittot To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org Cc: tj@kernel.org, sargun@sargun.me, Vincent Guittot Subject: [PATCH v2] sched/fair: Fix insertion in rq->leaf_cfs_rq_list Date: Wed, 30 Jan 2019 06:22:47 +0100 Message-Id: <1548825767-10799-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548782332-18591-1-git-send-email-vincent.guittot@linaro.org> References: <1548782332-18591-1-git-send-email-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sargun reported a crash: "I picked up c40f7d74c741a907cfaeb73a7697081881c497d0 sched/fair: Fix infinite loop in update_blocked_averages() by reverting a9e7f6544b9c and put it on top of 4.19.13. In addition to this, I uninlined list_add_leaf_cfs_rq for debugging. This revealed a new bug that we didn't get to because we kept getting crashes from the previous issue. When we are running with cgroups that are rapidly changing, with CFS bandwidth control, and in addition using the cpusets cgroup, we see this crash. Specifically, it seems to occur with cgroups that are throttled and we change the allowed cpuset." The algorithm used to order cfs_rq in rq->leaf_cfs_rq_list assumes that it will walk down to root the 1st time a cfs_rq is used and we will finish to add either a cfs_rq without parent or a cfs_rq with a parent that is already on the list. But this is not always true in presence of throttling. Because a cfs_rq can be throttled even if it has never been used but other CPUs of the cgroup have already used all the bandwdith, we are not sure to go down to the root and add all cfs_rq in the list. Ensure that all cfs_rq will be added in the list even if they are throttled. Reported-by: Sargun Dhillon Fixes: 9c2791f936ef ("Fix hierarchical order in rq->leaf_cfs_rq_list") Signed-off-by: Vincent Guittot --- v2: - Added dummy function for !CONFIG_FAIR_GROUP_SCHED This patch doesn't fix: a9e7f6544b9c ("sched/fair: Fix O(nr_cgroups) in load balance path") which has been reverted in v5.0-rc1. I'm working on an additonal patch that should be similar to this one to fix a9e7f6544b9c. kernel/sched/fair.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) -- 2.7.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e2ff4b6..826fbe5 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -352,6 +352,20 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq) } } +static inline void list_add_branch_cfs_rq(struct sched_entity *se, struct rq *rq) +{ + struct cfs_rq *cfs_rq; + + for_each_sched_entity(se) { + cfs_rq = cfs_rq_of(se); + list_add_leaf_cfs_rq(cfs_rq); + + /* If parent is already in the list, we can stop */ + if (rq->tmp_alone_branch == &rq->leaf_cfs_rq_list) + break; + } +} + /* Iterate through all leaf cfs_rq's on a runqueue: */ #define for_each_leaf_cfs_rq(rq, cfs_rq) \ list_for_each_entry_rcu(cfs_rq, &rq->leaf_cfs_rq_list, leaf_cfs_rq_list) @@ -446,6 +460,10 @@ static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq) { } +static inline void list_add_branch_cfs_rq(struct sched_entity *se, struct rq *rq) +{ +} + #define for_each_leaf_cfs_rq(rq, cfs_rq) \ for (cfs_rq = &rq->cfs; cfs_rq; cfs_rq = NULL) @@ -5179,6 +5197,9 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) } + /* Ensure that all cfs_rq have been added to the list */ + list_add_branch_cfs_rq(se, rq); + hrtick_update(rq); }