From: "Hongjie Fang (方洪杰)" <Hongjie.Fang@spreadtrum.com>
To: David Rientjes <rientjes@google.com>,
Michal Hocko <mhocko@kernel.org>,
"Eric W. Biederman" <ebiederm@xmission.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCHv2 4.3-rc6] proc: fix convert from oom_score_adj to oom_adj
Date: Thu, 22 Oct 2015 06:49:01 +0000 [thread overview]
Message-ID: <1f80189385e540c2a5b2747a7a265d8c@SHMBX01.spreadtrum.com> (raw)
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.
Signed-off-by: Hongjie Fang <hongjie.fang@spreadtrum.com>
---
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);
next reply other threads:[~2015-10-22 6:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 6:49 Hongjie Fang (方洪杰) [this message]
2015-10-22 9:47 ` Michal Hocko
2015-10-26 21:42 ` David Rientjes
2015-10-27 12:37 ` Michal Hocko
[not found] ` <5eff586de266418090f792077fcff993@SHMBX01.spreadtrum.com>
2015-10-28 23:54 ` 答复: " David Rientjes
2015-10-29 3:47 ` Eric W. Biederman
2015-11-01 4:30 ` David Rientjes
2015-10-29 17:04 ` Michal Hocko
2015-10-30 12:59 ` Michal Hocko
2015-10-30 14:46 ` Michal Hocko
2015-11-01 4:38 ` David Rientjes
2015-11-02 13:08 ` Michal Hocko
2015-11-02 17:18 ` Dave Jones
2015-11-02 20:24 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1f80189385e540c2a5b2747a7a265d8c@SHMBX01.spreadtrum.com \
--to=hongjie.fang@spreadtrum.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@kernel.org \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®