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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 1D285C433DB for ; Thu, 18 Mar 2021 15:07:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B9EE964F1D for ; Thu, 18 Mar 2021 15:07:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9EE964F1D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5E9276B0078; Thu, 18 Mar 2021 11:07:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C1E56B007B; Thu, 18 Mar 2021 11:07:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 461958D0001; Thu, 18 Mar 2021 11:07:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 276D86B0078 for ; Thu, 18 Mar 2021 11:07:56 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D8383824999B for ; Thu, 18 Mar 2021 15:07:55 +0000 (UTC) X-FDA: 77933324910.01.8FD05B5 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf04.hostedemail.com (Postfix) with ESMTP id 4941E3757 for ; Thu, 18 Mar 2021 15:07:31 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id d20so2304521qkc.2 for ; Thu, 18 Mar 2021 08:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fbzGRMSg35Yk7urbJWTBF/LFrWpG+uSfyGbnx+dj3t0=; b=YnGk2Gkg4F4VvEzaISXtVkjvk97Qrijt2BYdZXCmtZvDgopwnUvrdbiEgmzSjdca8i LOGqc2jFPYkk7w8JqSaQu/0tXg3/dujRJQ8C7/rvrC/ExOY5oGEpviDlgvcV9a+6Eh/1 rG/y/UdySEHq6xwg/3Jmbd5cD2nhGiX+uOXSXIs8pznMBuUis3eK74kW3rEj4ZPpHRlK zz2zgQabP+miGKRY9FUEwlGuaE2jZ4An87vNYT3gU+AL2b3TAa3IYzp+GuvTPAm/Fg+n +jcaLh+MuyUVsEKF3OzcAk7WAaxHTD4XwhVDxS212TySZhAUBVZIpXEz5b9FDTPinCiO dnBQ== 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=fbzGRMSg35Yk7urbJWTBF/LFrWpG+uSfyGbnx+dj3t0=; b=Cd5lCMwBI3slIKOOvZSKPQWMIq1a9eBzlOgFRxpsrLrBM0LJ0nOVVj0eQJg5BYyDbr k3noFioifrt+yExhz91gTZQ5iKPVD9+a9aDZmwHAr0PDpMzhY8/baYXOQfSZWLkVhShr S6vPn5VHUFqERRUvKqCQ3YRgOdwYg2SR0WN+cyUC3DiAYUXev+lfM+ZbkIypYnKedv/L u6Q5KCv33Itg0DD+2DpTJckbsG+5lZVQ0utx1vT9t6Fb0I9ytwfUnBPjc6+Rl0Pro+Tj 4DLbC3b8Fd2oNX5PlEeacA1cXmNLosEF29MG6Vyp/cpIxxzMYVYnqTQ6ItcZ7e+XmLAI 3B8g== X-Gm-Message-State: AOAM531hIXmyH2D8oRTPahpisbuOIa2fVAKHnjTd2Tw603qNst0/SLVb xnLoFYlGekrbClVfQqXzlVFHjg== X-Google-Smtp-Source: ABdhPJyIQeHdZA/rfnRB/C17jU6bZVTKobbbpa/iz+WUIeYllggLUQMyN9HqrYM3KdWSrlzD4zDhFA== X-Received: by 2002:a05:620a:981:: with SMTP id x1mr4514571qkx.501.1616080045272; Thu, 18 Mar 2021 08:07:25 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:e46c]) by smtp.gmail.com with ESMTPSA id t2sm1612214qtd.13.2021.03.18.08.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Mar 2021 08:07:24 -0700 (PDT) Date: Thu, 18 Mar 2021 11:07:23 -0400 From: Johannes Weiner To: Michal Hocko Cc: Matthew Wilcox , 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-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: 14dsyh8nsqtjj63okdgoez88zx5kz8so X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4941E3757 Received-SPF: none (cmpxchg.org>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=mail-qk1-f179.google.com; client-ip=209.85.222.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616080051-74659 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, Mar 18, 2021 at 03:05:00PM +0100, Michal Hocko wrote: > 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? I'll post a proper patch.