Re: [PATCH 3/6] mm, oom_adj: make sure processes sharing mm have same view of oom_score_adj

From: Vladimir Davydov
Date: Fri May 27 2016 - 12:18:36 EST


On Fri, May 27, 2016 at 01:18:03PM +0200, Michal Hocko wrote:
...
> @@ -1087,7 +1105,25 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
> unlock_task_sighand(task, &flags);
> err_put_task:
> put_task_struct(task);
> +
> + if (mm) {
> + struct task_struct *p;
> +
> + rcu_read_lock();
> + for_each_process(p) {
> + task_lock(p);
> + if (!p->vfork_done && process_shares_mm(p, mm)) {
> + p->signal->oom_score_adj = oom_adj;
> + if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE))
> + p->signal->oom_score_adj_min = (short)oom_adj;
> + }
> + task_unlock(p);

I.e. you write to /proc/pid1/oom_score_adj and get
/proc/pid2/oom_score_adj updated if pid1 and pid2 share mm?
IMO that looks unexpected from userspace pov.

May be, we'd better add mm->oom_score_adj and set it to the min
signal->oom_score_adj over all processes sharing it? This would
require iterating over all processes every time oom_score_adj gets
updated, but that's a slow path.