Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp26503rwl; Tue, 28 Mar 2023 20:07:50 -0700 (PDT) X-Google-Smtp-Source: AK7set+0Lb5wjRYNGVrIXk2nXhi1icjaZyiG2Ov3DaJF4W7HitejZfjd5dWATTz7fUJYI7jCAdwE X-Received: by 2002:a05:6a20:9325:b0:cd:71de:e757 with SMTP id r37-20020a056a20932500b000cd71dee757mr14473133pzh.32.1680059270508; Tue, 28 Mar 2023 20:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680059270; cv=none; d=google.com; s=arc-20160816; b=GeZcgSqtyOgDO6JGDm1d/mrswJbJ/WkiNRvkRgrXKMElXYk5E0chtYXaZLlaO7PK/4 +pLMBOHGNwmp5NJwRaO+ZfA2AgziJiN47KmQaUnolmxcTGvUJkhtPkoukw8hReaLVuJc R+vVIHpJtk4fr8pzOT6xrtU2WyfZYxqtQkSz5Mm7H4l3zXz5AXvfWyNzHeL5b/nc1emr 4fKbzsYnJl7vZIyfp2k4EeOcxVWgR6VfI48LWVMluVncwcTPzcBzaZtEorGFCA0E5Phd OIvZY6cK9SZWxcN+ed0vI66BjcoVT52lfMIReSQ2kGzq2V3Ds2mopLZDZt0EWbVzvy4X /gSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=L6oe7fC3/mHI/luYdbPv+vw9eT1o83NLKjT6NHGcNrY=; b=BU/evE26VYpKP+NDj01Zdg3MbKrmfkmYG/WuYPMuNCESd5dUA9jcGz2PM1myhY/gpa yaUVpwGilzIm0+OwYYHDgj7hnvznsLeyZzoZTvipM10VcRAIqxhgkm239x/X9IeozAIu 80Ce0Dg6DUGOK9fgbdtFqafEZAYqsD6NnOag3HOCvJq1rSQtdTA48uMlAIMC+y5ZU8wQ ucEWj01Z9Og1TiGk1nssk83eAUxsrT+6DrTEplWd0RiUq6YJW7wCPjVwqCl/3kOBIA0o /08ADhMwS8YS8tFhDsmbnI9ZxznysS6YRje7vMBSUBVNail7LKr76Xu28Dpy51k4ogk4 DCog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=K8POhdRG; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc22-20020a656d96000000b005034a57b4d1si309688pgb.406.2023.03.28.20.07.38; Tue, 28 Mar 2023 20:07:50 -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=@redhat.com header.s=mimecast20190719 header.b=K8POhdRG; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229706AbjC2Ctk (ORCPT + 99 others); Tue, 28 Mar 2023 22:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbjC2Ctj (ORCPT ); Tue, 28 Mar 2023 22:49:39 -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 807DC3A84 for ; Tue, 28 Mar 2023 19:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680058131; 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=L6oe7fC3/mHI/luYdbPv+vw9eT1o83NLKjT6NHGcNrY=; b=K8POhdRGA9l6areWdpPRqKKBjpTNNUJKTbFhTuP0qJWkBD+5rINVe8sZY5CrW8IqBH+sLG sbjkjg0j2QjRtEqj0uxnXDFUnCI6KJl0cFUgMQHGd2xrO0+GjxlU/teWRR61RnA5tOXBgl PJLV+Jhkc0hmhY9qHEDaFQFTMFPWvag= 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-618-jZhO2YEHONGK9_fNoXIrnA-1; Tue, 28 Mar 2023 22:48:50 -0400 X-MC-Unique: jZhO2YEHONGK9_fNoXIrnA-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 E94C638060E1; Wed, 29 Mar 2023 02:48:49 +0000 (UTC) Received: from [10.22.18.156] (unknown [10.22.18.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82F43140EBF4; Wed, 29 Mar 2023 02:48:49 +0000 (UTC) Message-ID: <5937b51b-164a-b6b3-532d-43b46f2d49a2@redhat.com> Date: Tue, 28 Mar 2023 22:48:49 -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: CLONE_INTO_CGROUP probably needs to call controller attach handlers Content-Language: en-US From: Waiman Long To: Christian Brauner , Tejun Heo , Johannes Weiner Cc: Zefan Li , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, gscrivan@redhat.com References: <20230328153943.op62j3sw7qaixdsq@wittgenstein> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 On 3/28/23 21:30, Waiman Long wrote: > On 3/28/23 11:39, Christian Brauner wrote: >> Hey, >> >> Giuseppe reported that the the affinity mask isn't updated when a >> process is spawned directly into the target cgroup via >> CLONE_INTO_CGROUP. However, migrating a process will cause the affinity >> mask to be updated (see the repro at [1]. >> >> I took a quick look and the issue seems to be that we don't call the >> various attach handlers during CLONE_INTO_CGROUP whereas we do for >> migration. So the solution seems to roughly be that we need to call the >> various attach handlers during CLONE_INTO_CGROUP as well when the >> parent's cgroups is different from the child cgroup. I think we need to >> call all of them, can, cancel and attach. >> >> The plumbing here might be a bit intricate since the arguments that the >> fork handlers take are different from the attach handlers. >> >> Christian >> >> [1]: https://paste.centos.org/view/f434fa1a >> > I saw that the current cgroup code already have the can_fork, fork and > cancel_fork callbacks. Unfortunately such callbacks are not defined > for cpuset yet. That is why the cpu affinity isn't correctly updated. > I can post a patch to add those callback functions to cpuset which > should then able to correctly address this issue. Looking further into this issue, I am thinking that forking into a cgroup should be equivalent to write the child pid into the "cgroup.threads" file of the target cgroup. By taking this route, all the existing can_attach, attach and cancel_attach methods can be used. I believe the original fork method is for the limited use case of forking into the same cgroup. So right now, only the pids controller has the fork methods. Otherwise, we will have to modify a number of different controllers to add the necessary fork methods. They will be somewhat similar to the existing attach methods and so it will be a lot of duplication. What do you think about this idea? Cheers, Longman