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=-9.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 39D7EC5DF60 for ; Thu, 7 Nov 2019 06:09:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E3FE921882 for ; Thu, 7 Nov 2019 06:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qgGJOBaY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3FE921882 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 994646B000C; Thu, 7 Nov 2019 01:09:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96B7A6B000D; Thu, 7 Nov 2019 01:09:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80BF06B000E; Thu, 7 Nov 2019 01:09:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 68DDF6B000C for ; Thu, 7 Nov 2019 01:09:05 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 1F7592DFD for ; Thu, 7 Nov 2019 06:09:05 +0000 (UTC) X-FDA: 76128453450.04.blade33_8979242b96211 X-HE-Tag: blade33_8979242b96211 X-Filterd-Recvd-Size: 8279 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 Nov 2019 06:09:04 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id 193so1636863pfc.13 for ; Wed, 06 Nov 2019 22:09:04 -0800 (PST) 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=nHHPpymPLZDPZyUX+onE+rIyRzuuTD5D0cpgPbuUkXM=; b=qgGJOBaYPTyUI4SOHaUy9anRFG8Ouj3tiI5F4cpjBxhhVg6iSyth3RSRZIl9rZ8RYt hVoRBB7T9bfi4Cq5+sDMNtaTiGs6yL0rOsBCTd0YcLdxzhof9Oy8UKGdPzkHopcJkOSM SqqLAvKojfBnu5s7ej/t9T64bY/XvEpVEdOC+Q+QDvigAKNcXs54u/AHX6aSkVercnw5 vThBT+YNMpITomHCf6b+FKmpL1EsqB0IIEfyZXvt46djhzlPEqbZ/s41jVR2Zb8lpscg 3cwjX/cwwFGI9yNKRwojFIA3obBpeWQ6PWopjcdyUQGhcn3mcqgA6fSJUaAr5Js4HdmV 2t8g== 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=nHHPpymPLZDPZyUX+onE+rIyRzuuTD5D0cpgPbuUkXM=; b=K3wUMlqQZmkLk0yWhprSMpXLlU2nysG6Gth7h2tn5o+91MbABP/5tzxtciHJPBLvGs +uPD8YisO9wSZh1Tne5LG1QbhMxM04+7nLL6WOSqSQ6CxnIZQ/m6vFM1t0Fm9EnYj7vm AtvobHRlGMfQQ/hn4BpNk8HSUdfAAk1JC+S/LzhpiYMc3zPZtYphWGQrPDtfH57PjXoG +aIAgShEW00clgX3ONnoB9h/UG98G/c+8/eqsuAv6dis6K+mOXc6DzA74Pwpa3M3LQhW 6W/FDyoJB23t7EH3WyR5108rnLa4oTJ5bFQSOJyQ23/br4jpFsD4D/xSOffog5fGTH7m NDDw== X-Gm-Message-State: APjAAAVDLLuv/yNPDcnJgCgrQ+/dueo4fZNc5MqBmkkdnGASOcuOlfp5 eghwkzc1UqRfuxrlvwEJnOWV+TXE X-Google-Smtp-Source: APXvYqxlIn1aaDMnCrjBZrnAqIcZ6SET/bp7QePUkZ6iQkK8nT5P9eXmFqObvUzs1tALNET6fKvURg== X-Received: by 2002:a63:5605:: with SMTP id k5mr2420125pgb.14.1573106943698; Wed, 06 Nov 2019 22:09:03 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id y16sm1083474pfo.62.2019.11.06.22.09.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Nov 2019 22:09:03 -0800 (PST) From: Yafang Shao To: mhocko@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao Subject: [PATCH 2/2] mm, memcg: introduce passive reclaim counters for non-root memcg Date: Thu, 7 Nov 2019 01:08:09 -0500 Message-Id: <1573106889-4939-2-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1573106889-4939-1-git-send-email-laoar.shao@gmail.com> References: <1573106889-4939-1-git-send-email-laoar.shao@gmail.com> 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: The memory.{min, low} protection can prevent the reclaimers to reclaim the pages from a memcg when there're memory pressure outside of a memcg. We'd better introduce some counters to show this behavior. This patch introduce two counters, pgscan_passive and pgsteal_passive. pgscan_passive: pages scanned due to memory pressure outside this memcg pgsteal_passive: pages reclaimed due to memory pressure outside this memcg memcg set with higher memory.{min, low} setting, will get a lower pgscan_passive and pgsteal_passive. For example, if memory.min is equal to memory.max, then these passive reclaim counters should always be zero. These counters are only for non-root memory cgroup. It's not easy to introduce some container-only vmstat counters, because it will make lots of changes. So I introduce some global vmstat counters, but they are always zero for root memory cgroup. Signed-off-by: Yafang Shao --- Documentation/admin-guide/cgroup-v2.rst | 10 ++++++++++ include/linux/vm_event_item.h | 2 ++ mm/memcontrol.c | 4 ++++ mm/vmscan.c | 11 +++++++++-- mm/vmstat.c | 2 ++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index cdacc9c..11e0129 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1336,10 +1336,20 @@ PAGE_SIZE multiple when read back. Amount of scanned pages (in an inactive LRU list) + pgscan_passive + + Amount of scanned pages due to memory pressure outside this + memcg + pgsteal Amount of reclaimed pages + pgsteal_passive + + Amount of reclaimed pages due to memory pressure outside + this memcg + pgactivate Amount of pages moved to the active LRU list diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 47a3441..0fcdaa3 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -32,8 +32,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, PGREFILL, PGSTEAL_KSWAPD, PGSTEAL_DIRECT, + PGSTEAL_PASSIVE, PGSCAN_KSWAPD, PGSCAN_DIRECT, + PGSCAN_PASSIVE, PGSCAN_DIRECT_THROTTLE, #ifdef CONFIG_NUMA PGSCAN_ZONE_RECLAIM_FAILED, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9da4ef9..0a2bf9a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1443,9 +1443,13 @@ static char *memory_stat_format(struct mem_cgroup *memcg) seq_buf_printf(&s, "pgscan %lu\n", memcg_events(memcg, PGSCAN_KSWAPD) + memcg_events(memcg, PGSCAN_DIRECT)); + seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGSCAN_PASSIVE), + memcg_events(memcg, PGSCAN_PASSIVE)); seq_buf_printf(&s, "pgsteal %lu\n", memcg_events(memcg, PGSTEAL_KSWAPD) + memcg_events(memcg, PGSTEAL_DIRECT)); + seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGSTEAL_PASSIVE), + memcg_events(memcg, PGSTEAL_PASSIVE)); seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGACTIVATE), memcg_events(memcg, PGACTIVATE)); seq_buf_printf(&s, "%s %lu\n", vm_event_name(PGDEACTIVATE), diff --git a/mm/vmscan.c b/mm/vmscan.c index 3b08e85..0ea6c4a0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1910,6 +1910,7 @@ static int current_may_throttle(void) struct pglist_data *pgdat = lruvec_pgdat(lruvec); struct zone_reclaim_stat *reclaim_stat = &lruvec->reclaim_stat; bool stalled = false; + struct mem_cgroup *memcg; while (unlikely(too_many_isolated(pgdat, file, sc))) { if (stalled) @@ -1934,10 +1935,13 @@ static int current_may_throttle(void) __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, nr_taken); reclaim_stat->recent_scanned[file] += nr_taken; + memcg = lruvec_memcg(lruvec); item = current_is_kswapd() ? PGSCAN_KSWAPD : PGSCAN_DIRECT; if (!cgroup_reclaim(sc)) __count_vm_events(item, nr_scanned); - __count_memcg_events(lruvec_memcg(lruvec), item, nr_scanned); + if (memcg != sc->target_mem_cgroup) + __count_memcg_events(memcg, PGSCAN_PASSIVE, nr_scanned); + __count_memcg_events(memcg, item, nr_scanned); spin_unlock_irq(&pgdat->lru_lock); if (nr_taken == 0) @@ -1948,10 +1952,13 @@ static int current_may_throttle(void) spin_lock_irq(&pgdat->lru_lock); + memcg = lruvec_memcg(lruvec); item = current_is_kswapd() ? PGSTEAL_KSWAPD : PGSTEAL_DIRECT; if (!cgroup_reclaim(sc)) __count_vm_events(item, nr_reclaimed); - __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed); + if (memcg != sc->target_mem_cgroup) + __count_memcg_events(memcg, PGSTEAL_PASSIVE, nr_reclaimed); + __count_memcg_events(memcg, item, nr_reclaimed); reclaim_stat->recent_rotated[0] += stat.nr_activate[0]; reclaim_stat->recent_rotated[1] += stat.nr_activate[1]; diff --git a/mm/vmstat.c b/mm/vmstat.c index 78d5337..5d2a053 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1196,8 +1196,10 @@ int fragmentation_index(struct zone *zone, unsigned int order) "pgrefill", "pgsteal_kswapd", "pgsteal_direct", + "pgsteal_passive", "pgscan_kswapd", "pgscan_direct", + "pgscan_passive", "pgscan_direct_throttle", #ifdef CONFIG_NUMA -- 1.8.3.1