Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

oom: remove deprecated oom_adj

The deprecated /proc/<pid>/oom_adj is scheduled for removal this month.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Acked-by: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Davidlohr Bueso and committed by
Linus Torvalds
01dc52eb d5dc0ad9

+7 -171
-22
Documentation/ABI/obsolete/proc-pid-oom_adj
··· 1 - What: /proc/<pid>/oom_adj 2 - When: August 2012 3 - Why: /proc/<pid>/oom_adj allows userspace to influence the oom killer's 4 - badness heuristic used to determine which task to kill when the kernel 5 - is out of memory. 6 - 7 - The badness heuristic has since been rewritten since the introduction of 8 - this tunable such that its meaning is deprecated. The value was 9 - implemented as a bitshift on a score generated by the badness() 10 - function that did not have any precise units of measure. With the 11 - rewrite, the score is given as a proportion of available memory to the 12 - task allocating pages, so using a bitshift which grows the score 13 - exponentially is, thus, impossible to tune with fine granularity. 14 - 15 - A much more powerful interface, /proc/<pid>/oom_score_adj, was 16 - introduced with the oom killer rewrite that allows users to increase or 17 - decrease the badness score linearly. This interface will replace 18 - /proc/<pid>/oom_adj. 19 - 20 - A warning will be emitted to the kernel log if an application uses this 21 - deprecated interface. After it is printed once, future warnings will be 22 - suppressed until the kernel is rebooted.
+4 -18
Documentation/filesystems/proc.txt
··· 33 33 2 Modifying System Parameters 34 34 35 35 3 Per-Process Parameters 36 - 3.1 /proc/<pid>/oom_adj & /proc/<pid>/oom_score_adj - Adjust the oom-killer 36 + 3.1 /proc/<pid>/oom_score_adj - Adjust the oom-killer 37 37 score 38 38 3.2 /proc/<pid>/oom_score - Display current oom-killer score 39 39 3.3 /proc/<pid>/io - Display the IO accounting fields ··· 1320 1320 CHAPTER 3: PER-PROCESS PARAMETERS 1321 1321 ------------------------------------------------------------------------------ 1322 1322 1323 - 3.1 /proc/<pid>/oom_adj & /proc/<pid>/oom_score_adj- Adjust the oom-killer score 1323 + 3.1 /proc/<pid>/oom_score_adj- Adjust the oom-killer score 1324 1324 -------------------------------------------------------------------------------- 1325 1325 1326 - These file can be used to adjust the badness heuristic used to select which 1326 + This file can be used to adjust the badness heuristic used to select which 1327 1327 process gets killed in out of memory conditions. 1328 1328 1329 1329 The badness heuristic assigns a value to each candidate task ranging from 0 ··· 1361 1361 equivalent to discounting 50% of the task's allowed memory from being considered 1362 1362 as scoring against the task. 1363 1363 1364 - For backwards compatibility with previous kernels, /proc/<pid>/oom_adj may also 1365 - be used to tune the badness score. Its acceptable values range from -16 1366 - (OOM_ADJUST_MIN) to +15 (OOM_ADJUST_MAX) and a special value of -17 1367 - (OOM_DISABLE) to disable oom killing entirely for that task. Its value is 1368 - scaled linearly with /proc/<pid>/oom_score_adj. 1369 - 1370 - Writing to /proc/<pid>/oom_score_adj or /proc/<pid>/oom_adj will change the 1371 - other with its scaled value. 1372 - 1373 1364 The value of /proc/<pid>/oom_score_adj may be reduced no lower than the last 1374 1365 value set by a CAP_SYS_RESOURCE process. To reduce the value any lower 1375 1366 requires CAP_SYS_RESOURCE. 1376 - 1377 - NOTICE: /proc/<pid>/oom_adj is deprecated and will be removed, please see 1378 - Documentation/feature-removal-schedule.txt. 1379 1367 1380 1368 Caveat: when a parent task is selected, the oom killer will sacrifice any first 1381 1369 generation children with separate address spaces instead, if possible. This ··· 1375 1387 ------------------------------------------------------------- 1376 1388 1377 1389 This file can be used to check the current score used by the oom-killer is for 1378 - any given <pid>. Use it together with /proc/<pid>/oom_adj to tune which 1379 - process should be killed in an out-of-memory situation. 1380 - 1390 + any given <pid>. 1381 1391 1382 1392 3.3 /proc/<pid>/io - Display the IO accounting fields 1383 1393 -------------------------------------------------------
+1 -116
fs/proc/base.c
··· 873 873 .release = mem_release, 874 874 }; 875 875 876 - static ssize_t oom_adjust_read(struct file *file, char __user *buf, 877 - size_t count, loff_t *ppos) 878 - { 879 - struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode); 880 - char buffer[PROC_NUMBUF]; 881 - size_t len; 882 - int oom_adjust = OOM_DISABLE; 883 - unsigned long flags; 884 - 885 - if (!task) 886 - return -ESRCH; 887 - 888 - if (lock_task_sighand(task, &flags)) { 889 - oom_adjust = task->signal->oom_adj; 890 - unlock_task_sighand(task, &flags); 891 - } 892 - 893 - put_task_struct(task); 894 - 895 - len = snprintf(buffer, sizeof(buffer), "%i\n", oom_adjust); 896 - 897 - return simple_read_from_buffer(buf, count, ppos, buffer, len); 898 - } 899 - 900 - static ssize_t oom_adjust_write(struct file *file, const char __user *buf, 901 - size_t count, loff_t *ppos) 902 - { 903 - struct task_struct *task; 904 - char buffer[PROC_NUMBUF]; 905 - int oom_adjust; 906 - unsigned long flags; 907 - int err; 908 - 909 - memset(buffer, 0, sizeof(buffer)); 910 - if (count > sizeof(buffer) - 1) 911 - count = sizeof(buffer) - 1; 912 - if (copy_from_user(buffer, buf, count)) { 913 - err = -EFAULT; 914 - goto out; 915 - } 916 - 917 - err = kstrtoint(strstrip(buffer), 0, &oom_adjust); 918 - if (err) 919 - goto out; 920 - if ((oom_adjust < OOM_ADJUST_MIN || oom_adjust > OOM_ADJUST_MAX) && 921 - oom_adjust != OOM_DISABLE) { 922 - err = -EINVAL; 923 - goto out; 924 - } 925 - 926 - task = get_proc_task(file->f_path.dentry->d_inode); 927 - if (!task) { 928 - err = -ESRCH; 929 - goto out; 930 - } 931 - 932 - task_lock(task); 933 - if (!task->mm) { 934 - err = -EINVAL; 935 - goto err_task_lock; 936 - } 937 - 938 - if (!lock_task_sighand(task, &flags)) { 939 - err = -ESRCH; 940 - goto err_task_lock; 941 - } 942 - 943 - if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) { 944 - err = -EACCES; 945 - goto err_sighand; 946 - } 947 - 948 - /* 949 - * Warn that /proc/pid/oom_adj is deprecated, see 950 - * Documentation/feature-removal-schedule.txt. 951 - */ 952 - printk_once(KERN_WARNING "%s (%d): /proc/%d/oom_adj is deprecated, please use /proc/%d/oom_score_adj instead.\n", 953 - current->comm, task_pid_nr(current), task_pid_nr(task), 954 - task_pid_nr(task)); 955 - task->signal->oom_adj = oom_adjust; 956 - /* 957 - * Scale /proc/pid/oom_score_adj appropriately ensuring that a maximum 958 - * value is always attainable. 959 - */ 960 - if (task->signal->oom_adj == OOM_ADJUST_MAX) 961 - task->signal->oom_score_adj = OOM_SCORE_ADJ_MAX; 962 - else 963 - task->signal->oom_score_adj = (oom_adjust * OOM_SCORE_ADJ_MAX) / 964 - -OOM_DISABLE; 965 - trace_oom_score_adj_update(task); 966 - err_sighand: 967 - unlock_task_sighand(task, &flags); 968 - err_task_lock: 969 - task_unlock(task); 970 - put_task_struct(task); 971 - out: 972 - return err < 0 ? err : count; 973 - } 974 - 975 - static const struct file_operations proc_oom_adjust_operations = { 976 - .read = oom_adjust_read, 977 - .write = oom_adjust_write, 978 - .llseek = generic_file_llseek, 979 - }; 980 - 981 876 static ssize_t oom_score_adj_read(struct file *file, char __user *buf, 982 877 size_t count, loff_t *ppos) 983 878 { ··· 946 1051 if (has_capability_noaudit(current, CAP_SYS_RESOURCE)) 947 1052 task->signal->oom_score_adj_min = oom_score_adj; 948 1053 trace_oom_score_adj_update(task); 949 - /* 950 - * Scale /proc/pid/oom_adj appropriately ensuring that OOM_DISABLE is 951 - * always attainable. 952 - */ 953 - if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MIN) 954 - task->signal->oom_adj = OOM_DISABLE; 955 - else 956 - task->signal->oom_adj = (oom_score_adj * OOM_ADJUST_MAX) / 957 - OOM_SCORE_ADJ_MAX; 1054 + 958 1055 err_sighand: 959 1056 unlock_task_sighand(task, &flags); 960 1057 err_task_lock: ··· 2597 2710 REG("cgroup", S_IRUGO, proc_cgroup_operations), 2598 2711 #endif 2599 2712 INF("oom_score", S_IRUGO, proc_oom_score), 2600 - REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adjust_operations), 2601 2713 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations), 2602 2714 #ifdef CONFIG_AUDITSYSCALL 2603 2715 REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations), ··· 2963 3077 REG("cgroup", S_IRUGO, proc_cgroup_operations), 2964 3078 #endif 2965 3079 INF("oom_score", S_IRUGO, proc_oom_score), 2966 - REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adjust_operations), 2967 3080 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations), 2968 3081 #ifdef CONFIG_AUDITSYSCALL 2969 3082 REG("loginuid", S_IWUSR|S_IRUGO, proc_loginuid_operations),
-11
include/linux/oom.h
··· 2 2 #define __INCLUDE_LINUX_OOM_H 3 3 4 4 /* 5 - * /proc/<pid>/oom_adj is deprecated, see 6 - * Documentation/feature-removal-schedule.txt. 7 - * 8 - * /proc/<pid>/oom_adj set to -17 protects from the oom-killer 9 - */ 10 - #define OOM_DISABLE (-17) 11 - /* inclusive */ 12 - #define OOM_ADJUST_MIN (-16) 13 - #define OOM_ADJUST_MAX 15 14 - 15 - /* 16 5 * /proc/<pid>/oom_score_adj set to OOM_SCORE_ADJ_MIN disables oom killing for 17 6 * pid. 18 7 */
-1
include/linux/sched.h
··· 671 671 struct rw_semaphore group_rwsem; 672 672 #endif 673 673 674 - int oom_adj; /* OOM kill score adjustment (bit shift) */ 675 674 int oom_score_adj; /* OOM kill score adjustment */ 676 675 int oom_score_adj_min; /* OOM kill score adjustment minimum value. 677 676 * Only settable by CAP_SYS_RESOURCE. */
-1
kernel/fork.c
··· 1056 1056 init_rwsem(&sig->group_rwsem); 1057 1057 #endif 1058 1058 1059 - sig->oom_adj = current->signal->oom_adj; 1060 1059 sig->oom_score_adj = current->signal->oom_score_adj; 1061 1060 sig->oom_score_adj_min = current->signal->oom_score_adj_min; 1062 1061
+2 -2
mm/oom_kill.c
··· 428 428 { 429 429 task_lock(current); 430 430 pr_warning("%s invoked oom-killer: gfp_mask=0x%x, order=%d, " 431 - "oom_adj=%d, oom_score_adj=%d\n", 432 - current->comm, gfp_mask, order, current->signal->oom_adj, 431 + "oom_score_adj=%d\n", 432 + current->comm, gfp_mask, order, 433 433 current->signal->oom_score_adj); 434 434 cpuset_print_task_mems_allowed(current); 435 435 task_unlock(current);