Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4373677pxb; Tue, 2 Mar 2021 13:32:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5P/p+rae2Gg3t6z2xS7iL+ugT/rIeWHD91CvS02NdI6L5WSoYYd6C+ATKzuXuo6QIQfXn X-Received: by 2002:a05:6402:4d5:: with SMTP id n21mr22147006edw.201.1614720775617; Tue, 02 Mar 2021 13:32:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614720775; cv=none; d=google.com; s=arc-20160816; b=Hw/JTDm2ReO5tG9k9QHqieaeGy7ucMQvZLlAJHjPRLxKbnAPm4Bj++T7LL6rl+3BGw 3ScvIqAGdKOuSqO+c+EMryKXdwXb1nImjp8cbOqlyU8aZlZJrQUcuRE6uE9QoeCGUtKH lMhBjzPRLZ3YagPzT4sl53+4Meez6dc0ktxkpLmejBEj5hAmxGhfR2sYjO5lgjdOJcAx kv9iAREEFuFJfa99l0TKY8HqjoYtP1BxucA8cUpln7ZTJcVBd8fD0yGdMsQQe+sCoXsm ypK1t12BNkBrNHG2x+BqI7lo0t5nwxs/zI03IFltK3pyJ1zQEZ/+0qDlH0LcMjETshVZ 9WNg== 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=2lTNGUQOU5ZRn8hHITEAj8ERC6Szv7NUv4WYSpUAvfo=; b=fDOIUYF4a8rkE7/smHwBZmqTOkggJ7ZZuuTrgtW/RSwYatHA8X9LItJCreFeI41Lwk ByFd8KRTa0Zu/FS0UP1qF7WIMOAiyxfLlm6YuXSyrIU5EIJ+DVEk6P6f5r4FwveUAPbp 6c7H7BgFWmrlbwCjPTWBRpPrVVdAkuihLgdq9OqWOOdgi8bCMQ5OSvgq1VXKeDheDJaq jEPq2bJj1F/xsQ8AQ6CLYS1jQ4FjVjCoOjNlwxFlg8uU8Mq7MHj1CGTFeZYiOYnJjPV9 qrjnHtSOG5Nr+KxBpTPU9HL6ws1hQjAhVARIUi4vaCnCFrRpmZ5azhi58qYuaBji9h6c Z2mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=ONVwZQZr; 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 k6si10216440edj.545.2021.03.02.13.32.31; Tue, 02 Mar 2021 13:32:55 -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=ONVwZQZr; 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 S1382573AbhCBJj7 (ORCPT + 99 others); Tue, 2 Mar 2021 04:39:59 -0500 Received: from mx2.suse.de ([195.135.220.15]:50002 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1838025AbhCBJRu (ORCPT ); Tue, 2 Mar 2021 04:17:50 -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=1614676623; 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=2lTNGUQOU5ZRn8hHITEAj8ERC6Szv7NUv4WYSpUAvfo=; b=ONVwZQZrA45Na87INciY0J/4eHEq8CM4tW4gUsuWgvkwKbb+1pYu/hLH1FaZxKguoGXPoX 8d2fQgFqw877ImT19JUUBURst+EUUkY//7eBxrVGrH6Ms9g7zrKSPB23BQc1uwBlJv/vSm 7usGuaI7NIMf/W7FyuAF+BBJvbLvKhc= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3C880AFCE; Tue, 2 Mar 2021 09:17:03 +0000 (UTC) Date: Tue, 2 Mar 2021 10:17:02 +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: <20210302013451.118701-1-zhouguanghui1@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [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. > +} > + > struct mem_cgroup *lock_page_memcg(struct page *page); > void __unlock_page_memcg(struct mem_cgroup *memcg); > void unlock_page_memcg(struct page *page); > @@ -1291,6 +1297,10 @@ mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) > { > } > > +static inline void copy_page_memcg(struct page *dst, struct page *src) > +{ > +} > + > static inline struct mem_cgroup *lock_page_memcg(struct page *page) > { > return NULL; > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3e4b29ee2b1e..ee0a63dc1c9b 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3307,8 +3307,10 @@ void split_page(struct page *page, unsigned int order) > VM_BUG_ON_PAGE(PageCompound(page), page); > VM_BUG_ON_PAGE(!page_count(page), page); > > - for (i = 1; i < (1 << order); i++) > + for (i = 1; i < (1 << order); i++) { > set_page_refcounted(page + i); > + copy_page_memcg(page + i, page); > + } > split_page_owner(page, 1 << order); > } > EXPORT_SYMBOL_GPL(split_page); > -- > 2.25.0 > -- Michal Hocko SUSE Labs