From: Andrey Ryabinin <[email protected]>

Reclaiming memory above memory.cache.limit_in_bytes always in direct
reclaim mode adds to much of a cost for vstorage. Instead of direct
reclaim allow to overflow memory.cache.limit_in_bytes but launch
the reclaim in background task.

https://pmc.acronis.com/browse/VSTOR-24395
https://jira.sw.ru/browse/PSBM-94761
Signed-off-by: Andrey Ryabinin <[email protected]>
(cherry picked from commit c7235680e58c0d7d792e8f47264ef233d2752b0b)

see ms 1a3e1f40 ("mm: memcontrol: decouple reference counting from page 
accounting")

https://jira.sw.ru/browse/PSBM-131957

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
---
 mm/memcontrol.c | 43 ++++++++++++++++++-------------------------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ac0ece68a17a..46fa926e35e2 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2538,12 +2538,16 @@ static unsigned long reclaim_high(struct mem_cgroup 
*memcg,
        unsigned long nr_reclaimed = 0;
 
        do {
-               if (page_counter_read(&memcg->memory) <=
-                   READ_ONCE(memcg->memory.high))
-                       continue;
-               memcg_memory_event(memcg, MEMCG_HIGH);
-               nr_reclaimed += try_to_free_mem_cgroup_pages(memcg, nr_pages,
-                                                            gfp_mask, true);
+               if (page_counter_read(&memcg->memory) >
+                   READ_ONCE(memcg->memory.high)) {
+                       memcg_memory_event(memcg, MEMCG_HIGH);
+                       nr_reclaimed += try_to_free_mem_cgroup_pages(memcg,
+                                               nr_pages, gfp_mask, true);
+               }
+
+               if (page_counter_read(&memcg->cache) > memcg->cache.max)
+                       nr_reclaimed += try_to_free_mem_cgroup_pages(memcg,
+                                               nr_pages, gfp_mask, false);
        } while ((memcg = parent_mem_cgroup(memcg)) &&
                 !mem_cgroup_is_root(memcg));
 
@@ -2825,12 +2829,7 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
                        goto charge;
                }
 
-               if (cache_charge && !page_counter_try_charge(
-                               &memcg->cache, nr_pages, &counter)) {
-                       refill_stock(memcg, nr_pages);
-                       goto charge;
-               }
-               return 0;
+               goto done;
        }
 
 charge:
@@ -2855,19 +2854,6 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
                }
        }
 
-       if (!mem_over_limit && cache_charge) {
-               if (page_counter_try_charge(&memcg->cache, nr_pages, &counter))
-                       goto done_restock;
-
-               may_swap = false;
-               mem_over_limit = mem_cgroup_from_counter(counter, cache);
-               page_counter_uncharge(&memcg->memory, batch);
-               if (do_memsw_account())
-                       page_counter_uncharge(&memcg->memsw, batch);
-               if (kmem_charge)
-                       page_counter_uncharge(&memcg->kmem, nr_pages);
-       }
-
        if (!mem_over_limit)
                goto done_restock;
 
@@ -3006,6 +2992,9 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
 
        if (batch > nr_pages)
                refill_stock(memcg, batch - nr_pages);
+done:
+       if (cache_charge)
+               page_counter_charge(&memcg->cache, nr_pages);
 
        /*
         * If the hierarchy is above the normal consumption range, schedule
@@ -3046,7 +3035,11 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t 
gfp_mask, bool kmem_charge
                        current->memcg_nr_pages_over_high += batch;
                        set_notify_resume(current);
                        break;
+               } else if (page_counter_read(&memcg->cache) > memcg->cache.max) 
{
+                       if (!work_pending(&memcg->high_work))
+                               schedule_work(&memcg->high_work);
                }
+
        } while ((memcg = parent_mem_cgroup(memcg)));
 
        return 0;
-- 
2.28.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to