Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp510463pxf; Thu, 11 Mar 2021 08:30:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9OafvEKtwJgUiIhz0m5iU1PmpBHPTR2vrxLiuQDUUmC/chZUhjNe6XXnp1FKIAV0XxX97 X-Received: by 2002:aa7:d347:: with SMTP id m7mr9194347edr.260.1615480235392; Thu, 11 Mar 2021 08:30:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615480235; cv=none; d=google.com; s=arc-20160816; b=koL25b2ddH4+exqHtOiwSLEvrY45G3AEyVfuaUr/I4+aMhFKx3eVNqxAolBr+mZ4NE d0lyR/DdJQFSeTcQNOOrda4ExEaoN8TfjWLcA5bnnFpd5KlAOhlR+RNF10UFK+h2V4WH Pic8wfBspSFsmtbxpZqmLhDlUJ12K9oiOmTFPSMGEbmon8I1hbUL2aU7iVCDN9LBOohR OR+NAjHsIvppOTeCIIZY0+YRqKaByUIFvFTStslsH04wBItEJYtOL1GsgLUsBFYsfSlf J2PqKHumK2hDkvMJaeDmfMXkJqNtMYUYD1nbAFbvp6gKj2Y6s7p4w/R8LZ8m4I7WTMj8 ILCw== 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:dkim-signature; bh=hZ0PtrodtSFeTEipYW7mvjHwoefyVlEAYBMe9XX6QM8=; b=qGkYnxtak9ir/hrXJxQmmXXdICQydaIV5Ad0+hQJTAkA89ZtEqRdU4YIAg/J8L8LUV SNJqia+rdJK7/Q+EUlvk/YJKayMwrCF4UIFSVxU2jBEXKL1nvEjrJlizcLMzM0I2BKY4 YtAcSUBFpJ3E2ECgCuhfExWDttBK/8PaaXUHSvKudL9Jl/qSCEFFULZLnAGRjBS3T3Qf ps/hHvS71cA0rgnlQJte3CL68H7W9JMsgFDsFJNPL9ZJ9qXui10imcNchNJoQppDGbW6 tZqLQe1YLi/Os5SYJ5ewOunjRGve1yZ7iFHgVNkoIxuvdO9yWEv5zmDTWeMWmhrOyjoN fUuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=aekJaOlA; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb2si2096392ejc.547.2021.03.11.08.30.11; Thu, 11 Mar 2021 08:30:35 -0800 (PST) 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; dkim=pass header.i=@suse.com header.s=susede1 header.b=aekJaOlA; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234498AbhCKQ11 (ORCPT + 99 others); Thu, 11 Mar 2021 11:27:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:55608 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234532AbhCKQ04 (ORCPT ); Thu, 11 Mar 2021 11:26:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1615480014; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hZ0PtrodtSFeTEipYW7mvjHwoefyVlEAYBMe9XX6QM8=; b=aekJaOlAAG6CNJAyUaRWxlaKLeGTHlmTXhd6YKWemSgqKFo9loFGMoNnyRJ2sXwW2CsB0H Rhwu+OHtuIDJ8ND1vv5lvSZVjz3CRXC9LeibGRWLKlgNGdilqgfNjs6cL7ritguwRhI+7E 8d2GnruXAWGp0zswaFW9yi/ZmBCF86I= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BCB63AE1F; Thu, 11 Mar 2021 16:26:54 +0000 (UTC) Date: Thu, 11 Mar 2021 17:26:53 +0100 From: Michal Hocko To: Johannes Weiner Cc: Matthew Wilcox , Zhou Guanghui , linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, hughd@google.com, kirill.shutemov@linux.intel.com, npiggin@gmail.com, ziy@nvidia.com, wangkefeng.wang@huawei.com, guohanjun@huawei.com, dingtianhong@huawei.com, chenweilong@huawei.com, rui.xiang@huawei.com Subject: Re: [PATCH v2 2/2] mm/memcg: set memcg when split page Message-ID: References: <20210304074053.65527-1-zhouguanghui1@huawei.com> <20210304074053.65527-3-zhouguanghui1@huawei.com> <20210308210225.GF3479805@casper.infradead.org> <20210309123255.GI3479805@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 11-03-21 10:21:39, Johannes Weiner wrote: > On Thu, Mar 11, 2021 at 09:37:02AM +0100, Michal Hocko wrote: > > Johannes, Hugh, > > > > what do you think about this approach? If we want to stick with > > split_page approach then we need to update the missing place Matthew has > > pointed out. > > I find the __free_pages() code quite tricky as well. But for that > reason I would actually prefer to initiate the splitting in there, > since that's the place where we actually split the page, rather than > spread the handling of this situation further out. > > The race condition shouldn't be hot, so I don't think we need to be as > efficient about setting page->memcg_data only on the higher-order > buddies as in Willy's scratch patch. We can call split_page_memcg(), > which IMO should actually help document what's happening to the page. > > I think that function could also benefit a bit more from step-by-step > documentation about what's going on. The kerneldoc is helpful, but I > don't think it does justice to how tricky this race condition is. > > Something like this? > > void __free_pages(struct page *page, unsigned int order) > { > /* > * Drop the base reference from __alloc_pages and free. In > * case there is an outstanding speculative reference, from > * e.g. the page cache, it will put and free the page later. > */ > if (likely(put_page_testzero(page))) { > free_the_page(page, order); > return; > } > > /* > * The speculative reference will put and free the page. > * > * However, if the speculation was into a higher-order page > * that isn't marked compound, the other side will know > * nothing about our buddy pages and only free the order-0 > * page at the start of our chunk! We must split off and free > * the buddy pages here. > * > * The buddy pages aren't individually refcounted, so they > * can't have any pending speculative references themselves. > */ > if (!PageHead(page) && order > 0) { > split_page_memcg(page, 1 << order); > while (order-- > 0) > free_the_page(page + (1 << order), order); > } > } Fine with me. Mathew was concerned about more places that do something similar but I would say that if we find out more places we might reconsider and currently stay with a reasonably clear model that it is only head patch that carries the memcg information and split_page_memcg is necessary to break such page into smaller pieces. -- Michal Hocko SUSE Labs