Skip to content

Commit a9c58b9

Browse files
rientjestorvalds
authored andcommitted
mm, oom: change type of oom_score_adj to short
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>
1 parent fa26437 commit a9c58b9

9 files changed

Lines changed: 31 additions & 31 deletions

File tree

‎drivers/staging/android/lowmemorykiller.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <linux/notifier.h>
4141

4242
static uint32_t lowmem_debug_level = 2;
43-
static int lowmem_adj[6] = {
43+
static short lowmem_adj[6] = {
4444
0,
4545
1,
4646
6,
@@ -70,9 +70,9 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
7070
int rem = 0;
7171
int tasksize;
7272
int i;
73-
int min_score_adj = OOM_SCORE_ADJ_MAX + 1;
73+
short min_score_adj = OOM_SCORE_ADJ_MAX + 1;
7474
int selected_tasksize = 0;
75-
int selected_oom_score_adj;
75+
short selected_oom_score_adj;
7676
int array_size = ARRAY_SIZE(lowmem_adj);
7777
int other_free = global_page_state(NR_FREE_PAGES);
7878
int other_file = global_page_state(NR_FILE_PAGES) -
@@ -90,7 +90,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
9090
}
9191
}
9292
if (sc->nr_to_scan > 0)
93-
lowmem_print(3, "lowmem_shrink %lu, %x, ofree %d %d, ma %d\n",
93+
lowmem_print(3, "lowmem_shrink %lu, %x, ofree %d %d, ma %hd\n",
9494
sc->nr_to_scan, sc->gfp_mask, other_free,
9595
other_file, min_score_adj);
9696
rem = global_page_state(NR_ACTIVE_ANON) +
@@ -107,7 +107,7 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
107107
rcu_read_lock();
108108
for_each_process(tsk) {
109109
struct task_struct *p;
110-
int oom_score_adj;
110+
short oom_score_adj;
111111

112112
if (tsk->flags & PF_KTHREAD)
113113
continue;
@@ -141,11 +141,11 @@ static int lowmem_shrink(struct shrinker *s, struct shrink_control *sc)
141141
selected = p;
142142
selected_tasksize = tasksize;
143143
selected_oom_score_adj = oom_score_adj;
144-
lowmem_print(2, "select %d (%s), adj %d, size %d, to kill\n",
144+
lowmem_print(2, "select %d (%s), adj %hd, size %d, to kill\n",
145145
p->pid, p->comm, oom_score_adj, tasksize);
146146
}
147147
if (selected) {
148-
lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n",
148+
lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n",
149149
selected->pid, selected->comm,
150150
selected_oom_score_adj, selected_tasksize);
151151
lowmem_deathpending_timeout = jiffies + HZ;
@@ -176,7 +176,7 @@ static void __exit lowmem_exit(void)
176176
}
177177

178178
module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR);
179-
module_param_array_named(adj, lowmem_adj, int, &lowmem_adj_size,
179+
module_param_array_named(adj, lowmem_adj, short, &lowmem_adj_size,
180180
S_IRUGO | S_IWUSR);
181181
module_param_array_named(minfree, lowmem_minfree, uint, &lowmem_minfree_size,
182182
S_IRUGO | S_IWUSR);

‎fs/proc/base.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
985985
{
986986
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
987987
char buffer[PROC_NUMBUF];
988-
int oom_score_adj = OOM_SCORE_ADJ_MIN;
988+
short oom_score_adj = OOM_SCORE_ADJ_MIN;
989989
unsigned long flags;
990990
size_t len;
991991

@@ -996,7 +996,7 @@ static ssize_t oom_score_adj_read(struct file *file, char __user *buf,
996996
unlock_task_sighand(task, &flags);
997997
}
998998
put_task_struct(task);
999-
len = snprintf(buffer, sizeof(buffer), "%d\n", oom_score_adj);
999+
len = snprintf(buffer, sizeof(buffer), "%hd\n", oom_score_adj);
10001000
return simple_read_from_buffer(buf, count, ppos, buffer, len);
10011001
}
10021002

@@ -1043,15 +1043,15 @@ static ssize_t oom_score_adj_write(struct file *file, const char __user *buf,
10431043
goto err_task_lock;
10441044
}
10451045

1046-
if (oom_score_adj < task->signal->oom_score_adj_min &&
1046+
if ((short)oom_score_adj < task->signal->oom_score_adj_min &&
10471047
!capable(CAP_SYS_RESOURCE)) {
10481048
err = -EACCES;
10491049
goto err_sighand;
10501050
}
10511051

1052-
task->signal->oom_score_adj = oom_score_adj;
1052+
task->signal->oom_score_adj = (short)oom_score_adj;
10531053
if (has_capability_noaudit(current, CAP_SYS_RESOURCE))
1054-
task->signal->oom_score_adj_min = oom_score_adj;
1054+
task->signal->oom_score_adj_min = (short)oom_score_adj;
10551055
trace_oom_score_adj_update(task);
10561056

10571057
err_sighand:

‎include/linux/oom.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ enum oom_scan_t {
2929
OOM_SCAN_SELECT, /* always select this thread first */
3030
};
3131

32-
extern void compare_swap_oom_score_adj(int old_val, int new_val);
33-
extern int test_set_oom_score_adj(int new_val);
32+
extern void compare_swap_oom_score_adj(short old_val, short new_val);
33+
extern short test_set_oom_score_adj(short new_val);
3434

3535
extern unsigned long oom_badness(struct task_struct *p,
3636
struct mem_cgroup *memcg, const nodemask_t *nodemask,

‎include/linux/sched.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ struct signal_struct {
631631
struct rw_semaphore group_rwsem;
632632
#endif
633633

634-
int oom_score_adj; /* OOM kill score adjustment */
635-
int oom_score_adj_min; /* OOM kill score adjustment minimum value.
636-
* Only settable by CAP_SYS_RESOURCE. */
634+
short oom_score_adj; /* OOM kill score adjustment */
635+
short oom_score_adj_min; /* OOM kill score adjustment min value.
636+
* Only settable by CAP_SYS_RESOURCE. */
637637

638638
struct mutex cred_guard_mutex; /* guard against foreign influences on
639639
* credential calculations

‎include/trace/events/oom.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TRACE_EVENT(oom_score_adj_update,
1414
TP_STRUCT__entry(
1515
__field( pid_t, pid)
1616
__array( char, comm, TASK_COMM_LEN )
17-
__field( int, oom_score_adj)
17+
__field( short, oom_score_adj)
1818
),
1919

2020
TP_fast_assign(
@@ -23,7 +23,7 @@ TRACE_EVENT(oom_score_adj_update,
2323
__entry->oom_score_adj = task->signal->oom_score_adj;
2424
),
2525

26-
TP_printk("pid=%d comm=%s oom_score_adj=%d",
26+
TP_printk("pid=%d comm=%s oom_score_adj=%hd",
2727
__entry->pid, __entry->comm, __entry->oom_score_adj)
2828
);
2929

‎include/trace/events/task.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TRACE_EVENT(task_newtask,
1515
__field( pid_t, pid)
1616
__array( char, comm, TASK_COMM_LEN)
1717
__field( unsigned long, clone_flags)
18-
__field( int, oom_score_adj)
18+
__field( short, oom_score_adj)
1919
),
2020

2121
TP_fast_assign(
@@ -25,7 +25,7 @@ TRACE_EVENT(task_newtask,
2525
__entry->oom_score_adj = task->signal->oom_score_adj;
2626
),
2727

28-
TP_printk("pid=%d comm=%s clone_flags=%lx oom_score_adj=%d",
28+
TP_printk("pid=%d comm=%s clone_flags=%lx oom_score_adj=%hd",
2929
__entry->pid, __entry->comm,
3030
__entry->clone_flags, __entry->oom_score_adj)
3131
);
@@ -40,7 +40,7 @@ TRACE_EVENT(task_rename,
4040
__field( pid_t, pid)
4141
__array( char, oldcomm, TASK_COMM_LEN)
4242
__array( char, newcomm, TASK_COMM_LEN)
43-
__field( int, oom_score_adj)
43+
__field( short, oom_score_adj)
4444
),
4545

4646
TP_fast_assign(
@@ -50,7 +50,7 @@ TRACE_EVENT(task_rename,
5050
__entry->oom_score_adj = task->signal->oom_score_adj;
5151
),
5252

53-
TP_printk("pid=%d oldcomm=%s newcomm=%s oom_score_adj=%d",
53+
TP_printk("pid=%d oldcomm=%s newcomm=%s oom_score_adj=%hd",
5454
__entry->pid, __entry->oldcomm,
5555
__entry->newcomm, __entry->oom_score_adj)
5656
);

‎mm/ksm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
19191919
if (ksm_run != flags) {
19201920
ksm_run = flags;
19211921
if (flags & KSM_RUN_UNMERGE) {
1922-
int oom_score_adj;
1922+
short oom_score_adj;
19231923

19241924
oom_score_adj = test_set_oom_score_adj(OOM_SCORE_ADJ_MAX);
19251925
err = unmerge_and_remove_all_rmap_items();

‎mm/oom_kill.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static DEFINE_SPINLOCK(zone_scan_lock);
5353
* @old_val. Usually used to reinstate a previous value to prevent racing with
5454
* userspacing tuning the value in the interim.
5555
*/
56-
void compare_swap_oom_score_adj(int old_val, int new_val)
56+
void compare_swap_oom_score_adj(short old_val, short new_val)
5757
{
5858
struct sighand_struct *sighand = current->sighand;
5959

@@ -72,7 +72,7 @@ void compare_swap_oom_score_adj(int old_val, int new_val)
7272
* synchronization and returns the old value. Usually used to temporarily
7373
* set a value, save the old value in the caller, and then reinstate it later.
7474
*/
75-
int test_set_oom_score_adj(int new_val)
75+
short test_set_oom_score_adj(short new_val)
7676
{
7777
struct sighand_struct *sighand = current->sighand;
7878
int old_val;
@@ -193,7 +193,7 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg,
193193
if (!p)
194194
return 0;
195195

196-
adj = p->signal->oom_score_adj;
196+
adj = (long)p->signal->oom_score_adj;
197197
if (adj == OOM_SCORE_ADJ_MIN) {
198198
task_unlock(p);
199199
return 0;
@@ -399,7 +399,7 @@ static void dump_tasks(const struct mem_cgroup *memcg, const nodemask_t *nodemas
399399
continue;
400400
}
401401

402-
pr_info("[%5d] %5d %5d %8lu %8lu %7lu %8lu %5d %s\n",
402+
pr_info("[%5d] %5d %5d %8lu %8lu %7lu %8lu %5hd %s\n",
403403
task->pid, from_kuid(&init_user_ns, task_uid(task)),
404404
task->tgid, task->mm->total_vm, get_mm_rss(task->mm),
405405
task->mm->nr_ptes,
@@ -415,7 +415,7 @@ static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
415415
{
416416
task_lock(current);
417417
pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, "
418-
"oom_score_adj=%d\n",
418+
"oom_score_adj=%hd\n",
419419
current->comm, gfp_mask, order,
420420
current->signal->oom_score_adj);
421421
cpuset_print_task_mems_allowed(current);

‎mm/swapfile.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
14981498
struct address_space *mapping;
14991499
struct inode *inode;
15001500
struct filename *pathname;
1501-
int oom_score_adj;
1501+
short oom_score_adj;
15021502
int i, type, prev;
15031503
int err;
15041504

0 commit comments

Comments
 (0)