Message ID | 20231027093004.681270-1-suruifeng1@huawei.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm, memcg: avoid recycling when there is no more recyclable memory | expand |
Hello. On Fri, Oct 27, 2023 at 05:30:04PM +0800, Ruifeng Su <suruifeng1@huawei.com> wrote: > The test result shows that the program frequently sync iCache & dcache. > As a result, > the number of anon pages requested by the program cannot increase. memory.high can be a tar-pit (instead of OOM). > This patch changes the behavior of retry recycling. What is behavior of your program after the change? And what behavior do you expect? > @@ -2616,7 +2615,7 @@ void mem_cgroup_handle_over_high(gfp_t gfp_mask) > * memory.high, we want to encourage that rather than doing allocator > * throttling. > */ > - if (nr_reclaimed || nr_retries--) { > + if (nr_reclaimed >= (in_retry ? SWAP_CLUSTER_MAX : nr_pages)) { So this reads better as if (nr_reclaimed >= to_reclaim) > in_retry = true; > goto retry_reclaim; > } So it would unnecessarily overreclaim in some cases. Regards, Michal
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5b009b233ab8..e6b5d2ddb4d2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2561,7 +2561,6 @@ void mem_cgroup_handle_over_high(gfp_t gfp_mask) unsigned long pflags; unsigned long nr_reclaimed; unsigned int nr_pages = current->memcg_nr_pages_over_high; - int nr_retries = MAX_RECLAIM_RETRIES; struct mem_cgroup *memcg; bool in_retry = false; @@ -2616,7 +2615,7 @@ void mem_cgroup_handle_over_high(gfp_t gfp_mask) * memory.high, we want to encourage that rather than doing allocator * throttling. */ - if (nr_reclaimed || nr_retries--) { + if (nr_reclaimed >= (in_retry ? SWAP_CLUSTER_MAX : nr_pages)) { in_retry = true; goto retry_reclaim; }
When the number of alloc anonymous pages exceeds the memory.high, exc_page_fault successfully alloc code pages, and is released by mem_cgroup_handle_over_high before return to user mode. As a result, the program is trapped in a loop to exc page fault and reclaim pages. Here is an example of test code(do_alloc_memory is static compilation): Execution Procedure: mkdir -p /sys/fs/cgroup/memory/memcg_high_A echo 50M > /sys/fs/cgroup/memory/memcg_high_A/memory.high cgexec -g memory:memcg_high_A ./common/do_alloc_memory anon 100M & Phenomenon: [root@localhost memcg_high_A]# cat memory.usage_in_bytes 53903360 The test result shows that the program frequently sync iCache & dcache. As a result, the number of anon pages requested by the program cannot increase. This patch changes the behavior of retry recycling. As long as the number of successfully reclaimed pages is less than the target number of reclaimed pages, memory reclamation exits, indicating that there is no more memory to reclaim directly. Signed-off-by: Ruifeng Su <suruifeng1@huawei.com> --- mm/memcontrol.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)