Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2147665lqz; Tue, 2 Apr 2024 08:31:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvzPaR9UXGYRqh8OMUsPMjvBwZ98TNHxk9mTuvXvkxPTPbzpP+fh/TO1hfhIQb9Ekq5567BqUeIYbw3qFyhJAl9rZvXfrLUiSJa8knQg== X-Google-Smtp-Source: AGHT+IGka+cHegPO4iO8unzF7Gr7jGzpI/ZV0M1K7+B8iswWcbedLP8RDvVb+XJQScwOZqaS8yID X-Received: by 2002:a17:906:c42:b0:a47:3526:2e0f with SMTP id t2-20020a1709060c4200b00a4735262e0fmr7768124ejf.75.1712071878240; Tue, 02 Apr 2024 08:31:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712071878; cv=pass; d=google.com; s=arc-20160816; b=HB1eOw3qqVLTgB1UYXDmb4rf/qkBFxbrxsR2iuc05DWUesDDzo5Wv1KsWWe556gGRh z0QisthWgsuRqPCA+B5HVMOVjeOWe5J8Il76J2hSAlfUzoLdYaqYhIC2dRg3KAi5rgxA QTX2mzxJtbb6/ZoXQb3TTfEBmRkI6PtcKgzUI6EjWHg+VIlzKuGBDlCV4pkQ0bsyyfJz 9KirNxO7s0Fuk1lPWyOHlQiajn1bRJiGOIneYcCka7ptqeaiNPO4HKcLtJaeWQZNuLMX NaRZs8K6Cxr70yKx1CWeTx+kdhDPWd9LVKSJknuCBeLo+INbwWv3KN9v27A+ULTih0Rr qqDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=9CES7zO5vAsVp440eN4HWeKNk0OJ2Kki5eVVcnl1iPU=; fh=qsVxCzq0UHu5WOfI7BJiQcf1ekmjQMxosgHdzOvwtEs=; b=pc3lxHsaMaJ3Aq2UafQdyRwXNTnlWC7VLrzmU0I7o2ya88corGxY1NM5WWwxMuU1xI oGUn/ZWQC6XlG4hzQprJxx8IcmqWT5VXuTv/IesNbxdOYfKzEiTEgu0LczN3KGAiDPV5 X4UkjS4WDkk0iessQAgXkMc18gY4DW+2MRLDWVtHAOzjGGZP6JRwEGyvq41oSJVDVU+c kHKqrkp9x7wArE6Y1F4QkN0sGup59DCw8Vna1t9C9Rd6NfB2HtS6o3VI4dWT8MWG9laA 5OGYPHs3t5Ur6kgAcsOSnzMIUzObAMFWcR2Jc4PQtHrQRylFHvl9uGEnw73C20gldLkK RhvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ccWtYnl2; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-128245-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id he36-20020a1709073da400b00a4e41d4080dsi4046739ejc.1021.2024.04.02.08.31.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 08:31:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128245-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ccWtYnl2; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-128245-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 00A501F23DAE for ; Tue, 2 Apr 2024 15:31:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C40C2134CC7; Tue, 2 Apr 2024 15:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ccWtYnl2" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 212E3132C39 for ; Tue, 2 Apr 2024 15:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712071821; cv=none; b=CPK8izU4ENT1v/9NVBnWdEACR8Fj2DWa9fwotlyPNNp1ZtrmYK4f1nyx8d3hY9cCw4UwDQfRaueczcSYbKMGo4xi42nonDQYQ7r9Xkat1aFbXSdl/8ZbXZ/c+BgRVFrwPPQnPzFh2bFwkbzH91f+sigj4EN30CiW+i5w+iZpb84= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712071821; c=relaxed/simple; bh=23qNJ4ftegx5H447MVacyBoGDIcrxV1t1VQ4lsSZJ/A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NrLqk0QA7tKGov7+ujbeYaJxnGKzm5i5LJSIRHNYGQvrYXN51iaV8TGWigQZJG2BDnXjqsTb1HzP5QmHqHuEmrxYwYcjC9kKOLPDkV7WZKquep6OQ+ITeH/g4zCzaGcRBdZAPjaxY7MJgPNYA5KAiPQ80D5YbH/Ca/rqizTIV+Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ccWtYnl2; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712071819; 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=9CES7zO5vAsVp440eN4HWeKNk0OJ2Kki5eVVcnl1iPU=; b=ccWtYnl23mrz3Nm3cutm92nzgcpcMKmTLd4LDdW8ugk+FodpvfVj+EthhezvqewwImJNxw AOy/IUunSdxJSmqy3h7R/4vBzbhulOK3hecXhvyRK+gIjT7nossy0ITIPfd3bUmwGYrYgm NJdWulTn3uLvmGE5tg9pOncEn2tRz/o= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-611-mCLhMP9nP1GCXUty7wZCZQ-1; Tue, 02 Apr 2024 11:30:14 -0400 X-MC-Unique: mCLhMP9nP1GCXUty7wZCZQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 575BD1E441D0; Tue, 2 Apr 2024 15:30:13 +0000 (UTC) Received: from [10.22.33.108] (unknown [10.22.33.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id E66122022EA7; Tue, 2 Apr 2024 15:30:11 +0000 (UTC) Message-ID: <548efd52-e45f-41fa-a477-bc5112d7b00c@redhat.com> Date: Tue, 2 Apr 2024 11:30:11 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] cgroup/cpuset: Make cpuset hotplug processing synchronous Content-Language: en-US To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Tejun Heo , Zefan Li , Johannes Weiner , Thomas Gleixner , Peter Zijlstra , "Rafael J. Wysocki" , Len Brown , Pavel Machek , Shuah Khan , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-pm@vger.kernel.org, linux-kselftest@vger.kernel.org, Frederic Weisbecker , "Paul E. McKenney" , Ingo Molnar , Valentin Schneider , Anna-Maria Behnsen , Alex Shi , Vincent Guittot , Barry Song References: <20240401145858.2656598-1-longman@redhat.com> <20240401145858.2656598-2-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 On 4/2/24 10:13, Michal Koutný wrote: > Hello Waiman. > > (I have no opinion on the overall locking reworks, only the bits about > v1 migrations caught my attention.) > > On Mon, Apr 01, 2024 at 10:58:57AM -0400, Waiman Long wrote: > ... >> @@ -4383,12 +4377,20 @@ hotplug_update_tasks_legacy(struct cpuset *cs, >> /* >> * 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. >> + * cpuset. Execute it asynchronously using workqueue. > ...to avoid deadlock on cpus_read_lock > > Is this the reason? > Also, what happens with the tasks in the window till the migration > happens? > Is it handled gracefully that their cpu is gone? Yes, there is a potential that a cpus_read_lock() may be called leading to deadlock. So unless we reverse the current cgroup_mutex --> cpu_hotplug_lock ordering, it is not safe to call cgroup_transfer_tasks() directly. > > >> - if (is_empty) { >> - mutex_unlock(&cpuset_mutex); >> - remove_tasks_in_empty_cpuset(cs); >> - mutex_lock(&cpuset_mutex); >> + if (is_empty && css_tryget_online(&cs->css)) { >> + struct cpuset_remove_tasks_struct *s; >> + >> + s = kzalloc(sizeof(*s), GFP_KERNEL); > Is there a benefit of having a work for each cpuset? > Instead of traversing whole top_cpuset once in the async work. We could do that too. It's just that we have the repeat the iteration process once the workfn is invoked, but that has the advantage of not needing to do memory allocation. I am OK with either way. Let's see what other folks think about that. Cheers, Longman