Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3202196pxk; Mon, 21 Sep 2020 07:46:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu6pYOy+yA+WmRQOlb23/6VschhffJFa6yIUqG5Mwy5Cq3R1z+ViEfM5JBRrbl0QvLnoau X-Received: by 2002:a17:906:850e:: with SMTP id i14mr49365085ejx.168.1600699569327; Mon, 21 Sep 2020 07:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600699569; cv=none; d=google.com; s=arc-20160816; b=PCS5PAMmFjdChDWGYyKzyogKlb4UWGKFllr4SqZFl9JRtrxyHL/HdtwcVL3WdtyYhI 2hlLifNqr7z8ERhgtFjTj0poLhfUjzx9as9kRw1IAjj1MsLaDjj6eAGpF+dR1+grUd+O UjGvT+HIirwyvSzhgH5yPEjGXjNQyb+Ja8gCU82g4DZkjGW3T3AKEnN0eKj102Z4eBAE nZ9I3hP0rVh9WMg2vaZrsclAMO2ErlaKIvgefYK5MDNmwzoBMLn4rEMfM6a0iKvzzOxN ygAY3030L/F6kTq89sh0vhRv6xrlqjhf7VodSPMDVQn9JhIWVkh0jXrRqHlyiG7Pk7DL /y4A== 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; bh=uFxqea8nf6RUnIstQ5DdTtw2ZG9FSdiEiXYf8eGUF/0=; b=VRKf0Lht0Tez9L40a4h8o9XbOxrtH7IdB3qrAOC4eRsbIgRdFlQe3Uq6XGpUs0Upsg +nApdelkCSk/FQ1ovWl+W7p4xNJucqOXc/87CHRGcSmAWsyjPXcapWlmpQbZJTREs1d7 MHHwW7RR7VvPk/yL5Av4dcxX8AL0Goquzx6KarJEC1+8liYyvs4zI2gjFjlkwem94t6M FnOq0ywbWDDTZ1dOVe62cNRLhk1txaR3ObE+Jf7AHReRsW4RdCVqwGU0J/Ex6jG0MkOQ +oUm31sJH2EvLnH/c9u5LiYoFvyXBNnJgRQlrSkOBthf4x1Eqa88o6ZVdvF8sLV8TaHR MdWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si8260747edw.573.2020.09.21.07.45.46; Mon, 21 Sep 2020 07:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728127AbgIUOl6 (ORCPT + 99 others); Mon, 21 Sep 2020 10:41:58 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:35548 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727793AbgIUOlr (ORCPT ); Mon, 21 Sep 2020 10:41:47 -0400 Received: from ip5f5af089.dynamic.kabel-deutschland.de ([95.90.240.137] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kKN0Z-00037W-8i; Mon, 21 Sep 2020 14:41:35 +0000 Date: Mon, 21 Sep 2020 16:41:34 +0200 From: Christian Brauner To: Michal Hocko Cc: Peter Xu , Tejun Heo , Linus Torvalds , Jason Gunthorpe , John Hubbard , Leon Romanovsky , Linux-MM , Linux Kernel Mailing List , "Maya B . Gokhale" , Yang Shi , Marty Mcfadden , Kirill Shutemov , Oleg Nesterov , Jann Horn , Jan Kara , Kirill Tkhai , Andrea Arcangeli , Christoph Hellwig , Andrew Morton Subject: Re: [PATCH 1/4] mm: Trial do_wp_page() simplification Message-ID: <20200921144134.fuvkkv6wgrzpbwnv@wittgenstein> References: <20200915232238.GO1221970@ziepe.ca> <20200916174804.GC8409@ziepe.ca> <20200916184619.GB40154@xz-x1> <20200917112538.GD8409@ziepe.ca> <20200917193824.GL8409@ziepe.ca> <20200918164032.GA5962@xz-x1> <20200921134200.GK12990@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200921134200.GK12990@dhcp22.suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 03:42:00PM +0200, Michal Hocko wrote: > [Cc Tejun and Christian - this is a part of a larger discussion which is > not directly related to this particular question so let me trim the > original email to the bare minimum.] > > On Fri 18-09-20 12:40:32, Peter Xu wrote: > [...] > > One issue is when we charge for cgroup we probably can't do that onto the new > > mm/task, since copy_namespaces() is called after copy_mm(). I don't know > > enough about cgroup, I thought the child will inherit the parent's, but I'm not > > sure. Or, can we change that order of copy_namespaces() && copy_mm()? I don't > > see a problem so far but I'd like to ask first.. > > I suspect you are referring to CLONE_INTO_CGROUP, right? I have only now > learned about this feature so I am not deeply familiar with all the > details and I might be easily wrong. Normally all the cgroup aware > resources are accounted to the parent's cgroup. For memcg that includes > all the page tables, early CoW and other allocations with __GFP_ACCOUNT. > IIUC CLONE_INTO_CGROUP properly then this hasn't changed as the child is > associated to its new cgroup (and memcg) only in cgroup_post_fork. If > that is correct then we might have quite a lot of resources bound to > child's lifetime but accounted to the parent's memcg which can lead to > all sorts of interesting problems (e.g. unreclaimable memory - even by > the oom killer). > > Christian, Tejun is this the expected semantic or I am just misreading > the code? Hey Michal, Thanks for the Cc! If I understand your question correctly, then you are correct. The logic is split in three simple parts: 1. Child gets created and doesn't live in any cset - This should mean that resources are still charged against the parent's memcg which is what you're asking afiu. 1. cgroup_can_fork() - create new or find existing matching cset for the child 3. cgroup_post_fork() - move/attach child to the new or found cset _Purely from a CLONE_INTO_CGROUP perspective_ you should be ok to reverse the order of copy_mm() and copy_namespaces(). Christian