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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 3830BC433B4 for ; Wed, 21 Apr 2021 13:03:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C899B61457 for ; Wed, 21 Apr 2021 13:03:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C899B61457 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 376C86B006C; Wed, 21 Apr 2021 09:03:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 313966B006E; Wed, 21 Apr 2021 09:03:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DC3C6B0070; Wed, 21 Apr 2021 09:03:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0198.hostedemail.com [216.40.44.198]) by kanga.kvack.org (Postfix) with ESMTP id 011096B006C for ; Wed, 21 Apr 2021 09:03:25 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A9D2B4DC5 for ; Wed, 21 Apr 2021 13:03:25 +0000 (UTC) X-FDA: 78056390370.06.5228F29 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf10.hostedemail.com (Postfix) with ESMTP id 2D01A40002C4 for ; Wed, 21 Apr 2021 13:03:17 +0000 (UTC) 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=1619010201; 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=7Ybdj/fzU2bZRYjiULaAlp9LEAozBU/5F769WjomL9o=; b=FwNpjTAQ6/tVzAdHxCKKtyRhZI311dm0XNmvqBDpqllIsyzXcDB/cJuVwb263FExHg8O/u zyVEOXPmyDRoR3wc5G19i4WDlF+H1WIfF7ErzdKBc7jCnmt6Oy/e9ZHCCl51+Sv3OfvJRc EZSji6GQhUL+0Gb+i+jwlCIUVUcCQDE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9EE21B314; Wed, 21 Apr 2021 13:03:21 +0000 (UTC) Date: Wed, 21 Apr 2021 15:03:20 +0200 From: Michal Hocko To: Muchun Song Cc: Roman Gushchin , Johannes Weiner , Andrew Morton , Shakeel Butt , Vladimir Davydov , LKML , Linux Memory Management List , Xiongchun duan , fam.zheng@bytedance.com Subject: Re: [External] Re: [PATCH] mm: memcontrol: fix root_mem_cgroup charging Message-ID: References: <20210421062644.68331-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: opqxqxbt3kdqracd39z6tn6bou1c86dm X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2D01A40002C4 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619010197-279047 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 Wed 21-04-21 17:50:06, Muchun Song wrote: > On Wed, Apr 21, 2021 at 3:34 PM Michal Hocko wrote: > > > > On Wed 21-04-21 14:26:44, Muchun Song wrote: > > > The below scenario can cause the page counters of the root_mem_cgroup > > > to be out of balance. > > > > > > CPU0: CPU1: > > > > > > objcg = get_obj_cgroup_from_current() > > > obj_cgroup_charge_pages(objcg) > > > memcg_reparent_objcgs() > > > // reparent to root_mem_cgroup > > > WRITE_ONCE(iter->memcg, parent) > > > // memcg == root_mem_cgroup > > > memcg = get_mem_cgroup_from_objcg(objcg) > > > // do not charge to the root_mem_cgroup > > > try_charge(memcg) > > > > > > obj_cgroup_uncharge_pages(objcg) > > > memcg = get_mem_cgroup_from_objcg(objcg) > > > // uncharge from the root_mem_cgroup > > > page_counter_uncharge(&memcg->memory) > > > > > > This can cause the page counter to be less than the actual value, > > > Although we do not display the value (mem_cgroup_usage) so there > > > shouldn't be any actual problem, but there is a WARN_ON_ONCE in > > > the page_counter_cancel(). Who knows if it will trigger? So it > > > is better to fix it. > > > > The changelog doesn't explain the fix and why you have chosen to charge > > kmem objects to root memcg and left all other try_charge users intact. > > The object cgroup is special (because the page can reparent). Only the > user of objcg APIs should be fixed. > > > The reason is likely that those are not reparented now but that just > > adds an inconsistency. > > > > Is there any reason you haven't simply matched obj_cgroup_uncharge_pages > > to check for the root memcg and bail out early? > > Because obj_cgroup_uncharge_pages() uncharges pages from the > root memcg unconditionally. Why? Because some pages can be > reparented to root memcg, in order to ensure the correctness of > page counter of root memcg. We have to uncharge pages from > root memcg. So we do not check whether the page belongs to > the root memcg when it uncharges. I am not sure I follow. Let me ask differently. Wouldn't you achieve the same if you simply didn't uncharge root memcg in obj_cgroup_charge_pages? Btw. which tree is this patch based on? The current linux-next doesn't uncharge from memcg->memory inside obj_cgroup_uncharge_pages (nor does the Linus tree). -- Michal Hocko SUSE Labs