From patchwork Thu Nov 7 06:08:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11231911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9661D1850 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 54AAF21882 for ; Thu, 7 Nov 2019 06:09:06 +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 54AAF21882 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) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 96B7A6B000D; Thu, 7 Nov 2019 01:09:05 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org 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-Original-To: linux-mm@kvack.org 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-Spam-Summary: 2,0,0,a32f7750104eadc4,d41d8cd98f00b204,laoar.shao@gmail.com,:mhocko@kernel.org:hannes@cmpxchg.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org::laoar.shao@gmail.com,RULES_HIT:2:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1605:1606:1730:1747:1777:1792:1801:2195:2198:2199:2200:2393:2559:2562:2693:2731:2897:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4119:4250:4321:4605:5007:6119:6261:6653:7514:8784:9010:9149:9413:10004:11026:11232:11233:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:12986:13161:13229:13869:14394:14687:14877:21080:21444:21451:21627:21666:30005:30054:30056,0,RBL:209.85.210.194:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none 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