From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 431AD241A11 for ; Wed, 15 Jan 2025 11:55:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736942112; cv=none; b=OvrcVJp8PXsAOGnfSlMacbpCrw2JQQKRsLarOyF8L5hLLx+4ex6b+szjvXshIUSd7niO9h3iuL7ESUqYVeg3BV9A3xFhl2fq2thWSUlpd2EeNL0bg8cQRNTsaVEs3iZvVP8jp+4ewJDfvY83OIoZw7a8Jlr1S1horh60+3hw1XQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736942112; c=relaxed/simple; bh=+9aKAyLQEaAhivSB+ZH6kKBOx1tpnns18TYjFJcrVYc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=sfz3cbZBYIKjEHdH3lBpuiHEtRHtmWB5DIxsG6NqwVCopxayVYLs7AtU95thw6uYh6i4jr1t4Y77RGONBhui+SML7vxxOEJnyr8q0pcylYygpmKDdO7wpy1NSbLK36qefBd18RzpLTfzpQf2GZZ8PLOq4NjIEfFfb40PIEOuaOc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XXpdUOWr; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XXpdUOWr" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-21644aca3a0so145231525ad.3 for ; Wed, 15 Jan 2025 03:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736942110; x=1737546910; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=g2mvuWLmUnZYZavCcf+wnZhqpcLs8BMAtjDh23BAtSk=; b=XXpdUOWrbL/w+qbbrwm6Z+I59lDb2CjSw+RQ8V0SaCbneCWzVGTqJ4/vTL+h2xngLY ODBisjERujKdAuq+BdfYT037yVemnzuAjk2cfckcRttbLB6eOxAzo8Pz5oMzE//oTA2f T5pMc1Qxw5vox4oX6eYFne620hSAZnN2C7T3uIPfP7xu0pTlZ6aKJYZdjg833Mgzjnd1 ivAlYsiNyhFLYHbYRu1gbrpZyerhCqPjCdfh1hNkB2HdA+BnMsBWU727tpXtIkS4RQ7n cFbV3AKqf0iB/tiPgQ5DPhCe6j68PN0H321REFhcb0/3balBgELxZEctYg0viqru8nhk vWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736942110; x=1737546910; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=g2mvuWLmUnZYZavCcf+wnZhqpcLs8BMAtjDh23BAtSk=; b=R0k0L2ZxE+T5pc17ES2SyjMoO2fAlrjnA/IDd4hnbI+c/vNGWttO00jrrXrQZ0EWQZ KKrA9KW0me9kJkJPQ/Nm9fQQiR6cBUzOWMvkhfarVngEGATXsFAkhOr5CVML7n4M4V8y F/XMfgIoSRaYwzAWBBm6vJEAkjwDH2kEtCZPZqKD/KW8Z61u6My0Xxh191nqsOFWlAtJ RvgDZ7VnmoFW2blytSTwqmgetSC5L0SzlU7/elbzr4/GeiuK81NjgVK5T2BHv5ZIdUzK b8o9SOyDT/B3qCxGwq6nrD5QlZOf++iKXUeiuNSIt8bj1e+BGZwXNFfGVB7vpZksXLDs Vhgw== X-Forwarded-Encrypted: i=1; AJvYcCWKlEEUJwI8VjZPf6SxBu3lmE1eRmjb6RZ+g1nl5PFocKm8ZKCvy8fq6mXDVhVkwhG/K7mny+hw9XrPp1E=@vger.kernel.org X-Gm-Message-State: AOJu0YzeNWLJOgXYVra98e4D29vtnYWGdarpJeFZP2nJBqI9mlK8T3YI hZTloo649i1asCDuG8iZ7nZKHi1sXphPfmi7RHxudtqrDLz2fhvE X-Gm-Gg: ASbGncsgrUkkK2RKh6DXMRpa2jConTTlVdFdgP6pNK3mmADdoFE05QQTtLwEVkFvtDj w/ibwsVmzKYfu7aA9AVw+IkP5OK0k4aEgW/HApP+x3V3Pm6hD7a5zjdjgA2Au7pfw0ZOw5tQXKM ma+3F9uMwhIkD7RyxVcSerXG9bUQ4pgC0MqnNAGZfGVuDKkGAJOJTIwT6nbcPYWpLBW1WZ9Bhwl tB8vXHo0tk/IBRq7KcjDxQIK4UgJ6AVPq2JRK2cIHK8NdBiSjo02Dv4KOVLcc1gpTzJhVJ823c= X-Google-Smtp-Source: AGHT+IEybcg5a1TplyQmlYq6Ijms8I/5UTf6KHYEn8+PvRYAJqJ50bzxwFd0uWEvj2K12iFryOgmHw== X-Received: by 2002:a17:902:cec1:b0:216:3c36:69a7 with SMTP id d9443c01a7336-21a83ffbe22mr444000495ad.45.1736942110386; Wed, 15 Jan 2025 03:55:10 -0800 (PST) Received: from [10.125.112.6] ([103.165.80.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f10df7asm80871375ad.47.2025.01.15.03.55.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Jan 2025 03:55:09 -0800 (PST) Message-ID: <56d9d6cc-021e-4bd5-7254-aa39c9845500@gmail.com> Date: Wed, 15 Jan 2025 19:55:04 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH v2] sched/core: Prioritize migrating eligible tasks in sched_balance_rq() To: Vincent Guittot Cc: mingo@redhat.com, peterz@infradead.org, mingo@kernel.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org, Hao Jia References: <20241223091446.90208-1-jiahao.kernel@gmail.com> <597384e3-6519-b10e-081b-30c3f89b6e3f@gmail.com> From: Hao Jia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2025/1/15 17:28, Vincent Guittot wrote: > On Wed, 15 Jan 2025 at 09:55, Hao Jia wrote: >> >> >> >> On 2025/1/14 16:07, Vincent Guittot wrote: >>> On Tue, 14 Jan 2025 at 04:18, Hao Jia wrote: >>>> >>>> >>>> >>>> On 2025/1/14 00:40, Vincent Guittot wrote: >>>>> On Mon, 13 Jan 2025 at 10:21, Hao Jia wrote: >>>>>> >>>>>> Friendly ping... >>>>>> >>>>>> >>>>>> On 2024/12/23 17:14, Hao Jia wrote: >>>>>>> From: Hao Jia >>>>>>> >>>>>>> When the PLACE_LAG scheduling feature is enabled and >>>>>>> dst_cfs_rq->nr_queued is greater than 1, if a task is >>>>>>> ineligible (lag < 0) on the source cpu runqueue, it will >>>>>>> also be ineligible when it is migrated to the destination >>>>>>> cpu runqueue. Because we will keep the original equivalent >>>>>>> lag of the task in place_entity(). So if the task was >>>>>>> ineligible before, it will still be ineligible after >>>>>>> migration. >>>>>>> >>>>>>> So in sched_balance_rq(), we prioritize migrating eligible >>>>>>> tasks, and we soft-limit ineligible tasks, allowing them >>>>>>> to migrate only when nr_balance_failed is non-zero to >>>>>>> avoid load-balancing trying very hard to balance the load. >>>>> >>>>> Could you explain why you think it's better to balance eligible tasks >>>>> in priority and potentially skip a load balance ? >>>> >>>> In place_entity(), we maintain the task's original equivalent lag, even >>>> if we migrate the task to dst_rq, this does not change its eligibility >>>> attribute. >>> >>> Yes, but you don't answer the question why it's better to select an >>> eligible task vs a non eligible task. >>> >>>> >>>> When there are multiple tasks on src_rq, and the dst_cpu has some >>>> runnable tasks, migrating ineligible tasks to dst_rq will not allow them >>>> to run. Therefore, such task migration is inefficient. We should >>> >>> Why is it inefficient ? load balance is about evenly balancing the >>> number of tasks or the load between CPUs, it never says that the newly >>> migrated task should run immediately >> >> >> My initial thought is that when we need to migrate some tasks during >> load balancing, at the current point in time, migrating ineligible tasks >> to dst_cpu means they definitely cannot run there. Therefore, I prefer >> to keep them on src_cpu to reduce the overhead of dequeueing and >> enqueueing ineligible tasks. > > Sorry but I still don't get why it's important and would make a > difference. They are all runnable but ineligible tasks got more > runtime than other at that point in time so there is no real > difference I adopt a lazy strategy for ineligible tasks. At the current point in time, even if we migrate ineligible tasks to the dst CPU, they still have to wait on the dst CPU until they become eligible. We do not see clear benefits from migrating ineligible tasks, but their dequeueing and enqueueing would instead incur overhead. Let them wait on the src CPU until they become eligible before migrating them. this can reduce the number of task migrations. Thanks, Hao > >> >> Migrating eligible tasks to dst_cpu does not guarantee that they will >> run earlier than on src_cpu. it depends on too many factors. >> >> >> >>> >>>> prioritize migrating tasks that can run on dst_rq. >>>> >>>> In other words, migrating ineligible tasks is merely moving them to >>>> another runqueue to wait until they become eligible. >>> >>> But I don't get why it's a problem. Migrating an eligible task might >>> delay its scheduling because of its deadline vs other tasks already >>> eligible on the dst_rq. Eligible and non eligible tasks are all >>> runnable, it's just how much they have already run. In addition, >>> migrating an eligible task will clear its positive vlag with >>> DELAY_ZERO which is unfair IMO >> >> >> Sorry, I'd like to ask you a question that confuses me: Why does >> migrating eligible task will clear the positive vlag? > > sorry I mess up everything that only for delayed dequeue task > >> >> In detach_task(), the ENQUEUE_DELAYED and DEQUEUE_SLEEP flags are not >> set, and in dequeue_entity(), eligible tasks will not set sched_delayed, >> so they will be dequeued normally with se->on_rq being 0. >> >> Similarly, attach_task() does not set the ENQUEUE_DELAYED and >> DEQUEUE_SLEEP flags, and since se->on_rq is 0, it will not call >> requeue_delayed_entity(). >> >> >> Thanks, >> Hao