From mboxrd@z Thu Jan 1 00:00:00 1970 From: Waiman Long Subject: [PATCH v5 0/3] sched, cgroup/cpuset: Keep user set cpus affinity Date: Tue, 16 Aug 2022 15:27:31 -0400 Message-ID: <20220816192734.67115-1-longman@redhat.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660678067; 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; bh=AdMi5hAffNheIEpe+PDcz4KKHqhLgVrtN02bVmFviGo=; b=MwPHGHOyB8upoeOr7x4VfOGs8gr6xOo5J9Nq39uye3xBcVfAHxhfwbOxRY3POTdaIb+OII 1K5Oqv1Ly3ApxcXLw2WwrVvt6MzqE+QRKVsJ4zTf3xPyU8K2uSe7ApyUly5ukyHOTJBNqE 8o8FOOYmP8wfxnIF3V8uYCArPnirCcs= List-ID: Content-Type: text/plain; charset="us-ascii" To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tejun Heo , Zefan Li , Johannes Weiner , Will Deacon Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Linus Torvalds , Waiman Long v5: - Update patch 3 to handle race with concurrent sched_setaffinity() by rechecking a previously cleared user_cpus_ptr afterward. v4: - Update patch 1 to make sched_setaffinity() the only function to update user_cpus_ptr to make the logic simpler and easier to understand. restrict_cpus_allowed_ptr() and relax_compatible_cpus_allowed_ptr() will just use it if present. v3: - Attach a new patch 2 to introduce a copy_user_cpus_mask() to copy out user masks with lock protection & use it in patch 3. v2: - Rework the v1 patch by extending the semantics of user_cpus_ptr to store user set cpus affinity and keeping to it as much as possible. The user_cpus_ptr field is added by commit b90ca8badbd1 ("sched: Introduce task_struct::user_cpus_ptr to track requested affinity") which uses it narrowly to allow keeping cpus affinity intact with asymmetric cpu setup. This patchset extends user_cpus_ptr to store user set cpus affinity via sched_setaffinity() API. With that information available, it will enable cpuset to keep cpus afinity as close to what the user wants as possible within the cpu list constraint of the current cpuset. Otherwise some change to the cpuset hierarchy may reset the cpumask of the tasks in the affected cpusets to the default cpuset value even if those tasks have cpus affinity explicitly set by the users before. It also means that once sched_setaffinity() is called, user_cpus_ptr will remain allocated until the task exits. Waiman Long (3): sched: Use user_cpus_ptr for saving user provided cpumask in sched_setaffinity() sched: Provide copy_user_cpus_mask() to copy out user mask cgroup/cpuset: Keep user set cpus affinity include/linux/sched.h | 1 + kernel/cgroup/cpuset.c | 42 ++++++++++++++- kernel/sched/core.c | 119 ++++++++++++++++++++++++----------------- kernel/sched/sched.h | 1 - 4 files changed, 112 insertions(+), 51 deletions(-) -- 2.31.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 9AF5DC3F6B0 for ; Tue, 16 Aug 2022 19:28:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237199AbiHPT2D (ORCPT ); Tue, 16 Aug 2022 15:28:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237177AbiHPT1u (ORCPT ); Tue, 16 Aug 2022 15:27:50 -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 DB4D67549C for ; Tue, 16 Aug 2022 12:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660678068; 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; bh=AdMi5hAffNheIEpe+PDcz4KKHqhLgVrtN02bVmFviGo=; b=ZTk6SZqx+RRZenOWJjcPwJxjM8s0uAcmgQdFnzGkxALtTlC25qwl2XVMM2G6aUVbhek1K2 6CScuwZhF5Dbll3onqVWu39GwCWePTioyPLaIL1OZ9Z2iXFCx2lcRp4m+YhUYesZLXQGxP g3i5RhtqTchzswQaMtsBKvWoX6Airnk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-462-3UYZxSw9PVS8DynTZNmmKw-1; Tue, 16 Aug 2022 15:27:44 -0400 X-MC-Unique: 3UYZxSw9PVS8DynTZNmmKw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 091C03800C27; Tue, 16 Aug 2022 19:27:44 +0000 (UTC) Received: from llong.com (unknown [10.22.10.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6B801121314; Tue, 16 Aug 2022 19:27:42 +0000 (UTC) From: Waiman Long To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tejun Heo , Zefan Li , Johannes Weiner , Will Deacon Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Waiman Long Subject: [PATCH v5 0/3] sched, cgroup/cpuset: Keep user set cpus affinity Date: Tue, 16 Aug 2022 15:27:31 -0400 Message-Id: <20220816192734.67115-1-longman@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org v5: - Update patch 3 to handle race with concurrent sched_setaffinity() by rechecking a previously cleared user_cpus_ptr afterward. v4: - Update patch 1 to make sched_setaffinity() the only function to update user_cpus_ptr to make the logic simpler and easier to understand. restrict_cpus_allowed_ptr() and relax_compatible_cpus_allowed_ptr() will just use it if present. v3: - Attach a new patch 2 to introduce a copy_user_cpus_mask() to copy out user masks with lock protection & use it in patch 3. v2: - Rework the v1 patch by extending the semantics of user_cpus_ptr to store user set cpus affinity and keeping to it as much as possible. The user_cpus_ptr field is added by commit b90ca8badbd1 ("sched: Introduce task_struct::user_cpus_ptr to track requested affinity") which uses it narrowly to allow keeping cpus affinity intact with asymmetric cpu setup. This patchset extends user_cpus_ptr to store user set cpus affinity via sched_setaffinity() API. With that information available, it will enable cpuset to keep cpus afinity as close to what the user wants as possible within the cpu list constraint of the current cpuset. Otherwise some change to the cpuset hierarchy may reset the cpumask of the tasks in the affected cpusets to the default cpuset value even if those tasks have cpus affinity explicitly set by the users before. It also means that once sched_setaffinity() is called, user_cpus_ptr will remain allocated until the task exits. Waiman Long (3): sched: Use user_cpus_ptr for saving user provided cpumask in sched_setaffinity() sched: Provide copy_user_cpus_mask() to copy out user mask cgroup/cpuset: Keep user set cpus affinity include/linux/sched.h | 1 + kernel/cgroup/cpuset.c | 42 ++++++++++++++- kernel/sched/core.c | 119 ++++++++++++++++++++++++----------------- kernel/sched/sched.h | 1 - 4 files changed, 112 insertions(+), 51 deletions(-) -- 2.31.1