mm, oom: change type of oom_score_adj to short
authorDavid Rientjes <rientjes@google.com>
Wed, 12 Dec 2012 00:02:54 +0000 (16:02 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 12 Dec 2012 01:22:27 +0000 (17:22 -0800)
The maximum oom_score_adj is 1000 and the minimum oom_score_adj is -1000,
so this range can be represented by the signed short type with no
functional change.  The extra space this frees up in struct signal_struct
will be used for per-thread oom kill flags in the next patch.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Cc: Anton Vorontsov <anton.vorontsov@linaro.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/staging/android/lowmemorykiller.c
fs/proc/base.c
include/linux/oom.h
include/linux/sched.h
include/trace/events/oom.h
include/trace/events/task.h
mm/ksm.c
mm/oom_kill.c
mm/swapfile.c

index b91e4bc332a77c2e6ea1219e99f92c5ee924c418..3b91b0fd4de3c7194c68e18f5a10b514c1544e75 100644 (file)
@@ -40,7 +40,7 @@
 #include <linux/notifier.h>
 
 static uint32_t lowmem_debug_level = 2;
-static int lowmem_adj[6] = {
+static short lowmem_adj[6] = {
        0,
        1,
        6,
@@ -70,9 +70,9 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
        int rem = 0;
        int tasksize;
        int i;
-       int min_score_adj = OOM_SCORE_ADJ_MAX + 1;
+       short min_score_adj = OOM_SCORE_ADJ_MAX + 1;
        int selected_tasksize = 0;
-       int selected_oom_score_adj;
+       short selected_oom_score_adj;
        int array_size = ARRAY_SIZE(lowmem_adj);
        int other_free = global_page_state(NR_FREE_PAGES);
        int other_file = global_page_state(NR_FILE_PAGES) -
@@ -90,7 +90,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
                }
        }
        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 %hd\n",
                                sc->nr_to_scan, sc->gfp_mask, other_free,
                                other_file, min_score_adj);
        rem = global_page_state(NR_ACTIVE_ANON) +
@@ -107,7 +107,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
        rcu_read_lock();
        for_each_process(tsk) {
                struct task_struct *p;
-               int oom_score_adj;
+               short oom_score_adj;
 
                if (tsk->flags & PF_KTHREAD)
                        continue;
@@ -141,11 +141,11 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
                selected = p;
                selected_tasksize = tasksize;
                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 %hd, size %d, to kill\n",
                             p->pid, p->comm, oom_score_adj, tasksize);
        }
        if (selected) {
-               lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
+               lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n",
                             selected->pid, selected->comm,
                             selected_oom_score_adj, selected_tasksize);
                lowmem_deathpending_timeout = jiffies + HZ;
@@ -176,7 +176,7 @@ static void __exit lowmem_exit(void)
 }
 
 module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR);
-module_param_array_named(adj, lowmem_adj, int, &lowmem_adj_size,
+module_param_array_named(adj, lowmem_adj, short, &lowmem_adj_size,
                         S_IRUGO | S_IWUSR);
 module_param_array_named(minfree, lowmem_minfree, uint, &lowmem_minfree_size,
                         S_IRUGO | S_IWUSR);
index 9e28356a959a2f4f0aecddd6170ebacfa799a5b3..aa63d25157b8d396a9a7d0f1728fe673fa577e31 100644 (file)
@@ -985,7 +985,7 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
 {
        struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
        char buffer[PROC_NUMBUF];
-       int oom_score_adj = OOM_SCORE_ADJ_MIN;
+       short oom_score_adj = OOM_SCORE_ADJ_MIN;
        unsigned long flags;
        size_t len;
 
@@ -996,7 +996,7 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
                unlock_task_sighand(task, &flags);
        }
        put_task_struct(task);
-       len = snprintf(buffer, sizeof(buffer), "%d\n", oom_score_adj);
+       len = snprintf(buffer, sizeof(buffer), "%hd\n", oom_score_adj);
        return simple_read_from_buffer(buf, count, ppos, buffer, len);
 }
 
