Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 272118
b: refs/heads/master
c: 43362a4
h: refs/heads/master
v: v3
  • Loading branch information
David Rientjes authored and Linus Torvalds committed Nov 1, 2011
1 parent 7cc4046 commit f99efe3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c9f01245b6a7d77d17deaa71af10f6aca14fa24e
refs/heads/master: 43362a4977e37db46f86f7e6ab935f0006956632
1 change: 1 addition & 0 deletions trunk/include/linux/oom.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum oom_constraint {
CONSTRAINT_MEMCG,
};

extern void compare_swap_oom_score_adj(int old_val, int new_val);
extern int test_set_oom_score_adj(int new_val);

extern unsigned int oom_badness(struct task_struct *p, struct mem_cgroup *mem,
Expand Down
3 changes: 2 additions & 1 deletion trunk/mm/ksm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,8 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,

oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
err = unmerge_and_remove_all_rmap_items();
test_set_oom_score_adj(oom_score_adj);
compare_swap_oom_score_adj(OOM_SCORE_ADJ_MAX,
oom_score_adj);
if (err) {
ksm_run = KSM_RUN_STOP;
count = err;
Expand Down
19 changes: 19 additions & 0 deletions trunk/mm/oom_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ int sysctl_oom_kill_allocating_task;
int sysctl_oom_dump_tasks = 1;
static DEFINE_SPINLOCK(zone_scan_lock);

/*
* compare_swap_oom_score_adj() - compare and swap current's oom_score_adj
* @old_val: old oom_score_adj for compare
* @new_val: new oom_score_adj for swap
*
* Sets the oom_score_adj value for current to @new_val iff its present value is
* @old_val. Usually used to reinstate a previous value to prevent racing with
* userspacing tuning the value in the interim.
*/
void compare_swap_oom_score_adj(int old_val, int new_val)
{
struct sighand_struct *sighand = current->sighand;

spin_lock_irq(&sighand->siglock);
if (current->signal->oom_score_adj == old_val)
current->signal->oom_score_adj = new_val;
spin_unlock_irq(&sighand->siglock);
}

/**
* test_set_oom_score_adj() - set current's oom_score_adj and return old value
* @new_val: new oom_score_adj value
Expand Down
2 changes: 1 addition & 1 deletion trunk/mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)

oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
err = try_to_unuse(type);
test_set_oom_score_adj(oom_score_adj);
compare_swap_oom_score_adj(OOM_SCORE_ADJ_MAX, oom_score_adj);

if (err) {
/*
Expand Down

0 comments on commit f99efe3

Please sign in to comment.