mm.h (754451342fc5954061ede74b0a8485ec4a4c6eaa) mm.h (46ca359955fee63486dc1cfc528ae5692bb16dcd)
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_SCHED_MM_H
3#define _LINUX_SCHED_MM_H
4
5#include <linux/kernel.h>
6#include <linux/atomic.h>
7#include <linux/sched.h>
8#include <linux/mm_types.h>

--- 14 unchanged lines hidden (view full) ---

23 * will still exist later on and mmget_not_zero() has to be used before
24 * accessing it.
25 *
26 * This is a preferred way to to pin @mm for a longer/unbounded amount
27 * of time.
28 *
29 * Use mmdrop() to release the reference acquired by mmgrab().
30 *
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_SCHED_MM_H
3#define _LINUX_SCHED_MM_H
4
5#include <linux/kernel.h>
6#include <linux/atomic.h>
7#include <linux/sched.h>
8#include <linux/mm_types.h>

--- 14 unchanged lines hidden (view full) ---

23 * will still exist later on and mmget_not_zero() has to be used before
24 * accessing it.
25 *
26 * This is a preferred way to to pin @mm for a longer/unbounded amount
27 * of time.
28 *
29 * Use mmdrop() to release the reference acquired by mmgrab().
30 *
31 * See also <Documentation/vm/active_mm.txt> for an in-depth explanation
31 * See also <Documentation/vm/active_mm.rst> for an in-depth explanation
32 * of &mm_struct.mm_count vs &mm_struct.mm_users.
33 */
34static inline void mmgrab(struct mm_struct *mm)
35{
36 atomic_inc(&mm->mm_count);
37}
38
39extern void __mmdrop(struct mm_struct *mm);

--- 17 unchanged lines hidden (view full) ---

57 * go away. This does not protect against parts of the address space being
58 * modified or freed, however.
59 *
60 * Never use this function to pin this address space for an
61 * unbounded/indefinite amount of time.
62 *
63 * Use mmput() to release the reference acquired by mmget().
64 *
32 * of &mm_struct.mm_count vs &mm_struct.mm_users.
33 */
34static inline void mmgrab(struct mm_struct *mm)
35{
36 atomic_inc(&mm->mm_count);
37}
38
39extern void __mmdrop(struct mm_struct *mm);

--- 17 unchanged lines hidden (view full) ---

57 * go away. This does not protect against parts of the address space being
58 * modified or freed, however.
59 *
60 * Never use this function to pin this address space for an
61 * unbounded/indefinite amount of time.
62 *
63 * Use mmput() to release the reference acquired by mmget().
64 *
65 * See also <Documentation/vm/active_mm.txt> for an in-depth explanation
65 * See also <Documentation/vm/active_mm.rst> for an in-depth explanation
66 * of &mm_struct.mm_count vs &mm_struct.mm_users.
67 */
68static inline void mmget(struct mm_struct *mm)
69{
70 atomic_inc(&mm->mm_users);
71}
72
73static inline bool mmget_not_zero(struct mm_struct *mm)

--- 91 unchanged lines hidden (view full) ---

165#ifdef CONFIG_LOCKDEP
166extern void fs_reclaim_acquire(gfp_t gfp_mask);
167extern void fs_reclaim_release(gfp_t gfp_mask);
168#else
169static inline void fs_reclaim_acquire(gfp_t gfp_mask) { }
170static inline void fs_reclaim_release(gfp_t gfp_mask) { }
171#endif
172
66 * of &mm_struct.mm_count vs &mm_struct.mm_users.
67 */
68static inline void mmget(struct mm_struct *mm)
69{
70 atomic_inc(&mm->mm_users);
71}
72
73static inline bool mmget_not_zero(struct mm_struct *mm)

--- 91 unchanged lines hidden (view full) ---

165#ifdef CONFIG_LOCKDEP
166extern void fs_reclaim_acquire(gfp_t gfp_mask);
167extern void fs_reclaim_release(gfp_t gfp_mask);
168#else
169static inline void fs_reclaim_acquire(gfp_t gfp_mask) { }
170static inline void fs_reclaim_release(gfp_t gfp_mask) { }
171#endif
172
173/**
174 * memalloc_noio_save - Marks implicit GFP_NOIO allocation scope.
175 *
176 * This functions marks the beginning of the GFP_NOIO allocation scope.
177 * All further allocations will implicitly drop __GFP_IO flag and so
178 * they are safe for the IO critical section from the allocation recursion
179 * point of view. Use memalloc_noio_restore to end the scope with flags
180 * returned by this function.
181 *
182 * This function is safe to be used from any context.
183 */
173static inline unsigned int memalloc_noio_save(void)
174{
175 unsigned int flags = current->flags & PF_MEMALLOC_NOIO;
176 current->flags |= PF_MEMALLOC_NOIO;
177 return flags;
178}
179
184static inline unsigned int memalloc_noio_save(void)
185{
186 unsigned int flags = current->flags & PF_MEMALLOC_NOIO;
187 current->flags |= PF_MEMALLOC_NOIO;
188 return flags;
189}
190
191/**
192 * memalloc_noio_restore - Ends the implicit GFP_NOIO scope.
193 * @flags: Flags to restore.
194 *
195 * Ends the implicit GFP_NOIO scope started by memalloc_noio_save function.
196 * Always make sure that that the given flags is the return value from the
197 * pairing memalloc_noio_save call.
198 */
180static inline void memalloc_noio_restore(unsigned int flags)
181{
182 current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags;
183}
184
199static inline void memalloc_noio_restore(unsigned int flags)
200{
201 current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags;
202}
203
204/**
205 * memalloc_nofs_save - Marks implicit GFP_NOFS allocation scope.
206 *
207 * This functions marks the beginning of the GFP_NOFS allocation scope.
208 * All further allocations will implicitly drop __GFP_FS flag and so
209 * they are safe for the FS critical section from the allocation recursion
210 * point of view. Use memalloc_nofs_restore to end the scope with flags
211 * returned by this function.
212 *
213 * This function is safe to be used from any context.
214 */
185static inline unsigned int memalloc_nofs_save(void)
186{
187 unsigned int flags = current->flags & PF_MEMALLOC_NOFS;
188 current->flags |= PF_MEMALLOC_NOFS;
189 return flags;
190}
191
215static inline unsigned int memalloc_nofs_save(void)
216{
217 unsigned int flags = current->flags & PF_MEMALLOC_NOFS;
218 current->flags |= PF_MEMALLOC_NOFS;
219 return flags;
220}
221
222/**
223 * memalloc_nofs_restore - Ends the implicit GFP_NOFS scope.
224 * @flags: Flags to restore.
225 *
226 * Ends the implicit GFP_NOFS scope started by memalloc_nofs_save function.
227 * Always make sure that that the given flags is the return value from the
228 * pairing memalloc_nofs_save call.
229 */
192static inline void memalloc_nofs_restore(unsigned int flags)
193{
194 current->flags = (current->flags & ~PF_MEMALLOC_NOFS) | flags;
195}
196
197static inline unsigned int memalloc_noreclaim_save(void)
198{
199 unsigned int flags = current->flags & PF_MEMALLOC;

--- 56 unchanged lines hidden ---
230static inline void memalloc_nofs_restore(unsigned int flags)
231{
232 current->flags = (current->flags & ~PF_MEMALLOC_NOFS) | flags;
233}
234
235static inline unsigned int memalloc_noreclaim_save(void)
236{
237 unsigned int flags = current->flags & PF_MEMALLOC;

--- 56 unchanged lines hidden ---