mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 4.3-rc6] proc: fix oom_adj value read from /proc/<pid>/oom_adj
@ 2015-10-20 12:34 Hongjie Fang (方洪杰)
  2015-10-20 17:27 ` Eric W. Biederman
  2015-10-21 20:59 ` David Rientjes
  0 siblings, 2 replies; 4+ messages in thread
From: Hongjie Fang (方洪杰) @ 2015-10-20 12:34 UTC (permalink / raw)
  To: ebiederm, gregkh; +Cc: linux-kernel

The oom_adj's value reading through /proc/<pid>/oom_adj is different 
with the value written into /proc/<pid>/oom_adj. 
Fix this by adding a adjustment factor.

Signed-off-by: Hongjie Fang <hongjie.fang@spreadtrum.com>
---
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b25eee4..1ea0589 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1043,6 +1043,7 @@ static ssize_t oom_adj_write(struct file *file, const char __user *buf,
 	int oom_adj;
 	unsigned long flags;
 	int err;
+	int adjust;
 
 	memset(buffer, 0, sizeof(buffer));
 	if (count > sizeof(buffer) - 1)
@@ -1084,8 +1085,10 @@ static ssize_t oom_adj_write(struct file *file, const char __user *buf,
 	 */
 	if (oom_adj == OOM_ADJUST_MAX)
 		oom_adj = OOM_SCORE_ADJ_MAX;
-	else
-		oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
+	else{
+		adjust = oom_adj > 0 ? (-OOM_DISABLE-1) : -(-OOM_DISABLE-1);
+		oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX + adjust) / -OOM_DISABLE;
+	}
 
 	if (oom_adj < task->signal->oom_score_adj &&
 	    !capable(CAP_SYS_RESOURCE)) {


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-21 20:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-20 12:34 [PATCH 4.3-rc6] proc: fix oom_adj value read from /proc/<pid>/oom_adj Hongjie Fang (方洪杰)
2015-10-20 17:27 ` Eric W. Biederman
2015-10-21  9:37   ` Michal Hocko
2015-10-21 20:59 ` David Rientjes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®