linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: speedup memory cgroup resize
@ 2022-12-05 11:49 lirongqing
  2022-12-05 16:32 ` Shakeel Butt
  0 siblings, 1 reply; 5+ messages in thread
From: lirongqing @ 2022-12-05 11:49 UTC (permalink / raw)
  To: linux-mm, cgroups, hannes, mhocko, roman.gushchin, shakeelb,
	songmuchun, akpm

From: Li RongQing <lirongqing@baidu.com>

when resize memory cgroup, avoid to free memory cgroup page
one by one, and try to free needed number pages once

same to emtpy a memory cgroup memory

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 mm/memcontrol.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 2d8549ae1b30..86993d055d86 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3464,6 +3464,7 @@ static int mem_cgroup_resize_max(struct mem_cgroup *memcg,
 	bool drained = false;
 	int ret;
 	bool limits_invariant;
+	unsigned long nr_pages;
 	struct page_counter *counter = memsw ? &memcg->memsw : &memcg->memory;
 
 	do {
@@ -3498,7 +3499,13 @@ static int mem_cgroup_resize_max(struct mem_cgroup *memcg,
 			continue;
 		}
 
-		if (!try_to_free_mem_cgroup_pages(memcg, 1, GFP_KERNEL,
+		nr_pages = page_counter_read(counter);
+
+		if (nr_pages > max)
+			nr_pages = nr_pages - max;
+		else
+			nr_pages = 1;
+		if (!try_to_free_mem_cgroup_pages(memcg, nr_pages, GFP_KERNEL,
 					memsw ? 0 : MEMCG_RECLAIM_MAY_SWAP)) {
 			ret = -EBUSY;
 			break;
@@ -3598,6 +3605,7 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order,
 static int mem_cgroup_force_empty(struct mem_cgroup *memcg)
 {
 	int nr_retries = MAX_RECLAIM_RETRIES;
+	unsigned long nr_pages;
 
 	/* we call try-to-free pages for make this cgroup empty */
 	lru_add_drain_all();
@@ -3605,11 +3613,11 @@ static int mem_cgroup_force_empty(struct mem_cgroup *memcg)
 	drain_all_stock(memcg);
 
 	/* try to free all pages in this cgroup */
-	while (nr_retries && page_counter_read(&memcg->memory)) {
+	while (nr_retries && (nr_pages = page_counter_read(&memcg->memory))) {
 		if (signal_pending(current))
 			return -EINTR;
 
-		if (!try_to_free_mem_cgroup_pages(memcg, 1, GFP_KERNEL,
+		if (!try_to_free_mem_cgroup_pages(memcg, nr_pages, GFP_KERNEL,
 						  MEMCG_RECLAIM_MAY_SWAP))
 			nr_retries--;
 	}
-- 
2.27.0



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

end of thread, other threads:[~2022-12-07 12:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-05 11:49 [PATCH] mm: memcontrol: speedup memory cgroup resize lirongqing
2022-12-05 16:32 ` Shakeel Butt
2022-12-06 10:33   ` Michal Hocko
2022-12-07  2:31     ` Li,Rongqing
2022-12-07 12:18       ` Michal Hocko

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