aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sched/mm.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/sched/mm.h')
-rw-r--r--include/linux/sched/mm.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 830953ebb391..9daabe138c99 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -149,13 +149,21 @@ static inline bool in_vfork(struct task_struct *tsk)
149 return ret; 149 return ret;
150} 150}
151 151
152/* __GFP_IO isn't allowed if PF_MEMALLOC_NOIO is set in current->flags 152/*
153 * __GFP_FS is also cleared as it implies __GFP_IO. 153 * Applies per-task gfp context to the given allocation flags.
154 * PF_MEMALLOC_NOIO implies GFP_NOIO
155 * PF_MEMALLOC_NOFS implies GFP_NOFS
154 */ 156 */
155static inline gfp_t memalloc_noio_flags(gfp_t flags) 157static inline gfp_t current_gfp_context(gfp_t flags)
156{ 158{
159 /*
160 * NOIO implies both NOIO and NOFS and it is a weaker context
161 * so always make sure it makes precendence
162 */
157 if (unlikely(current->flags & PF_MEMALLOC_NOIO)) 163 if (unlikely(current->flags & PF_MEMALLOC_NOIO))
158 flags &= ~(__GFP_IO | __GFP_FS); 164 flags &= ~(__GFP_IO | __GFP_FS);
165 else if (unlikely(current->flags & PF_MEMALLOC_NOFS))
166 flags &= ~__GFP_FS;
159 return flags; 167 return flags;
160} 168}
161 169
@@ -171,4 +179,16 @@ static inline void memalloc_noio_restore(unsigned int flags)
171 current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags; 179 current->flags = (current->flags & ~PF_MEMALLOC_NOIO) | flags;
172} 180}
173 181
182static inline unsigned int memalloc_nofs_save(void)
183{
184 unsigned int flags = current->flags & PF_MEMALLOC_NOFS;
185 current->flags |= PF_MEMALLOC_NOFS;
186 return flags;
187}
188
189static inline void memalloc_nofs_restore(unsigned int flags)
190{
191 current->flags = (current->flags & ~PF_MEMALLOC_NOFS) | flags;
192}
193
174#endif /* _LINUX_SCHED_MM_H */ 194#endif /* _LINUX_SCHED_MM_H */