Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1468387ybz; Wed, 22 Apr 2020 22:31:19 -0700 (PDT) X-Google-Smtp-Source: APiQypLxvwbqTQ9jFNufLEfEXJmTEaJpH1Kx7loElGrfMS7CFn3FpdwiaS3NtueJYP3OrdOHWtz4 X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr1257449ejb.299.1587619879679; Wed, 22 Apr 2020 22:31:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587619879; cv=none; d=google.com; s=arc-20160816; b=KHSUBYAzXxZOWJh3GJxa2XY0CVMGJR7g2lDSokyMd1rdc4Ik0XnNJ40FgiC375DRD9 jBJ6HvXj2hOteLS0n/kO8P9UTesr8oMxJiheNwXfi8GvigIZKaSx3vh1P0iQdeKznCdG +tQXCmGuCT+0edfMRnYFrGu3zLO5TyixHYUd5L8+Bu+2BinSdv6vVx/ehrMTY3j2bW0y x90OxO99jmgLp7sbkIvD7l2wo4Z5A7qI/MdeDYfa9MmzSBrsO6Mgc/c5FLlbegq36C3y xp3yJqx+j//gxX7bhTIkESvMHQYNSMW2jGSWF6JK+9DdfeCo/nOBqucV4DZsrEyiIKaf NdIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5dRfGuiAmG9ezbEhwEm/4CtR44lsDucqUbK7PXbEl8Y=; b=JmB1svVtYBH2u2DaiSqPMIXgU414htfxUcdVk73F/JGWlXfEQ3fdlfQxWIMm2dNpYp WZjQ3swo7llPzLys0bJXREELqnAgHHx5E65xFwDxNLrrazOlDAf9vAIQ2xWDxQxKzZzB XO+AVoAHA1x3cwfyLQav2qVOBY8BxiUOxw2j6uXTcf+cb2tmkYUk9/xpUmNePk7Jg7sR vqyFFfzn1Nv0Q/V55J9Hd/qxaon8l6PZggr6lTpIZcidINzLeNBbsSROrOTzL8k/KAXM jpLKTmh9IHR1D9i9UCiYsQoU782hYk1UDQo28zid5su8qYXx0O9JRQQBfnIH3T++/6RY ZGmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=F5M1LLms; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h64si642304edd.10.2020.04.22.22.30.56; Wed, 22 Apr 2020 22:31:19 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=F5M1LLms; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726108AbgDWF1J (ORCPT + 99 others); Thu, 23 Apr 2020 01:27:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726122AbgDWF1I (ORCPT ); Thu, 23 Apr 2020 01:27:08 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E24AC03C1AB; Wed, 22 Apr 2020 22:27:07 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id f8so1910672plt.2; 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=AmFdId67i8VZ3bZRXDeDvz96da8qFnzJAC0iLo97Iw6ONXtfyq4a/H0GlleJlLOQBt TN5uMmywMtf/Iqkif/SdWaybkQOyEZpi0UaulxDoMy0yBMuwXa2IC/tBkwHlousglDQn vBWp/EGDzgS9UBFua54kO/m/8KfwYPgXDpOxC42WR+p81f4jYJQxVPghq8utg3IfG4Ym jJKLrZ71mHzyhKIquxf+YBKaFjcUnBG8rBk213a5Ot4holHscQEjfmtGmLSd1O0udZuP CgBet/lcD0pNCg73KpmH4J/3GHDdtulyQChC1gG0Dj2lytHkoC+SCuzkP6WTSAWdbdUt 5nXw== X-Gm-Message-State: AGi0PuZgHE8plJSxag6xb101g91xCHUCqEPloWPJ9cnaGm2Xt4Le9C6N lQbusrunbKVuuOIk96fj204= 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.