From patchwork Mon Jul 20 08:34:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 235758 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1774074ilg; Mon, 20 Jul 2020 01:34:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK6mzJuXn+5D05piJwxD/ygEQeF0DSL4nAFa1lalGzaLsAQu35w4ttNekob4CDKF92XByX X-Received: by 2002:a17:906:3a9b:: with SMTP id y27mr19604670ejd.38.1595234055793; Mon, 20 Jul 2020 01:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595234055; cv=none; d=google.com; s=arc-20160816; b=rVmWuPNqqP8/AJ+ZT2alg+M24Pg4LQRiM9YuGAT/fz/szu+2Jg5h5dfNoHlZvMS90F Nz0G9ocoS1eYKM24gBtVHyd1/A3YKMkjqd7ldOnbNjg9l4iv9ngg6Tr9BVXQL2rjSteP jbt0wEG/IPe33CYC2mAiXGkxmyi/kv8dAJezGfTnVBMoEHXBDoZB9pPhUjfYwVnAkwt8 XSkxl7qkQZjo2cnALkEOyhp5N4DFu55pnifAsClfrk3MSNVSBLGeXXqg/8hl65B7Nh9x 1cxINJ1SLkfIIUoo5zRBEwryQ5rTytKkb4BJupYfAnr4OGBknbzRSzOo9xWwAzFSV15H gqww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=NQ0TByaTMYGuIND8hZglNUNSd92F891BfsAU17IV3Es=; b=j45HSb8yWVcTaGMmwI0VKk/6LqUOvK7KAaiuiC4I6uDPTYf5ypwEB2BM+lujOZZwET xiWhWEomBnAasdiNDXTLq8yIgkyvYRdMbrRulaytOcyqPSBjYEjlPaB7TbLwoGY5SqkU /ar+3bt1NvXWAc5l4/onFnJALaPdy/mxN70IwkFW2KFY/X+UJiWxvu2rYzqOzra5HnEn h4cPd+hofw2iK+sGGiCi2EcD6BZu2bLBvtUgvU8pyEMJMECX2FGXDnxyAl8et1/jVWR2 0HoQaU+zHziDzXt1yFPWHm3gOBB0WUnp6RGGXqiHSjtoY6aCrhvXZhNT6EUqf2ScjVcQ tfuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T4pO31Um; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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. [23.128.96.18]) by mx.google.com with ESMTP id bt23si9882811edb.545.2020.07.20.01.34.15; Mon, 20 Jul 2020 01:34:15 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T4pO31Um; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1728010AbgGTIeM (ORCPT + 15 others); Mon, 20 Jul 2020 04:34:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726520AbgGTIeL (ORCPT ); Mon, 20 Jul 2020 04:34:11 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE0DC0619D2 for ; Mon, 20 Jul 2020 01:34:10 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id f2so16899356wrp.7 for ; Mon, 20 Jul 2020 01:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=NQ0TByaTMYGuIND8hZglNUNSd92F891BfsAU17IV3Es=; b=T4pO31UmMyzqx2qMpzkFtoXF19ZYw+k2zekVoaJTg9KWSyQR7wqjM5sIhpsYrkhi+Y sZtQOwDUt3iffbHLIxLwpS4yX8pYmSVWIlgcwtBtVVH/1mdwHWHtBZLo9sZVwObEDcna +rE1aqP4cr0i1kcqEdrlc+9FnNGFI5S15lALJizv4NXARKUdDmo+n4XbrvccZixmOyIj l+lpDfOih5/VJoLWBus67FuxgoToWVZdNxrwyXrPe0uS8/AI1yukwTW5ZkYJ4WQQJEA8 rQ5QWdeeRC7OqPKL10nPa0+XZXk/Yr6sEd68AdmXNTeUF5v0KhGkyQWnQzwxHDJW4gRb uSkA== 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; bh=NQ0TByaTMYGuIND8hZglNUNSd92F891BfsAU17IV3Es=; b=jFSAGMrha4VjLvBU42D3smVW7lCrwYdbMaHbiI+vv4B5E2D2162ZGIiI9teo5b2X4t IoO8FJFt4BZQzYxt8XPDFbtW/MP3MJHz4NPlXaD3RxuLp8vSMMeXQ60yJx1Bj28oGJlq viOH52bNnovUm4PQYdQm4P9hCNR/blK12tTFYPfjKzbJDq+GCnxomluJbTfHTFXfwBm5 KOas7obSgcg2KenymIdWxldnDk2NKgu+WuhWDu7JVejTIZvsbs/usstyFczlT37SYeS5 kR2Oyow/HjVhpFyr/rHIZGgXHauPuWJ3d0P9BASsSEV5+Xk83fKugfBL3kc0EEFJPKUT fK2Q== X-Gm-Message-State: AOAM531/3kLXX4OFNhjO1ABG3IkhACs1FCc+dXxtDcnRet0qBj8Zi294 DQcxSb71kCxiYFr1yIEWCB+JQA== X-Received: by 2002:adf:82a5:: with SMTP id 34mr10385755wrc.266.1595234049333; Mon, 20 Jul 2020 01:34:09 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:7da7:684d:4a8a:3f66]) by smtp.gmail.com with ESMTPSA id b8sm405707wrv.4.2020.07.20.01.34.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 01:34:08 -0700 (PDT) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: valentin.schneider@arm.com, sashal@kernel.org, Vincent Guittot Subject: [PATCH v4.19] sched/fair: handle case of task_h_load() returning 0 Date: Mon, 20 Jul 2020 10:34:01 +0200 Message-Id: <20200720083401.22164-1-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 01cfcde9c26d8555f0e6e9aea9d6049f87683998 ] task_h_load() can return 0 in some situations like running stress-ng mmapfork, which forks thousands of threads, in a sched group on a 224 cores system. The load balance doesn't handle this correctly because env->imbalance never decreases and it will stop pulling tasks only after reaching loop_max, which can be equal to the number of running tasks of the cfs. Make sure that imbalance will be decreased by at least 1. We can't simply ensure that task_h_load() returns at least one because it would imply to handle underflow in other places. Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) [removed misfit part which was not implemented yet] Signed-off-by: Vincent Guittot Reviewed-by: Valentin Schneider Reviewed-by: Dietmar Eggemann Tested-by: Dietmar Eggemann Cc: # v4.19 v4.14 v4.9 v4.4 cc: Sasha Levin Link: https://lkml.kernel.org/r/20200710152426.16981-1-vincent.guittot@linaro.org --- This patch also applies on v4.14.188 v4.9.230 and v4.4.230 kernel/sched/fair.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 92b1e71f13c8..d8c249e6dcb7 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7337,7 +7337,15 @@ static int detach_tasks(struct lb_env *env) if (!can_migrate_task(p, env)) goto next; - load = task_h_load(p); + /* + * Depending of the number of CPUs and tasks and the + * cgroup hierarchy, task_h_load() can return a null + * value. Make sure that env->imbalance decreases + * otherwise detach_tasks() will stop only after + * detaching up to loop_max tasks. + */ + load = max_t(unsigned long, task_h_load(p), 1); + if (sched_feat(LB_MIN) && load < 16 && !env->sd->nr_balance_failed) goto next;