From: Mandeep Singh Baines <msb@google.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Rik van Riel <riel@redhat.com>, Ying Han <yinghan@google.com>,
linux-kernel@vger.kernel.org, gspencer@chromium.org,
piman@chromium.org, wad@chromium.org, olofj@chromium.org,
Bodo Eggert <7eggert@web.de>
Subject: [PATCH] oom: allow a non-CAP_SYS_RESOURCE proces to oom_score_adj down
Date: Fri, 12 Nov 2010 16:46:57 -0800 [thread overview]
Message-ID: <20101113004657.GN7363@google.com> (raw)
In-Reply-To: <20101111235620.GK7363@google.com>
We'd like to be able to oom_score_adj a process up/down as its
enters/leaves the foreground. Currently, it is not possible to oom_adj
down without CAP_SYS_RESOURCE. This patch allows a task to decrease
its oom_score_adj back to the value that a CAP_SYS_RESOURCE thread set
it or its inherited value at fork. Assuming the thread that has forked
it has oom_score_adj of 0, each tab could decrease it back from 0 upon
activation unless a CAP_SYS_RESOURCE thread elevated it to something
higher.
Alternative considered:
* a setuid binary
* a daemon with CAP_SYS_RESOURCE
Since you don't wan't all processes to be able to reduce their
oom_adj, a setuid or daemon implementation would be complex. The
alternatives also have much higher overhead.
This patch updated based on feedback from
David Rientjes <rientjes@google.com>.
Change-Id: If8f52363fd6c156e1730f43148aee987260e9c72
Signed-off-by: Mandeep Singh Baines <msb@chromium.org>
---
fs/proc/base.c | 4 +++-
include/linux/sched.h | 2 ++
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index f3d02ca..e617413 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1164,7 +1164,7 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
goto err_task_lock;
}
- if (oom_score_adj < task->signal->oom_score_adj &&
+ if (oom_score_adj < task->signal->oom_score_adj_min &&
!capable(CAP_SYS_RESOURCE)) {
err = -EACCES;
goto err_sighand;
@@ -1177,6 +1177,8 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
atomic_dec(&task->mm->oom_disable_count);
}
task->signal->oom_score_adj = oom_score_adj;
+ if (capable(CAP_SYS_RESOURCE))
+ task->signal->oom_score_adj_min = oom_score_adj;
/*
* Scale /proc/pid/oom_adj appropriately ensuring that OOM_DISABLE is
* always attainable.
diff --git a/include/linux/sched.h b/include/linux/sched.h
index f53cdf2..2a71ee0 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -626,6 +626,8 @@ struct signal_struct {
int oom_adj; /* OOM kill score adjustment (bit shift) */
int oom_score_adj; /* OOM kill score adjustment */
+ int oom_score_adj_min; /* OOM kill score adjustment minimum value.
+ * Only settable by CAP_SYS_RESOURCE. */
struct mutex cred_guard_mutex; /* guard against foreign influences on
* credential calculations
--
1.7.3.1
next prev parent reply other threads:[~2010-11-13 0:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-11 4:35 [PATCH] oom: create a resource limit for oom_adj Mandeep Singh Baines
2010-11-11 7:35 ` David Rientjes
2010-11-11 18:30 ` Mandeep Singh Baines
2010-11-11 20:57 ` David Rientjes
2010-11-11 22:25 ` Mandeep Singh Baines
2010-11-11 23:19 ` David Rientjes
2010-11-11 23:56 ` Mandeep Singh Baines
2010-11-13 0:46 ` Mandeep Singh Baines [this message]
2010-11-14 1:37 ` [PATCH] oom: allow a non-CAP_SYS_RESOURCE proces to oom_score_adj down David Rientjes
2010-11-15 22:01 ` [PATCH v2] " Mandeep Singh Baines
2010-11-15 22:06 ` David Rientjes
2010-11-16 0:03 ` [PATCH v3] " Mandeep Singh Baines
2010-11-14 5:07 ` [PATCH] oom: create a resource limit for oom_adj KOSAKI Motohiro
[not found] <fNx73-1cI-1@gated-at.bofh.it>
[not found] ` <fNzVf-5UY-3@gated-at.bofh.it>
[not found] ` <fNKdY-6FU-11@gated-at.bofh.it>
[not found] ` <fNMps-1S1-21@gated-at.bofh.it>
[not found] ` <fNNOx-4qf-1@gated-at.bofh.it>
[not found] ` <fNOAW-5Oi-35@gated-at.bofh.it>
[not found] ` <fNPdF-6Hu-33@gated-at.bofh.it>
[not found] ` <fOctz-4o0-9@gated-at.bofh.it>
2010-11-14 0:05 ` [PATCH] oom: allow a non-CAP_SYS_RESOURCE proces to oom_score_adj down Bodo Eggert
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=20101113004657.GN7363@google.com \
--to=msb@google.com \
--cc=7eggert@web.de \
--cc=akpm@linux-foundation.org \
--cc=gspencer@chromium.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=olofj@chromium.org \
--cc=piman@chromium.org \
--cc=riel@redhat.com \
--cc=rientjes@google.com \
--cc=wad@chromium.org \
--cc=yinghan@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