Skip to content

Commit

Permalink
mm, oom: organize oom context into struct
Browse files Browse the repository at this point in the history
There are essential elements to an oom context that are passed around to
multiple functions.

Organize these elements into a new struct, struct oom_control, that
specifies the context for an oom condition.

This patch introduces no functional change.

Signed-off-by: David Rientjes <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rientjes authored and torvalds committed Sep 8, 2015
1 parent 2c0b80d commit 6e0fc46
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 80 deletions.
12 changes: 10 additions & 2 deletions drivers/tty/sysrq.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,17 @@ static struct sysrq_key_op sysrq_term_op = {

static void moom_callback(struct work_struct *ignored)
{
const gfp_t gfp_mask = GFP_KERNEL;
struct oom_control oc = {
.zonelist = node_zonelist(first_memory_node, gfp_mask),
.nodemask = NULL,
.gfp_mask = gfp_mask,
.order = 0,
.force_kill = true,
};

mutex_lock(&oom_lock);
if (!out_of_memory(node_zonelist(first_memory_node, GFP_KERNEL),
GFP_KERNEL, 0, NULL, true))
if (!out_of_memory(&oc))
pr_info("OOM request ignored because killer is disabled\n");
mutex_unlock(&oom_lock);
}
Expand Down
25 changes: 15 additions & 10 deletions include/linux/oom.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ struct notifier_block;
struct mem_cgroup;
struct task_struct;

struct oom_control {
struct zonelist *zonelist;
nodemask_t *nodemask;
gfp_t gfp_mask;
int order;
bool force_kill;
};

/*
* Types of limitations to the nodes from which allocations may occur
*/
Expand Down Expand Up @@ -57,21 +65,18 @@ extern unsigned long oom_badness(struct task_struct *p,

extern int oom_kills_count(void);
extern void note_oom_kill(void);
extern void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
extern void oom_kill_process(struct oom_control *oc, struct task_struct *p,
unsigned int points, unsigned long totalpages,
struct mem_cgroup *memcg, nodemask_t *nodemask,
const char *message);
struct mem_cgroup *memcg, const char *message);

extern void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask,
int order, const nodemask_t *nodemask,
extern void check_panic_on_oom(struct oom_control *oc,
enum oom_constraint constraint,
struct mem_cgroup *memcg);

extern enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
unsigned long totalpages, const nodemask_t *nodemask,
bool force_kill);
extern enum oom_scan_t oom_scan_process_thread(struct oom_control *oc,
struct task_struct *task, unsigned long totalpages);

extern bool out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
int order, nodemask_t *mask, bool force_kill);
extern bool out_of_memory(struct oom_control *oc);

extern void exit_oom_victim(void);

Expand Down
16 changes: 11 additions & 5 deletions mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,13 @@ static unsigned long mem_cgroup_get_limit(struct mem_cgroup *memcg)
static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
int order)
{
struct oom_control oc = {
.zonelist = NULL,
.nodemask = NULL,
.gfp_mask = gfp_mask,
.order = order,
.force_kill = false,
};
struct mem_cgroup *iter;
unsigned long chosen_points = 0;
unsigned long totalpages;
Expand All @@ -1563,16 +1570,15 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
goto unlock;
}

check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, order, NULL, memcg);
check_panic_on_oom(&oc, CONSTRAINT_MEMCG, memcg);
totalpages = mem_cgroup_get_limit(memcg) ? : 1;
for_each_mem_cgroup_tree(iter, memcg) {
struct css_task_iter it;
struct task_struct *task;

css_task_iter_start(&iter->css, &it);
while ((task = css_task_iter_next(&it))) {
switch (oom_scan_process_thread(task, totalpages, NULL,
false)) {
switch (oom_scan_process_thread(&oc, task, totalpages)) {
case OOM_SCAN_SELECT:
if (chosen)
put_task_struct(chosen);
Expand Down Expand Up @@ -1610,8 +1616,8 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,

if (chosen) {
points = chosen_points * 1000 / totalpages;
oom_kill_process(chosen, gfp_mask, order, points, totalpages,
memcg, NULL, "Memory cgroup out of memory");
oom_kill_process(&oc, chosen, points, totalpages, memcg,
"Memory cgroup out of memory");
}
unlock:
mutex_unlock(&oom_lock);
Expand Down
Loading

0 comments on commit 6e0fc46

Please sign in to comment.