vmscan: force scan offline memory cgroups
Subsystems (4)
PATCH 1/1 vmscan: force scan offline memory cgroups
Since commit b2052564e66d ("mm: memcontrol: continue cache reclaim from offlined groups") pages charged to a memory cgroup are not reparented when the cgroup is removed. Instead, they are supposed to be reclaimed in a regular way, along with pages accounted to online memory cgroups.
However, an lruvec of an offline memory cgroup will sooner or later get so small that it will be scanned only at low scan priorities (see get_scan_count()). Therefore, if there are enough reclaimable pages in big lruvecs, pages accounted to offline memory cgroups will never be scanned at all, wasting memory.
Fix this by unconditionally forcing scanning dead lruvecs from kswapd.
--- include/linux/memcontrol.h | 6 ++++++ mm/memcontrol.c | 14 ++++++++++++++ mm/vmscan.c | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-)
include/linux/memcontrol.h +6 -0
@@ -102,6 +102,7 @@ void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);* For memory reclaim. */ int mem_cgroup_inactive_anon_is_low (struct lruvec *lruvec); +bool mem_cgroup_need_force_scan (struct lruvec *lruvec);int mem_cgroup_select_victim_node (struct mem_cgroup *memcg);unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list );void mem_cgroup_update_lru_size (struct lruvec *,enum lru_list ,int );
@@ -266,6 +267,11 @@ mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return 1 ; } +bool mem_cgroup_need_force_scan (struct lruvec *lruvec) +{ +return false; +} +static inline unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list lru) {
mm/memcontrol.c +14 -0
@@ -1367,6 +1367,20 @@ int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return inactive * inactive_ratio < active; } +bool mem_cgroup_need_force_scan (struct lruvec *lruvec) +{ +struct mem_cgroup_per_zone *mz; +struct mem_cgroup *memcg; + +if (mem_cgroup_disabled ()) +return false; + + mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec); + memcg = mz->memcg; + +return !(memcg->css.flags &CSS_ONLINE ); +} +#define mem_cgroup_from_counter (counter, member) \ container_of(counter, struct mem_cgroup, member)
mm/vmscan.c +2 -1
@@ -1935,7 +1935,8 @@ static void get_scan_count(struct lruvec *lruvec, int swappiness,* latencies, so it's better to scan a minimum amount there as * well. */ -if (current_is_kswapd () && !zone_reclaimable (zone)) +if (current_is_kswapd () && + (!zone_reclaimable (zone) ||mem_cgroup_need_force_scan (lruvec))) force_scan = true;if (!global_reclaim (sc)) force_scan = true;
Signature · 7 lines
1.7.10.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>
Johannes Weiner
maintainerQuoted 11 lines · Vladimir Davydov
Since commit
b2052564e66d("mm: memcontrol: continue cache reclaim from offlined groups") pages charged to a memory cgroup are not reparented when the cgroup is removed. Instead, they are supposed to be reclaimed in a regular way, along with pages accounted to online memory cgroups.However, an lruvec of an offline memory cgroup will sooner or later get so small that it will be scanned only at low scan priorities (see
get_scan_count()). Therefore, if there are enough reclaimable pages in big lruvecs, pages accounted to offline memory cgroups will never be scanned at all, wasting memory.
Quoted 3 lines
Fix this by unconditionally forcing scanning dead lruvecs from kswapd.
Signed-off-by Vladimir Davydov <[email protected]>
Yes, it makes sense to continue draining them at this point. I just have a few comments inline:
Quoted 7 lines
mm/memcontrol.c +3
-0@@ -1367,6 +1367,20 @@ int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return inactive * inactive_ratio < active; } +bool mem_cgroup_need_force_scan (struct lruvec *lruvec) +{ +struct mem_cgroup_per_zone *mz;
mm/memcontrol.c int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec) · line 1382
Quoted 10 lines
mm/memcontrol.c +10
-0+struct mem_cgroup *memcg; + +if (mem_cgroup_disabled ()) +return false; + + mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec); + memcg = mz->memcg; + +return !(memcg->css.flags &CSS_ONLINE ); +}
It's better to name functions after what they do, rather than what they are used for, to make reuse easy. mem_cgroup_lruvec_online()?
mm/vmscan.c static void get_scan_count(struct lruvec *lruvec, int swappiness, · line 1940
Quoted 8 lines
mm/vmscan.c +2
-1@@ -1935,7 +1935,8 @@ static void get_scan_count(struct lruvec *lruvec, int swappiness,* latencies, so it's better to scan a minimum amount there as * well. */ -if (current_is_kswapd () && !zone_reclaimable (zone)) +if (current_is_kswapd () && + (!zone_reclaimable (zone) ||mem_cgroup_need_force_scan (lruvec))) force_scan = true;
This would probably be easier on the eyes if you broke that up:
if (current_is_kswapd()) {
if (!zone_reclaimable(zone))
force_scan = true;
else if (!mem_cgroup_online_from_lruvec(lruvec))
force_scan = true;
} else if (!global_reclaim(sc)) {
force_scan = true;
}--
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>
PATCH v2 1/1 vmscan: force scan offline memory cgroups
Since commit b2052564e66d ("mm: memcontrol: continue cache reclaim from offlined groups") pages charged to a memory cgroup are not reparented when the cgroup is removed. Instead, they are supposed to be reclaimed in a regular way, along with pages accounted to online memory cgroups.
However, an lruvec of an offline memory cgroup will sooner or later get so small that it will be scanned only at low scan priorities (see get_scan_count()). Therefore, if there are enough reclaimable pages in big lruvecs, pages accounted to offline memory cgroups will never be scanned at all, wasting memory.
Fix this by unconditionally forcing scanning dead lruvecs from kswapd.
---
Changes in v2:
- code style fixes (Johannes)
include/linux/memcontrol.h | 6 ++++++ mm/memcontrol.c | 14 ++++++++++++++ mm/vmscan.c | 8 ++++++-- 3 files changed, 26 insertions(+), 2 deletions(-)
include/linux/memcontrol.h +6 -0
@@ -102,6 +102,7 @@ void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);* For memory reclaim. */ int mem_cgroup_inactive_anon_is_low (struct lruvec *lruvec); +bool mem_cgroup_lruvec_online (struct lruvec *lruvec);int mem_cgroup_select_victim_node (struct mem_cgroup *memcg);unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list );void mem_cgroup_update_lru_size (struct lruvec *,enum lru_list ,int );
@@ -266,6 +267,11 @@ mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return 1 ; } +bool mem_cgroup_lruvec_online (struct lruvec *lruvec) +{ +return true; +} +static inline unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list lru) {
mm/memcontrol.c +14 -0
@@ -1367,6 +1367,20 @@ int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return inactive * inactive_ratio < active; } +bool mem_cgroup_lruvec_online (struct lruvec *lruvec) +{ +struct mem_cgroup_per_zone *mz; +struct mem_cgroup *memcg; + +if (mem_cgroup_disabled ()) +return true; + + mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec); + memcg = mz->memcg; + +return !!(memcg->css.flags &CSS_ONLINE ); +} +#define mem_cgroup_from_counter (counter, member) \ container_of(counter, struct mem_cgroup, member)
mm/vmscan.c +6 -2
@@ -1935,8 +1935,12 @@ static void get_scan_count(struct lruvec *lruvec, int swappiness,* latencies, so it's better to scan a minimum amount there as * well. */ -if (current_is_kswapd () && !zone_reclaimable (zone)) - force_scan = true; +if (current_is_kswapd ()) { +if (!zone_reclaimable (zone)) + force_scan = true; +if (!mem_cgroup_lruvec_online (lruvec)) + force_scan = true; + }if (!global_reclaim (sc)) force_scan = true;
Signature · 7 lines
1.7.10.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>
Quoted 11 lines · Vladimir Davydov
Since commit
b2052564e66d("mm: memcontrol: continue cache reclaim from offlined groups") pages charged to a memory cgroup are not reparented when the cgroup is removed. Instead, they are supposed to be reclaimed in a regular way, along with pages accounted to online memory cgroups.However, an lruvec of an offline memory cgroup will sooner or later get so small that it will be scanned only at low scan priorities (see
get_scan_count()). Therefore, if there are enough reclaimable pages in big lruvecs, pages accounted to offline memory cgroups will never be scanned at all, wasting memory.
Quoted 3 lines
Fix this by unconditionally forcing scanning dead lruvecs from kswapd.
Signed-off-by Vladimir Davydov <[email protected]>
Thanks!
Quoted 80 lines
---
Changes in v2:
- code style fixes (Johannes)include/linux/memcontrol.h | 6 ++++++ mm/memcontrol.c | 14 ++++++++++++++ mm/vmscan.c | 8 ++++++-- 3 files changed, 26 insertions(+), 2 deletions(-)include/linux/memcontrol.h +6
-0@@ -102,6 +102,7 @@ void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *);* For memory reclaim. */ int mem_cgroup_inactive_anon_is_low (struct lruvec *lruvec); +bool mem_cgroup_lruvec_online (struct lruvec *lruvec);int mem_cgroup_select_victim_node (struct mem_cgroup *memcg);unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list );void mem_cgroup_update_lru_size (struct lruvec *,enum lru_list ,int );@@ -266,6 +267,11 @@ mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return 1 ; } +bool mem_cgroup_lruvec_online (struct lruvec *lruvec) +{ +return true; +} +static inline unsigned long mem_cgroup_get_lru_size (struct lruvec *lruvec,enum lru_list lru) {mm/memcontrol.c +14
-0@@ -1367,6 +1367,20 @@ int mem_cgroup_inactive_anon_is_low(struct lruvec *lruvec)return inactive * inactive_ratio < active; } +bool mem_cgroup_lruvec_online (struct lruvec *lruvec) +{ +struct mem_cgroup_per_zone *mz; +struct mem_cgroup *memcg; + +if (mem_cgroup_disabled ()) +return true; + + mz = container_of(lruvec, struct mem_cgroup_per_zone, lruvec); + memcg = mz->memcg; + +return !!(memcg->css.flags &CSS_ONLINE ); +} +#define mem_cgroup_from_counter (counter, member) \ container_of(counter, struct mem_cgroup, member)mm/vmscan.c +6
-2@@ -1935,8 +1935,12 @@ static void get_scan_count(struct lruvec *lruvec, int swappiness,* latencies, so it's better to scan a minimum amount there as * well. */ -if (current_is_kswapd () && !zone_reclaimable (zone)) - force_scan = true; +if (current_is_kswapd ()) { +if (!zone_reclaimable (zone)) + force_scan = true; +if (!mem_cgroup_lruvec_online (lruvec)) + force_scan = true; + }if (!global_reclaim (sc)) force_scan = true;Signature · 1 line
1.7.10.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>
Quoted 11 lines · Vladimir Davydov
Since commit
b2052564e66d("mm: memcontrol: continue cache reclaim from offlined groups") pages charged to a memory cgroup are not reparented when the cgroup is removed. Instead, they are supposed to be reclaimed in a regular way, along with pages accounted to online memory cgroups.However, an lruvec of an offline memory cgroup will sooner or later get so small that it will be scanned only at low scan priorities (see
get_scan_count()). Therefore, if there are enough reclaimable pages in big lruvecs, pages accounted to offline memory cgroups will never be scanned at all, wasting memory.
Quoted 3 lines
Fix this by unconditionally forcing scanning dead lruvecs from kswapd.
Signed-off-by Vladimir Davydov <[email protected]>
Looks good to me now, thank you.
--
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>