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=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL 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 4BF99C433DB for ; Thu, 11 Mar 2021 20:37:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B0CEB64F8C for ; Thu, 11 Mar 2021 20:37:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0CEB64F8C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 847B08D02F5; Thu, 11 Mar 2021 15:37:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81E4D8D02B2; Thu, 11 Mar 2021 15:37:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E5E18D02F5; Thu, 11 Mar 2021 15:37:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id 4E8F78D02B2 for ; Thu, 11 Mar 2021 15:37:37 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E7786180C114A for ; Thu, 11 Mar 2021 20:37:36 +0000 (UTC) X-FDA: 77908754112.13.8965FFA Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 4C3C0407F8F8 for ; Thu, 11 Mar 2021 20:37:32 +0000 (UTC) Received: by mail-qt1-f170.google.com with SMTP id r14so2188136qtt.7 for ; Thu, 11 Mar 2021 12:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=WSwg5k9sbPudFOPM+Iuoe2XRIHWLu4xDbEOxpss2E8Q=; b=p71mpGqcQh2nGYEwGZbDtJNzVYMLNwCvhItHWCWoXdSBl+gUn3fIDs6zx0Ecogvm7M /udVQPr9G6nsLZ4Vk9EoLyO8XERCpEx2jzP1jqAxXSNUcjirHgBAoubjv1D3l3Mei+LD OUiHxciyl9BaZbRcZp/hnDwFDe89W8zEzhYi8jSumr7GF+Nzjhme1pAJKRyF/aT0i9j2 uXL53EHv+fHY1SZVs2Z97xZBF72wvCfsKNxvObrllw0qpx5F75hS5DHI6U4bjQLEfcb0 CxERUQEa1tEsmE73GW7lPYP2aYsNbvZ1rXJZ3dcHQaRw6XRXIP4NlXwO45G8jVNZ//Yq MNJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=WSwg5k9sbPudFOPM+Iuoe2XRIHWLu4xDbEOxpss2E8Q=; b=geoYk6mwvhrcjMdzJRSfAcxV1uMK3L0xqvRtukpwjY7oAUzOyVlbP1qF8n019r5bX7 zxHyTQHW3f4s8JtBJuYtt7++m6i8wWcxHuECbWfA3NnhCDHeee+3V9TQ/9OYBwaCA8T8 ku5hHMSLV/iU/65CDddGD5MrAIk0LvkKeAcbKftqnpR/vTP9BLF4gN5Et+5Mfg1uYnLB 6L4XJkRSBWeM+oY0GbdFV6/vvuHmu24yPwq8Eo4taUFJbOt9BQ9t9DkC9mmFz9Ou4Ske m27cDJ0RavJuGVYyVrw+IIikC/vROQNaO7Pr8TEMcuQPmtXHNuW3HIlQ/eK1inHhf874 4arQ== X-Gm-Message-State: AOAM531gXcqV4vOizkXiA3VkO00IBOaSxX85RKJ1SE1iVD6V35YP1/RR RZ4z98YPPg1FPeOC8F2PqxuqGA== X-Google-Smtp-Source: ABdhPJyQ3iwvyAvEG4lQaXukQSMbO+5NKXJD5sMobCpHlGQzyLkPHZAYbRMR7r/vKURPU7kdP7p+BQ== X-Received: by 2002:a05:622a:1c9:: with SMTP id t9mr9071842qtw.244.1615495055065; Thu, 11 Mar 2021 12:37:35 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id f27sm2692401qkh.118.2021.03.11.12.37.33 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Thu, 11 Mar 2021 12:37:34 -0800 (PST) Date: Thu, 11 Mar 2021 12:37:20 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Michal Hocko cc: Johannes Weiner , 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 In-Reply-To: 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> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Stat-Signature: 5ha8e5cf4r8h63b1zzk7qft5c6rrm4sz X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4C3C0407F8F8 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-qt1-f170.google.com; client-ip=209.85.160.170 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615495052-260936 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 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. Hugh