Re: [Devel] [PATCH rh7 v4] mm/memcg: fix cache growth above cache.limit_in_bytes

2020-09-24 Thread Konstantin Khorenko

Andrey, please port fixes for memcg.cache.limit_in_bytes feature to vz8 as well.

AFAIS, the initial patch has been committed to vz8 already:
vz8: 0d64967242fd mm/memcg: limit page cache in memcg hack

But vz7 has several more fixes for it, which are to be ported yet:
vz7: 1bfd6445b3f29f503d9693254826283a8be65cfe mm/memcg: reclaim 
memory.cache.limit_in_bytes from background
vz7: 7e96384c9557dc9bd2525a2afb95630c866c7090 mm/memcg: fix cache growth above 
cache.limit_in_bytes
vz7: d7bab0af6a65 mm: try harder to decrease cache.limit_in_bytes

Thank you.

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 07/30/2020 06:02 PM, Andrey Ryabinin wrote:

Exceeding cache above cache.limit_in_bytes schedules high_work_func()
which tries to reclaim 32 pages. If cache generated fast enough or it allows
cgroup to steadily grow above cache.limit_in_bytes because we don't reclaim
enough. Try to reclaim exceeded amount of cache instead.

https://jira.sw.ru/browse/PSBM-106384
Signed-off-by: Andrey Ryabinin 
---

 - Changes since v1: add bug link to changelog
 - Changes since v2: Fix cache_overused check (We should check if it's 
positive).
Made this stupid bug during cleanup, patch was tested without bogus cleanup,
so it shoud work.
 - Chnages since v3: Compilation fixes, properly tested now.

 mm/memcontrol.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3cf200f506c3..16cbd451a588 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3080,12 +3080,16 @@ static void reclaim_high(struct mem_cgroup *memcg,
 {

do {
+   long cache_overused;
+
if (page_counter_read(>memory) > memcg->high)
try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
0);

-   if (page_counter_read(>cache) > memcg->cache.limit)
-   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask,
-   MEM_CGROUP_RECLAIM_NOSWAP);
+   cache_overused = page_counter_read(>cache) -
+   memcg->cache.limit;
+   if (cache_overused > 0)
+   try_to_free_mem_cgroup_pages(memcg, cache_overused,
+   gfp_mask, MEM_CGROUP_RECLAIM_NOSWAP);

} while ((memcg = parent_mem_cgroup(memcg)));
 }


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH rh7 v4] mm/memcg: fix cache growth above cache.limit_in_bytes

2020-07-30 Thread Andrey Ryabinin


On 7/30/20 6:52 PM, Evgenii Shatokhin wrote:
> Hi,
> 
> On 30.07.2020 18:02, Andrey Ryabinin wrote:
>> Exceeding cache above cache.limit_in_bytes schedules high_work_func()
>> which tries to reclaim 32 pages. If cache generated fast enough or it allows
>> cgroup to steadily grow above cache.limit_in_bytes because we don't reclaim
>> enough. Try to reclaim exceeded amount of cache instead.
>>
>> https://jira.sw.ru/browse/PSBM-106384
>> Signed-off-by: Andrey Ryabinin 
>> ---
>>
>>   - Changes since v1: add bug link to changelog
>>   - Changes since v2: Fix cache_overused check (We should check if it's 
>> positive).
>>  Made this stupid bug during cleanup, patch was tested without bogus 
>> cleanup,
>>  so it shoud work.
>>   - Chnages since v3: Compilation fixes, properly tested now.
>>
>>   mm/memcontrol.c | 10 +++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
>> index 3cf200f506c3..16cbd451a588 100644
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -3080,12 +3080,16 @@ static void reclaim_high(struct mem_cgroup *memcg,
>>   {
>>     do {
>> +    long cache_overused;
>> +
>>   if (page_counter_read(>memory) > memcg->high)
>>   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 0);
>>   -    if (page_counter_read(>cache) > memcg->cache.limit)
>> -    try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask,
>> -    MEM_CGROUP_RECLAIM_NOSWAP);
>> +    cache_overused = page_counter_read(>cache) -
>> +    memcg->cache.limit;
> 
> If cache_overused is less than 32 pages, the kernel would try to reclaim less 
> than before the patch. It it OK, or should it try to reclaim at least 32 
> pages?

It's ok, try_to_free_mem_cgroup_pages will increase it:

unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
   unsigned long nr_pages,
   gfp_t gfp_mask,
   int flags)


