mempolicy.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #ifndef _LINUX_MEMPOLICY_H
  2. #define _LINUX_MEMPOLICY_H 1
  3. #include <linux/errno.h>
  4. /*
  5. * NUMA memory policies for Linux.
  6. * Copyright 2003,2004 Andi Kleen SuSE Labs
  7. */
  8. /* Policies */
  9. #define MPOL_DEFAULT 0
  10. #define MPOL_PREFERRED 1
  11. #define MPOL_BIND 2
  12. #define MPOL_INTERLEAVE 3
  13. #define MPOL_MAX MPOL_INTERLEAVE
  14. /* Flags for get_mem_policy */
  15. #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
  16. #define MPOL_F_ADDR (1<<1) /* look up vma using address */
  17. #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
  18. /* Flags for mbind */
  19. #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
  20. #define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
  21. #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
  22. #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
  23. #ifdef __KERNEL__
  24. #include <linux/mmzone.h>
  25. #include <linux/slab.h>
  26. #include <linux/rbtree.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/nodemask.h>
  29. struct vm_area_struct;
  30. struct mm_struct;
  31. #ifdef CONFIG_NUMA
  32. /*
  33. * Describe a memory policy.
  34. *
  35. * A mempolicy can be either associated with a process or with a VMA.
  36. * For VMA related allocations the VMA policy is preferred, otherwise
  37. * the process policy is used. Interrupts ignore the memory policy
  38. * of the current process.
  39. *
  40. * Locking policy for interlave:
  41. * In process context there is no locking because only the process accesses
  42. * its own state. All vma manipulation is somewhat protected by a down_read on
  43. * mmap_sem.
  44. *
  45. * Freeing policy:
  46. * Mempolicy objects are reference counted. A mempolicy will be freed when
  47. * mpol_free() decrements the reference count to zero.
  48. *
  49. * Copying policy objects:
  50. * mpol_copy() allocates a new mempolicy and copies the specified mempolicy
  51. * to the new storage. The reference count of the new object is initialized
  52. * to 1, representing the caller of mpol_copy().
  53. */
  54. struct mempolicy {
  55. atomic_t refcnt;
  56. short policy; /* See MPOL_* above */
  57. union {
  58. short preferred_node; /* preferred */
  59. nodemask_t nodes; /* interleave/bind */
  60. /* undefined for default */
  61. } v;
  62. nodemask_t cpuset_mems_allowed; /* mempolicy relative to these nodes */
  63. };
  64. /*
  65. * Support for managing mempolicy data objects (clone, copy, destroy)
  66. * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
  67. */
  68. extern void __mpol_free(struct mempolicy *pol);
  69. static inline void mpol_free(struct mempolicy *pol)
  70. {
  71. if (pol)
  72. __mpol_free(pol);
  73. }
  74. extern struct mempolicy *__mpol_copy(struct mempolicy *pol);
  75. static inline struct mempolicy *mpol_copy(struct mempolicy *pol)
  76. {
  77. if (pol)
  78. pol = __mpol_copy(pol);
  79. return pol;
  80. }
  81. #define vma_policy(vma) ((vma)->vm_policy)
  82. #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
  83. static inline void mpol_get(struct mempolicy *pol)
  84. {
  85. if (pol)
  86. atomic_inc(&pol->refcnt);
  87. }
  88. extern int __mpol_equal(struct mempolicy *a, struct mempolicy *b);
  89. static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
  90. {
  91. if (a == b)
  92. return 1;
  93. return __mpol_equal(a, b);
  94. }
  95. #define vma_mpol_equal(a,b) mpol_equal(vma_policy(a), vma_policy(b))
  96. /* Could later add inheritance of the process policy here. */
  97. #define mpol_set_vma_default(vma) ((vma)->vm_policy = NULL)
  98. /*
  99. * Tree of shared policies for a shared memory region.
  100. * Maintain the policies in a pseudo mm that contains vmas. The vmas
  101. * carry the policy. As a special twist the pseudo mm is indexed in pages, not
  102. * bytes, so that we can work with shared memory segments bigger than
  103. * unsigned long.
  104. */
  105. struct sp_node {
  106. struct rb_node nd;
  107. unsigned long start, end;
  108. struct mempolicy *policy;
  109. };
  110. struct shared_policy {
  111. struct rb_root root;
  112. spinlock_t lock;
  113. };
  114. void mpol_shared_policy_init(struct shared_policy *info, int policy,
  115. nodemask_t *nodes);
  116. int mpol_set_shared_policy(struct shared_policy *info,
  117. struct vm_area_struct *vma,
  118. struct mempolicy *new);
  119. void mpol_free_shared_policy(struct shared_policy *p);
  120. struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
  121. unsigned long idx);
  122. extern void numa_default_policy(void);
  123. extern void numa_policy_init(void);
  124. extern void mpol_rebind_task(struct task_struct *tsk,
  125. const nodemask_t *new);
  126. extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
  127. extern void mpol_fix_fork_child_flag(struct task_struct *p);
  128. extern struct mempolicy default_policy;
  129. extern struct zonelist *huge_zonelist(struct vm_area_struct *vma,
  130. unsigned long addr, gfp_t gfp_flags,
  131. struct mempolicy **mpol, nodemask_t **nodemask);
  132. extern unsigned slab_node(struct mempolicy *policy);
  133. extern enum zone_type policy_zone;
  134. static inline void check_highest_zone(enum zone_type k)
  135. {
  136. if (k > policy_zone && k != ZONE_MOVABLE)
  137. policy_zone = k;
  138. }
  139. int do_migrate_pages(struct mm_struct *mm,
  140. const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags);
  141. #else
  142. struct mempolicy {};
  143. static inline int mpol_equal(struct mempolicy *a, struct mempolicy *b)
  144. {
  145. return 1;
  146. }
  147. #define vma_mpol_equal(a,b) 1
  148. #define mpol_set_vma_default(vma) do {} while(0)
  149. static inline void mpol_free(struct mempolicy *p)
  150. {
  151. }
  152. static inline void mpol_get(struct mempolicy *pol)
  153. {
  154. }
  155. static inline struct mempolicy *mpol_copy(struct mempolicy *old)
  156. {
  157. return NULL;
  158. }
  159. struct shared_policy {};
  160. static inline int mpol_set_shared_policy(struct shared_policy *info,
  161. struct vm_area_struct *vma,
  162. struct mempolicy *new)
  163. {
  164. return -EINVAL;
  165. }
  166. static inline void mpol_shared_policy_init(struct shared_policy *info,
  167. int policy, nodemask_t *nodes)
  168. {
  169. }
  170. static inline void mpol_free_shared_policy(struct shared_policy *p)
  171. {
  172. }
  173. static inline struct mempolicy *
  174. mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
  175. {
  176. return NULL;
  177. }
  178. #define vma_policy(vma) NULL
  179. #define vma_set_policy(vma, pol) do {} while(0)
  180. static inline void numa_policy_init(void)
  181. {
  182. }
  183. static inline void numa_default_policy(void)
  184. {
  185. }
  186. static inline void mpol_rebind_task(struct task_struct *tsk,
  187. const nodemask_t *new)
  188. {
  189. }
  190. static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
  191. {
  192. }
  193. static inline void mpol_fix_fork_child_flag(struct task_struct *p)
  194. {
  195. }
  196. static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
  197. unsigned long addr, gfp_t gfp_flags,
  198. struct mempolicy **mpol, nodemask_t **nodemask)
  199. {
  200. *mpol = NULL;
  201. *nodemask = NULL;
  202. return node_zonelist(0, gfp_flags);
  203. }
  204. static inline int do_migrate_pages(struct mm_struct *mm,
  205. const nodemask_t *from_nodes,
  206. const nodemask_t *to_nodes, int flags)
  207. {
  208. return 0;
  209. }
  210. static inline void check_highest_zone(int k)
  211. {
  212. }
  213. #endif /* CONFIG_NUMA */
  214. #endif /* __KERNEL__ */
  215. #endif