File Index
Files and directories
Sign in
FILE

mempolicy.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/mempolicy.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * NUMA memory policies for Linux.
  4 * Copyright 2003,2004 Andi Kleen SuSE Labs
  5 */
  6#ifndef _LINUX_MEMPOLICY_H
  7#define _LINUX_MEMPOLICY_H 1
  8
  9#include <linux/sched.h>
 10#include <linux/mmzone.h>
 11#include <linux/slab.h>
 12#include <linux/rbtree.h>
 13#include <linux/spinlock.h>
 14#include <linux/node.h>
 15#include <linux/nodemask.h>
 16#include <linux/pagemap.h>
 17#include <uapi/linux/mempolicy.h>
 18
 19struct mm_struct;
 20
 21#define NO_INTERLEAVE_INDEX (-1UL)	/* use task il_prev for interleaving */
 22
 23#ifdef CONFIG_NUMA
 24
 25/*
 26 * Describe a memory policy.
 27 *
 28 * A mempolicy can be either associated with a process or with a VMA.
 29 * For VMA related allocations the VMA policy is preferred, otherwise
 30 * the process policy is used. Interrupts ignore the memory policy
 31 * of the current process.
 32 *
 33 * Locking policy for interleave:
 34 * In process context there is no locking because only the process accesses
 35 * its own state. All vma manipulation is somewhat protected by a down_read on
 36 * mmap_lock.
 37 *
 38 * Freeing policy:
 39 * Mempolicy objects are reference counted.  A mempolicy will be freed when
 40 * mpol_put() decrements the reference count to zero.
 41 *
 42 * Duplicating policy objects:
 43 * mpol_dup() allocates a new mempolicy and copies the specified mempolicy
 44 * to the new storage.  The reference count of the new object is initialized
 45 * to 1, representing the caller of mpol_dup().
 46 */
 47struct mempolicy {
 48	atomic_t refcnt;
 49	unsigned short mode; 	/* See MPOL_* above */
 50	unsigned short flags;	/* See set_mempolicy() MPOL_F_* above */
 51	nodemask_t nodes;	/* interleave/bind/preferred/etc */
 52	int home_node;		/* Home node to use for MPOL_BIND and MPOL_PREFERRED_MANY */
 53
 54	union {
 55		nodemask_t cpuset_mems_allowed;	/* relative to these nodes */
 56		nodemask_t user_nodemask;	/* nodemask passed by user */
 57	} w;
 58	struct rcu_head rcu;
 59};
 60
 61/*
 62 * Support for managing mempolicy data objects (clone, copy, destroy)
 63 * The default fast path of a NULL MPOL_DEFAULT policy is always inlined.
 64 */
 65
 66extern void __mpol_put(struct mempolicy *pol);
 67static inline void mpol_put(struct mempolicy *pol)
 68{
 69	if (pol)
 70		__mpol_put(pol);
 71}
 72
 73/*
 74 * Does mempolicy pol need explicit unref after use?
 75 * Currently only needed for shared policies.
 76 */
 77static inline int mpol_needs_cond_ref(struct mempolicy *pol)
 78{
 79	return (pol && (pol->flags & MPOL_F_SHARED));
 80}
 81
 82static inline void mpol_cond_put(struct mempolicy *pol)
 83{
 84	if (mpol_needs_cond_ref(pol))
 85		__mpol_put(pol);
 86}
 87
 88extern struct mempolicy *__mpol_dup(struct mempolicy *pol);
 89static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
 90{
 91	if (pol)
 92		pol = __mpol_dup(pol);
 93	return pol;
 94}
 95
 96static inline void mpol_get(struct mempolicy *pol)
 97{
 98	if (pol)
 99		atomic_inc(&pol->refcnt);
100}
101
102extern bool __mpol_equal(struct mempolicy *a, struct mempolicy *b);
103static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b)
104{
105	if (a == b)
106		return true;
107	return __mpol_equal(a, b);
108}
109
110/*
111 * Tree of shared policies for a shared memory region.
112 */
113struct shared_policy {
114	struct rb_root root;
115	rwlock_t lock;
116};
117struct sp_node {
118	struct rb_node nd;
119	pgoff_t start, end;
120	struct mempolicy *policy;
121};
122
123int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst);
124void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol);
125int mpol_set_shared_policy(struct shared_policy *sp,
126			   struct vm_area_struct *vma, struct mempolicy *mpol);
127void mpol_free_shared_policy(struct shared_policy *sp);
128struct mempolicy *mpol_shared_policy_lookup(struct shared_policy *sp,
129					    pgoff_t idx);
130
131struct mempolicy *get_task_policy(struct task_struct *p);
132struct mempolicy *__get_vma_policy(struct vm_area_struct *vma,
133		unsigned long addr, pgoff_t *ilx);
134struct mempolicy *get_vma_policy(struct vm_area_struct *vma,
135		unsigned long addr, int order, pgoff_t *ilx);
136bool vma_policy_mof(struct vm_area_struct *vma);
137
138extern void numa_default_policy(void);
139extern void numa_policy_init(void);
140extern void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new);
141extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
142
143extern int huge_node(struct vm_area_struct *vma,
144				unsigned long addr, gfp_t gfp_flags,
145				struct mempolicy **mpol, nodemask_t **nodemask);
146extern bool init_nodemask_of_mempolicy(nodemask_t *mask);
147extern bool mempolicy_in_oom_domain(struct task_struct *tsk,
148				const nodemask_t *mask);
149extern unsigned int mempolicy_slab_node(void);
150
151extern enum zone_type policy_zone;
152
153static inline void check_highest_zone(enum zone_type k)
154{
155	if (k > policy_zone && k != ZONE_MOVABLE)
156		policy_zone = k;
157}
158
159int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
160		     const nodemask_t *to, int flags);
161
162
163#ifdef CONFIG_TMPFS
164extern int mpol_parse_str(char *str, struct mempolicy **mpol);
165#endif
166
167extern void mpol_to_str(char *buffer, int maxlen, struct mempolicy *pol);
168
169/* Check if a vma is migratable */
170extern bool vma_migratable(struct vm_area_struct *vma);
171
172int mpol_misplaced(struct folio *folio, struct vm_fault *vmf,
173					unsigned long addr);
174extern void mpol_put_task_policy(struct task_struct *);
175
176static inline bool mpol_is_preferred_many(struct mempolicy *pol)
177{
178	return  (pol->mode == MPOL_PREFERRED_MANY);
179}
180
181extern bool apply_policy_zone(struct mempolicy *policy, enum zone_type zone);
182
183extern int mempolicy_set_node_perf(unsigned int node,
184				   struct access_coordinate *coords);
185
186#else
187
188struct mempolicy {};
189
190static inline struct mempolicy *get_task_policy(struct task_struct *p)
191{
192	return NULL;
193}
194
195static inline bool mpol_equal(struct mempolicy *a, struct mempolicy *b)
196{
197	return true;
198}
199
200static inline void mpol_put(struct mempolicy *pol)
201{
202}
203
204static inline void mpol_cond_put(struct mempolicy *pol)
205{
206}
207
208static inline void mpol_get(struct mempolicy *pol)
209{
210}
211
212struct shared_policy {};
213
214static inline void mpol_shared_policy_init(struct shared_policy *sp,
215						struct mempolicy *mpol)
216{
217}
218
219static inline void mpol_free_shared_policy(struct shared_policy *sp)
220{
221}
222
223static inline struct mempolicy *
224mpol_shared_policy_lookup(struct shared_policy *sp, pgoff_t idx)
225{
226	return NULL;
227}
228
229static inline struct mempolicy *get_vma_policy(struct vm_area_struct *vma,
230				unsigned long addr, int order, pgoff_t *ilx)
231{
232	*ilx = 0;
233	return NULL;
234}
235
236static inline int
237vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
238{
239	return 0;
240}
241
242static inline void numa_policy_init(void)
243{
244}
245
246static inline void numa_default_policy(void)
247{
248}
249
250static inline void mpol_rebind_task(struct task_struct *tsk,
251				const nodemask_t *new)
252{
253}
254
255static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
256{
257}
258
259static inline int huge_node(struct vm_area_struct *vma,
260				unsigned long addr, gfp_t gfp_flags,
261				struct mempolicy **mpol, nodemask_t **nodemask)
262{
263	*mpol = NULL;
264	*nodemask = NULL;
265	return 0;
266}
267
268static inline bool init_nodemask_of_mempolicy(nodemask_t *m)
269{
270	return false;
271}
272
273static inline int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from,
274				   const nodemask_t *to, int flags)
275{
276	return 0;
277}
278
279static inline void check_highest_zone(int k)
280{
281}
282
283#ifdef CONFIG_TMPFS
284static inline int mpol_parse_str(char *str, struct mempolicy **mpol)
285{
286	return 1;	/* error */
287}
288#endif
289
290static inline int mpol_misplaced(struct folio *folio,
291				 struct vm_fault *vmf,
292				 unsigned long address)
293{
294	return -1; /* no node preference */
295}
296
297static inline void mpol_put_task_policy(struct task_struct *task)
298{
299}
300
301static inline bool mpol_is_preferred_many(struct mempolicy *pol)
302{
303	return  false;
304}
305
306#endif /* CONFIG_NUMA */
307#endif
~/ Read-only file preview.