Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4258041pxf; Tue, 30 Mar 2021 03:22:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6bdXV0JtEevJP8Lo19DruJoTMsEZXmjD1OpC7LI2pL4EIQ87L3pZtHalCq/A98ij2eEBz X-Received: by 2002:a17:906:75a:: with SMTP id z26mr32230640ejb.22.1617099763913; Tue, 30 Mar 2021 03:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617099763; cv=none; d=google.com; s=arc-20160816; b=m6d3jGrzUXbZ/VyV2HoIOoMXm0qvkDarQi0yWhr28t/hJuhuCRGbPXro6zPosvC2Rp ry8cvqC3pMUR0th6nKrXJxkEUoE6gN+gjfHEZTpvHdSAKEk368MuJ1WcVjwRUaTzvYqX pQzqKUyHBonH7UCPzizfDiPA5WSvL7nQCgQMk40H4MJRje0Vj+pPzMcSd5U3HxhvTGIs 05wYfwBT9Gi1fECZ5q9KSOZEFxTyB8PC3+HgOLQAqrB67zT36qIdWTAQvRRtWEV4vst6 RD/vUJyM3hTruj97Iy/yeUuTsXZqtY2ry5f3MptGvo926R4uXo5NXCneyHGOO4Q4xmZZ qTxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mcUfJURbaW0/pk8mnMuxrluSpP/XrND4LfgaV4Zkidk=; b=KxRsIbi4U+xPBOARVMVeLqdJkVuA/AKXdrf0s50FxKnd6mOUdzzQ4ZhXnX8w2Rr4fW nhfsRn0ZVtsPyvsQ5HFDR8ViDTz4DNWzU9BU0vLCJ4UA2jhK1HAT//wHTa+kMRbrdD1u V73EmcR4Zk3ObgJII7TaATZ9J7nqgtBq6lDQwVp+9DTmPK2KQ/RTThV0GdX4E9H+cRQh HvRA8q4fyHlXcJ8r2NW/ps3u5TOq+toJhn4fQVEAu4SURC1xeYxyTiPer9xspopOp8C4 xBjxP+PFOyXy4I91ELycOLOWZr4a4VI3TjgOU/BxbqTJcWlUBnM7ve7rlgfoPOGRlzcN Ha5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=PsPsxTwX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si14581493eji.719.2021.03.30.03.22.20; Tue, 30 Mar 2021 03:22:43 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=PsPsxTwX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231749AbhC3KVO (ORCPT + 99 others); Tue, 30 Mar 2021 06:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231737AbhC3KUp (ORCPT ); Tue, 30 Mar 2021 06:20:45 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2412C061574 for ; Tue, 30 Mar 2021 03:20:44 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id m7so11378965pgj.8 for ; Tue, 30 Mar 2021 03:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mcUfJURbaW0/pk8mnMuxrluSpP/XrND4LfgaV4Zkidk=; b=PsPsxTwX9RegUj+h72lWw56jPXRtpLCx/YV8Qn7VSIrVh4YWoCvlIbbwkN/7NNwyk+ dEMKW9ogd4Z0M8+Q822sY3pwhvICGO7iYNVOTGuVy53sxIaZ5KdqsI/WyR8ZgDw/TYDO o9jDHfwYW556VZbS0jJiRkNIjf7VfjVCkG/JwgNweU4W9+4pV1T1VvsbCXUx4ypeLAG7 ptxVNfOszwBVySCntGTnWvJEL51GfJ1+AGDD2Q15o40rANP/n04vEDnimelG2SNYxHLB RRVF6fqkddY0HI70W3cBM7jVmBMcqlRDEzt1to5Y3q1g9Bn7CpWUR3Hwkx+oNtusgEa5 Uelw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mcUfJURbaW0/pk8mnMuxrluSpP/XrND4LfgaV4Zkidk=; b=awmXMLaRlXSab3AJIPoeADBvdub0JPC7v+oJ+3LmHhuRQpQ5IPuZ2M32DVB2tGqlDQ D7ClAMrP5yx7kEUkR/5y/Akm/+2UsAThKAaurg0kS6SY/mM3PzzQ2nFfWU7PxUIF8H+E R4ejQYm9xeFa1OeTP1EOEm+zjs5OBmLJiveclZSEhhX4/JW1rAMGC2ucrA20ql7eNmgb QsnXF+6bCbnS4iHBPz3YlLz13475yjHIzFvLGyqm9mMF6P9zqIleSzqfvTTLZA0sesgB 91nZzsnFlb68BoXjFchyB9FB0FhAdEWjM3FJXND/TJfnfVOQkCjlpypBAf0dIPbxRcLL ESTQ== X-Gm-Message-State: AOAM530tpMdW6duZ5wN/+dpINnDdwB209Mzi8oVvuFeXKDOuZbgmXGtr JsI5rdjyihgB5rlLIo65Wgy+vw== X-Received: by 2002:a65:5308:: with SMTP id m8mr26343234pgq.266.1617099644225; Tue, 30 Mar 2021 03:20:44 -0700 (PDT) Received: from localhost.localdomain ([2408:8445:ad30:68d8:c87f:ca1b:dc00:4730]) by smtp.gmail.com with ESMTPSA id k10sm202259pfk.205.2021.03.30.03.20.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Mar 2021 03:20:43 -0700 (PDT) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, Muchun Song Subject: [RFC PATCH 01/15] mm: memcontrol: fix page charging in page replacement Date: Tue, 30 Mar 2021 18:15:17 +0800 Message-Id: <20210330101531.82752-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210330101531.82752-1-songmuchun@bytedance.com> References: <20210330101531.82752-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pages aren't accounted at the root level, so do not charge the page to the root memcg in page replacement. 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. Signed-off-by: Muchun Song --- mm/memcontrol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 249bf6b4d94c..d0c4f6e91e17 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6936,9 +6936,11 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage) /* Force-charge the new page. The old one will be freed soon */ nr_pages = thp_nr_pages(newpage); - page_counter_charge(&memcg->memory, nr_pages); - if (do_memsw_account()) - page_counter_charge(&memcg->memsw, nr_pages); + if (!mem_cgroup_is_root(memcg)) { + page_counter_charge(&memcg->memory, nr_pages); + if (do_memsw_account()) + page_counter_charge(&memcg->memsw, nr_pages); + } css_get(&memcg->css); commit_charge(newpage, memcg); -- 2.11.0