Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1311097pxf; Fri, 9 Apr 2021 05:32:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrOJiqllRmfvLcTqKZQruw36PN3KCsQ53XrwX6nC3hg1ZDIZVcWfnXIqaSjul7r5H/htnU X-Received: by 2002:a17:90a:70c2:: with SMTP id a2mr13328499pjm.63.1617971578660; Fri, 09 Apr 2021 05:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617971578; cv=none; d=google.com; s=arc-20160816; b=sOGTHYxY0gkYDrFfny01Lmhxrnt5GCYQDAe5ndNCBS0o/8y+3mO9lfqnNUGj1mwFiP niKYcH5ziO7RJcrQxO0eScnlkfwhB/+EHoO3mZbPhuQfEF5ePRmg0O1W24OtWl5NCCzE VJ7lzbfxmCejaXnvP8yUlGj0pcuu5T7Xe28Uwkx2bXbSzlo/sBjbn/2gfuEoT6XDsw03 6nO+sVL19pkbK/i023Ip8YI8DfRlKxf/tkJWC8ZHIdUxJWTvfmlC4m6B5H9P4btbpHM0 yOTx5CF+KAm1jRaHV/DQRBhLTLHvhp6QOy5CQAofOzYqMKcHfHAy3AwVs60+gW5DbMeb 7qGQ== 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=58kw73zULk1M3QRMYpGesyQhzu0BFPE8Fnems3AjAyI=; b=USZORgBwp3Q4smT9ZU52KuEQlw6KrrZ3c1OtlQVCq0z7eG+CzwWDO4IpE5uQSDvAds 8SmbtjEHWOM7tnbxpyYQp2Ovh74TeVHfV0UzocrCydrJt0uQmR9PcrREik2bR1nvf84e 6CWEwrPI+7jesv9O6kqd+606uhH7gE98n7Wn2eVWnACdUqQGLXmj7TgBY2PKqkBy1b44 Si0+tfpVFJ4HHg5uFHj1hdbFk6LEDVB6DRm7chSz6iyo5QA0ZlPJVnnJyT+bNq6pWLFX bjQc30DYEWoZPw/15NW/LeHgjxXnleNWcxSGCIUoAYaZ7l3UTIXiYALliT+0CM4xCwwI Ut9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=jSUh5hJW; 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 m189si2977760pfb.79.2021.04.09.05.32.46; Fri, 09 Apr 2021 05:32:58 -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=jSUh5hJW; 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 S233470AbhDIMcM (ORCPT + 99 others); Fri, 9 Apr 2021 08:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbhDIMcL (ORCPT ); Fri, 9 Apr 2021 08:32:11 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0C98C061760 for ; Fri, 9 Apr 2021 05:31:58 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id ep1-20020a17090ae641b029014d48811e37so3109718pjb.4 for ; Fri, 09 Apr 2021 05:31:58 -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=58kw73zULk1M3QRMYpGesyQhzu0BFPE8Fnems3AjAyI=; b=jSUh5hJWnp8EpV/wkefSJdZoi2UIab+EAWPvsDiKxRQZFhbegQ6L+Dl6eawxYH4xVP Z5VSbvD4uyhDlqJvsvJE7nm/k4W55DfqLKoNSuW9g0pMbgvsj6VyLm54oHXzQYVgaYOE 1eLC/i/3dlP0Ne5mvo6Zr5HbA191dng758K50uL4U8eC04wsiOi6hu06CioZQfggRe1l cTX182sfC625GWoWUSxyVFANLDFjhgIeRuJ8PabTFygDuLtG7KPWnb+YCntxJixUVreS fnBFBvxfh8qKkvW8XSdGg6kg0d4QTUqphO4HAAsi7LIkqyhWlhrUvL9nB9J62VMFJRCT AIQw== 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=58kw73zULk1M3QRMYpGesyQhzu0BFPE8Fnems3AjAyI=; b=MhLrPTpnvWdfLFfqzRvwEoDLIG00KhwBhRYcLfGFBsYmrZsPDOA/s45WRhFP9Ba3QO rE3GRuwfJZ5AWkehK//hFKcxP754YlMFmNk0gtQpe7YTXVa5E8syxnlWNcXZ711EUrHS WBkAGGNfs9cOYKu+D/0lwhQA4ipuW5Ub9JMxEhYX7RI2Me+zNThVU1kFfb+MQ4Fkb6WU XCAx7iATPECEnGR6NsYeJbMV2OCLAYAhvvhKcCWMgavAIoHRAVD5h/88L5bj71hDkugD YNM1Czj+x7U4IJcLteqgjaBe3FzADQLJNaes5znzgtM014dmFjcFAtZYuJR5QQusBDUk dX5Q== X-Gm-Message-State: AOAM531v6KG+PMRXQXVTWyx0qxCh7OtNDsDX5jSxZWtSEXghA8ICvOEj xDQW3W4e8Xbm46J9qeBylqgyFA== X-Received: by 2002:a17:90a:e016:: with SMTP id u22mr13094679pjy.134.1617971518281; Fri, 09 Apr 2021 05:31:58 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id t3sm2167785pfg.176.2021.04.09.05.31.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 05:31:57 -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, fam.zheng@bytedance.com, bsingharora@gmail.com, shy828301@gmail.com, alex.shi@linux.alibaba.com, Muchun Song Subject: [RFC PATCH v2 01/18] mm: memcontrol: fix page charging in page replacement Date: Fri, 9 Apr 2021 20:29:42 +0800 Message-Id: <20210409122959.82264-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210409122959.82264-1-songmuchun@bytedance.com> References: <20210409122959.82264-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 Acked-by: Johannes Weiner --- mm/memcontrol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 64ada9e650a5..f229de925aa5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6806,9 +6806,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