Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp970435rwl; Wed, 29 Mar 2023 10:45:40 -0700 (PDT) X-Google-Smtp-Source: AKy350Z5FveSjM2aLCciltJOKV6nHKBo7UPOiaqbIy12zdhwNzxZjPSqKT7wN5OItPjbyOoRSniy X-Received: by 2002:a17:906:4b08:b0:928:796d:71e8 with SMTP id y8-20020a1709064b0800b00928796d71e8mr19847601eju.3.1680111940491; Wed, 29 Mar 2023 10:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680111940; cv=none; d=google.com; s=arc-20160816; b=WMHT6M3ewk1kDE+xLHA8AFVCkHeiwPr6K6BExmHXd0EXVeu0Cvh01Fu9XpG/w6bAD2 A8L18cXByuAsgMfUXYz90OlcBpuRNBIXgBCV1uSQlSMX4zyzBr/H3hhAl6MDfXBcNepR 4i/OuVDC930OYfYloUzRCzOduWWzwrI4X1aGPIjsSIAIY5yTMCt2Mn+qY6M4eoiYSoG8 yn3YnOuI0AjyMzcdvGlzP1L8+WLOwgGeAmbF6K9uNAB8RLFB8VMW3F2ryr3Y6oR9EkPP yAWugfEGyM1Fey1eNqag5kaf8yY0Xqg4MY+lY+dKPRRY10mI6C8ixkVa+ejwIeukd8hw I8yA== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=dNiOEETt5ceepAWfcz8ECfQ8OGyjPyRpc2CWu+K0Sd4=; b=QRvn+X3VJPgdoyUzBkQOkkg/d6MEtLHYKOSZ5MYL2+/kCgX3jJye5kHyhHKS8VL+Jx CkXvhY1rhA96ZAte4UdseAK3p4+PP3vp2lS1iXOduA88+D3L/UPGxGMg/GdvLgWl5nY0 UMF5CxBWUzosLmEsn6Sg/9Juw00xqbs1kTVotlMQu6HzBcIGzBEkL7+fNu1rOhL7SrJE CAPrdu8vrUSj2T1EK44P1NtzHoJRGbAZ+0p8w2ydaCOP3AE4swTgOY2FrAtE8WvcqU6a +EvxZMTF8BIbMG7qdrZEeRccf3vVkHPArzDq0oEYLI7wu81jAV/R/elO3nJ738OVwHKV dVkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PZpbwvFH; 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 j9-20020a170906474900b008de42a0a7a8si13206276ejs.186.2023.03.29.10.45.12; Wed, 29 Mar 2023 10:45:40 -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=PZpbwvFH; 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 S229880AbjC2RoU (ORCPT + 99 others); Wed, 29 Mar 2023 13:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbjC2RoT (ORCPT ); Wed, 29 Mar 2023 13:44:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 392FC59E5 for ; Wed, 29 Mar 2023 10:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680111817; 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=dNiOEETt5ceepAWfcz8ECfQ8OGyjPyRpc2CWu+K0Sd4=; b=PZpbwvFH9veQkgEXtvQ5HCjuinul9iQJCR2THwyNT2lg7RFDnfBY91xdn8AC3cNHSP+jzr AO8D8zlEpSY7WSCeO5HT66miJX6gnOGxABO+MwBTgHn5+t4Gf6kPmfCJslCreYdzbw6JxB Sr5p770cv2iXHRKWDMqvZGcrb2Ankmc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-439-g2rJpyJjMyW__HbcjQzbpQ-1; Wed, 29 Mar 2023 13:43:33 -0400 X-MC-Unique: g2rJpyJjMyW__HbcjQzbpQ-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 6263C85C069; Wed, 29 Mar 2023 17:43:33 +0000 (UTC) Received: from [10.22.34.224] (unknown [10.22.34.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 135E71121331; Wed, 29 Mar 2023 17:43:32 +0000 (UTC) Message-ID: <47d478a9-9730-eda8-e4dd-c848f01c0834@redhat.com> Date: Wed, 29 Mar 2023 13:43:32 -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 To: Johannes Weiner Cc: Christian Brauner , Tejun Heo , Zefan Li , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, gscrivan@redhat.com References: <20230328153943.op62j3sw7qaixdsq@wittgenstein> <5937b51b-164a-b6b3-532d-43b46f2d49a2@redhat.com> From: Waiman Long 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.3 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/29/23 10:52, Johannes Weiner wrote: > On Tue, Mar 28, 2023 at 10:48:49PM -0400, Waiman Long wrote: >> 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? > That's what I thought at first too, but then I had some doubts. > > The callback is called 'attach', but it's historically implemented > when moving an established task between two cgroups. Many controllers > use it to move state between groups (memcg, pids, cpuset). So in > practice it isn't the natural fit that its name would suggest, and it > would require reworking those controllers to handle both scenarios: > moving tasks between groups, and new tasks attaching to a cgroup. > > Now I'm thinking it probably makes more sense to keep using attach for > moving between groups, and fork for being born into a cgroup. That's > what the pid controller does, and it handles CLONE_INTO_CGROUP fine. > > There is naturally some overlap between the two operations. But it > seems cleaner to me to use common helpers for that, as opposed to > having both attach and fork callbacks handling forks. I was thinking along the line of using common helpers for doing fork and attach. However, the expected method function prototypes are quite different. For example, int (*can_attach)(struct cgroup_taskset *tset); int (*can_fork)(struct task_struct *task, css_set *cset); We need to make them more similar before we can use common helpers. I can take a look at that. Thanks, Longman