@@ -1043,15 +1043,15 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
                goto err_task_lock;
        }
 
-       if (oom_score_adj < task->signal->oom_score_adj_min &&
+       if ((short)oom_score_adj < task->signal->oom_score_adj_min &&
                        !capable(CAP_SYS_RESOURCE)) {
                err = -EACCES;
                goto err_sighand;
        }
 
-       task->signal->oom_score_adj = oom_score_adj;
+       task->signal->oom_score_adj = (short)oom_score_adj;
        if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
-               task->signal->oom_score_adj_min = oom_score_adj;
+               task->signal->oom_score_adj_min = (short)oom_score_adj;
        trace_oom_score_adj_update(task);
 
 err_sighand:
index 4a4188da45700221af4e7b97200a229a23b29416..922dab164eb03baacb693955866c7dcd847c3eb7 100644 (file)
@@ -29,8 +29,8 @@ enum oom_scan_t {
        OOM_SCAN_SELECT,        /* always select this thread first */
 };
 
-extern void compare_swap_oom_score_adj(int old_val, int new_val);
-extern int test_set_oom_score_adj(int new_val);
+extern void compare_swap_oom_score_adj(short old_val, short new_val);
+extern short test_set_oom_score_adj(short new_val);
 
 extern unsigned long oom_badness(struct task_struct *p,
                struct mem_cgroup *memcg, const nodemask_t *nodemask,
index 0dd42a02df2e851e0847df640dd559f3689c36ed..ed30456152dace302786a6bc4cf084fd49181a87 100644 (file)
@@ -631,9 +631,9 @@ struct signal_struct {
        struct rw_semaphore group_rwsem;
 #endif
 
-       int oom_score_adj;      /* OOM kill score adjustment */
-       int oom_score_adj_min;  /* OOM kill score adjustment minimum value.
-                                * Only settable by CAP_SYS_RESOURCE. */
+       short oom_score_adj;            /* OOM kill score adjustment */
+       short oom_score_adj_min;        /* OOM kill score adjustment min value.
+                                        * Only settable by CAP_SYS_RESOURCE. */
 
        struct mutex cred_guard_mutex;  /* guard against foreign influences on
                                         * credential calculations
index dd4ba3b92002aabff6bbecc226c1b37848daebd0..1e974983757eb2e9974d0ac619ff8b8b27a491d5 100644 (file)
@@ -14,7 +14,7 @@ TRACE_EVENT(oom_score_adj_update,
        TP_STRUCT__entry(
                __field(        pid_t,  pid)
                __array(        char,   comm,   TASK_COMM_LEN )
-               __field(         int,   oom_score_adj)
+               __field(        short,  oom_score_adj)
        ),
 
        TP_fast_assign(
@@ -23,7 +23,7 @@ TRACE_EVENT(oom_score_adj_update,
                __entry->oom_score_adj = task->signal->oom_score_adj;
        ),
 
-       TP_printk("pid=%d comm=%s oom_score_adj=%d",
+       TP_printk("pid=%d comm=%s oom_score_adj=%hd",
                __entry->pid, __entry->comm, __entry->oom_score_adj)
 );
 
index b53add02e929efc4133fee35684e8ec06bf3c496..102a646e1996694bd16b536ef9c292093115e39c 100644 (file)
@@ -15,7 +15,7 @@ TRACE_EVENT(task_newtask,
                __field(        pid_t,  pid)
                __array(        char,   comm, TASK_COMM_LEN)
                __field( unsigned long, clone_flags)
-               __field(        int,    oom_score_adj)
+               __field(        short,  oom_score_adj)
        ),
 
        TP_fast_assign(
@@ -25,7 +25,7 @@ TRACE_EVENT(task_newtask,
                __entry->oom_score_adj = task->signal->oom_score_adj;
        ),
 
-       TP_printk("pid=%d comm=%s clone_flags=%lx oom_score_adj=%d",
+       TP_printk("pid=%d comm=%s clone_flags=%lx oom_score_adj=%hd",
                __entry->pid, __entry->comm,
                __entry->clone_flags, __entry->oom_score_adj)
 );
@@ -40,7 +40,7 @@ TRACE_EVENT(task_rename,
                __field(        pid_t,  pid)
                __array(        char, oldcomm,  TASK_COMM_LEN)
                __array(        char, newcomm,  TASK_COMM_LEN)
-               __field(        int, oom_score_adj)
+               __field(        short,  oom_score_adj)
        ),
 
        TP_fast_assign(
@@ -50,7 +50,7 @@ TRACE_EVENT(task_rename,
                __entry->oom_score_adj = task->signal->oom_score_adj;
        ),
 
-       TP_printk("pid=%d oldcomm=%s newcomm=%s oom_score_adj=%d",
+       TP_printk("pid=%d oldcomm=%s newcomm=%s oom_score_adj=%hd",
                __entry->pid, __entry->oldcomm,
                __entry->newcomm, __entry->oom_score_adj)
 );
index 31ae5ea1eac05594411e8ba2f1c748ce52471e99..b4d5a9deb17f5e8a82d6cc726595995700d3884f 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1919,7 +1919,7 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
        if (ksm_run != flags) {
                ksm_run = flags;
                if (flags & KSM_RUN_UNMERGE) {
-                       int oom_score_adj;
+                       short oom_score_adj;
 
                        oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
                        err = unmerge_and_remove_all_rmap_items();
index 7e9e9113bd058e8196f817ea521621857ad8bc5c..37ab4c5ab6e8fc2210bc4442693b05bafa884cb1 100644 (file)
@@ -53,7 +53,7 @@ static DEFINE_SPINLOCK(zone_scan_lock);
  * @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)
+void compare_swap_oom_score_adj(short old_val, short new_val)
 {
        struct sighand_struct *sighand = current->sighand;
 
@@ -72,7 +72,7 @@ void compare_swap_oom_score_adj(int old_val, int new_val)
  * synchronization and returns the old value.  Usually used to temporarily
  * set a value, save the old value in the caller, and then reinstate it later.
  */
-int test_set_oom_score_adj(int new_val)
+short test_set_oom_score_adj(short new_val)
 {
        struct sighand_struct *sighand = current->sighand;
        int old_val;
@@ -193,7 +193,7 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg,
        if (!p)
                return 0;
 
-       adj = p->signal->oom_score_adj;
+       adj = (long)p->signal->oom_score_adj;
        if (adj == OOM_SCORE_ADJ_MIN) {
                task_unlock(p);
                return 0;
@@ -399,7 +399,7 @@ static void dump_tasks(const struct mem_cgroup *memcg, const nodemask_t *nodemas
                        continue;
                }
 
-               pr_info("[%5d] %5d %5d %8lu %8lu %7lu %8lu         %5d %s\n",
+               pr_info("[%5d] %5d %5d %8lu %8lu %7lu %8lu         %5hd %s\n",
                        task->pid, from_kuid(&init_user_ns, task_uid(task)),
                        task->tgid, task->mm->total_vm, get_mm_rss(task->mm),
                        task->mm->nr_ptes,
@@ -415,7 +415,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
 {
        task_lock(current);
        pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, "
-               "oom_score_adj=%d\n",
+               "oom_score_adj=%hd\n",
                current->comm, gfp_mask, order,
                current->signal->oom_score_adj);
        cpuset_print_task_mems_allowed(current);
index 0fbb45283c6641cf1bdb8b5a39b4c9eb414f61f7..bb6f6a04e92de9412be0b0869a78bec8fc414acb 100644 (file)
@@ -1498,7 +1498,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
        struct address_space *mapping;
        struct inode *inode;
        struct filename *pathname;
-       int oom_score_adj;
+       short oom_score_adj;
        int i, type, prev;
        int err;