From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BE0AC433DB for ; Thu, 18 Mar 2021 14:05:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A97EB64F30 for ; Thu, 18 Mar 2021 14:05:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A97EB64F30 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5B556B0073; Thu, 18 Mar 2021 10:05:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0B436B0074; Thu, 18 Mar 2021 10:05:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B850A6B0075; Thu, 18 Mar 2021 10:05:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 9F64C6B0073 for ; Thu, 18 Mar 2021 10:05:06 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 463F39085 for ; Thu, 18 Mar 2021 14:05:06 +0000 (UTC) X-FDA: 77933166612.10.8973E36 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf17.hostedemail.com (Postfix) with ESMTP id 8F6824000A46 for ; Thu, 18 Mar 2021 14:05:04 +0000 (UTC) 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=1616076301; 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=2YjcpbtwdVI/APrsI9Zcf81J0BSt89BZgsgX6xBL890=; b=Wu+vpj2R+8y65EaQ5dkVM9/xfyT8XAAWZ+3zNDvhZZh/gEHEbCfwMOJIGp7OgZmwMnrHdq 85VJvf7ZVNflyX2iZn6A1ItVQbbBgshIZyiw1ceGmk2w4/q0gAvWr2tfkf7GVQskLfumgz O2m2iF5JOyggdQTMIhcGQw07ZkpcRp0= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C4504AB8C; Thu, 18 Mar 2021 14:05:01 +0000 (UTC) Date: Thu, 18 Mar 2021 15:05:00 +0100 From: Michal Hocko To: Matthew Wilcox Cc: Johannes Weiner , Hugh Dickins , Zhou Guanghui , linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, 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: X-Stat-Signature: pgonp1653m6kf1fpxmnakjkpmnyfdjrz X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 8F6824000A46 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616076304-185427 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu 11-03-21 12:37:20, Hugh Dickins wrote: > On Thu, 11 Mar 2021, Michal Hocko wrote: > > 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. > > I agree: I do like Johannes' suggestion best, now that we already > have split_page_memcg(). Not too worried about contrived use of > free_unref_page() here; and whether non-compound high-order pages > should be perpetuated is a different discussion. Matthew, are you planning to post a patch with suggested changes or should I do it? -- Michal Hocko SUSE Labs