mempolicy.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. #define MPOL_F_RELATIVE_NODES (1 << 14)
  24. /*
  25. * MPOL_MODE_FLAGS is the union of all possible optional mode flags passed to
  26. * either set_mempolicy() or mbind().
  27. */
  28. #define MPOL_MODE_FLAGS (MPOL_F_STATIC_NODES | MPOL_F_RELATIVE_NODES)
  29. /* Flags for get_mempolicy */
  30. #define MPOL_F_NODE (1<<0) /* return next IL mode instead of node mask */
  31. #define MPOL_F_ADDR (1<<1) /* look up vma using address */
  32. #define MPOL_F_MEMS_ALLOWED (1<<2) /* return allowed memories */
  33. /* Flags for mbind */
  34. #define MPOL_MF_STRICT (1<<0) /* Verify existing pages in the mapping */
  35. #define MPOL_MF_MOVE (1<<1) /* Move pages owned by this process to conform to mapping */
  36. #define MPOL_MF_MOVE_ALL (1<<2) /* Move every page to conform to mapping */
  37. #define MPOL_MF_INTERNAL (1<<3) /* Internal flags start here */
  38. #ifdef __KERNEL__
  39. #include <linux/mmzone.h>
  40. #include <linux/slab.h>
  41. #include <linux/rbtree.h>
  42. #include <linux/spinlock.h>
  43. #include <linux/nodemask.h>
  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_put() decrements the reference count to zero.
  62. *
  63. * Duplicating policy objects:
  64. * mpol_dup() 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_dup().
  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_put(struct mempolicy *pol);
  87. static inline void mpol_put(struct mempolicy *pol)
  88. {
  89. if (pol)
  90. __mpol_put(pol);
  91. }
  92. extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
  93. static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
  94. {
  95. if (pol)
  96. pol = __mpol_dup(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. /*
  114. * Tree of shared policies for a shared memory region.
  115. * Maintain the policies in a pseudo mm that contains vmas. The vmas
  116. * carry the policy. As a special twist the pseudo mm is indexed in pages, not
  117. * bytes, so that we can work with shared memory segments bigger than
  118. * unsigned long.
  119. */
  120. struct sp_node {
  121. struct rb_node nd;
  122. unsigned long start, end;
  123. struct mempolicy *policy;
  124. };
  125. struct shared_policy {
  126. struct rb_root root;
  127. spinlock_t lock;
  128. };
  129. void mpol_shared_policy_init(struct shared_policy *info, unsigned short policy,
  130. unsigned short flags, nodemask_t *nodes);
  131. int mpol_set_shared_policy(struct shared_policy *info,
  132. struct vm_area_struct *vma,
  133. struct mempolicy *new);
  134. void mpol_free_shared_policy(struct shared_policy *p);
  135. struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
  136. unsigned long idx);
  137. extern void numa_default_policy(void);
  138. extern void numa_policy_init(void);
  139. extern void mpol_rebind_task(struct task_struct *tsk,
  140. const nodemask_t *new);
  141. extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
  142. extern void mpol_fix_fork_child_flag(struct task_struct *p);
  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. static inline void mpol_put(struct mempolicy *p)
  162. {
  163. }
  164. static inline void mpol_get(struct mempolicy *pol)
  165. {
  166. }
  167. static inline struct mempolicy *mpol_dup(struct mempolicy *old)
  168. {
  169. return NULL;
  170. }
  171. struct shared_policy {};
  172. static inline int mpol_set_shared_policy(struct shared_policy *info,
  173. struct vm_area_struct *vma,
  174. struct mempolicy *new)
  175. {
  176. return -EINVAL;
  177. }
  178. static inline void mpol_shared_policy_init(struct shared_policy *info,
  179. unsigned short policy, unsigned short flags, nodemask_t *nodes)
  180. {
  181. }
  182. static inline void mpol_free_shared_policy(struct shared_policy *p)
  183. {
  184. }
  185. static inline struct mempolicy *
  186. mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
  187. {
  188. return NULL;
  189. }
  190. #define vma_policy(vma) NULL
  191. #define vma_set_policy(vma, pol) do {} while(0)
  192. static inline void numa_policy_init(void)
  193. {
  194. }
  195. static inline void numa_default_policy(void)
  196. {
  197. }
  198. static inline void mpol_rebind_task(struct task_struct *tsk,
  199. const nodemask_t *new)
  200. {
  201. }
  202. static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
  203. {
  204. }
  205. static inline void mpol_fix_fork_child_flag(struct task_struct *p)
  206. {
  207. }
  208. static inline struct zonelist *huge_zonelist(struct vm_area_struct *vma,
  209. unsigned long addr, gfp_t gfp_flags,
  210. struct mempolicy **mpol, nodemask_t **nodemask)
  211. {
  212. *mpol = NULL;
  213. *nodemask = NULL;
  214. return node_zonelist(0, gfp_flags);
  215. }
  216. static inline int do_migrate_pages(struct mm_struct *mm,
  217. const nodemask_t *from_nodes,
  218. const nodemask_t *to_nodes, int flags)
  219. {
  220. return 0;
  221. }
  222. static inline void check_highest_zone(int k)
  223. {
  224. }
  225. #endif /* CONFIG_NUMA */
  226. #endif /* __KERNEL__ */
  227. #endif