mempolicy.h 7.1 KB

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