Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3522872ybi; Fri, 5 Jul 2019 08:50:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaTtAe/2KqF4/KnfqWJw0k1uTkLKyW3QK8zum2gwEyHnoIc8jRdUD7lEZVmerH5Qc5pwYk X-Received: by 2002:a63:7e42:: with SMTP id o2mr6209701pgn.162.1562341844454; Fri, 05 Jul 2019 08:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562341844; cv=none; d=google.com; s=arc-20160816; b=K53BKdOpozVPim7BCrDO5uGe9cNlKvFb9KoydK4eBpMuREF4MSqD/nuC0MD1qnE4o4 o2DedyKyFVjwfFziUIANkvHJGvYQ3vl02bqVZ+8p5MeUOWqXdxMVmmaahI9vPBY3YrIw AxCLKlqluSfB4bit81JDrBgK1dBBmm8enEtZcfWUGV7byXIF13vYxapoew9ZLEQFdSgQ Ap2jbf+JIwE1KK1dTbzSKMa2WNkPVw3BcNBJbxDd/4I6oubZCSYzmuOGNES+6wKoJ6T5 81Zh/laA5ynWBx/4Aphj5Bst4dx38yN/mIDUR72VsqynHwxk1mQjtsEGSp9bwFGyUm0A qGIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3MvpTP2fFCaQkoA+f5/CTtpJaXvZZnBt/GIh5Twe+DA=; b=yn+v+EvB+P4g4XW1WH3HhChCBzsG9JCGn4YrygtzykFxCsBLgNF6EjbJpuQvRDYFNN ITu9CJ3TTGZuCu0tRE+Qy+ibd7SjNGrOH7HwgAIwFPjVaPdojyLlZzm8clyUhtl+eaI/ ZEwnZLAxOr24Y3LqM/7qmgb/GLk8fcUwlWiqcUDJqJ7k2bxHpJRnzD5icg7NyQKqsfop /IjlVmLSP8x3Ev1PPvbg5Vb3WjrXleE7zA+iR181NaLzOn7VZiVDSSZ+H60f0Bl3h+Hy XxfniisfeOG9HxE42lZ9dQWy18HpBMiHlLdmPU3e6nO7jrtxXmzFkN7e5X0PzZadoOPJ otXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GuKnXgcd; 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 k13si9466841pfa.17.2019.07.05.08.50.28; Fri, 05 Jul 2019 08:50:44 -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=@linaro.org header.s=google header.b=GuKnXgcd; 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 S1727010AbfGEOv6 (ORCPT + 99 others); Fri, 5 Jul 2019 10:51:58 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:43219 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbfGEOv6 (ORCPT ); Fri, 5 Jul 2019 10:51:58 -0400 Received: by mail-lf1-f66.google.com with SMTP id c19so886694lfm.10 for ; Fri, 05 Jul 2019 07:51:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3MvpTP2fFCaQkoA+f5/CTtpJaXvZZnBt/GIh5Twe+DA=; b=GuKnXgcdfHnBxseTuVOzqohK5pv/apckKuFKURCRMLJHjFBV2NQfMuVvKSTB6LCf9I EmUwt7JSggxOQtq0bV8q2RFTsgqCpMyKQy47G1kVTeJvvUSKlw/2VkjXhKRn6IweN6gB rZmgpyBI4B7GD4oZ7BoblZ5DVyQfETZZYytzmKlARlAEQ883E2xtewsSG+aMNUT8Svf4 rxqOTALu0JFeC7OewPOQx5UdYy8trHGaVogPvlPMo/Y2D1OY8yC/Yy1p/HCXpGSHuWZw kCLaU2PN1LVIS3nXoO+VHkSVU4Z4/WTcPlyuEoWYs7j+c/KgvVuMPaZFIH5qg632VUYi 9gdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3MvpTP2fFCaQkoA+f5/CTtpJaXvZZnBt/GIh5Twe+DA=; b=KrAcFZb+G6lLVlS3jqgHxSKmYSAahMYn7f2oD0I68v1STYBB3yVkH8sP9UZaYpcCvK 0rtFqr73DaihM2CcOvElOtwU9RDAPAXZXY48uAIDEkj/pq2G5zdoBThsFpxbZolJNegE kNGOiYPASY9s0pZPAwh4yuWBTDIcBxBrkwHbD+9OBWCgJhrKp2etY0mDOELh9ncxBsGO 8gMFeDFuYteAEa0untyW9VK1qpHYLVgIxU0j9K5yxGesnOGB/H+SUf4DQlTmZcfgcvxp hlLwjQmrU+HZapj2m855+zbfyRCsVhG54vxCKhOBolPmGBOPV6R6nVo//7SLvfF1WvQZ FSuw== X-Gm-Message-State: APjAAAUSsqbYlZFEMfO/b+urdMK0EfpX/IuOAwuCgWHul2zMTWx8rCL6 zy5bVJdyQ7blBDmfhb0eIFd8P/s+7rwaBvRtW9XejQ== X-Received: by 2002:ac2:4a78:: with SMTP id q24mr2086995lfp.59.1562338316187; Fri, 05 Jul 2019 07:51:56 -0700 (PDT) MIME-Version: 1.0 References: <20190628204913.10287-1-riel@surriel.com> <20190628204913.10287-8-riel@surriel.com> In-Reply-To: <20190628204913.10287-8-riel@surriel.com> From: Vincent Guittot Date: Fri, 5 Jul 2019 16:51:45 +0200 Message-ID: Subject: Re: [PATCH 07/10] sched,cfs: fix zero length timeslice calculation To: Rik van Riel Cc: linux-kernel , Kernel Team , Paul Turner , Dietmar Eggemann , Peter Zijlstra , Ingo Molnar , Morten Rasmussen , Thomas Gleixner , Mel Gorman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 28 Jun 2019 at 22:49, Rik van Riel wrote: > > The way the time slice length is currently calculated, not only do high > priority tasks get longer time slices than low priority tasks, but due > to fixed point math, low priority tasks could end up with a zero length > time slice. This can lead to cache thrashing and other inefficiencies. > > Simplify the logic a little bit, and cap the minimum time slice length > to sysctl_sched_min_granularity. > > Tasks that end up getting a time slice length too long for their relative > priority will simply end up having their vruntime advanced much faster than > other tasks, resulting in them receiving time slices less frequently. > > Signed-off-by: Rik van Riel > --- > kernel/sched/fair.c | 25 ++++++++----------------- > 1 file changed, 8 insertions(+), 17 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index d48bff5118fc..8da2823401ca 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -671,22 +671,6 @@ static inline u64 calc_delta_fair(u64 delta, struct sched_entity *se) > return delta; > } > > -/* > - * The idea is to set a period in which each task runs once. > - * > - * When there are too many tasks (sched_nr_latency) we have to stretch > - * this period because otherwise the slices get too small. > - * > - * p = (nr <= nl) ? l : l*nr/nl > - */ > -static u64 __sched_period(unsigned long nr_running) > -{ > - if (unlikely(nr_running > sched_nr_latency)) > - return nr_running * sysctl_sched_min_granularity; > - else > - return sysctl_sched_latency; > -} > - > /* > * We calculate the wall-time slice from the period by taking a part > * proportional to the weight. > @@ -695,7 +679,7 @@ static u64 __sched_period(unsigned long nr_running) > */ > static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) > { > - u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq); > + u64 slice = sysctl_sched_latency; Is the change above and the remove of __sched_period() really needed for fixing the null time slice problem ? This change impacts how tasks will preempt each other and as a result the throughput. It should have it dedicated patch so we can evaluate its impact > > for_each_sched_entity(se) { > struct load_weight *load; > @@ -712,6 +696,13 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se) > } > slice = __calc_delta(slice, se->load.weight, load); > } > + > + /* > + * To avoid cache thrashing, run at least sysctl_sched_min_granularity. > + * The vruntime of a low priority task advances faster; those tasks > + * will simply get time slices less frequently. > + */ > + slice = max_t(u64, slice, sysctl_sched_min_granularity); > return slice; > } > > -- > 2.20.1 >