Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3397309ybh; Mon, 16 Mar 2020 22:44:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtEY+REGmHWzlFITnK53ngBABBAUq95cogQWBZDLuu5iFm6HOCq8zYf3WWoAb0LGibNpQ0e X-Received: by 2002:a05:6830:1498:: with SMTP id s24mr2415268otq.350.1584423853631; Mon, 16 Mar 2020 22:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584423853; cv=none; d=google.com; s=arc-20160816; b=huOOAn7mqAquUE8mVP0WhpfLo9D5SyUhiai+bzEKI8PW3WH3oBX3Z/BQJAuDcw/ZBE /xP1yNsVF2m03bhjMgleBMACy+Yvgvdg69QZZUX6ju3I4KV75Cbq+M3Q/U+f/0O7JAZx LD6bHR3TFRnjQDSnIMlPqHhWSdm7IclLehti9kddwbX59KUyPcmHlCDxFM979rLBKAwn uSe0Pxs0+/NM1XAfudJofgHM2bLz/0gL7aPXThiH5hwBhB6yDgAvzcFqAFkVbqBYKZtK p94fIgGhK7RCogYXp/1kGsDlMdrsZ+hKrKhQfmm1H/9CNTWN9V7uGXR5RvVHS+1Fo9Fh jihw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=9wb/P3LPDlbugq1CDyVA5kSUSv6vOvUhfJXNTDD+0wY=; b=YMQAOWDxxeOAzHGKKgj3dzVJhz5LG8Wv3bdBtj9jLp25NptQcey+h7IwGcG5Hgjfbx CK3yPMsDFP919RJPy0/GIdOwvY18yHcotDWAxOtR9dDLIm8xaHydUhp5Gtvi7LHkpwTh uSWlgzzspNRGCeKNOHC6v1gPuV9eHP3ge37YYII1ZB4JHZvsXhxoVudJoZ9URQ9AO2fr PZmMc+nnrWLMZNsTJc9cU7hgh0f4eBftgRd+A2s4l0ahU8ZomRBf6ebfAO8AXtdpo6sk uDqGvDfBkGfxPya3DHm1fdkbbkHjrZk6l185uR2PY+HvYo8e6mxZRUzaaycksL6m4bI7 Jtjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HUFtryvr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id i15si1098066oib.46.2020.03.16.22.44.01; Mon, 16 Mar 2020 22:44:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HUFtryvr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726549AbgCQFmY (ORCPT + 99 others); Tue, 17 Mar 2020 01:42:24 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39769 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgCQFmX (ORCPT ); Tue, 17 Mar 2020 01:42:23 -0400 Received: by mail-pl1-f195.google.com with SMTP id m1so919814pll.6 for ; Mon, 16 Mar 2020 22:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9wb/P3LPDlbugq1CDyVA5kSUSv6vOvUhfJXNTDD+0wY=; b=HUFtryvrggxqsdgMcaIJkI5PlHQpf/d426P43SkE68+uCxMmRxAgW29VbfpzX8Gv1c yuYoqfiyoGFGojyZCxXmM7OdvkkEXwLDG1qua3NoH6gYyqfvI/Vymne5r4jy+y1dTkVo nySuJtnMji4kGXAhfr83BtEllAi49vmjFpF4vBMshA9AF8T1dzHb/w83+KamUimjlTYC HTSHtUEYdZMdjf5oRc3H4Fz3Bcr2Mp2nEBTzMczPYr3oXCfXmuDp+u6mrelq1LwZH3fy RQrw6sd6fy44g54QZkG9MuAF87HzmemOJ1CEOBNoJcf9fHC0kPtqNoy6Uq5VzwwuVPLg +aXw== 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; bh=9wb/P3LPDlbugq1CDyVA5kSUSv6vOvUhfJXNTDD+0wY=; b=DgaeaMcrqbfpQSImKV5C10VOa7/uyVDWYQ+Rix+v5rziV0H/GHY8syRF8zLx2DaSFF Qsrjt3qWHakBaItNCbPn2yP+BZnMUyFpsrJ1WVLLbDQQ4cbfAg3sJy9GHy+7pBF5dJH4 mHcYnuS+flVhKUHbwpA0s8Gl7Q94ZWTh19CsIvAeEhrY250wfKKfRGxg5EoERcyY6W+C O96EQmrbF+QR72PAldFWa+XcA9yTLxDmyFGS46vObQt3x7Jaj08xLt9+/ZZXIM2pRik5 poIA7LnySEVXj6wv0RO9CxEG7ewSeh4er6UKcAaLkEtJVmxiP5BtIKpihDsxPDkmNrqM 6iYQ== X-Gm-Message-State: ANhLgQ3v0SPyq+/hAqlBMQCV0Wv3NWLOJ6iLNjGBYoDz1r6LHr2TwTXr God2SzAUFuHi6vM9Hr/2jFU= X-Received: by 2002:a17:90a:d80b:: with SMTP id a11mr3492749pjv.21.1584423742470; Mon, 16 Mar 2020 22:42:22 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id i21sm1141757pgn.5.2020.03.16.22.42.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Mar 2020 22:42:21 -0700 (PDT) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Hugh Dickins , Minchan Kim , Vlastimil Babka , Mel Gorman , kernel-team@lge.com, Joonsoo Kim Subject: [PATCH v3 5/9] mm/workingset: use the node counter if memcg is the root memcg Date: Tue, 17 Mar 2020 14:41:53 +0900 Message-Id: <1584423717-3440-6-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1584423717-3440-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1584423717-3440-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joonsoo Kim In the following patch, workingset detection is implemented for the swap cache. Swap cache's node is usually allocated by kswapd and it isn't charged by kmemcg since it is from the kernel thread. So the swap cache's shadow node is managed by the node list of the list_lru rather than the memcg specific one. If counting the shadow node on the root memcg happens to reclaim the slab object, the shadow node count returns the number of the shadow node on the node list of the list_lru since root memcg has the kmem_cache_id, -1. However, the size of pages on the LRU is calculated by using the specific memcg, so mismatch happens. This causes the number of shadow node not to be increased to the enough size and, therefore, workingset detection cannot work correctly. This patch fixes this bug by checking if the memcg is the root memcg or not. If it is the root memcg, instead of using the memcg-specific LRU, the system-wide LRU is used to calculate proper size of the shadow node so that the number of the shadow node can grow as expected. Signed-off-by: Joonsoo Kim --- mm/workingset.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/workingset.c b/mm/workingset.c index 5fb8f85..a9f474a 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -468,7 +468,13 @@ static unsigned long count_shadow_nodes(struct shrinker *shrinker, * PAGE_SIZE / xa_nodes / node_entries * 8 / PAGE_SIZE */ #ifdef CONFIG_MEMCG - if (sc->memcg) { + /* + * Kernel allocation on root memcg isn't regarded as allocation of + * specific memcg. So, if sc->memcg is the root memcg, we need to + * use the count for the node rather than one for the specific + * memcg. + */ + if (sc->memcg && !mem_cgroup_is_root(sc->memcg)) { struct lruvec *lruvec; int i; -- 2.7.4