oom.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef __INCLUDE_LINUX_OOM_H
  2. #define __INCLUDE_LINUX_OOM_H
  3. #include <linux/sched.h>
  4. #include <linux/types.h>
  5. #include <linux/nodemask.h>
  6. #include <uapi/linux/oom.h>
  7. struct zonelist;
  8. struct notifier_block;
  9. struct mem_cgroup;
  10. struct task_struct;
  11. /*
  12. * Types of limitations to the nodes from which allocations may occur
  13. */
  14. enum oom_constraint {
  15. CONSTRAINT_NONE,
  16. CONSTRAINT_CPUSET,
  17. CONSTRAINT_MEMORY_POLICY,
  18. CONSTRAINT_MEMCG,
  19. };
  20. enum oom_scan_t {
  21. OOM_SCAN_OK, /* scan thread and find its badness */
  22. OOM_SCAN_CONTINUE, /* do not consider thread for oom kill */
  23. OOM_SCAN_ABORT, /* abort the iteration and return */
  24. OOM_SCAN_SELECT, /* always select this thread first */
  25. };
  26. /* Thread is the potential origin of an oom condition; kill first on oom */
  27. #define OOM_FLAG_ORIGIN ((__force oom_flags_t)0x1)
  28. static inline void set_current_oom_origin(void)
  29. {
  30. current->signal->oom_flags |= OOM_FLAG_ORIGIN;
  31. }
  32. static inline void clear_current_oom_origin(void)
  33. {
  34. current->signal->oom_flags &= ~OOM_FLAG_ORIGIN;
  35. }
  36. static inline bool oom_task_origin(const struct task_struct *p)
  37. {
  38. return !!(p->signal->oom_flags & OOM_FLAG_ORIGIN);
  39. }
  40. extern unsigned long oom_badness(struct task_struct *p,
  41. struct mem_cgroup *memcg, const nodemask_t *nodemask,
  42. unsigned long totalpages);
  43. extern void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
  44. unsigned int points, unsigned long totalpages,
  45. struct mem_cgroup *memcg, nodemask_t *nodemask,
  46. const char *message);
  47. extern int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
  48. extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
  49. extern void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask,
  50. int order, const nodemask_t *nodemask);
  51. extern enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
  52. unsigned long totalpages, const nodemask_t *nodemask,
  53. bool force_kill);
  54. extern void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
  55. int order, nodemask_t *mask, bool force_kill);
  56. extern int register_oom_notifier(struct notifier_block *nb);
  57. extern int unregister_oom_notifier(struct notifier_block *nb);
  58. extern bool oom_killer_disabled;
  59. static inline void oom_killer_disable(void)
  60. {
  61. oom_killer_disabled = true;
  62. }
  63. static inline void oom_killer_enable(void)
  64. {
  65. oom_killer_disabled = false;
  66. }
  67. extern struct task_struct *find_lock_task_mm(struct task_struct *p);
  68. /* sysctls */
  69. extern int sysctl_oom_dump_tasks;
  70. extern int sysctl_oom_kill_allocating_task;
  71. extern int sysctl_panic_on_oom;
  72. #endif /* _INCLUDE_LINUX_OOM_H */