oom.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __INCLUDE_LINUX_OOM_H
  3. #define __INCLUDE_LINUX_OOM_H
  4. #include <linux/sched/signal.h>
  5. #include <linux/types.h>
  6. #include <linux/nodemask.h>
  7. #include <uapi/linux/oom.h>
  8. #include <linux/sched/coredump.h> /* MMF_* */
  9. #include <linux/mm.h> /* VM_FAULT* */
  10. struct zonelist;
  11. struct notifier_block;
  12. struct mem_cgroup;
  13. struct task_struct;
  14. enum oom_constraint {
  15. CONSTRAINT_NONE,
  16. CONSTRAINT_CPUSET,
  17. CONSTRAINT_MEMORY_POLICY,
  18. CONSTRAINT_MEMCG,
  19. };
  20. /*
  21. * Details of the page allocation that triggered the oom killer that are used to
  22. * determine what should be killed.
  23. */
  24. struct oom_control {
  25. /* Used to determine cpuset */
  26. struct zonelist *zonelist;
  27. /* Used to determine mempolicy */
  28. nodemask_t *nodemask;
  29. /* Memory cgroup in which oom is invoked, or NULL for global oom */
  30. struct mem_cgroup *memcg;
  31. /* Used to determine cpuset and node locality requirement */
  32. const gfp_t gfp_mask;
  33. /*
  34. * order == -1 means the oom kill is required by sysrq, otherwise only
  35. * for display purposes.
  36. */
  37. const int order;
  38. /* Used by oom implementation, do not set */
  39. unsigned long totalpages;
  40. struct task_struct *chosen;
  41. long chosen_points;
  42. struct task_struct *chosen_non_negative_adj;
  43. long chosen_non_negative_adj_points;
  44. /* Used to print the constraint info. */
  45. enum oom_constraint constraint;
  46. };
  47. extern struct mutex oom_lock;
  48. extern struct mutex oom_adj_mutex;
  49. static inline void set_current_oom_origin(void)
  50. {
  51. current->signal->oom_flag_origin = true;
  52. }
  53. static inline void clear_current_oom_origin(void)
  54. {
  55. current->signal->oom_flag_origin = false;
  56. }
  57. static inline bool oom_task_origin(const struct task_struct *p)
  58. {
  59. return p->signal->oom_flag_origin;
  60. }
  61. static inline bool tsk_is_oom_victim(struct task_struct * tsk)
  62. {
  63. return tsk->signal->oom_mm;
  64. }
  65. /*
  66. * Use this helper if tsk->mm != mm and the victim mm needs a special
  67. * handling. This is guaranteed to stay true after once set.
  68. */
  69. static inline bool mm_is_oom_victim(struct mm_struct *mm)
  70. {
  71. return test_bit(MMF_OOM_VICTIM, &mm->flags);
  72. }
  73. /*
  74. * Checks whether a page fault on the given mm is still reliable.
  75. * This is no longer true if the oom reaper started to reap the
  76. * address space which is reflected by MMF_UNSTABLE flag set in
  77. * the mm. At that moment any !shared mapping would lose the content
  78. * and could cause a memory corruption (zero pages instead of the
  79. * original content).
  80. *
  81. * User should call this before establishing a page table entry for
  82. * a !shared mapping and under the proper page table lock.
  83. *
  84. * Return 0 when the PF is safe VM_FAULT_SIGBUS otherwise.
  85. */
  86. static inline vm_fault_t check_stable_address_space(struct mm_struct *mm)
  87. {
  88. if (unlikely(test_bit(MMF_UNSTABLE, &mm->flags)))
  89. return VM_FAULT_SIGBUS;
  90. return 0;
  91. }
  92. bool __oom_reap_task_mm(struct mm_struct *mm);
  93. long oom_badness(struct task_struct *p,
  94. unsigned long totalpages);
  95. extern bool out_of_memory(struct oom_control *oc);
  96. extern void exit_oom_victim(void);
  97. extern int register_oom_notifier(struct notifier_block *nb);
  98. extern int unregister_oom_notifier(struct notifier_block *nb);
  99. extern bool oom_killer_disable(signed long timeout);
  100. extern void oom_killer_enable(void);
  101. extern struct task_struct *find_lock_task_mm(struct task_struct *p);
  102. /* sysctls */
  103. extern int sysctl_oom_dump_tasks;
  104. extern int sysctl_oom_kill_allocating_task;
  105. extern int sysctl_panic_on_oom;
  106. /* call for adding killed process to reaper. */
  107. extern void add_to_oom_reaper(struct task_struct *p);
  108. #endif /* _INCLUDE_LINUX_OOM_H */