mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-31 12:10:52 -04:00
mm: introduce memalloc_noreclaim_{save,restore}
The previous patch ("mm: prevent potential recursive reclaim due to
clearing PF_MEMALLOC") has shown that simply setting and clearing
PF_MEMALLOC in current->flags can result in wrongly clearing a
pre-existing PF_MEMALLOC flag and potentially lead to recursive reclaim.
Let's introduce helpers that support proper nesting by saving the
previous stat of the flag, similar to the existing memalloc_noio_* and
memalloc_nofs_* helpers. Convert existing setting/clearing of
PF_MEMALLOC within mm to the new helpers.
There are no known issues with the converted code, but the change makes
it more robust.
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Vlastimil Babka <[email protected]>
Suggested-by: Michal Hocko <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Hillf Danton <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Boris Brezillon <[email protected]>
Cc: Chris Leech <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Josef Bacik <[email protected]>
Cc: Lee Duncan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Richard Weinberger <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
62be1511b1
commit
499118e966
3 changed files with 29 additions and 11 deletions
17
mm/vmscan.c
17
mm/vmscan.c
|
|
@ -3036,6 +3036,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
|
|||
struct zonelist *zonelist;
|
||||
unsigned long nr_reclaimed;
|
||||
int nid;
|
||||
unsigned int noreclaim_flag;
|
||||
struct scan_control sc = {
|
||||
.nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX),
|
||||
.gfp_mask = (current_gfp_context(gfp_mask) & GFP_RECLAIM_MASK) |
|
||||
|
|
@ -3062,9 +3063,9 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
|
|||
sc.gfp_mask,
|
||||
sc.reclaim_idx);
|
||||
|
||||
current->flags |= PF_MEMALLOC;
|
||||
noreclaim_flag = memalloc_noreclaim_save();
|
||||
nr_reclaimed = do_try_to_free_pages(zonelist, &sc);
|
||||
current->flags &= ~PF_MEMALLOC;
|
||||
memalloc_noreclaim_restore(noreclaim_flag);
|
||||
|
||||
trace_mm_vmscan_memcg_reclaim_end(nr_reclaimed);
|
||||
|
||||
|
|
@ -3589,8 +3590,9 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
|
|||
struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask);
|
||||
struct task_struct *p = current;
|
||||
unsigned long nr_reclaimed;
|
||||
unsigned int noreclaim_flag;
|
||||
|
||||
p->flags |= PF_MEMALLOC;
|
||||
noreclaim_flag = memalloc_noreclaim_save();
|
||||
lockdep_set_current_reclaim_state(sc.gfp_mask);
|
||||
reclaim_state.reclaimed_slab = 0;
|
||||
p->reclaim_state = &reclaim_state;
|
||||
|
|
@ -3599,7 +3601,7 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim)
|
|||
|
||||
p->reclaim_state = NULL;
|
||||
lockdep_clear_current_reclaim_state();
|
||||
p->flags &= ~PF_MEMALLOC;
|
||||
memalloc_noreclaim_restore(noreclaim_flag);
|
||||
|
||||
return nr_reclaimed;
|
||||
}
|
||||
|
|
@ -3764,6 +3766,7 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in
|
|||
struct task_struct *p = current;
|
||||
struct reclaim_state reclaim_state;
|
||||
int classzone_idx = gfp_zone(gfp_mask);
|
||||
unsigned int noreclaim_flag;
|
||||
struct scan_control sc = {
|
||||
.nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX),
|
||||
.gfp_mask = (gfp_mask = current_gfp_context(gfp_mask)),
|
||||
|
|
@ -3781,7 +3784,8 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in
|
|||
* and we also need to be able to write out pages for RECLAIM_WRITE
|
||||
* and RECLAIM_UNMAP.
|
||||
*/
|
||||
p->flags |= PF_MEMALLOC | PF_SWAPWRITE;
|
||||
noreclaim_flag = memalloc_noreclaim_save();
|
||||
p->flags |= PF_SWAPWRITE;
|
||||
lockdep_set_current_reclaim_state(gfp_mask);
|
||||
reclaim_state.reclaimed_slab = 0;
|
||||
p->reclaim_state = &reclaim_state;
|
||||
|
|
@ -3797,7 +3801,8 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in
|
|||
}
|
||||
|
||||
p->reclaim_state = NULL;
|
||||
current->flags &= ~(PF_MEMALLOC | PF_SWAPWRITE);
|
||||
current->flags &= ~PF_SWAPWRITE;
|
||||
memalloc_noreclaim_restore(noreclaim_flag);
|
||||
lockdep_clear_current_reclaim_state();
|
||||
return sc.nr_reclaimed >= nr_pages;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue