Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp613509imn; Thu, 28 Jul 2022 10:24:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uRME24K1ps4ZwZxMt+JAyMbFSzFYquWMcdKW5iNoiP0GzTcEkwUxK9k6YeBNoRowm4DZ5X X-Received: by 2002:a17:907:7295:b0:72b:8207:bdc2 with SMTP id dt21-20020a170907729500b0072b8207bdc2mr22014081ejc.753.1659029086981; Thu, 28 Jul 2022 10:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659029086; cv=none; d=google.com; s=arc-20160816; b=Nwkz1sMmT+r3ClraRT618Adssip3Ofq9zy2xDH2dluFEJgSjAOf9VjQqNq6vKGFmHn NcxrIKbrp1GX9bjOR5O2x2cMixj1oW0Ey2KkAZSW2UmoURjPsF0xqono1vznULbE2ua3 /qz/p5i9MFc8K6zvO3ze+LLbdPYG1M2Ov9ILfwcFjbRtUIzX/t40c790vel0QWV5OrkA ecJwO4w7Z/KxIa/NuEtK1rckTPMMeYUDAgFjXPrnoVrUSSGyfFa4kLY+UODmgpOqz+7u AEjzlJJhkXaVozR1yV5OfW/F7MjWe3TUT9JsnimfASfl6FM4nEqpafLzElHhywPJE9aG oKZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=N+EDZeN9hOjgggv+GakuBGOt5cAU+R6TAmQfKefuGy4=; b=Ks0E0qA78tBTWq2S/ciHA3Gkl2HW2uLFhRhr3wx2g2cY5fXttBddaqH52jnqBemgAw 0vvFtIlUp8wRVbo2kGvhJa7mP8iPT6jdzHzruriA2092AtUAw/aXcozc0Yosm6Ho20zT usZYBbLEBQgQx+J56fX1rM0RDYYvsi1H/3xB6AtwO1OMLefGB85B70Mz6mmV245OABUm 2xtRehdWvpZ05Ov839nlQlOhO7f5hot4Kp00IEkJvnEwSqi8o3RsLLmgeJpu1T7EiZoh IX+5ItyQ0vOrtb473v3ppT9HeeQSrsY6UPEixU3Yny4lbghf0xfC5AttyhlOdNP+hIdj tsew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Emg3DdK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a056402268400b0043bf3d294c2si1229279edd.604.2022.07.28.10.24.22; Thu, 28 Jul 2022 10:24:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Emg3DdK7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiG1RXM (ORCPT + 99 others); Thu, 28 Jul 2022 13:23:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiG1RXK (ORCPT ); Thu, 28 Jul 2022 13:23:10 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B254F2A27D; Thu, 28 Jul 2022 10:23:09 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id b133so2479941pfb.6; Thu, 28 Jul 2022 10:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc; bh=N+EDZeN9hOjgggv+GakuBGOt5cAU+R6TAmQfKefuGy4=; b=Emg3DdK7LSA+NPGtwUNvKOne+VsyeeyNXbQvyE/VGpLz3/txaN1mHFE01gAsuDkCbB 2K7lXPS/nzQZA2KQw6vB/AgSjSFuh5/PtFjUpNz/VSASorhlSmLD2FS3h2HbfMkcTDG2 fxBFMM8xJyVClKV9xW3aMewFxSDcY7TeKGj4/W3nEqhO62yY+c9uMYLUim1v3S2aZWn2 iguQ331j5j8wWHjY9b26yu1dsHepHq14knp9Lp2mh3CssireX5EasKZP+fh+IoToiO9d uOOzEZXLpe1nmRc16BoqGuojFL+81jyLgTuwt2FYlVdkxONSwxluMiO3xqYUjVk9MEFQ +7pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-message-state:from:to:cc; bh=N+EDZeN9hOjgggv+GakuBGOt5cAU+R6TAmQfKefuGy4=; b=Kk+7gkYKa6CO+hfYwExgmlpOKVhCxRkihGiowlk/mkbTgb7iidzVleCsOeGltFKFI6 nM0nvqezQZim3uUX0MGVKatasB3agMWcrTHr8QjmJC61YM2vDggWMkJwNWdpfPJ/FlhR g85EDKUkRQtg7AVhteTPw9bH7Q3eTrpKxnuBfQZ6ZkKVvj2LdUumwN9mVMfWJadNIp2b TLDv7WtbLifAAJqCzex049SG0UQypox3qR/8qq8VA7QXXq+fuCrysULe1IAVh7CLb4y+ FcSzr/yjdlLPTeylLvQRc+XY4Q8c5ccCukiIi4SvHImwtxU9yMR1wcEqL6Ip7Pnrr07i QgOw== X-Gm-Message-State: AJIora/I+uNPqfN2xJ1KgoywUayh7CbgeHbbwrb/d0Hq6WVb7a1ktu1U nh59TN9Gr+IIEpdU8RjY4Ak= X-Received: by 2002:a05:6a00:8cf:b0:522:93a6:46e9 with SMTP id s15-20020a056a0008cf00b0052293a646e9mr28490624pfu.62.1659028989086; Thu, 28 Jul 2022 10:23:09 -0700 (PDT) Received: from localhost (2603-800c-1a02-1bae-a7fa-157f-969a-4cde.res6.spectrum.com. [2603:800c:1a02:1bae:a7fa:157f:969a:4cde]) by smtp.gmail.com with ESMTPSA id d5-20020a170902cec500b0016dc808f29bsm1408662plg.13.2022.07.28.10.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 10:23:08 -0700 (PDT) Sender: Tejun Heo Date: Thu, 28 Jul 2022 07:23:07 -1000 From: Tejun Heo To: Waiman Long Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Zefan Li , Johannes Weiner , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] cgroup/cpuset: Keep current cpus list if cpus affinity was explicitly set Message-ID: References: <20220728005815.1715522-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220728005815.1715522-1-longman@redhat.com> X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, Jul 27, 2022 at 08:58:14PM -0400, Waiman Long wrote: > It was found that any change to the current cpuset hierarchy may reset > the cpus_allowed list 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. That is especially easy to trigger under a > cgroup v2 environment where writing "+cpuset" to the root cgroup's > cgroup.subtree_control file will reset the cpus affinity of all the > processes in the system. > > That is especially problematic in a nohz_full environment where the > tasks running in the nohz_full CPUs usually have their cpus affinity > explicitly set and will behave incorrectly if cpus affinity changes. > > Fix this problem by adding a flag in the task structure to indicate that > a task has their cpus affinity explicitly set before and make cpuset > code not to change their cpus_allowed list unless the user chosen cpu > list is no longer a subset of the cpus_allowed list of the cpuset itself. > > With that change in place, it was verified that tasks that have its > cpus affinity explicitly set will not be affected by changes made to > the v2 cgroup.subtree_control files. I think the underlying cause here is cpuset overwriting the cpumask the user configured but that's a longer discussion. > +/* > + * Don't change the cpus_allowed list if cpus affinity has been explicitly > + * set before unless the current cpu list is not a subset of the new cpu list. > + */ > +static int cpuset_set_cpus_allowed_ptr(struct task_struct *p, > + const struct cpumask *new_mask) > +{ > + if (p->cpus_affinity_set && cpumask_subset(p->cpus_ptr, new_mask)) > + return 0; > + > + p->cpus_affinity_set = 0; > + return set_cpus_allowed_ptr(p, new_mask); > +} I wonder whether the more predictable behavior would be always not resetting the cpumask if it's a subset of the new_mask. Also, shouldn't this check p->cpus_mask instead of p->cpus_ptr? Thanks. -- tejun