Skip to content

Commit 6ba749e

Browse files
shakeelbtorvalds
authored andcommitted
mm, oom: remove redundant task_in_mem_cgroup() check
oom_unkillable_task() can be called from three different contexts i.e. global OOM, memcg OOM and oom_score procfs interface. At the moment oom_unkillable_task() does a task_in_mem_cgroup() check on the given process. Since there is no reason to perform task_in_mem_cgroup() check for global OOM and oom_score procfs interface, those contexts provide NULL memcg and skips the task_in_mem_cgroup() check. However for memcg OOM context, the oom_unkillable_task() is always called from mem_cgroup_scan_tasks() and thus task_in_mem_cgroup() check becomes redundant and effectively dead code. So, just remove the task_in_mem_cgroup() check altogether. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Shakeel Butt <[email protected]> Signed-off-by: Tetsuo Handa <[email protected]> Acked-by: Roman Gushchin <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: David Rientjes <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: KOSAKI Motohiro <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Paul Jackson <[email protected]> Cc: Vladimir Davydov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5eee7e1 commit 6ba749e

File tree

5 files changed

+9
-47
lines changed

5 files changed

+9
-47
lines changed

fs/proc/base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static int proc_oom_score(struct seq_file *m, struct pid_namespace *ns,
532532
unsigned long totalpages = totalram_pages() + total_swap_pages;
533533
unsigned long points = 0;
534534

535-
points = oom_badness(task, NULL, NULL, totalpages) *
535+
points = oom_badness(task, NULL, totalpages) *
536536
1000 / totalpages;
537537
seq_printf(m, "%lu\n", points);
538538

include/linux/memcontrol.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ static inline struct lruvec *mem_cgroup_lruvec(struct pglist_data *pgdat,
394394

395395
struct lruvec *mem_cgroup_page_lruvec(struct page *, struct pglist_data *);
396396

397-
bool task_in_mem_cgroup(struct task_struct *task, struct mem_cgroup *memcg);
398397
struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
399398

400399
struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm);
@@ -875,12 +874,6 @@ static inline bool mm_match_cgroup(struct mm_struct *mm,
875874
return true;
876875
}
877876

878-
static inline bool task_in_mem_cgroup(struct task_struct *task,
879-
const struct mem_cgroup *memcg)
880-
{
881-
return true;
882-
}
883-
884877
static inline struct mem_cgroup *get_mem_cgroup_from_mm(struct mm_struct *mm)
885878
{
886879
return NULL;

include/linux/oom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline vm_fault_t check_stable_address_space(struct mm_struct *mm)
108108
bool __oom_reap_task_mm(struct mm_struct *mm);
109109

110110
extern unsigned long oom_badness(struct task_struct *p,
111-
struct mem_cgroup *memcg, const nodemask_t *nodemask,
111+
const nodemask_t *nodemask,
112112
unsigned long totalpages);
113113

114114
extern bool out_of_memory(struct oom_control *oc);

mm/memcontrol.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,32 +1259,6 @@ void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru,
12591259
*lru_size += nr_pages;
12601260
}
12611261

1262-
bool task_in_mem_cgroup(struct task_struct *task, struct mem_cgroup *memcg)
1263-
{
1264-
struct mem_cgroup *task_memcg;
1265-
struct task_struct *p;
1266-
bool ret;
1267-
1268-
p = find_lock_task_mm(task);
1269-
if (p) {
1270-
task_memcg = get_mem_cgroup_from_mm(p->mm);
1271-
task_unlock(p);
1272-
} else {
1273-
/*
1274-
* All threads may have already detached their mm's, but the oom
1275-
* killer still needs to detect if they have already been oom
1276-
* killed to prevent needlessly killing additional tasks.
1277-
*/
1278-
rcu_read_lock();
1279-
task_memcg = mem_cgroup_from_task(task);
1280-
css_get(&task_memcg->css);
1281-
rcu_read_unlock();
1282-
}
1283-
ret = mem_cgroup_is_descendant(task_memcg, memcg);
1284-
css_put(&task_memcg->css);
1285-
return ret;
1286-
}
1287-
12881262
/**
12891263
* mem_cgroup_margin - calculate chargeable space of a memory cgroup
12901264
* @memcg: the memory cgroup

mm/oom_kill.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,13 @@ static inline bool is_memcg_oom(struct oom_control *oc)
153153

154154
/* return true if the task is not adequate as candidate victim task. */
155155
static bool oom_unkillable_task(struct task_struct *p,
156-
struct mem_cgroup *memcg, const nodemask_t *nodemask)
156+
const nodemask_t *nodemask)
157157
{
158158
if (is_global_init(p))
159159
return true;
160160
if (p->flags & PF_KTHREAD)
161161
return true;
162162

163-
/* When mem_cgroup_out_of_memory() and p is not member of the group */
164-
if (memcg && !task_in_mem_cgroup(p, memcg))
165-
return true;
166-
167163
/* p may not have freeable memory in nodemask */
168164
if (!has_intersects_mems_allowed(p, nodemask))
169165
return true;
@@ -194,20 +190,19 @@ static bool is_dump_unreclaim_slabs(void)
194190
* oom_badness - heuristic function to determine which candidate task to kill
195191
* @p: task struct of which task we should calculate
196192
* @totalpages: total present RAM allowed for page allocation
197-
* @memcg: task's memory controller, if constrained
198193
* @nodemask: nodemask passed to page allocator for mempolicy ooms
199194
*
200195
* The heuristic for determining which task to kill is made to be as simple and
201196
* predictable as possible. The goal is to return the highest value for the
202197
* task consuming the most memory to avoid subsequent oom failures.
203198
*/
204-
unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg,
199+
unsigned long oom_badness(struct task_struct *p,
205200
const nodemask_t *nodemask, unsigned long totalpages)
206201
{
207202
long points;
208203
long adj;
209204

210-
if (oom_unkillable_task(p, memcg, nodemask))
205+
if (oom_unkillable_task(p, nodemask))
211206
return 0;
212207

213208
p = find_lock_task_mm(p);
@@ -318,7 +313,7 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
318313
struct oom_control *oc = arg;
319314
unsigned long points;
320315

321-
if (oom_unkillable_task(task, NULL, oc->nodemask))
316+
if (oom_unkillable_task(task, oc->nodemask))
322317
goto next;
323318

324319
/*
@@ -342,7 +337,7 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
342337
goto select;
343338
}
344339

345-
points = oom_badness(task, NULL, oc->nodemask, oc->totalpages);
340+
points = oom_badness(task, oc->nodemask, oc->totalpages);
346341
if (!points || points < oc->chosen_points)
347342
goto next;
348343

@@ -387,7 +382,7 @@ static int dump_task(struct task_struct *p, void *arg)
387382
struct oom_control *oc = arg;
388383
struct task_struct *task;
389384

390-
if (oom_unkillable_task(p, NULL, oc->nodemask))
385+
if (oom_unkillable_task(p, oc->nodemask))
391386
return 0;
392387

393388
task = find_lock_task_mm(p);
@@ -1084,7 +1079,7 @@ bool out_of_memory(struct oom_control *oc)
10841079
check_panic_on_oom(oc);
10851080

10861081
if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task &&
1087-
current->mm && !oom_unkillable_task(current, NULL, oc->nodemask) &&
1082+
current->mm && !oom_unkillable_task(current, oc->nodemask) &&
10881083
current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {
10891084
get_task_struct(current);
10901085
oc->chosen = current;

0 commit comments

Comments
 (0)