Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27586357rwd; Tue, 4 Jul 2023 05:13:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UvE4imAjAV+kbwuecV/BofUeYYP0ZxTUxjIMyPU3pHXtsswcOT7ui59EmMgq+I0m2xqPd X-Received: by 2002:a05:6808:1294:b0:3a3:82a1:d1e7 with SMTP id a20-20020a056808129400b003a382a1d1e7mr14643632oiw.6.1688472785684; Tue, 04 Jul 2023 05:13:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688472785; cv=none; d=google.com; s=arc-20160816; b=x8I+DVDP/HuXg3VtUZn5Or3QYL8DhBBuvdrz9OC308GBmEefciXDn6XgZFvNsl3ckT rsA+yvcbqqkXVOhkORTDH1E1WEqbUHY2sty/AhGK/JOUusUhCl13ugJ7PbsmLz1qvKsJ b6Dn8Xof7o4bsC5zLhYBzjIAhZpRHfpOJYfH1T0UOVvs78rgTxIOFDL1Yz2/D/u622mt AF8iH73Y9h0Sm1qOwHVgVhYuIhkUQVQeVVYKO+LOxje8ZsuuTy7IXGl60195kkl4g6ct xOd3errLBiPu4Z2ogCf389UnCnNTiUp+XCgAlbJva71hgv7WDdtWVeAMbIuo8FfHbyt8 q/DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KQpjH4di1VO1U3FEdIvi7edd0iZld7Y3v2PyvyPLVwQ=; fh=xm61FqaKFbVtJj3DZjMBwIjT3viqbFfn4Ws5hFHxOsg=; b=DYfgCNjZqXgdYx20gFGtUGmVT16ud4f0pFxEG3xDT1vewHLY0CNgscO7eLZRgam20d DbfOl9lCvSt0PzsNPTgY2seJnPxvt2mHmTuX8ibSFoZ3iMOifoHYvPNY/OdPkOn8Alyp Uc0BtZ8KZJsfSIeYww6UbJluIJcj/Yf6MpPItO/TSB8TCxWbUe6iOb1h0AiFDzs8DI5N VQp6ElC7lIXWyVIrUO2Bzl3bF1LnuFTI7857vaVvnntQGr7J26pDvlRdbJo8wW94gl+w PVEs94UVfuMJEKTnJ+DSraOAGlYJW+38Y3gabiWNFN6+4Zldqj5yh7XV6MpItC8zAftJ hjPw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w71-20020a63824a000000b0054fcef3f7b9si21600274pgd.504.2023.07.04.05.12.50; Tue, 04 Jul 2023 05:13:05 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbjGDMEd (ORCPT + 99 others); Tue, 4 Jul 2023 08:04:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbjGDMEc (ORCPT ); Tue, 4 Jul 2023 08:04:32 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6EB9E7E; Tue, 4 Jul 2023 05:03:58 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QwLws1dBlzLmsg; Tue, 4 Jul 2023 20:01:17 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 4 Jul 2023 20:03:28 +0800 From: Miaohe Lin To: , , , CC: , , Subject: [PATCH] cgroup/cpuset: avoid unneeded cpuset_mutex re-lock Date: Tue, 4 Jul 2023 20:03:52 +0800 Message-ID: <20230704120352.1226787-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 cpuset_mutex unlock and lock pair is only needed when transferring tasks out of empty cpuset. Avoid unneeded cpuset_mutex re-lock when !is_empty to save cpu cycles. Signed-off-by: Miaohe Lin --- kernel/cgroup/cpuset.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 601c40da8e03..e136269c152c 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3521,17 +3521,16 @@ hotplug_update_tasks_legacy(struct cpuset *cs, is_empty = cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed); - mutex_unlock(&cpuset_mutex); - /* * Move tasks to the nearest ancestor with execution resources, * This is full cgroup operation which will also call back into * cpuset. Should be done outside any lock. */ - if (is_empty) + if (is_empty) { + mutex_unlock(&cpuset_mutex); remove_tasks_in_empty_cpuset(cs); - - mutex_lock(&cpuset_mutex); + mutex_lock(&cpuset_mutex); + } } static void -- 2.33.0