Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1486217pxb; Thu, 4 Mar 2021 12:35:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzPP3AyP7rF37sen1LEgrczF0zlEPs5ZjGv8vA9lUOfMbE2q6lnVCkSwCDpVk84azsC7YH X-Received: by 2002:a50:fb10:: with SMTP id d16mr6535526edq.73.1614890136601; Thu, 04 Mar 2021 12:35:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614890136; cv=none; d=google.com; s=arc-20160816; b=mQ7D0DPwHfjX8CqRoHEx5GV7bxWbfcv0m66h/gPktNvkK+xCEDYemB7X5tV3RrsjUq my24TDLklRynKo5VW0ZDKUPP3ma5bz8f+ADCXzOT/ZCcFZDSVF/RiODC+aU2yO3od1es W2/gRKMvlSXuKDgotNcHnBdyj5nWz6vcqIZzbwduFiFdTfIaWLRtQ+ot9+q0deVhqgJ9 kWOUr7xFOTvKlWXekCi0hutBRuZvjHYevZDFnVFHHYpFDOBRjyfP4w1S6e//YKptt5gi PEwaXZALgg0h2KVZkOR2qoSF/HYWHuVYOpGacLQLHGDN7HHPQ/IddlpGEX9gFKL9+OYw 8SYQ== 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=r+fMIB41xOYEqnsla9E5/yzrzusPJDUgvLmNk6+uq+k=; b=IbdrGxcjnPE4DLA9VndeRKwNYXVhE3VVGYD8hptAi918PGbRvsDnEZRI7pbwY1Gi7S JDCo3G9tAmYxX5RsFFNZ8E3MrI4sF6haryuJkI1WdjLwZWaDtffRHi/szTFv0LIbx47g iv8ztbdpRDFMq78s/NEHPqs3aHtppM/iHfNKNArgphn23c2nrOy0PYtV/tpBOS41GkqF hqjBrtCB5SSIB6Az5ejNT8OryYJjrk4xDx6smMQhbovxbyT+o1hy2hJDep6aWNodZbr/ zZEv7zdanR4uI+K082V6VvyS6wQR7vcBbV5Ulm9bhFrJp6ClFHwAIJb7npI3P1dbXbQN bVwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=wxHlRMSw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q28si369594edc.389.2021.03.04.12.35.13; Thu, 04 Mar 2021 12:35:36 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=wxHlRMSw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350655AbhCCKqV (ORCPT + 99 others); Wed, 3 Mar 2021 05:46:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1838206AbhCBXGL (ORCPT ); Tue, 2 Mar 2021 18:06:11 -0500 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1BB9C061794 for ; Tue, 2 Mar 2021 14:56:09 -0800 (PST) Received: by mail-qt1-x834.google.com with SMTP id j8so373993qtq.11 for ; Tue, 02 Mar 2021 14:56:09 -0800 (PST) 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=r+fMIB41xOYEqnsla9E5/yzrzusPJDUgvLmNk6+uq+k=; b=wxHlRMSwda//NqymsO5OXpIykQpggXV0HzX2Z6Mj+UrNCrHIV9ZpuUTq39SWQu/RmE ePa3mhqvpgUovYvkwVKGO/PZ+c09yTDqlkDPjCE1pOxv5K3aUay03tI6oVfK4INReIZs htsXUoHOvZnttwIzH2BESW+GWwxWe1DaB48Lq+0+lcLBK2x9sqT85w7BsouuilnB7j8L 4D61l58hazf+lQ0guT2J2CYPNYCFBUzrAXn6+7PvtxH4LKWxMTEktH+ohR7XeS1HCX4y zuVCTtQ5b9LO1wjdTo+CH0ULf+UuEW9qvxZoiQgm/WFNK2nCIBG98JEYudiizIt6PHCo DQuA== 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=r+fMIB41xOYEqnsla9E5/yzrzusPJDUgvLmNk6+uq+k=; b=JhWo0WITtWO4Efa3RE6CH7KKTK4ITS2QfvyHXZ+xdy+mRbhzku7lBOPzRSiKziswc0 mM/VtiiANF9eFqU6NQwO29ydeRrI8YEAa/14wSp127mm5Vwp2syzmy2hN3r4HPK/L/V+ hc1pedNQAoE79QfWyChGCVrQRr79uQ54FPvxwl2EyCXoA19bHaPTBrIhj52zIX4ShgDx tSOL2jpDg37uONJOkmGWOencrv9KzLr2WaKLquNLJdla510VYquTaCHjSofZughA5Sac U+K28TVKHMhXxrna1txW83AN4hhMakfZ2KcrLkazIFzssX4GgxR/Fr2QB/2BPjGxJfkR p0kw== X-Gm-Message-State: AOAM531+8IV+Ywi26ScqmXmmOsjT9tZ38yD3stzFUTapfmUPsHuQwjwE /eVoBx9wYWAeY2UBUdyZeY+dAg== X-Received: by 2002:ac8:5752:: with SMTP id 18mr1588115qtx.385.1614725769215; Tue, 02 Mar 2021 14:56:09 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:9de8]) by smtp.gmail.com with ESMTPSA id j20sm16287943qtl.36.2021.03.02.14.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 14:56:08 -0800 (PST) Date: Tue, 2 Mar 2021 17:56:07 -0500 From: Johannes Weiner To: Hugh Dickins Cc: Zhou Guanghui , Michal Hocko , linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, wangkefeng.wang@huawei.com, guohanjun@huawei.com, dingtianhong@huawei.com, chenweilong@huawei.com, rui.xiang@huawei.com, Nicholas Piggin , "Kirill A. Shutemov" Subject: Re: [PATCH] mm/memcg: set memcg when split pages Message-ID: References: <20210302013451.118701-1-zhouguanghui1@huawei.com> 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 Tue, Mar 02, 2021 at 12:24:41PM -0800, Hugh Dickins wrote: > On Tue, 2 Mar 2021, Michal Hocko wrote: > > [Cc Johannes for awareness and fixup Nick's email] > > > > On Tue 02-03-21 01:34:51, Zhou Guanghui wrote: > > > When split page, the memory cgroup info recorded in first page is > > > not copied to tail pages. In this case, when the tail pages are > > > freed, the uncharge operation is not performed. As a result, the > > > usage of this memcg keeps increasing, and the OOM may occur. > > > > > > So, the copying of first page's memory cgroup info to tail pages > > > is needed when split page. > > > > I was not aware that alloc_pages_exact is used for accounted allocations > > but git grep told me otherwise so this is not a theoretical one. Both > > users (arm64 and s390 kvm) are quite recent AFAICS. split_page is also > > used in dma allocator but I got lost in indirection so I have no idea > > whether there are any users there. > > Yes, it's a bit worrying that such a low-level thing as split_page() > can now get caught up in memcg accounting, but I suppose that's okay. > > I feel rather strongly that whichever way it is done, THP splitting > and split_page() should use the same interface to memcg. > > And a look at mem_cgroup_split_huge_fixup() suggests that nowadays > there need to be css_get()s too - or better, a css_get_many(). > > Its #ifdef CONFIG_TRANSPARENT_HUGEPAGE should be removed, rename > it mem_cgroup_split_page_fixup(), and take order from caller. +1 There is already a split_page_owner() in both these places as well which does a similar thing. Mabye we can match that by calling it split_page_memcg() and having it take a nr of pages? > Though I've never much liked that separate pass: would it be > better page by page, like this copy_page_memcg() does? Though > mem_cgroup_disabled() and css_getting make that less appealing. Agreed on both counts. mem_cgroup_disabled() is a jump label and would be okay, IMO, but the refcounting - though it is (usually) per-cpu - adds at least two branches and rcu read locking.