mempolicy.h 7.1 KB

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