Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1874043ybv; Fri, 14 Feb 2020 07:29:09 -0800 (PST) X-Google-Smtp-Source: APXvYqw9dUUdAfdIe5K+lawr47DYKOWDUDYKa5jnG9G9HETcrbPZW612NUB7g3jtOTmYj4ncHMkx X-Received: by 2002:aca:a810:: with SMTP id r16mr133035oie.116.1581694149381; Fri, 14 Feb 2020 07:29:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581694149; cv=none; d=google.com; s=arc-20160816; b=OpQ07jgFDXo2nInzj3Jde7aINl4cn6esyJC6zwg2oHLAbPSH3lHsORlcMldCckHNvb hxvKnqBmnIzmxCmt4mWoiY/OrMuLIZjCuW+9EAmmt2bpQaPkRj2u6g1IZTKO7EG308rZ 4XzqLHyewRCwhS57T6fm+ro4kLReMfOsCEOElZgRVIN5c0pIJZoDfjRbI1cciVUNlaEI rlhkvbDg1PbsFMcdy5OiKYBEE2BtyUhfGHfCTcmVLTApAMyc0QBHzweOzFzBrMuW4sQp ocJe9qEv+yYtIgNVY4XZMa4myLFY277S5+ozW41YB86tkijEjgshuPzh8uGkpNtBPVxA gGOA== 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=53ngjg9JhA2q1DD1qwBuU9TKGF91CSQgYHS0UwTt7oY=; b=J8UeUfCqynPqZZHGflGTiGNL86xRK5a/mOWMeLcY0kIZiQx7Jtqq5P+Mf/T06kVSpc 7waePLgn97oJ/OHAA4TKah3jfCVOtF8F7Quwz7vYpdrW2Iel3Co0VjLL1K5+Sw2QEGZq ConTCkZEsmxuZ+EPIDQyOtI7v2fBxNKd5lXDNgKlliMHw4qI9usMd4fkYadfLxe3uBHR TQ0PlOeK2i0YlsLv5q7xU1YbtuDoZ8IJpJaaaC+5Szz99yDBnq1GCVI1B+B/rbVbXo9+ ee6OXEOg1JKyAY3lpZSXm8ouDVkhXwMwGKxvIcLIi5x4pSBjVIHtrCHgVy/vvKcHdZ61 OCtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fBWBtkQ3; 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 r26si3156778otc.163.2020.02.14.07.28.57; Fri, 14 Feb 2020 07:29:09 -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=fBWBtkQ3; 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 S2387401AbgBNP1q (ORCPT + 99 others); Fri, 14 Feb 2020 10:27:46 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34859 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387398AbgBNP1p (ORCPT ); Fri, 14 Feb 2020 10:27:45 -0500 Received: by mail-wr1-f67.google.com with SMTP id w12so11352309wrt.2 for ; Fri, 14 Feb 2020 07:27:43 -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=53ngjg9JhA2q1DD1qwBuU9TKGF91CSQgYHS0UwTt7oY=; b=fBWBtkQ3iOVr33tkdY6P11CgyTyYsy82Dx5cJZt9xvwJLq1m/0p9P4X4jD+QGXl3O/ um26CtpprkNsXDpO2WKoePIWyExFNBqpbIC37vDGFxKTkd6+aGolvmUu3Nvve1btqKED IHXBJGbiycsCwEyW9DslYG4VmzkMO0B2BzYn5VvSyGaUXxfSqymwWfzYY7nRghWb7oDc /E+aMTD9T27ZUnWt0dHHaEppk4ykw7nCfFq4tVDNjan0I03gPxcGUDexMRq4luKg8XQk WMdrmngobufCJX3nvuaMOQpgON9Okwh4WEhzYsC2DXQIZF0FcwSP6lA1UU95cmTSVREM ijHA== 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=53ngjg9JhA2q1DD1qwBuU9TKGF91CSQgYHS0UwTt7oY=; b=OLTHzo/5/EzPnZeDYg0a2E7irFpBtZuN+zIUUkJnvHluB8Vb7lFpfKYpy7XfN0TmXB r5l0m2m1Y4jZzj+B32etdh2HFlNGd/csMQi9ErHq3DgeXypetqCW8Mb9t0RYTj/lZGHm xjoI7I10wMjtnM2/QXsP4NrRA8HuIVVTGDAx02W0teW0f8mnXf4scfbIQrReO7RSra7c H3+fIQWsY5lFDrby2OmCirk9rJj295YFjR33NV0Csv8RRq1DvZaD9LTT6gOyl55rZVjD h2bLn6Iv09ObSUi/IjU+Rn9ICOMBKctI4z2vsz7Vs3wn8JcZ8/ipI6UOJR9QO276MNev aovg== X-Gm-Message-State: APjAAAWfUwPUWP2cBaTYRNH1N+/7/0CcIHrnJrpa41hWGJwq5CuypzVp uPOW8e7t1sTm7K8ZT5xtU7JKaA== X-Received: by 2002:adf:dd0b:: with SMTP id a11mr4861102wrm.150.1581694063110; Fri, 14 Feb 2020 07:27:43 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:f:6020:b5b3:5d19:723a:398f]) by smtp.gmail.com with ESMTPSA id c13sm7442963wrn.46.2020.02.14.07.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Feb 2020 07:27:42 -0800 (PST) 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 Cc: pauld@redhat.com, parth@linux.ibm.com, valentin.schneider@arm.com, hdanton@sina.com, Vincent Guittot Subject: [PATCH v2 2/5] sched/numa: Replace runnable_load_avg by load_avg Date: Fri, 14 Feb 2020 16:27:26 +0100 Message-Id: <20200214152729.6059-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200214152729.6059-1-vincent.guittot@linaro.org> References: <20200214152729.6059-1-vincent.guittot@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similarly to what has been done for the normal load balancer, we can replace runnable_load_avg by load_avg in numa load balancing and track the other statistics like the utilization and the number of running tasks to get to better view of the current state of a node. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 102 ++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 27450c4ddc81..12266b248f52 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1473,38 +1473,35 @@ bool should_numa_migrate_memory(struct task_struct *p, struct page * page, group_faults_cpu(ng, src_nid) * group_faults(p, dst_nid) * 4; } -static inline unsigned long cfs_rq_runnable_load_avg(struct cfs_rq *cfs_rq); - -static unsigned long cpu_runnable_load(struct rq *rq) -{ - return cfs_rq_runnable_load_avg(&rq->cfs); -} +/* + * 'numa_type' describes the node at the moment of load balancing. + */ +enum numa_type { + /* The node has spare capacity that can be used to run more tasks. */ + node_has_spare = 0, + /* + * The node is fully used and the tasks don't compete for more CPU + * cycles. Nevertheless, some tasks might wait before running. + */ + node_fully_busy, + /* + * The node is overloaded and can't provide expected CPU cycles to all + * tasks. + */ + node_overloaded +}; /* Cached statistics for all CPUs within a node */ struct numa_stats { unsigned long load; - + unsigned long util; /* Total compute capacity of CPUs on a node */ unsigned long compute_capacity; + unsigned int nr_running; + unsigned int weight; + enum numa_type node_type; }; -/* - * XXX borrowed from update_sg_lb_stats - */ -static void update_numa_stats(struct numa_stats *ns, int nid) -{ - int cpu; - - memset(ns, 0, sizeof(*ns)); - for_each_cpu(cpu, cpumask_of_node(nid)) { - struct rq *rq = cpu_rq(cpu); - - ns->load += cpu_runnable_load(rq); - ns->compute_capacity += capacity_of(cpu); - } - -} - struct task_numa_env { struct task_struct *p; @@ -1521,6 +1518,47 @@ struct task_numa_env { int best_cpu; }; +static unsigned long cpu_load(struct rq *rq); +static unsigned long cpu_util(int cpu); + +static inline enum +numa_type numa_classify(unsigned int imbalance_pct, + struct numa_stats *ns) +{ + if ((ns->nr_running > ns->weight) && + ((ns->compute_capacity * 100) < (ns->util * imbalance_pct))) + return node_overloaded; + + if ((ns->nr_running < ns->weight) || + ((ns->compute_capacity * 100) > (ns->util * imbalance_pct))) + return node_has_spare; + + return node_fully_busy; +} + +/* + * XXX borrowed from update_sg_lb_stats + */ +static void update_numa_stats(struct task_numa_env *env, + struct numa_stats *ns, int nid) +{ + int cpu; + + memset(ns, 0, sizeof(*ns)); + for_each_cpu(cpu, cpumask_of_node(nid)) { + struct rq *rq = cpu_rq(cpu); + + ns->load += cpu_load(rq); + ns->util += cpu_util(cpu); + ns->nr_running += rq->cfs.h_nr_running; + ns->compute_capacity += capacity_of(cpu); + } + + ns->weight = cpumask_weight(cpumask_of_node(nid)); + + ns->node_type = numa_classify(env->imbalance_pct, ns); +} + static void task_numa_assign(struct task_numa_env *env, struct task_struct *p, long imp) { @@ -1556,6 +1594,11 @@ static bool load_too_imbalanced(long src_load, long dst_load, long orig_src_load, orig_dst_load; long src_capacity, dst_capacity; + + /* If dst node has spare capacity, there is no real load imbalance */ + if (env->dst_stats.node_type == node_has_spare) + return false; + /* * The load is corrected for the CPU capacity available on each node. * @@ -1788,10 +1831,10 @@ static int task_numa_migrate(struct task_struct *p) dist = env.dist = node_distance(env.src_nid, env.dst_nid); taskweight = task_weight(p, env.src_nid, dist); groupweight = group_weight(p, env.src_nid, dist); - update_numa_stats(&env.src_stats, env.src_nid); + update_numa_stats(&env, &env.src_stats, env.src_nid); taskimp = task_weight(p, env.dst_nid, dist) - taskweight; groupimp = group_weight(p, env.dst_nid, dist) - groupweight; - update_numa_stats(&env.dst_stats, env.dst_nid); + update_numa_stats(&env, &env.dst_stats, env.dst_nid); /* Try to find a spot on the preferred nid. */ task_numa_find_cpu(&env, taskimp, groupimp); @@ -1824,7 +1867,7 @@ static int task_numa_migrate(struct task_struct *p) env.dist = dist; env.dst_nid = nid; - update_numa_stats(&env.dst_stats, env.dst_nid); + update_numa_stats(&env, &env.dst_stats, env.dst_nid); task_numa_find_cpu(&env, taskimp, groupimp); } } @@ -5446,6 +5489,11 @@ static unsigned long cpu_load_without(struct rq *rq, struct task_struct *p) return load; } +static unsigned long cpu_runnable_load(struct rq *rq) +{ + return cfs_rq_runnable_load_avg(&rq->cfs); +} + static unsigned long capacity_of(int cpu) { return cpu_rq(cpu)->cpu_capacity; -- 2.17.1