oom.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /* Used to print the constraint info. */
  43. enum oom_constraint constraint;
  44. };
  45. extern struct mutex oom_lock;
  46. extern struct mutex oom_adj_mutex;
  47. static inline void set_current_oom_origin(void)
  48. {
  49. current->signal->oom_flag_origin = true;
  50. }
  51. static inline void clear_current_oom_origin(void)
  52. {
  53. current->signal->oom_flag_origin = false;
  54. }
  55. static inline bool oom_task_origin(const struct task_struct *p)
  56. {
  57. return p->signal->oom_flag_origin;
  58. }
  59. static inline bool tsk_is_oom_victim(struct task_struct * tsk)
  60. {
  61. return tsk->signal->oom_mm;
  62. }
  63. /*
  64. * Checks whether a page fault on the given mm is still reliable.
  65. * This is no longer true if the oom reaper started to reap the
  66. * address space which is reflected by MMF_UNSTABLE flag set in
  67. * the mm. At that moment any !shared mapping would lose the content
  68. * and could cause a memory corruption (zero pages instead of the
  69. * original content).
  70. *
  71. * User should call this before establishing a page table entry for
  72. * a !shared mapping and under the proper page table lock.
  73. *
  74. * Return 0 when the PF is safe VM_FAULT_SIGBUS otherwise.
  75. */
  76. static inline vm_fault_t check_stable_address_space(struct mm_struct *mm)
  77. {
  78. if (unlikely(test_bit(MMF_UNSTABLE, &mm->flags)))
  79. return VM_FAULT_SIGBUS;
  80. return 0;
  81. }
  82. long oom_badness(struct task_struct *p,
  83. unsigned long totalpages);
  84. extern bool out_of_memory(struct oom_control *oc);
  85. extern void exit_oom_victim(void);
  86. extern int register_oom_notifier(struct notifier_block *nb);
  87. extern int unregister_oom_notifier(struct notifier_block *nb);
  88. extern bool oom_killer_disable(signed long timeout);
  89. extern void oom_killer_enable(void);
  90. extern struct task_struct *find_lock_task_mm(struct task_struct *p);
  91. /* call for adding killed process to reaper. */
  92. extern void add_to_oom_reaper(struct task_struct *p);
  93. #endif /* _INCLUDE_LINUX_OOM_H */