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=-2.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 52271C2BA19 for ; Thu, 23 Apr 2020 05:27:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 13D93208E4 for ; Thu, 23 Apr 2020 05:27:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F5M1LLms" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 13D93208E4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8E958E0003; Thu, 23 Apr 2020 01:27:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3F028E0008; Thu, 23 Apr 2020 01:27:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A10D38E0003; Thu, 23 Apr 2020 01:27:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0123.hostedemail.com [216.40.44.123]) by kanga.kvack.org (Postfix) with ESMTP id 866D58E0003 for ; Thu, 23 Apr 2020 01:27:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3DFD45DF8 for ; Thu, 23 Apr 2020 05:27:08 +0000 (UTC) X-FDA: 76737986136.12.shade60_5b62b8f4fb759 X-HE-Tag: shade60_5b62b8f4fb759 X-Filterd-Recvd-Size: 5730 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Apr 2020 05:27:07 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id k18so1902997pll.6 for ; Wed, 22 Apr 2020 22:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=5dRfGuiAmG9ezbEhwEm/4CtR44lsDucqUbK7PXbEl8Y=; b=F5M1LLmsBpNN0fDAzQu31LTtIIQODx3f7aCxVlXmDLvGsnGmub9LLb8Jh86o59C0II 1P/8Jeuqhoov7oo0U654aVLXuP28nJ6gPHuf3fMG6chzvgRs5/yMdLNEs3Q1nRU0vhEt 1XPDILZXi9XIBnRazyV+VsjItkUFsIMht/cfD+/SDZV/g6ZfmHj5tYmtPtcwLVu/IQqU 2l6NZRxutaxvloiKPPxGTgOCPUnuioixocy10pqC4bZJxSPswExXdrlibTXIPM/ugqPq i7OoSRwdf9eeBkXujPpqR4Qz9HIOcFTM94ncbDh3tDNUFSTVs6ytMzZ3M36vVdOXndv9 ww+A== 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:user-agent; bh=5dRfGuiAmG9ezbEhwEm/4CtR44lsDucqUbK7PXbEl8Y=; b=ZrenmlxmbF+I5/UQ1Dc+CLuYJngsxEA6QzjjScdfD6jHYyS2dsXVdwp3KWcxfOP8nY 2ii9OAQ9c/VQDBH2Z5SmCG0wdlwpfb/7yROne71V7a2WlvRZSdy2JKxjgDpSHWA5LbX7 qO2MEJ0SDEILAAcx4nrtyQK5HvU/no+goB2gjo88SiTcH4SFL1LxoUgr+MOtwbF+tVoD I7CbfYPILZRs7J+tlpYEdVdt9p+xcPEKPt8PoSRIe5mdWOKSzaTu3qTm6sGvFdIRgrq9 hBbytvZt56qs1O8/6R5otKdcX4UC38HUiILDphFXTYD7lbwB/L/5dPamO5EMPfodsmac rU9A== X-Gm-Message-State: AGi0Pub1v3ZJpf8atCdkfwWRELkbUTLkABpH39qux+VTkS+Pw1fv94it ZY5nFi2M3GaHeGY4FewDJbw= X-Google-Smtp-Source: APiQypKZ1vg3B7CBVKCjT6RRrpVuaJ6pmpVjHiUxcDrwGFDDC+LfEX+3iekDoy33KuMefBsyLY965Q== X-Received: by 2002:a17:90a:9a89:: with SMTP id e9mr2548628pjp.108.1587619627027; Wed, 22 Apr 2020 22:27:07 -0700 (PDT) Received: from js1304-desktop ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id r4sm953199pgi.6.2020.04.22.22.27.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2020 22:27:06 -0700 (PDT) Date: Thu, 23 Apr 2020 14:27:01 +0900 From: Joonsoo Kim To: Johannes Weiner Cc: Alex Shi , Shakeel Butt , Hugh Dickins , Michal Hocko , "Kirill A. Shutemov" , Roman Gushchin , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 10/18] mm: memcontrol: switch to native NR_ANON_MAPPED counter Message-ID: <20200423052700.GB12538@js1304-desktop> References: <20200420221126.341272-1-hannes@cmpxchg.org> <20200420221126.341272-11-hannes@cmpxchg.org> <20200422065151.GJ6780@js1304-desktop> <20200422122818.GB358439@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422122818.GB358439@cmpxchg.org> User-Agent: Mutt/1.5.24 (2015-08-30) 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, Apr 22, 2020 at 08:28:18AM -0400, Johannes Weiner wrote: > Hello Joonsoo, > > On Wed, Apr 22, 2020 at 03:51:52PM +0900, Joonsoo Kim wrote: > > On Mon, Apr 20, 2020 at 06:11:18PM -0400, Johannes Weiner wrote: > > > @@ -3768,7 +3761,7 @@ static int memcg_numa_stat_show(struct seq_file *m, void *v) > > > > > > static const unsigned int memcg1_stats[] = { > > > NR_FILE_PAGES, > > > - MEMCG_RSS, > > > + NR_ANON_MAPPED, > > > MEMCG_RSS_HUGE, > > > NR_SHMEM, > > > NR_FILE_MAPPED, > > > @@ -5395,7 +5388,12 @@ static int mem_cgroup_move_account(struct page *page, > > > > > > lock_page_memcg(page); > > > > > > - if (!PageAnon(page)) { > > > + if (PageAnon(page)) { > > > + if (page_mapped(page)) { > > > > This page_mapped() check is newly inserted. Could you elaborate more > > on why mem_cgroup_charge_statistics() doesn't need this check? > > MEMCG_RSS extended from when the page was charged until it was > uncharged, but NR_ANON_MAPPED is only counted while the page is really > mapped into page tables. That starts shortly after we charge and ends > shortly before we uncharge, so pages could move between cgroups before > or after they are mapped, while they aren't counted in NR_ANON_MAPPED. > > So to know that the page is counted, charge_statistics() only needed > to know that the page is charged and Anon; move_account() also needs > to know that the page is mapped. Got it! > > > > @@ -1181,7 +1187,7 @@ void page_add_new_anon_rmap(struct page *page, > > > /* increment count (starts at -1) */ > > > atomic_set(&page->_mapcount, 0); > > > } > > > - __mod_node_page_state(page_pgdat(page), NR_ANON_MAPPED, nr); > > > + __mod_lruvec_page_state(page, NR_ANON_MAPPED, nr); > > > __page_set_anon_rmap(page, vma, address, 1); > > > } > > > > memcg isn't setup yet and accounting isn't applied to proper memcg. > > Maybe, it would be applied to root memcg. With this change, we don't > > need the mapping to commit the charge so switching the order of > > page_add_new_anon_rmap() and mem_cgroup_commit_charge() will solve the > > issue. > > Good catch, it's that dreaded circular dependency. It's fixed two > patches down when I charge anon pages earlier as well. But I'll change > the rmap<->commit order in this patch to avoid the temporary bug. Okay. > Thanks for your thorough review! Thanks.