mirror of https://gitee.com/openkylin/linux.git
staging: android, lowmemorykiller: convert to use oom_score_adj
/proc/pid/oom_adj is deprecated and will be removed in August 2012 according to Documentation/feature-removal-schedule.txt. Convert its usage in the lowmemorykiller to use the new interface, oom_score_adj, instead. Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ebb3bf5018
commit
940f77b07f
|
@ -1,16 +1,17 @@
|
||||||
/* drivers/misc/lowmemorykiller.c
|
/* drivers/misc/lowmemorykiller.c
|
||||||
*
|
*
|
||||||
* The lowmemorykiller driver lets user-space specify a set of memory thresholds
|
* The lowmemorykiller driver lets user-space specify a set of memory thresholds
|
||||||
* where processes with a range of oom_adj values will get killed. Specify the
|
* where processes with a range of oom_score_adj values will get killed. Specify
|
||||||
* minimum oom_adj values in /sys/module/lowmemorykiller/parameters/adj and the
|
* the minimum oom_score_adj values in
|
||||||
* number of free pages in /sys/module/lowmemorykiller/parameters/minfree. Both
|
* /sys/module/lowmemorykiller/parameters/adj and the number of free pages in
|
||||||
* files take a comma separated list of numbers in ascending order.
|
* /sys/module/lowmemorykiller/parameters/minfree. Both files take a comma
|
||||||
|
* separated list of numbers in ascending order.
|
||||||
*
|
*
|
||||||
* For example, write "0,8" to /sys/module/lowmemorykiller/parameters/adj and
|
* For example, write "0,8" to /sys/module/lowmemorykiller/parameters/adj and
|
||||||
* "1024,4096" to /sys/module/lowmemorykiller/parameters/minfree to kill
|
* "1024,4096" to /sys/module/lowmemorykiller/parameters/minfree to kill
|
||||||
* processes with a oom_adj value of 8 or higher when the free memory drops
|
* processes with a oom_score_adj value of 8 or higher when the free memory
|
||||||
* below 4096 pages and kill processes with a oom_adj value of 0 or higher
|
* drops below 4096 pages and kill processes with a oom_score_adj value of 0 or
|
||||||
* when the free memory drops below 1024 pages.
|
* higher when the free memory drops below 1024 pages.
|
||||||
*
|
*
|
||||||
* The driver considers memory used for caches to be free, but if a large
|
* The driver considers memory used for caches to be free, but if a large
|
||||||
* percentage of the cached memory is locked this can be very inaccurate
|
* percentage of the cached memory is locked this can be very inaccurate
|
||||||
|
@ -88,9 +89,9 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
|
||||||
int rem = 0;
|
int rem = 0;
|
||||||
int tasksize;
|
int tasksize;
|
||||||
int i;
|
int i;
|
||||||
int min_adj = OOM_ADJUST_MAX + 1;
|
int min_score_adj = OOM_SCORE_ADJ_MAX + 1;
|
||||||
int selected_tasksize = 0;
|
int selected_tasksize = 0;
|
||||||
int selected_oom_adj;
|
int selected_oom_score_adj;
|
||||||
int array_size = ARRAY_SIZE(lowmem_adj);
|
int array_size = ARRAY_SIZE(lowmem_adj);
|
||||||
int other_free = global_page_state(NR_FREE_PAGES);
|
int other_free = global_page_state(NR_FREE_PAGES);
|
||||||
int other_file = global_page_state(NR_FILE_PAGES) -
|
int other_file = global_page_state(NR_FILE_PAGES) -
|
||||||
|
@ -116,29 +117,29 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
|
||||||
for (i = 0; i < array_size; i++) {
|
for (i = 0; i < array_size; i++) {
|
||||||
if (other_free < lowmem_minfree[i] &&
|
if (other_free < lowmem_minfree[i] &&
|
||||||
other_file < lowmem_minfree[i]) {
|
other_file < lowmem_minfree[i]) {
|
||||||
min_adj = lowmem_adj[i];
|
min_score_adj = lowmem_adj[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sc->nr_to_scan > 0)
|
if (sc->nr_to_scan > 0)
|
||||||
lowmem_print(3, "lowmem_shrink %lu, %x, ofree %d %d, ma %d\n",
|
lowmem_print(3, "lowmem_shrink %lu, %x, ofree %d %d, ma %d\n",
|
||||||
sc->nr_to_scan, sc->gfp_mask, other_free,
|
sc->nr_to_scan, sc->gfp_mask, other_free,
|
||||||
other_file, min_adj);
|
other_file, min_score_adj);
|
||||||
rem = global_page_state(NR_ACTIVE_ANON) +
|
rem = global_page_state(NR_ACTIVE_ANON) +
|
||||||
global_page_state(NR_ACTIVE_FILE) +
|
global_page_state(NR_ACTIVE_FILE) +
|
||||||
global_page_state(NR_INACTIVE_ANON) +
|
global_page_state(NR_INACTIVE_ANON) +
|
||||||
global_page_state(NR_INACTIVE_FILE);
|
global_page_state(NR_INACTIVE_FILE);
|
||||||
if (sc->nr_to_scan <= 0 || min_adj == OOM_ADJUST_MAX + 1) {
|
if (sc->nr_to_scan <= 0 || min_score_adj == OOM_SCORE_ADJ_MAX + 1) {
|
||||||
lowmem_print(5, "lowmem_shrink %lu, %x, return %d\n",
|
lowmem_print(5, "lowmem_shrink %lu, %x, return %d\n",
|
||||||
sc->nr_to_scan, sc->gfp_mask, rem);
|
sc->nr_to_scan, sc->gfp_mask, rem);
|
||||||
return rem;
|
return rem;
|
||||||
}
|
}
|
||||||
selected_oom_adj = min_adj;
|
selected_oom_score_adj = min_score_adj;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
for_each_process(tsk) {
|
for_each_process(tsk) {
|
||||||
struct task_struct *p;
|
struct task_struct *p;
|
||||||
int oom_adj;
|
int oom_score_adj;
|
||||||
|
|
||||||
if (tsk->flags & PF_KTHREAD)
|
if (tsk->flags & PF_KTHREAD)
|
||||||
continue;
|
continue;
|
||||||
|
@ -147,8 +148,8 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
|
||||||
if (!p)
|
if (!p)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
oom_adj = p->signal->oom_adj;
|
oom_score_adj = p->signal->oom_score_adj;
|
||||||
if (oom_adj < min_adj) {
|
if (oom_score_adj < min_score_adj) {
|
||||||
task_unlock(p);
|
task_unlock(p);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -157,22 +158,22 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
|
||||||
if (tasksize <= 0)
|
if (tasksize <= 0)
|
||||||
continue;
|
continue;
|
||||||
if (selected) {
|
if (selected) {
|
||||||
if (oom_adj < selected_oom_adj)
|
if (oom_score_adj < selected_oom_score_adj)
|
||||||
continue;
|
continue;
|
||||||
if (oom_adj == selected_oom_adj &&
|
if (oom_score_adj == selected_oom_score_adj &&
|
||||||
tasksize <= selected_tasksize)
|
tasksize <= selected_tasksize)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
selected = p;
|
selected = p;
|
||||||
selected_tasksize = tasksize;
|
selected_tasksize = tasksize;
|
||||||
selected_oom_adj = oom_adj;
|
selected_oom_score_adj = oom_score_adj;
|
||||||
lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n",
|
lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n",
|
||||||
p->pid, p->comm, oom_adj, tasksize);
|
p->pid, p->comm, oom_score_adj, tasksize);
|
||||||
}
|
}
|
||||||
if (selected) {
|
if (selected) {
|
||||||
lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
|
lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
|
||||||
selected->pid, selected->comm,
|
selected->pid, selected->comm,
|
||||||
selected_oom_adj, selected_tasksize);
|
selected_oom_score_adj, selected_tasksize);
|
||||||
/*
|
/*
|
||||||
* If CONFIG_PROFILING is off, then task_handoff_register()
|
* If CONFIG_PROFILING is off, then task_handoff_register()
|
||||||
* is a nop. In that case we don't want to stall the killer
|
* is a nop. In that case we don't want to stall the killer
|
||||||
|
|
Loading…
Reference in New Issue