Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7522083ybi; Mon, 22 Jul 2019 15:00:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8F9u/h6lvorJUzvev+Dw95KtPy0e8KsglT+xKqn+KTjyCJWvr41vcVBOt7LmNrtrO7Nbu X-Received: by 2002:a17:902:9688:: with SMTP id n8mr75819987plp.227.1563832803637; Mon, 22 Jul 2019 15:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563832803; cv=none; d=google.com; s=arc-20160816; b=oDTHkyVoY0JU2oV2XZwdAr1917LcfkEREdHUJQDvmOosi5GttkCgatqFzljPAJBO7n OtLsF61G6Cop2SkiASKUJiMi8qz49F+T9WtJyv8dgWaSyBfdRU5js/hniSFZvFPkbqeD 8EnjZeTefLcLVQ5w83YFaVCBg04AeCtZYYiDCuPh+GAgfDCMLzA1gfXSr8rIUPAM5qQs T89iBoJR/vg8FOJ+Z4qwjEFSa1s9xNH3lCpiS69TDKWihWb5csw0OH+ot2dgayDWqlti XoYELcpzx1Ytm5kWLUS72iPX6Uja/HkDQsT3pPtyryGcldMd7FJTkQXEujC6CxFWPwkO 1bnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4iBAqEbqMfdEtQBpqwsQIhy/OUSVAU0tUklS7rqkXjc=; b=Lma9kEzPK4KHtR18Y/QMwRUFc5xjcVJn2Car4kLJ9ApJCRCFF+PgvN+hs+NkA0x6uw ncb1F+Kzs6m4gmCI9kea5SP72VxTP+xx/yzwwTNUeeR9y4E9pVKjyuL6Mkr0ZayOWFSC vzJILAFIBoo9pv8k/MraUWkBnJS6juwIvY3ii5sHaJKyxOw65WJyCf+7VBsR+Zv3wuaf VJG0m0y+hybjL3rS5cR+KgmBUUo1OIULphWCx2AishrZuzVu0un244vUIWn7LQ1kYlWZ TqeGTJKLr8m+LiFYMxjCY2nSKtTgFv/+EtlIiVhR7jZJKhkAxYQV2LZvd+rTqX43vk6e YU5A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si3850544pgl.318.2019.07.22.14.59.47; Mon, 22 Jul 2019 15:00:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728313AbfGVRec (ORCPT + 99 others); Mon, 22 Jul 2019 13:34:32 -0400 Received: from shelob.surriel.com ([96.67.55.147]:37862 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727908AbfGVReX (ORCPT ); Mon, 22 Jul 2019 13:34:23 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hpcC8-0003HL-8b; Mon, 22 Jul 2019 13:33:52 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, pjt@google.com, dietmar.eggemann@arm.com, peterz@infradead.org, mingo@redhat.com, morten.rasmussen@arm.com, tglx@linutronix.de, mgorman@techsingularity.net, vincent.guittot@linaro.org, Rik van Riel Subject: [PATCH 07/14] sched,cfs: fix zero length timeslice calculation Date: Mon, 22 Jul 2019 13:33:41 -0400 Message-Id: <20190722173348.9241-8-riel@surriel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722173348.9241-1-riel@surriel.com> References: <20190722173348.9241-1-riel@surriel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 39f7a2d810e1..9ff69b927a3c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -732,6 +732,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