memcontrol-v1.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __MM_MEMCONTROL_V1_H
  3. #define __MM_MEMCONTROL_V1_H
  4. #include <linux/cgroup-defs.h>
  5. /* Cgroup v1 and v2 common declarations */
  6. /*
  7. * Iteration constructs for visiting all cgroups (under a tree). If
  8. * loops are exited prematurely (break), mem_cgroup_iter_break() must
  9. * be used for reference counting.
  10. */
  11. #define for_each_mem_cgroup_tree(iter, root) \
  12. for (iter = mem_cgroup_iter(root, NULL, NULL); \
  13. iter != NULL; \
  14. iter = mem_cgroup_iter(root, iter, NULL))
  15. #define for_each_mem_cgroup(iter) \
  16. for (iter = mem_cgroup_iter(NULL, NULL, NULL); \
  17. iter != NULL; \
  18. iter = mem_cgroup_iter(NULL, iter, NULL))
  19. void drain_all_stock(struct mem_cgroup *root_memcg);
  20. unsigned long memcg_events(struct mem_cgroup *memcg, int event);
  21. int memory_stat_show(struct seq_file *m, void *v);
  22. void mem_cgroup_private_id_get_many(struct mem_cgroup *memcg, unsigned int n);
  23. struct mem_cgroup *mem_cgroup_private_id_get_online(struct mem_cgroup *memcg);
  24. /* Cgroup v1-specific declarations */
  25. #ifdef CONFIG_MEMCG_V1
  26. /* Whether legacy memory+swap accounting is active */
  27. static inline bool do_memsw_account(void)
  28. {
  29. return !cgroup_subsys_on_dfl(memory_cgrp_subsys);
  30. }
  31. unsigned long memcg_events_local(struct mem_cgroup *memcg, int event);
  32. unsigned long memcg_page_state_local(struct mem_cgroup *memcg, int idx);
  33. unsigned long memcg_page_state_local_output(struct mem_cgroup *memcg, int item);
  34. bool memcg1_alloc_events(struct mem_cgroup *memcg);
  35. void memcg1_free_events(struct mem_cgroup *memcg);
  36. void memcg1_memcg_init(struct mem_cgroup *memcg);
  37. void memcg1_remove_from_trees(struct mem_cgroup *memcg);
  38. static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg)
  39. {
  40. WRITE_ONCE(memcg->soft_limit, PAGE_COUNTER_MAX);
  41. }
  42. struct cgroup_taskset;
  43. void memcg1_css_offline(struct mem_cgroup *memcg);
  44. /* for encoding cft->private value on file */
  45. enum res_type {
  46. _MEM,
  47. _MEMSWAP,
  48. _KMEM,
  49. _TCP,
  50. };
  51. bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked);
  52. void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked);
  53. void memcg1_oom_recover(struct mem_cgroup *memcg);
  54. void memcg1_commit_charge(struct folio *folio, struct mem_cgroup *memcg);
  55. void memcg1_uncharge_batch(struct mem_cgroup *memcg, unsigned long pgpgout,
  56. unsigned long nr_memory, int nid);
  57. void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s);
  58. void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages);
  59. static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg)
  60. {
  61. return memcg->tcpmem_active;
  62. }
  63. bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
  64. gfp_t gfp_mask);
  65. static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages)
  66. {
  67. page_counter_uncharge(&memcg->tcpmem, nr_pages);
  68. }
  69. extern struct cftype memsw_files[];
  70. extern struct cftype mem_cgroup_legacy_files[];
  71. #else /* CONFIG_MEMCG_V1 */
  72. static inline bool do_memsw_account(void) { return false; }
  73. static inline bool memcg1_alloc_events(struct mem_cgroup *memcg) { return true; }
  74. static inline void memcg1_free_events(struct mem_cgroup *memcg) {}
  75. static inline void memcg1_memcg_init(struct mem_cgroup *memcg) {}
  76. static inline void memcg1_remove_from_trees(struct mem_cgroup *memcg) {}
  77. static inline void memcg1_soft_limit_reset(struct mem_cgroup *memcg) {}
  78. static inline void memcg1_css_offline(struct mem_cgroup *memcg) {}
  79. static inline bool memcg1_oom_prepare(struct mem_cgroup *memcg, bool *locked) { return true; }
  80. static inline void memcg1_oom_finish(struct mem_cgroup *memcg, bool locked) {}
  81. static inline void memcg1_oom_recover(struct mem_cgroup *memcg) {}
  82. static inline void memcg1_commit_charge(struct folio *folio,
  83. struct mem_cgroup *memcg) {}
  84. static inline void memcg1_uncharge_batch(struct mem_cgroup *memcg,
  85. unsigned long pgpgout,
  86. unsigned long nr_memory, int nid) {}
  87. static inline void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s) {}
  88. static inline void memcg1_account_kmem(struct mem_cgroup *memcg, int nr_pages) {}
  89. static inline bool memcg1_tcpmem_active(struct mem_cgroup *memcg) { return false; }
  90. static inline bool memcg1_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages,
  91. gfp_t gfp_mask) { return true; }
  92. static inline void memcg1_uncharge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages) {}
  93. #endif /* CONFIG_MEMCG_V1 */
  94. #endif /* __MM_MEMCONTROL_V1_H */