Refactor try_charge_memcg by flattening the nested memsw/memory page_counter operations to separate the logic between the two.
When page_counter_try_charge is made stock-aware, this flattening makes the control flow easier to follow since each page counter now has its own success/failure paths. No functional changes intended. Signed-off-by: Joshua Hahn <[email protected]> --- mm/memcontrol.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bf829638524b5..93c2fa04da4fd 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2679,18 +2679,21 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, batch = nr_pages; reclaim_options = MEMCG_RECLAIM_MAY_SWAP; - if (!do_memsw_account() || - page_counter_try_charge(&memcg->memsw, batch, &counter)) { - if (page_counter_try_charge(&memcg->memory, batch, &counter)) - goto done_restock; - if (do_memsw_account()) - page_counter_uncharge(&memcg->memsw, batch); - mem_over_limit = mem_cgroup_from_counter(counter, memory); - } else { + if (do_memsw_account() && + !page_counter_try_charge(&memcg->memsw, batch, &counter)) { mem_over_limit = mem_cgroup_from_counter(counter, memsw); reclaim_options &= ~MEMCG_RECLAIM_MAY_SWAP; + goto reclaim; } + if (page_counter_try_charge(&memcg->memory, batch, &counter)) + goto done_restock; + + if (do_memsw_account()) + page_counter_uncharge(&memcg->memsw, batch); + mem_over_limit = mem_cgroup_from_counter(counter, memory); + +reclaim: if (batch > nr_pages) { batch = nr_pages; goto retry; -- 2.53.0-Meta
