Received: by 10.192.165.148 with SMTP id m20csp4304980imm; Tue, 8 May 2018 06:28:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrb7A9iJhyixsejqWFDFp97H2wobbbE7PSf5XnAOWiDScSLw+oU9SkiCC/Qai/+AGKlKdK2 X-Received: by 2002:a17:902:1a6:: with SMTP id b35-v6mr41430925plb.80.1525786100078; Tue, 08 May 2018 06:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525786100; cv=none; d=google.com; s=arc-20160816; b=s/NeseU/q+obMYOk/NLzf4SmD2CYOwqzOnYtGjH42kG3yTPbKlSOU3Yn67qbt+C7yX v1GuDXdoOAK+xS6u8vI6Znil531n/J/ZV6BNe93lZbPhWZfVlBFcWJHmXlskRz2JKYW2 y9/bbfE9RVvhYRYhynxNKD6FY6sionsaoVSNu+sXClkYzCawJ/fVR0BjPERn1nZ1v8pS zrWoATNrilTYqri0AaiLQWnnZSj3rAXHCRjbyfetg18THvrmqn/c8YGdr5Rwa3KWMU1I apTD2dsvMBitwHnK8mjhlT966MvkYQLmiW1Q22953am+tdj6HDzIpKHayvhBEVAL4R75 NXqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=ULiHoT5GR9XlhZXYmuBYPExN/HkA8PKniPOoucFm/3M=; b=FlJuDNmg8bQgkTCNPsV7HKvLAnYRI1YLGbO25blGqGs+M88KF/aMLeO1Y89SqHblaG 8aQtp8F/05WAxwm4w4URBjjWv6CXZydmJJEaWpS/iuYhw2CTp/Nk9S1RteVIjLjlQnve C3E2rb8kpLWwgoUwhs06Rs1oQEyBn2uXSrLNZDZO/tIftBTOpCcUjJ8wQXqAg+yoPBp1 OG98G24ptHWcNDQfURIo35Fes1kfSTvkGfowr3EokSNEVJpQYSb/cEkaIJI5YpD+C5KT y5C8lVGroNlI83hZh5GM04ahATaJpMYBm87anMImA7FOYrU0VzGuQDmRdCQdPkZhM65F Pupg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=PgQBoNGo; 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=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20-v6si19280248pgc.209.2018.05.08.06.28.05; Tue, 08 May 2018 06:28:20 -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=@yandex-team.ru header.s=default header.b=PgQBoNGo; 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=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755033AbeEHN0d (ORCPT + 99 others); Tue, 8 May 2018 09:26:33 -0400 Received: from forwardcorp1g.cmail.yandex.net ([87.250.241.190]:57391 "EHLO forwardcorp1g.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754986AbeEHN0c (ORCPT ); Tue, 8 May 2018 09:26:32 -0400 Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1g.cmail.yandex.net (Yandex) with ESMTP id ADC2C202FA; Tue, 8 May 2018 16:26:26 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id A60592440DC0; Tue, 8 May 2018 16:26:26 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:fd7c:73e6:b819:b4c2]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id BzgF7oInyS-QQWeRlaq; Tue, 08 May 2018 16:26:26 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1525785986; bh=ULiHoT5GR9XlhZXYmuBYPExN/HkA8PKniPOoucFm/3M=; h=Subject:To:Cc:References:From:Message-ID:Date:In-Reply-To; b=PgQBoNGop0/uoYjtcjfdrCdKclnd9iMirC589G19VXzr1+Bu5dhwSxHP6fV46Tp4f cobqSbKuZ/bFQxKwJMR8h3Ejc7oxqGidojXuHele1iG27EXXSqq8RdYQsheyBZdB75 23MxNw+l74S3ps8GBhifk3DBr6PD8lNvJffKQMjQ= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: Re: [PATCH v2] mm: fix oom_kill event handling To: Roman Gushchin , kernel-team@fb.com Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org References: <20180508124637.29984-1-guro@fb.com> From: Konstantin Khlebnikov Message-ID: Date: Tue, 8 May 2018 16:26:26 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180508124637.29984-1-guro@fb.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08.05.2018 15:46, Roman Gushchin wrote: > Commit e27be240df53 ("mm: memcg: make sure memory.events is > uptodate when waking pollers") converted most of memcg event > counters to per-memcg atomics, which made them less confusing > for a user. The "oom_kill" counter remained untouched, so now > it behaves differently than other counters (including "oom"). > This adds nothing but confusion. > > Let's fix this by adding the MEMCG_OOM_KILL event, and follow > the MEMCG_OOM approach. This also removes a hack from > count_memcg_event_mm(), introduced earlier specially for the > OOM_KILL counter. > > Signed-off-by: Roman Gushchin > Cc: Johannes Weiner > Cc: Michal Hocko > Cc: Vladimir Davydov > Cc: Andrew Morton > Cc: Konstantin Khlebnikov > Cc: linux-kernel@vger.kernel.org > Cc: cgroups@vger.kernel.org > Cc: linux-mm@kvack.org Acked-by: Konstantin Khlebnikov > --- > include/linux/memcontrol.h | 26 ++++++++++++++++++++++---- > mm/memcontrol.c | 6 ++++-- > mm/oom_kill.c | 2 +- > 3 files changed, 27 insertions(+), 7 deletions(-) > > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h > index 6cbea2f25a87..794475db7368 100644 > --- a/include/linux/memcontrol.h > +++ b/include/linux/memcontrol.h > @@ -54,6 +54,7 @@ enum memcg_memory_event { > MEMCG_HIGH, > MEMCG_MAX, > MEMCG_OOM, > + MEMCG_OOM_KILL, > MEMCG_SWAP_MAX, > MEMCG_SWAP_FAIL, > MEMCG_NR_MEMORY_EVENTS, > @@ -721,11 +722,8 @@ static inline void count_memcg_event_mm(struct mm_struct *mm, > > rcu_read_lock(); > memcg = rcu_dereference(mm->memcg); > - if (likely(memcg)) { > + if (likely(memcg)) > count_memcg_events(memcg, idx, 1); > - if (idx == OOM_KILL) > - cgroup_file_notify(&memcg->events_file); > - } > rcu_read_unlock(); > } > > @@ -736,6 +734,21 @@ static inline void memcg_memory_event(struct mem_cgroup *memcg, > cgroup_file_notify(&memcg->events_file); > } > > +static inline void memcg_memory_event_mm(struct mm_struct *mm, > + enum memcg_memory_event event) > +{ > + struct mem_cgroup *memcg; > + > + if (mem_cgroup_disabled()) > + return; > + > + rcu_read_lock(); > + memcg = rcu_dereference(mm->memcg); > + if (likely(memcg)) > + memcg_memory_event(memcg, event); > + rcu_read_unlock(); > +} > + > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > void mem_cgroup_split_huge_fixup(struct page *head); > #endif > @@ -757,6 +770,11 @@ static inline void memcg_memory_event(struct mem_cgroup *memcg, > { > } > > +static inline void memcg_memory_event_mm(struct mm_struct *mm, > + enum memcg_memory_event event) > +{ > +} > + > static inline bool mem_cgroup_low(struct mem_cgroup *root, > struct mem_cgroup *memcg) > { > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 10973671e562..38717630305d 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -3772,7 +3772,8 @@ static int mem_cgroup_oom_control_read(struct seq_file *sf, void *v) > > seq_printf(sf, "oom_kill_disable %d\n", memcg->oom_kill_disable); > seq_printf(sf, "under_oom %d\n", (bool)memcg->under_oom); > - seq_printf(sf, "oom_kill %lu\n", memcg_sum_events(memcg, OOM_KILL)); > + seq_printf(sf, "oom_kill %lu\n", > + atomic_long_read(&memcg->memory_events[MEMCG_OOM_KILL])); > return 0; > } > > @@ -5529,7 +5530,8 @@ static int memory_events_show(struct seq_file *m, void *v) > atomic_long_read(&memcg->memory_events[MEMCG_MAX])); > seq_printf(m, "oom %lu\n", > atomic_long_read(&memcg->memory_events[MEMCG_OOM])); > - seq_printf(m, "oom_kill %lu\n", memcg_sum_events(memcg, OOM_KILL)); > + seq_printf(m, "oom_kill %lu\n", > + atomic_long_read(&memcg->memory_events[MEMCG_OOM_KILL])); > > return 0; > } > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > index 8f7d8dd99e5d..6b74142a1259 100644 > --- a/mm/oom_kill.c > +++ b/mm/oom_kill.c > @@ -868,7 +868,7 @@ static void __oom_kill_process(struct task_struct *victim) > > /* Raise event before sending signal: task reaper must see this */ > count_vm_event(OOM_KILL); > - count_memcg_event_mm(mm, OOM_KILL); > + memcg_memory_event_mm(mm, MEMCG_OOM_KILL); > > /* > * We should send SIGKILL before granting access to memory reserves >