linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm, memcg: avoid recycling when there is no more recyclable memory
@ 2023-10-13 15:40 Ruifeng Su
  0 siblings, 0 replies; 3+ messages in thread
From: Ruifeng Su @ 2023-10-13 15:40 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, cgroups

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(-)

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;
 	}
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] mm, memcg: avoid recycling when there is no more recyclable memory
@ 2023-10-27  9:30 Ruifeng Su
  2023-11-01 16:16 ` Michal Koutný
  0 siblings, 1 reply; 3+ messages in thread
From: Ruifeng Su @ 2023-10-27  9:30 UTC (permalink / raw)
  To: akpm
  Cc: linux-mm, cgroups, mhocko, roman.gushchin, hannes, linmiaohe,
	suruifeng1

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(-)

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;
 	}
-- 
2.33.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm, memcg: avoid recycling when there is no more recyclable memory
  2023-10-27  9:30 [PATCH] mm, memcg: avoid recycling when there is no more recyclable memory Ruifeng Su
@ 2023-11-01 16:16 ` Michal Koutný
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Koutný @ 2023-11-01 16:16 UTC (permalink / raw)
  To: Ruifeng Su
  Cc: akpm, linux-mm, cgroups, mhocko, roman.gushchin, hannes,
	linmiaohe

[-- Attachment #1: Type: text/plain, Size: 939 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-01 16:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27  9:30 [PATCH] mm, memcg: avoid recycling when there is no more recyclable memory Ruifeng Su
2023-11-01 16:16 ` Michal Koutný
  -- strict thread matches above, loose matches on Subject: below --
2023-10-13 15:40 Ruifeng Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).