Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp960573pxb; Wed, 3 Mar 2021 22:36:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJzzxOWvZ/s4mA0fKmbNwMsQ4AxNouQVGpFMFyCg1R+y3Rvq5BcnSEl7R9Yr+OCaTSKwvIet X-Received: by 2002:a05:6402:1691:: with SMTP id a17mr2701876edv.336.1614839781557; Wed, 03 Mar 2021 22:36:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839781; cv=none; d=google.com; s=arc-20160816; b=OvBVy82zDZCxChcQmJJqD4yEINVNZ2yBwNS/vvd3fXAWl2OT16jxe2ljgm3sDQGtUK B9y2ziVRY0LYBlhfsPc/i0I0MENxKYwMfSf1WnqYA0k8NZE2t1oqVvD9llhQpGF/RpQE BOV2alf2KDPNObw79Ftop2YpCeoKy4JoNkulQaOC2tUUE4I6R7YHo+Edc0ob4nhpcftS JTMdwUfHAR+nnp4zenHk33jh42t3bRhaK9ACqxfkyGmFA6mg7MFlhCcC4t+GSkz2wJvb ayE7N0fbBOmur+fLlZ6UcJg9EiHgwtQ2noZKkYaOGaEtNPQL8f7L1EyOY4CdTJIFc/is xg7g== 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=pdDWsFQcF7rXCFOv6YgPKx+U/DSX9HDlai1p+dLPtQc=; b=a3QrwiEUBHKV67g19JBdR2iETumBg+8MsfOhMIIe3eZvcFXM3+bAg3Swevp0JalW3w Jlsx4hbxjpQ7dxlFY/Or9xkZbhmb+8VzVniaCWKHY1p2P6fnTLtgpU0L45MdD0g3lQpJ h4dHhgJ5hJXkPkp0FqtK1ZkSrjMt+aqBZvx4DHyfl3VKqrOnO4u9SbYYzoO70sSSRGxP uvoRcvA9NjsUi3oY8BOXjNWiM7tM86pLV7MNxAtjBknpjONaatxvnGXtc7xkJiziVf9E qjw5sjU91H1qz2fTNVoZotz1w+16IEmaHwp17II3eQugOcwBkNAPz4S7q8uONH3qZfSy 6eIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=CUKK1D18; 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 bx25si6431159edb.242.2021.03.03.22.35.58; Wed, 03 Mar 2021 22:36:21 -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=CUKK1D18; 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 S1581433AbhCBSv3 (ORCPT + 99 others); Tue, 2 Mar 2021 13:51:29 -0500 Received: from mx2.suse.de ([195.135.220.15]:42628 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1449106AbhCBQE1 (ORCPT ); Tue, 2 Mar 2021 11:04:27 -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=1614700270; 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=pdDWsFQcF7rXCFOv6YgPKx+U/DSX9HDlai1p+dLPtQc=; b=CUKK1D189WviMnFB36MEnc7SszarLzXWujqx5F/zbGbrjbAMHbx+ODykvZMkOihPe4jgPF tNbDp+jlZb+Htf35AEd5RHN2RToqnRoSS4Kvg7KSFayMPDXjmLaI8DiP3AXqO4ZMPHJbD8 mPFJAXJztUY614pfLqEgcN6XgNcqrzE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 68E73B02E; Tue, 2 Mar 2021 15:51:09 +0000 (UTC) Date: Tue, 2 Mar 2021 16:51:05 +0100 From: Michal Hocko To: Zhou Guanghui Cc: 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, Johannes Weiner , Nicholas Piggin 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 02-03-21 10:17:03, 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. > > The page itself looks reasonable to me. > > > Signed-off-by: Zhou Guanghui > > Acked-by: Michal Hocko > > Minor nit > > > --- > > include/linux/memcontrol.h | 10 ++++++++++ > > mm/page_alloc.c | 4 +++- > > 2 files changed, 13 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > > index e6dc793d587d..c7e2b4421dc1 100644 > > --- a/include/linux/memcontrol.h > > +++ b/include/linux/memcontrol.h > > @@ -867,6 +867,12 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memcg); > > extern bool cgroup_memory_noswap; > > #endif > > > > +static inline void copy_page_memcg(struct page *dst, struct page *src) > > +{ > > + if (src->memcg_data) > > + dst->memcg_data = src->memcg_data; > > I would just drop the test. The struct page is a single cache line which > is dirty by the reference count so another store will unlikely be > noticeable even when NULL is stored here and you safe a conditional. Disregard this. As Zi Yan mentioned in other reply, we need to keep the check and take a css reference along with transfering the memcg. -- Michal Hocko SUSE Labs