From: Roman Gushchin <guro@fb.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@kernel.org>,
Vladimir Davydov <vdavydov.dev@gmail.com>,
Johannes Weiner <hannes@cmpxchg.org>, Tejun Heo <tj@kernel.org>,
<cgroups@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-mm@kvack.org>
Subject: Re: [patch -mm] mm, memcg: evaluate root and leaf memcgs fairly on oom
Date: Wed, 14 Mar 2018 12:17:06 +0000 [thread overview]
Message-ID: <20180314121700.GA20850@castle.DHCP.thefacebook.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1803131720470.247949@chino.kir.corp.google.com>
Hello, David!
Overall I like this idea.
Some questions below.
On Tue, Mar 13, 2018 at 05:21:09PM -0700, David Rientjes wrote:
> There are several downsides to the current implementation that compares
> the root mem cgroup with leaf mem cgroups for the cgroup-aware oom killer.
>
> For example, /proc/pid/oom_score_adj is accounted for processes attached
> to the root mem cgroup but not leaves. This leads to wild inconsistencies
> that unfairly bias for or against the root mem cgroup.
>
> Assume a 728KB bash shell is attached to the root mem cgroup without any
> other processes having a non-default /proc/pid/oom_score_adj. At the time
> of system oom, the root mem cgroup evaluated to 43,474 pages after boot.
> If the bash shell adjusts its /proc/self/oom_score_adj to 1000, however,
> the root mem cgroup evaluates to 24,765,482 pages lol. It would take a
> cgroup 95GB of memory to outweigh the root mem cgroup's evaluation.
>
> The reverse is even more confusing: if the bash shell adjusts its
> /proc/self/oom_score_adj to -999, the root mem cgroup evaluates to 42,268
> pages, a basically meaningless transformation.
>
> /proc/pid/oom_score_adj is discounted, however, for processes attached to
> leaf mem cgroups. If a sole process using 250MB of memory is attached to
> a mem cgroup, it evaluates to 250MB >> PAGE_SHIFT. If its
> /proc/pid/oom_score_adj is changed to -999, or even 1000, the evaluation
> remains the same for the mem cgroup.
>
> The heuristic that is used for the root mem cgroup also differs from leaf
> mem cgroups.
>
> For the root mem cgroup, the evaluation is the sum of all process's
> /proc/pid/oom_score. Besides factoring in oom_score_adj, it is based on
> the sum of rss + swap + page tables for all processes attached to it.
> For leaf mem cgroups, it is based on the amount of anonymous or
> unevictable memory + unreclaimable slab + kernel stack + sock + swap.
>
> There's also an exemption for root mem cgroup processes that do not
> intersect the allocating process's mems_allowed. Because the current
> heuristic is based on oom_badness(), the evaluation of the root mem
> cgroup disregards all processes attached to it that have disjoint
> mems_allowed making oom selection specifically dependant on the
> allocating process for system oom conditions!
>
> This patch introduces completely fair comparison between the root mem
> cgroup and leaf mem cgroups. It compares them with the same heuristic
> and does not prefer one over the other. It disregards oom_score_adj
> as the cgroup-aware oom killer should, if enabled by memory.oom_policy.
> The goal is to target the most memory consuming cgroup on the system,
> not consider per-process adjustment.
>
> The fact that the evaluation of all mem cgroups depends on the mempolicy
> of the allocating process, which is completely undocumented for the
> cgroup-aware oom killer, will be addressed in a subsequent patch.
>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
> Based on top of oom policy patch series at
> https://marc.info/?t=152090280800001
>
> Documentation/cgroup-v2.txt | 7 +-
> mm/memcontrol.c | 147 ++++++++++++++++++------------------
> 2 files changed, 74 insertions(+), 80 deletions(-)
>
> diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt
> --- a/Documentation/cgroup-v2.txt
> +++ b/Documentation/cgroup-v2.txt
> @@ -1328,12 +1328,7 @@ OOM killer to kill all processes attached to the cgroup, except processes
> with /proc/pid/oom_score_adj set to -1000 (oom disabled).
>
> The root cgroup is treated as a leaf memory cgroup as well, so it is
> -compared with other leaf memory cgroups. Due to internal implementation
> -restrictions the size of the root cgroup is the cumulative sum of
> -oom_badness of all its tasks (in other words oom_score_adj of each task
> -is obeyed). Relying on oom_score_adj (apart from OOM_SCORE_ADJ_MIN) can
> -lead to over- or underestimation of the root cgroup consumption and it is
> -therefore discouraged. This might change in the future, however.
> +compared with other leaf memory cgroups.
>
> Please, note that memory charges are not migrating if tasks
> are moved between different memory cgroups. Moving tasks with
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -94,6 +94,8 @@ int do_swap_account __read_mostly;
> #define do_swap_account 0
> #endif
>
> +static atomic_long_t total_sock_pages;
> +
> /* Whether legacy memory+swap accounting is active */
> static bool do_memsw_account(void)
> {
> @@ -2607,9 +2609,9 @@ static inline bool memcg_has_children(struct mem_cgroup *memcg)
> }
>
> static long memcg_oom_badness(struct mem_cgroup *memcg,
> - const nodemask_t *nodemask,
> - unsigned long totalpages)
> + const nodemask_t *nodemask)
> {
> + const bool is_root_memcg = memcg == root_mem_cgroup;
> long points = 0;
> int nid;
> pg_data_t *pgdat;
> @@ -2618,92 +2620,65 @@ static long memcg_oom_badness(struct mem_cgroup *memcg,
> if (nodemask && !node_isset(nid, *nodemask))
> continue;
>
> - points += mem_cgroup_node_nr_lru_pages(memcg, nid,
> - LRU_ALL_ANON | BIT(LRU_UNEVICTABLE));
> -
> pgdat = NODE_DATA(nid);
> - points += lruvec_page_state(mem_cgroup_lruvec(pgdat, memcg),
> - NR_SLAB_UNRECLAIMABLE);
> + if (is_root_memcg) {
> + points += node_page_state(pgdat, NR_ACTIVE_ANON) +
> + node_page_state(pgdat, NR_INACTIVE_ANON);
> + points += node_page_state(pgdat, NR_SLAB_UNRECLAIMABLE);
> + } else {
> + points += mem_cgroup_node_nr_lru_pages(memcg, nid,
> + LRU_ALL_ANON);
> + points += lruvec_page_state(mem_cgroup_lruvec(pgdat, memcg),
> + NR_SLAB_UNRECLAIMABLE);
> + }
> }
>
> - points += memcg_page_state(memcg, MEMCG_KERNEL_STACK_KB) /
> - (PAGE_SIZE / 1024);
> - points += memcg_page_state(memcg, MEMCG_SOCK);
> - points += memcg_page_state(memcg, MEMCG_SWAP);
> -
> + if (is_root_memcg) {
> + points += global_zone_page_state(NR_KERNEL_STACK_KB) /
> + (PAGE_SIZE / 1024);
> + points += atomic_long_read(&total_sock_pages);
^^^^^^^^^^^^^^^^
BTW, where do we change this counter?
I also doubt that global atomic variable can work here,
we probably need something better scaling.
Thanks!
next prev parent reply other threads:[~2018-03-14 12:17 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 0:57 [patch -mm v3 0/3] mm, memcg: introduce oom policies David Rientjes
2018-03-13 0:57 ` [patch -mm v3 1/3] mm, memcg: introduce per-memcg oom policy tunable David Rientjes
2018-03-14 12:38 ` Roman Gushchin
2018-03-14 20:58 ` David Rientjes
2018-03-15 17:10 ` Roman Gushchin
2018-03-15 20:16 ` David Rientjes
2018-03-13 0:57 ` [patch -mm v3 2/3] mm, memcg: replace cgroup aware oom killer mount option with tunable David Rientjes
2018-03-13 0:57 ` [patch -mm v3 3/3] mm, memcg: add hierarchical usage oom policy David Rientjes
2018-03-14 0:21 ` [patch -mm] mm, memcg: evaluate root and leaf memcgs fairly on oom David Rientjes
2018-03-14 12:17 ` Roman Gushchin [this message]
2018-03-14 20:41 ` David Rientjes
2018-03-15 16:46 ` Roman Gushchin
2018-03-15 20:01 ` David Rientjes
2018-03-15 20:34 ` [patch -mm] mm, memcg: separate oom_group from selection criteria David Rientjes
2018-03-15 20:51 ` [patch -mm] mm, memcg: disregard mempolicies for cgroup-aware oom killer David Rientjes
2018-03-15 20:54 ` [patch -mm v3 0/3] mm, memcg: introduce oom policies David Rientjes
2018-03-16 21:08 ` [patch -mm 0/6] rewrite cgroup aware oom killer for general use David Rientjes
2018-03-16 21:08 ` [patch -mm 1/6] mm, memcg: introduce per-memcg oom policy tunable David Rientjes
2018-03-16 21:08 ` [patch -mm 2/6] mm, memcg: replace cgroup aware oom killer mount option with tunable David Rientjes
2018-03-16 21:08 ` [patch -mm 3/6] mm, memcg: add hierarchical usage oom policy David Rientjes
2018-03-16 21:08 ` [patch -mm 4/6] mm, memcg: evaluate root and leaf memcgs fairly on oom David Rientjes
2018-03-18 15:00 ` kbuild test robot
2018-03-18 20:14 ` [patch -mm 4/6 updated] " David Rientjes
2018-03-18 18:18 ` [patch -mm 4/6] " kbuild test robot
2018-03-16 21:08 ` [patch -mm 5/6] mm, memcg: separate oom_group from selection criteria David Rientjes
2018-03-16 21:08 ` [patch -mm 6/6] mm, memcg: disregard mempolicies for cgroup-aware oom killer David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 0/6] rewrite cgroup aware oom killer for general use David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 1/6] mm, memcg: introduce per-memcg oom policy tunable David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 2/6] mm, memcg: replace cgroup aware oom killer mount option with tunable David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 3/6] mm, memcg: add hierarchical usage oom policy David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 4/6] mm, memcg: evaluate root and leaf memcgs fairly on oom David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 5/6] mm, memcg: separate oom_group from selection criteria David Rientjes
2018-03-22 21:53 ` [patch v2 -mm 6/6] mm, memcg: disregard mempolicies for cgroup-aware oom killer David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 0/6] rewrite cgroup aware oom killer for general use David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 1/6] mm, memcg: introduce per-memcg oom policy tunable David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 2/6] mm, memcg: replace cgroup aware oom killer mount option with tunable David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 3/6] mm, memcg: add hierarchical usage oom policy David Rientjes
2018-07-16 18:16 ` Roman Gushchin
2018-07-17 4:06 ` David Rientjes
2018-07-23 20:33 ` David Rientjes
2018-07-23 21:28 ` Roman Gushchin
2018-07-23 23:22 ` David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 4/6] mm, memcg: evaluate root and leaf memcgs fairly on oom David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 5/6] mm, memcg: separate oom_group from selection criteria David Rientjes
2018-07-13 23:07 ` [patch v3 -mm 6/6] mm, memcg: disregard mempolicies for cgroup-aware oom killer David Rientjes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180314121700.GA20850@castle.DHCP.thefacebook.com \
--to=guro@fb.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=rientjes@google.com \
--cc=tj@kernel.org \
--cc=vdavydov.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).