Skip to content

Commit 940f77b

Browse files
rientjesgregkh
authored andcommitted
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>
1 parent ebb3bf5 commit 940f77b

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

drivers/staging/android/lowmemorykiller.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/* drivers/misc/lowmemorykiller.c
22
*
33
* The lowmemorykiller driver lets user-space specify a set of memory thresholds
4-
* where processes with a range of oom_adj values will get killed. Specify the
5-
* minimum oom_adj values in /sys/module/lowmemorykiller/parameters/adj and the
6-
* number of free pages in /sys/module/lowmemorykiller/parameters/minfree. Both
7-
* files take a comma separated list of numbers in ascending order.
4+
* where processes with a range of oom_score_adj values will get killed. Specify
5+
* the minimum oom_score_adj values in
6+
* /sys/module/lowmemorykiller/parameters/adj and the number of free pages in
7+
* /sys/module/lowmemorykiller/parameters/minfree. Both files take a comma
8+
* separated list of numbers in ascending order.
89
*
910
* For example, write "0,8" to /sys/module/lowmemorykiller/parameters/adj and
1011
* "1024,4096" to /sys/module/lowmemorykiller/parameters/minfree to kill
11-
* processes with a oom_adj value of 8 or higher when the free memory drops
12-
* below 4096 pages and kill processes with a oom_adj value of 0 or higher
13-
* when the free memory drops below 1024 pages.
12+
* processes with a oom_score_adj value of 8 or higher when the free memory
13+
* drops below 4096 pages and kill processes with a oom_score_adj value of 0 or
14+
* higher when the free memory drops below 1024 pages.
1415
*
1516
* The driver considers memory used for caches to be free, but if a large
1617
* 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)
8889
int rem = 0;
8990
int tasksize;
9091
int i;
91-
int min_adj = OOM_ADJUST_MAX + 1;
92+
int min_score_adj = OOM_SCORE_ADJ_MAX + 1;
9293
int selected_tasksize = 0;
93-
int selected_oom_adj;
94+
int selected_oom_score_adj;
9495
int array_size = ARRAY_SIZE(lowmem_adj);
9596
int other_free = global_page_state(NR_FREE_PAGES);
9697
int other_file = global_page_state(NR_FILE_PAGES) -
@@ -116,29 +117,29 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
116117
for (i = 0; i < array_size; i++) {
117118
if (other_free < lowmem_minfree[i] &&
118119
other_file < lowmem_minfree[i]) {
119-
min_adj = lowmem_adj[i];
120+
min_score_adj = lowmem_adj[i];
120121
break;
121122
}
122123
}
123124
if (sc->nr_to_scan > 0)
124125
lowmem_print(3, "lowmem_shrink %lu, %x, ofree %d %d, ma %d\n",
125126
sc->nr_to_scan, sc->gfp_mask, other_free,
126-
other_file, min_adj);
127+
other_file, min_score_adj);
127128
rem = global_page_state(NR_ACTIVE_ANON) +
128129
global_page_state(NR_ACTIVE_FILE) +
129130
global_page_state(NR_INACTIVE_ANON) +
130131
global_page_state(NR_INACTIVE_FILE);
131-
if (sc->nr_to_scan <= 0 || min_adj == OOM_ADJUST_MAX + 1) {
132+
if (sc->nr_to_scan <= 0 || min_score_adj == OOM_SCORE_ADJ_MAX + 1) {
132133
lowmem_print(5, "lowmem_shrink %lu, %x, return %d\n",
133134
sc->nr_to_scan, sc->gfp_mask, rem);
134135
return rem;
135136
}
136-
selected_oom_adj = min_adj;
137+
selected_oom_score_adj = min_score_adj;
137138

138139
rcu_read_lock();
139140
for_each_process(tsk) {
140141
struct task_struct *p;
141-
int oom_adj;
142+
int oom_score_adj;
142143

143144
if (tsk->flags & PF_KTHREAD)
144145
continue;
@@ -147,8 +148,8 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
147148
if (!p)
148149
continue;
149150

150-
oom_adj = p->signal->oom_adj;
151-
if (oom_adj < min_adj) {
151+
oom_score_adj = p->signal->oom_score_adj;
152+
if (oom_score_adj < min_score_adj) {
152153
task_unlock(p);
153154
continue;
154155
}
@@ -157,22 +158,22 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
157158
if (tasksize <= 0)
158159
continue;
159160
if (selected) {
160-
if (oom_adj < selected_oom_adj)
161+
if (oom_score_adj < selected_oom_score_adj)
161162
continue;
162-
if (oom_adj == selected_oom_adj &&
163+
if (oom_score_adj == selected_oom_score_adj &&
163164
tasksize <= selected_tasksize)
164165
continue;
165166
}
166167
selected = p;
167168
selected_tasksize = tasksize;
168-
selected_oom_adj = oom_adj;
169+
selected_oom_score_adj = oom_score_adj;
169170
lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n",
170-
p->pid, p->comm, oom_adj, tasksize);
171+
p->pid, p->comm, oom_score_adj, tasksize);
171172
}
172173
if (selected) {
173174
lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
174175
selected->pid, selected->comm,
175-
selected_oom_adj, selected_tasksize);
176+
selected_oom_score_adj, selected_tasksize);
176177
/*
177178
* If CONFIG_PROFILING is off, then task_handoff_register()
178179
* is a nop. In that case we don't want to stall the killer

0 commit comments

Comments
 (0)