Skip to contentSkip to conversation

mm: bump PGSTEAL*/PGSCAN*/ALLOCSTALL counters in memcg reclaim

PATCH In review Roman Gushchin 2 participants 4 messages May 29, 2017 – May 30, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: bump PGSTEAL*/PGSCAN*/ALLOCSTALL counters in memcg reclaim

Historically, PGSTEAL*/PGSCAN*/ALLOCSTALL counters were used to account only for global reclaim events, memory cgroup targeted reclaim was ignored.

It doesn't make sense anymore, because the whole reclaim path is designed around cgroups. Also, per-cgroup counters can exceed the corresponding global counters, what can be confusing.

So, make PGSTEAL*/PGSCAN*/ALLOCSTALL counters reflect sum of any reclaim activity in the system.

---
 mm/vmscan.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
mm/vmscan.c +5 -10
index 7c2a36b..77253b1 100644
@@ -1765,13 +1765,11 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
 	reclaim_stat->recent_scanned[file] += nr_taken;
 
 	if (current_is_kswapd()) {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSCAN_KSWAPD, nr_scanned);
+		__count_vm_events(PGSCAN_KSWAPD, nr_scanned);
 		count_memcg_events(lruvec_memcg(lruvec), PGSCAN_KSWAPD,
 				   nr_scanned);
 	} else {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSCAN_DIRECT, nr_scanned);
+		__count_vm_events(PGSCAN_DIRECT, nr_scanned);
 		count_memcg_events(lruvec_memcg(lruvec), PGSCAN_DIRECT,
 				   nr_scanned);
 	}
@@ -1786,13 +1784,11 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
 	spin_lock_irq(&pgdat->lru_lock);
 
 	if (current_is_kswapd()) {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSTEAL_KSWAPD, nr_reclaimed);
+		__count_vm_events(PGSTEAL_KSWAPD, nr_reclaimed);
 		count_memcg_events(lruvec_memcg(lruvec), PGSTEAL_KSWAPD,
 				   nr_reclaimed);
 	} else {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSTEAL_DIRECT, nr_reclaimed);
+		__count_vm_events(PGSTEAL_DIRECT, nr_reclaimed);
 		count_memcg_events(lruvec_memcg(lruvec), PGSTEAL_DIRECT,
 				   nr_reclaimed);
 	}
@@ -2828,8 +2824,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
 retry:
 	delayacct_freepages_start();
 
-	if (global_reclaim(sc))
-		__count_zid_vm_events(ALLOCSTALL, sc->reclaim_idx, 1);
+	__count_zid_vm_events(ALLOCSTALL, sc->reclaim_idx, 1);
 
 	do {
 		vmpressure_prio(sc->gfp_mask, sc->target_mem_cgroup,
Signature · 7 lines
2.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
reviewer
#1 lore raw
Quoted 7 lines · Roman Gushchin

Historically, PGSTEAL*/PGSCAN*/ALLOCSTALL counters were used to account only for global reclaim events, memory cgroup targeted reclaim was ignored.

It doesn't make sense anymore, because the whole reclaim path is designed around cgroups. Also, per-cgroup counters can exceed the corresponding global counters, what can be confusing.

The whole reclaim is designed around cgroups but the source of the memory pressure is different. I agree that checking global_reclaim() for PGSTEAL_KSWAPD doesn't make much sense because we are _always_ in the global reclaim context but counting ALLOCSTALL even for targetted memcg reclaim is more confusing than helpful. We usually consider this counter to see whether the kswapd catches up with the memory demand and the global direct reclaim is indicator it doesn't. The similar applies to other counters as well.

So I do not think this is correct. What is the problem you are trying to solve here anyway.

Quoted 64 lines

So, make PGSTEAL*/PGSCAN*/ALLOCSTALL counters reflect sum of any reclaim activity in the system.

---
 mm/vmscan.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
mm/vmscan.c +5 -10
index 7c2a36b..77253b1 100644
@@ -1765,13 +1765,11 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
 	reclaim_stat->recent_scanned[file] += nr_taken;
 
 	if (current_is_kswapd()) {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSCAN_KSWAPD, nr_scanned);
+		__count_vm_events(PGSCAN_KSWAPD, nr_scanned);
 		count_memcg_events(lruvec_memcg(lruvec), PGSCAN_KSWAPD,
 				   nr_scanned);
 	} else {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSCAN_DIRECT, nr_scanned);
+		__count_vm_events(PGSCAN_DIRECT, nr_scanned);
 		count_memcg_events(lruvec_memcg(lruvec), PGSCAN_DIRECT,
 				   nr_scanned);
 	}
@@ -1786,13 +1784,11 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
 	spin_lock_irq(&pgdat->lru_lock);
 
 	if (current_is_kswapd()) {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSTEAL_KSWAPD, nr_reclaimed);
+		__count_vm_events(PGSTEAL_KSWAPD, nr_reclaimed);
 		count_memcg_events(lruvec_memcg(lruvec), PGSTEAL_KSWAPD,
 				   nr_reclaimed);
 	} else {
-		if (global_reclaim(sc))
-			__count_vm_events(PGSTEAL_DIRECT, nr_reclaimed);
+		__count_vm_events(PGSTEAL_DIRECT, nr_reclaimed);
 		count_memcg_events(lruvec_memcg(lruvec), PGSTEAL_DIRECT,
 				   nr_reclaimed);
 	}
@@ -2828,8 +2824,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
 retry:
 	delayacct_freepages_start();
 
-	if (global_reclaim(sc))
-		__count_zid_vm_events(ALLOCSTALL, sc->reclaim_idx, 1);
+	__count_zid_vm_events(ALLOCSTALL, sc->reclaim_idx, 1);
 
 	do {
 		vmpressure_prio(sc->gfp_mask, sc->target_mem_cgroup,
Signature · 1 line
2.7.4
Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
Quoted 18 lines · Michal Hocko
Quoted 7 lines · Roman Gushchin

Historically, PGSTEAL*/PGSCAN*/ALLOCSTALL counters were used to account only for global reclaim events, memory cgroup targeted reclaim was ignored.

It doesn't make sense anymore, because the whole reclaim path is designed around cgroups. Also, per-cgroup counters can exceed the corresponding global counters, what can be confusing.

The whole reclaim is designed around cgroups but the source of the memory pressure is different. I agree that checking global_reclaim() for PGSTEAL_KSWAPD doesn't make much sense because we are _always_ in the global reclaim context but counting ALLOCSTALL even for targetted memcg reclaim is more confusing than helpful. We usually consider this counter to see whether the kswapd catches up with the memory demand and the global direct reclaim is indicator it doesn't. The similar applies to other counters as well.

Quoted 2 lines

So I do not think this is correct. What is the problem you are trying to solve here anyway.

This is a follow-up patch after the discussion here:
https://lkml.org/lkml/2017/5/16/706.

I can agree with you, that a per-cgroup ALLOCSTALL is something different from a global one, and it's better to keep them separated.

But what about PGSTEAL*/PGSCAN* counters, isn't it better to make them reflect __all__ reclaim activity, no matter what was a root cause?

Thanks!

Roman

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

reviewer
#3 lore raw

On Tue 30-05-17 14:21:14, Roman Gushchin wrote:
[...]

Quoted 2 lines

But what about PGSTEAL*/PGSCAN* counters, isn't it better to make them reflect __all__ reclaim activity, no matter what was a root cause?

What would be the advantage? Those counters have always been global and we should better have a strong reason to change that.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>