History

mm/page_alloc: fix memalloc_nocma_{save/restore} APIs

Currently, memalloc_nocma_{save/restore} API that prevents CMA area in page allocation is implemented by using current_gfp_context(). However, there are two problems of this implementation. First, this doesn't work for allocation fastpath. In the fastpath, original gfp_mask is used since current_gfp_context() is introduced in order to control reclaim and it is on slowpath. So, CMA area can be allocated through the allocation fastpath even if memalloc_nocma_{save/restore} APIs are used. Currently, there is just one user for these APIs and it has a fallback method to prevent actual problem. Second, clearing __GFP_MOVABLE in current_gfp_context() has a side effect to exclude the memory on the ZONE_MOVABLE for allocation target. To fix these problems, this patch changes the implementation to exclude CMA area in page allocation. Main point of this change is using the alloc_flags. alloc_flags is mainly used to control allocation so it fits for excluding CMA area in allocation.

Joonsoo Kim committed 6 years ago

Commit 8510e691 parent 182f3d72 files · +22 −17Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/sched/mm.h+1−7
@@ -175,12 +175,10 @@ static inline bool in_vfork(struct task_struct *tsk) · 174 unmodified lines
175175 * Applies per-task gfp context to the given allocation flags.
176176 * PF_MEMALLOC_NOIO implies GFP_NOIO
177177 * PF_MEMALLOC_NOFS implies GFP_NOFS
178− * PF_MEMALLOC_NOCMA implies no allocation from CMA region.
179178 */
180179 static inline gfp_t current_gfp_context(gfp_t flags)
181180 {
182− if (unlikely(current->flags &
183− (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS | PF_MEMALLOC_NOCMA))) {
181+ if (unlikely(current->flags & (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS))) {
184182 /*
185183 * NOIO implies both NOIO and NOFS and it is a weaker context
186184 * so always make sure it makes precedence
@@ -189,10 +187,6 @@ static inline gfp_t current_gfp_context(gfp_t flags) · 2 unmodified lines
189187 flags &= ~(__GFP_IO | __GFP_FS);
190188 else if (current->flags & PF_MEMALLOC_NOFS)
191189 flags &= ~__GFP_FS;
192−#ifdef CONFIG_CMA
193− if (current->flags & PF_MEMALLOC_NOCMA)
194− flags &= ~__GFP_MOVABLE;
195−#endif
196190 }
197191 return flags;
198192 }