[Devel] [PATCH rh7] memcg: count all oom kills

Konstantin Khorenko khorenko at virtuozzo.com
Mon Aug 31 06:54:56 PDT 2015


Kirill, please review.

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 08/14/2015 12:48 PM, Vladimir Davydov wrote:
> We do not count processes killed because they share victim's mm. Fix it.
>
> Fixes: 66053f4201e41 ("memcg: count oom kills")
> Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
> ---
>   include/linux/memcontrol.h |  4 ++--
>   mm/memcontrol.c            | 15 +++++++++++++--
>   mm/oom_kill.c              |  3 ++-
>   3 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> index eb7ae43a57f9..ac3f16f0ee28 100644
> --- a/include/linux/memcontrol.h
> +++ b/include/linux/memcontrol.h
> @@ -122,7 +122,7 @@ unsigned long mem_cgroup_get_lru_size(struct lruvec *lruvec, enum lru_list);
>   void mem_cgroup_update_lru_size(struct lruvec *, enum lru_list, int);
>   extern bool mem_cgroup_below_oom_guarantee(struct task_struct *p);
>   extern void mem_cgroup_note_oom_kill(struct mem_cgroup *memcg,
> -				     struct mm_struct *mm);
> +				     struct task_struct *task);
>   extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
>   					struct task_struct *p);
>   extern void mem_cgroup_replace_page_cache(struct page *oldpage,
> @@ -351,7 +351,7 @@ static inline bool mem_cgroup_below_oom_guarantee(struct task_struct *p)
>   }
>
>   static inline void
> -mem_cgroup_note_oom_kill(struct mem_cgroup *memcg, struct mm_struct *mm)
> +mem_cgroup_note_oom_kill(struct mem_cgroup *memcg, struct task_struct *task)
>   {
>   }
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 52c787165b17..0cb329028a29 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1623,14 +1623,25 @@ bool mem_cgroup_below_oom_guarantee(struct task_struct *p)
>   }
>
>   void mem_cgroup_note_oom_kill(struct mem_cgroup *root_memcg,
> -			      struct mm_struct *mm)
> +			      struct task_struct *task)
>   {
>   	struct mem_cgroup *memcg, *memcg_to_put;
> +	struct task_struct *p;
>
>   	if (!root_memcg)
>   		root_memcg = root_mem_cgroup;
>
> -	memcg_to_put = memcg = try_get_mem_cgroup_from_mm(mm);
> +	p = find_lock_task_mm(task);
> +	if (p) {
> +		memcg = try_get_mem_cgroup_from_mm(p->mm);
> +		task_unlock(p);
> +	} else {
> +		rcu_read_lock();
> +		memcg = mem_cgroup_from_task(task);
> +		css_get(&memcg->css);
> +		rcu_read_unlock();
> +	}
> +	memcg_to_put = memcg;
>   	if (!memcg || !mem_cgroup_same_or_subtree(root_memcg, memcg))
>   		memcg = root_memcg;
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index c99a5f559286..70893730524a 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -498,7 +498,6 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
>
>   	/* mm cannot safely be dereferenced after task_unlock(victim) */
>   	mm = victim->mm;
> -	mem_cgroup_note_oom_kill(memcg, mm);
>   	pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
>   		task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
>   		K(get_mm_counter(victim->mm, MM_ANONPAGES)),
> @@ -526,11 +525,13 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
>   				task_pid_nr(p), p->comm);
>   			task_unlock(p);
>   			do_send_sig_info(SIGKILL, SEND_SIG_FORCED, p, true);
> +			mem_cgroup_note_oom_kill(memcg, p);
>   		}
>   	rcu_read_unlock();
>
>   	set_tsk_thread_flag(victim, TIF_MEMDIE);
>   	do_send_sig_info(SIGKILL, SEND_SIG_FORCED, victim, true);
> +	mem_cgroup_note_oom_kill(memcg, victim);
>   	put_task_struct(victim);
>   }
>   #undef K
>



More information about the Devel mailing list