Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C213C6FD1F for ; Tue, 14 Mar 2023 19:07:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbjCNTHe (ORCPT ); Tue, 14 Mar 2023 15:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjCNTHc (ORCPT ); Tue, 14 Mar 2023 15:07:32 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99FB328230 for ; Tue, 14 Mar 2023 12:06:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678820771; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UyKkF4M/yJ9pQotECcNeo3lMpmEkLTF8MPG6ILIYAd0=; b=HyBALDqPF7kDhUHuR+YMfoK6GGFRhKVjK5PT7003zedfUE7tVtDYoAZZL0Eylb9zUreFA7 f9W0NUFa0HKj+AOLnMaDaLAUtm/+TSyvnGSfdGLkBCrv1+UmlgCO2xQCR4PB9MaXi8Mfbu VvdQ5W3aqgBFfqWRqFUOaLfoEiFLLyo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-8WHvWdttNuWnaDuskp9sGQ-1; Tue, 14 Mar 2023 15:02:54 -0400 X-MC-Unique: 8WHvWdttNuWnaDuskp9sGQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 60130882820; Tue, 14 Mar 2023 19:02:54 +0000 (UTC) Received: from [10.22.18.199] (unknown [10.22.18.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id A45CA140EBF4; Tue, 14 Mar 2023 19:02:53 +0000 (UTC) Message-ID: <957bd5c2-1bae-de95-f119-483ef64dab60@redhat.com> Date: Tue, 14 Mar 2023 15:02:53 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH 2/5] cgroup/cpuset: Include offline CPUs when tasks' cpumasks in top_cpuset are updated Content-Language: en-US To: =?UTF-8?Q?Michal_Koutn=c3=bd?= Cc: Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Will Deacon , Peter Zijlstra References: <20230306200849.376804-1-longman@redhat.com> <20230306200849.376804-3-longman@redhat.com> <20230314173411.fqaxoa2tfifnj6i3@blackpad> From: Waiman Long In-Reply-To: <20230314173411.fqaxoa2tfifnj6i3@blackpad> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/14/23 13:34, Michal Koutný wrote: > Hello Waiman. > > On Mon, Mar 06, 2023 at 03:08:46PM -0500, Waiman Long wrote: >> - /* >> - * Percpu kthreads in top_cpuset are ignored >> - */ >> - if (top_cs && (task->flags & PF_KTHREAD) && >> - kthread_is_per_cpu(task)) >> - continue; >> + const struct cpumask *possible_mask = task_cpu_possible_mask(task); >> >> - cpumask_and(new_cpus, cs->effective_cpus, >> - task_cpu_possible_mask(task)); >> + if (top_cs) { >> + /* >> + * Percpu kthreads in top_cpuset are ignored >> + */ >> + if ((task->flags & PF_KTHREAD) && kthread_is_per_cpu(task)) >> + continue; >> + cpumask_andnot(new_cpus, possible_mask, cs->subparts_cpus); >> + } else { >> + cpumask_and(new_cpus, cs->effective_cpus, possible_mask); >> + } > I'm wrapping my head around this slightly. > 1) I'd suggest swapping args in of cpumask_and() to have possible_mask > consistently first. I don't quite understand what you meant by "swapping args". It is effective new_cpus = cs->effective_cpus ∩ possible_mask. What is the point of swapping cs->effective_cpus and possible_mask. > 2) Then I'm wondering whether two branches are truly different when > effective_cpus := cpus_allowed - subparts_cpus > top_cpuset.cpus_allowed == possible_mask (1) effective_cpus may not be equal "cpus_allowed - subparts_cpus" if some of the CPUs are offline as effective_cpus contains only online CPUs. subparts_cpu can include offline cpus too. That is why I choose that expression. I will add a comment to clarify that. > > IOW, can you see a difference in what affinities are set to eligible > top_cpuset tasks before and after this patch upon CPU hotplug? > (Hm, (1) holds only in v2. So is this a fix for v1 only?) This is due to the fact that cpu hotplug code currently doesn't update the cpu affinity of tasks in the top cpuset. Tasks not in the top cpuset can rely on the hotplug code to update the cpu affinity appropriately. For the tasks in the top cpuset, we have to make sure that all the offline CPUs are included. Cheers, Longman