mempolicy.h 6.6 KB

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