From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932607AbbJVJr4 (ORCPT ); Thu, 22 Oct 2015 05:47:56 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:35530 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932443AbbJVJry (ORCPT ); Thu, 22 Oct 2015 05:47:54 -0400 Date: Thu, 22 Oct 2015 11:47:52 +0200 From: Michal Hocko To: Hongjie Fang =?utf-8?B?KOaWuea0quadsCk=?= Cc: David Rientjes , "Eric W. Biederman" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCHv2 4.3-rc6] proc: fix convert from oom_score_adj to oom_adj Message-ID: <20151022094752.GC26854@dhcp22.suse.cz> References: <1f80189385e540c2a5b2747a7a265d8c@SHMBX01.spreadtrum.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1f80189385e540c2a5b2747a7a265d8c@SHMBX01.spreadtrum.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 22-10-15 06:49:01, Hongjie Fang (方洪杰) wrote: > > The oom_adj has been replaced by oom_score_adj in kernel, > but the /proc/pid/oom_adj is provided for legacy purposes. > When write/read a value into/from /proc/pid/oom_adj, > there is a transformation between oom_adj and oom_score_adj. > > After writing a new value into /proc/pid/oom_adj, then read it. > The return value is a different value than you wrote. > Fix this by adding a adjustment factor. ... when printing the value. Your previous patch has changed the stored value while this one only changes the presented value. The previous one was more correct IMO but in reality the difference (+-1) in oom_score_adj should be hardly noticeable and nobody has complained about the current scaling for years so this approach is probably more conservative. > Signed-off-by: Hongjie Fang Acked-by: Michal Hocko > --- > Encountered the problem when I changed a task's oom_adj on > an Android smart phone. As follows, > 1. # cat /proc/1450/oom_adj > 15 > 2. # echo 10 > /proc/1450/oom_adj > 3. # cat /proc/1450/oom_adj > 9 > > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index b25eee4..2312e43 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -1019,15 +1019,19 @@ static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count, > int oom_adj = OOM_ADJUST_MIN; > size_t len; > unsigned long flags; > + int adjust; > > if (!task) > return -ESRCH; > if (lock_task_sighand(task, &flags)) { > - if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX) > + if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX) { > oom_adj = OOM_ADJUST_MAX; > - else > - oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) / > + } else { > + adjust = task->signal->oom_score_adj > 0 ? > + (OOM_SCORE_ADJ_MAX-1) : -(OOM_SCORE_ADJ_MAX-1); > + oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE + adjust) / > OOM_SCORE_ADJ_MAX; > + } > unlock_task_sighand(task, &flags); > } > put_task_struct(task); > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- Michal Hocko SUSE Labs