.nr_to_reclaim = max(nr_pages, SWAP_CLUSTER_MAX),


___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [PATCH rh7 v4] mm/memcg: fix cache growth above cache.limit_in_bytes

2020-07-30 Thread Evgenii Shatokhin

Hi,

On 30.07.2020 18:02, Andrey Ryabinin wrote:

Exceeding cache above cache.limit_in_bytes schedules high_work_func()
which tries to reclaim 32 pages. If cache generated fast enough or it allows
cgroup to steadily grow above cache.limit_in_bytes because we don't reclaim
enough. Try to reclaim exceeded amount of cache instead.

https://jira.sw.ru/browse/PSBM-106384
Signed-off-by: Andrey Ryabinin 
---

  - Changes since v1: add bug link to changelog
  - Changes since v2: Fix cache_overused check (We should check if it's 
positive).
 Made this stupid bug during cleanup, patch was tested without bogus 
cleanup,
 so it shoud work.
  - Chnages since v3: Compilation fixes, properly tested now.

  mm/memcontrol.c | 10 +++---
  1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3cf200f506c3..16cbd451a588 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3080,12 +3080,16 @@ static void reclaim_high(struct mem_cgroup *memcg,
  {
  
  	do {

+   long cache_overused;
+
if (page_counter_read(>memory) > memcg->high)
try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
0);
  
-		if (page_counter_read(>cache) > memcg->cache.limit)

-   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask,
-   MEM_CGROUP_RECLAIM_NOSWAP);
+   cache_overused = page_counter_read(>cache) -
+   memcg->cache.limit;


If cache_overused is less than 32 pages, the kernel would try to reclaim 
less than before the patch. It it OK, or should it try to reclaim at 
least 32 pages?



+   if (cache_overused > 0)
+   try_to_free_mem_cgroup_pages(memcg, cache_overused,
+   gfp_mask, MEM_CGROUP_RECLAIM_NOSWAP);
  
  	} while ((memcg = parent_mem_cgroup(memcg)));

  }



___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH rh7 v4] mm/memcg: fix cache growth above cache.limit_in_bytes

2020-07-30 Thread Andrey Ryabinin
Exceeding cache above cache.limit_in_bytes schedules high_work_func()
which tries to reclaim 32 pages. If cache generated fast enough or it allows
cgroup to steadily grow above cache.limit_in_bytes because we don't reclaim
enough. Try to reclaim exceeded amount of cache instead.

https://jira.sw.ru/browse/PSBM-106384
Signed-off-by: Andrey Ryabinin 
---

 - Changes since v1: add bug link to changelog
 - Changes since v2: Fix cache_overused check (We should check if it's 
positive).
Made this stupid bug during cleanup, patch was tested without bogus cleanup,
so it shoud work.
 - Chnages since v3: Compilation fixes, properly tested now.

 mm/memcontrol.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3cf200f506c3..16cbd451a588 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3080,12 +3080,16 @@ static void reclaim_high(struct mem_cgroup *memcg,
 {
 
do {
+   long cache_overused;
+
if (page_counter_read(>memory) > memcg->high)
try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask, 
0);
 
-   if (page_counter_read(>cache) > memcg->cache.limit)
-   try_to_free_mem_cgroup_pages(memcg, nr_pages, gfp_mask,
-   MEM_CGROUP_RECLAIM_NOSWAP);
+   cache_overused = page_counter_read(>cache) -
+   memcg->cache.limit;
+   if (cache_overused > 0)
+   try_to_free_mem_cgroup_pages(memcg, cache_overused,
+   gfp_mask, MEM_CGROUP_RECLAIM_NOSWAP);
 
} while ((memcg = parent_mem_cgroup(memcg)));
 }
-- 
2.26.2

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel