mm: memcg softlimit reclaim rework
Subsystems (5)
PATCH v8 1/2 mm: memcg softlimit reclaim rework
This patch reverts all the existing softlimit reclaim implementations and instead integrates the softlimit reclaim into existing global reclaim logic.
The new softlimit reclaim includes the following changes:
1. add function mem_cgroup_over_soft_limit()
Add the filter function mem_cgroup_over_soft_limit() under the common function shrink_zone(). The later one is being called both from per-memcg reclaim as well as global reclaim.
Today the softlimit takes effect only under global memory pressure. The memcgs get free run above their softlimit until there is a global memory contention. This patch doesn't change the semantics.
Under the global reclaim, we try to skip reclaiming from a memcg under its softlimit. To prevent reclaim from trying too hard on hitting memcgs (above softlimit) w/ only hard-to-reclaim pages, the reclaim priority is used to skip the softlimit check. This is a trade-off of system performance and resource isolation.
2. memcg set soft_limit_in_bytes to 0 by default
This idea is based on discussion with Michal and Johannes from LSF.
a) If soft_limit are all set to MAX, it wastes first three priority iterations without scanning anything.
b) By default every memcg is eligible for softlimit reclaim, and we can also set the value to MAX for special memcg which is immune to soft limit reclaim.
There is a behavior change after this patch: (N == DEF_PRIORITY)
A: usage > softlimit B: usage <= softlimit U: softlimit unset old: reclaim at each priority reclaim when priority < N reclaim when priority < N new: reclaim at each priority reclaim when priority < N reclaim at each priority
Note: I can leave the counter->soft_limit uninitialized, at least all the caller of res_counter_init() have the memcg as pre-zeroed structure. However, I might be better not rely on that.
3. forbid setting soft limit on root cgroup
Setting a soft limit in the root cgroup does not make sense, as soft limits are enforced hierarchically and the root cgroup is the hierarchical parent of every other cgroup. It would not provide the discrimination between groups that soft limits are usually used for.
With the current implementation of soft limits, it would only make global reclaim more aggressive compared to target reclaim, but we absolutely don't want anyone to rely on this behaviour.
4. "hierarchical" softlimit reclaim
This is consistant to how softlimit was previously implemented, where the pressure is put for the whole hiearchy as long as the "root" of the hierarchy over its softlimit.
What's the trusted and untrusted setups ?
case 1 : Administrator is the only one setting up the limits and also he expects gurantees of memory under each cgroup's softlimit:
Considering the following:
root (soft: unlimited, use_hierarchy = 1)
-- A (soft: unlimited, usage 22G)
-- A1 (soft: 10G, usage 17G)
-- A2 (soft: 6G, usage 5G)-- B (soft: 16G, usage 10G)
So we have A1 above its softlimit and none of its ancestor does, then global reclaim will only pick A1 to reclaim first.
case 2: Untrusted enviroment where cgroups changes its softlimit or adminstrator could make mistakes. In that case, we still want to attack the mis-configured child if its parent is above softlimit.
Considering the following:
root (soft: unlimited, use_hierarchy = 1)
-- A (soft: 16G, usage 22G)
-- A1 (soft: 10G, usage 17G)
-- A2 (soft: 1000G, usage 5G)-- B (soft: 16G, usage 10G)
Here A2 would set its softlimit way higher than its parent, but the current logic makes sure to still attack it when A exceeds its softlimit.
Tested the patch by over-committing the host by both hardlimit and softlimit. The host is on a stable state after the workload finished.
v8..v7:
1. only consider softlimit at DEF_PRIORITY. Rik made the comment on the last round that (DEF_PRIORITY - 2) is a bad idea and it turns out he might be right. The same priority level is used to indicate the reclaim getting into trouble, and bunch of places in vmscan.c uses that to take special action. So here I decide to make a smaller step by ony considering softlimit at highest ( or lowest, depending how you see it) priority level. This should be ok for laying down the ground work first, especially there are efforts going on to make optimization on top of that.
2. skip the root cgroup when detecting no memcg above softlimit. This is pointed out by Michal at last round since root cgroup by default has softlimit equals to 0.
v7..v6:
1. rebase to mmotm-2012-07-25-16-41
v5..v6:
1. updated w/ kosaki's latest patch.
2. squashed the "set softlimit to 0" patch.
3. applied patch from johannes which disallow root to change its softlimit.
v4..v5:
1. rebase the patchset on memcg-dev tree
2. apply KOSAKI's patch on do_try_to_free_pages()
--- include/linux/memcontrol.h | 20 +-- include/linux/swap.h | 4 - kernel/res_counter.c | 2 +- mm/memcontrol.c | 461 +++----------------------------------------- mm/vmscan.c | 82 ++------- 5 files changed, 57 insertions(+), 512 deletions(-)
include/linux/memcontrol.h +8 -12
@@ -122,6 +122,8 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,extern void mem_cgroup_replace_page_cache (struct page *oldpage,struct page *newpage); +extern bool mem_cgroup_over_soft_limit (struct mem_cgroup *memcg); +#ifdef CONFIG_MEMCG_SWAP extern int do_swap_account;#endif
@@ -177,10 +179,6 @@ static inline void mem_cgroup_dec_page_stat(struct page *page,mem_cgroup_update_page_stat (page, idx,-1 ); } -unsigned long mem_cgroup_soft_limit_reclaim (struct zone *zone,int order, -gfp_t gfp_mask, -unsigned long *total_scanned); -void mem_cgroup_count_vm_event (struct mm_struct *mm,enum vm_event_item idx);#ifdef CONFIG_TRANSPARENT_HUGEPAGE void mem_cgroup_split_huge_fixup (struct page *head);
@@ -354,14 +352,6 @@ static inline void mem_cgroup_dec_page_stat(struct page *page, { } -static inline -unsigned long mem_cgroup_soft_limit_reclaim (struct zone *zone,int order, -gfp_t gfp_mask, -unsigned long *total_scanned) -{ -return 0 ; -} -static inline void mem_cgroup_split_huge_fixup (struct page *head) { }
@@ -374,6 +364,12 @@ static inline void mem_cgroup_replace_page_cache(struct page *oldpage, struct page *newpage) { } + +static inline +bool mem_cgroup_over_soft_limit (struct mem_cgroup *memcg) +{ +return true; +}#endif /* CONFIG_MEMCG */ #if !defined(CONFIG_MEMCG ) || !defined(CONFIG_DEBUG_VM )
include/linux/swap.h +0 -4
@@ -259,10 +259,6 @@ extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,extern int __isolate_lru_page (struct page *page,isolate_mode_t mode);extern unsigned long try_to_free_mem_cgroup_pages (struct mem_cgroup *mem,gfp_t gfp_mask,bool noswap); -extern unsigned long mem_cgroup_shrink_node_zone (struct mem_cgroup *mem, -gfp_t gfp_mask,bool noswap, -struct zone *zone, -unsigned long *nr_scanned);extern unsigned long shrink_all_memory (unsigned long nr_pages);extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);
kernel/res_counter.c +1 -1
@@ -18,7 +18,7 @@ void res_counter_init(struct res_counter *counter, struct res_counter *parent) {spin_lock_init (&counter->lock); counter->limit =RESOURCE_MAX ; - counter->soft_limit =RESOURCE_MAX ; + counter->soft_limit =0 ; counter->parent = parent; }
mm/memcontrol.c +32 -429
591 lines not on this page · raw message
mm/vmscan.c +16 -66
118 lines not on this page · raw message
Signature · 7 lines
1.7.7.3 -- 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>
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]
Quoted 18 lines
mm/vmscan.c +9
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do { struct lruvec *lruvec = mem_cgroup_zone_lruvec(zone, memcg); - shrink_lruvec(lruvec, sc); + /* + * Reclaim from mem_cgroup if any of these conditions are met: + * - this is a targetted reclaim ( not global reclaim) + * - reclaim priority is less than DEF_PRIORITY + * - mem_cgroup or its ancestor ( not including root cgroup) + * exceeds its soft limit + * + * Note: The priority check is a balance of how hard to + * preserve the pages under softlimit. If the memcgs of the
mm/vmscan.c static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1887
Quoted 10 lines
mm/vmscan.c +7
-0+* zone having trouble to reclaim pages above their softlimit, +* we have to reclaim under softlimit instead of burning more +* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority <DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and
I am thinking that we could add a constant for the priority limit. Something like
#define MEMCG_LOW_SOFTLIMIT_PRIORITY DEF_PRIORITY
Although it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
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 35 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]Quoted 18 lines
mm/vmscan.c +9
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do { struct lruvec *lruvec = mem_cgroup_zone_lruvec(zone, memcg); - shrink_lruvec(lruvec, sc); + /* + * Reclaim from mem_cgroup if any of these conditions are met: + * - this is a targetted reclaim ( not global reclaim) + * - reclaim priority is less than DEF_PRIORITY + * - mem_cgroup or its ancestor ( not including root cgroup) + * exceeds its soft limit + * + * Note: The priority check is a balance of how hard to + * preserve the pages under softlimit. If the memcgs of themm/vmscan.c static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1887
Quoted 10 lines
mm/vmscan.c +7
-0+* zone having trouble to reclaim pages above their softlimit, +* we have to reclaim under softlimit instead of burning more +* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority<DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITY
Quoted 3 lines
Although it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
Signature · 7 lines
All rights reversed -- 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 51 lines · Rik van Riel
Quoted 45 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]Quoted 28 lines
mm/vmscan.c +2
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do {struct lruvec *lruvec =mem_cgroup_zone_lruvec (zone, memcg); -shrink_lruvec (lruvec, sc); +/* +* Reclaim from mem_cgroup if any of these conditions are met:
mm/vmscan.c +3
-0+* - this is a targetted reclaim ( not global reclaim) +* - reclaim priority is less than DEF_PRIORITY +* - mem_cgroup or its ancestor ( not including root cgroup)
mm/vmscan.c +4
-0+* exceeds its soft limit +* +* Note: The priority check is a balance of how hard to +* preserve the pages under softlimit. If the memcgs of the
+ * zone having trouble to reclaim pages above their
softlimit,
+ * we have to reclaim under softlimit instead of burning
moremm/vmscan.c static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1887
Quoted 8 lines
mm/vmscan.c +5
-0+* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority<DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYQuoted 3 lines
Although it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
Quoted 4 lines
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
--Ying
Quoted 3 lines
--
All rights reversed
--
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 52 lines · Ying Han
Quoted 51 lines · Rik van Riel
Quoted 48 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]Quoted 28 lines
mm/vmscan.c +2
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do {struct lruvec *lruvec =mem_cgroup_zone_lruvec (zone, memcg); -shrink_lruvec (lruvec, sc); +/* +* Reclaim from mem_cgroup if any of these conditions are met:
mm/vmscan.c +3
-0+* - this is a targetted reclaim ( not global reclaim) +* - reclaim priority is less than DEF_PRIORITY +* - mem_cgroup or its ancestor ( not including root cgroup)
mm/vmscan.c +4
-0+* exceeds its soft limit +* +* Note: The priority check is a balance of how hard to +* preserve the pages under softlimit. If the memcgs of the
+ * zone having trouble to reclaim pages above their
softlimit,
+ * we have to reclaim under softlimit instead of burning
moremm/vmscan.c static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1887
Quoted 8 lines
mm/vmscan.c +5
-0+* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority<DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYAlthough it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
Quoted 8 lines
Quoted 4 lines
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
I am afraid we will not move forward without a proper implementation of the "nobody under soft limit" case. Maybe Rik's idea would just work out but this patch on it's own could regress so taking it separately is no go IMO. I like how it reduces the code size but we are not "there" yet...
Quoted 6 lines
--Ying
Quoted 3 lines
--
All rights reversed
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 58 lines · Michal Hocko
Quoted 57 lines · Ying Han
Quoted 55 lines · Rik van Riel
Quoted 45 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]Quoted 28 lines
mm/vmscan.c +2
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do {struct lruvec *lruvec =mem_cgroup_zone_lruvec (zone, memcg); -shrink_lruvec (lruvec, sc); +/* +* Reclaim from mem_cgroup if any of these conditions are met:
mm/vmscan.c +3
-0+* - this is a targetted reclaim ( not global reclaim) +* - reclaim priority is less than DEF_PRIORITY +* - mem_cgroup or its ancestor ( not including root cgroup)
mm/vmscan.c +4
-0+* exceeds its soft limit +* +* Note: The priority check is a balance of how hard to +* preserve the pages under softlimit. If the memcgs of the
+ * zone having trouble to reclaim pages above their
softlimit,
+ * we have to reclaim under softlimit instead of burning
moremm/vmscan.c static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1887
Quoted 8 lines
mm/vmscan.c +5
-0+* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority<DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYQuoted 3 lines
Although it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
Quoted 9 lines
Quoted 3 lines
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
I am afraid we will not move forward without a proper implementation of the "nobody under soft limit" case. Maybe Rik's idea would just work out but this patch on it's own could regress so taking it separately is no go IMO. I like how it reduces the code size but we are not "there" yet...
Sorry for getting back to the thread late. Being distracted to something else which of course happens all the time.
Before me jumping into actions of any changes, let me clarify the problem I am facing:
All the concerns are related to the configuration where none of the memcg is eligible for reclaim ( usage < softlimit ) under global
pressure. The current code works like the following:
1. walk the memcg tree and for each checks the softlimit
2. if none of the memcg is being reclaimed, then set the ignore_softlimit
3. restart the walk and this round forget about the softlimit
There are two problems I heard here:
1. doing a full walk on step 1 would cause potential scalability issue.
Note: I would argue the admin need to adjust the configuration instead. In theory, it is not recommended to over-commit the soft-limit based on the concept. However, it could happen but and the case should be rare.
The issue hasn't been observed on our running environment by far.
2. root cgroup is a exception where it always eligible for reclaim ( softlimit = 0 always). That will cause root to be punished more than necessary.
Note: Not sure what would be the expected behavior. On one side, we declare the softlimit of root always be the default (0), and even future it can not be changed. Any pages above the soft-limit is low-priority and targeted to reclaim over others. So, in this case where no other memcg above their softlimit, why adding pressure on root would be a regression.
I would like to take a look at Rik's patch and especially I am interested in if the score scheme helps the case 1. On the other hand, I wonder how that would provide the gurantees of memory under softlimit. We might be able to accomplish that but w/ cost of more computation power.
Is there anything that I missed and need to look next as well?
Thanks
--Ying
Quoted 9 lines
Quoted 5 lines
--Ying
Quoted 3 lines
--
All rights reversed--
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 83 lines · Ying Han
Quoted 58 lines · Michal Hocko
Quoted 57 lines · Ying Han
Quoted 55 lines · Rik van Riel
Quoted 45 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]Quoted 28 lines
mm/vmscan.c +2
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do {struct lruvec *lruvec =mem_cgroup_zone_lruvec (zone, memcg); -shrink_lruvec (lruvec, sc); +/* +* Reclaim from mem_cgroup if any of these conditions are met:
mm/vmscan.c +3
-0+* - this is a targetted reclaim ( not global reclaim) +* - reclaim priority is less than DEF_PRIORITY +* - mem_cgroup or its ancestor ( not including root cgroup)
mm/vmscan.c +4
-0+* exceeds its soft limit +* +* Note: The priority check is a balance of how hard to +* preserve the pages under softlimit. If the memcgs of the
+ * zone having trouble to reclaim pages above their
softlimit,
+ * we have to reclaim under softlimit instead of burning
moremm/vmscan.c static void shrink_zone(struct zone *zone, struct scan_control *sc) · line 1887
Quoted 8 lines
mm/vmscan.c +5
-0+* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority<DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYQuoted 3 lines
Although it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
Quoted 9 lines
Quoted 3 lines
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
I am afraid we will not move forward without a proper implementation of the "nobody under soft limit" case. Maybe Rik's idea would just work out but this patch on it's own could regress so taking it separately is no go IMO. I like how it reduces the code size but we are not "there" yet...
Sorry for getting back to the thread late. Being distracted to something else which of course happens all the time.
Before me jumping into actions of any changes, let me clarify the problem I am facing:
All the concerns are related to the configuration where none of the memcg is eligible for reclaim ( usage < softlimit ) under global
pressure. The current code works like the following:1. walk the memcg tree and for each checks the softlimit
2. if none of the memcg is being reclaimed, then set theignore_softlimit
3. restart the walk and this round forget about the softlimit
Quoted 9 lines
There are two problems I heard here:
1. doing a full walk on step 1 would cause potential scalability issue.Note: I would argue the admin need to adjust the configuration instead. In theory, it is not recommended to over-commit the soft-limit based on the concept. However, it could happen but and the case should be rare.
The issue hasn't been observed on our running environment by far.
Can't you hash or add the memcgs to a list at charge time whenever they get close to the limit? You should be able to hook at the notifications mechanism for that, and reduce the number of memcgs to scan by a large factor in practice.
Or did I misunderstand what the problem is?
Quoted 11 lines
2. root cgroup is a exception where it always eligible for reclaim ( softlimit = 0 always). That will cause root to be punished more than necessary.
Note: Not sure what would be the expected behavior. On one side, we declare the softlimit of root always be the default (0), and even future it can not be changed. Any pages above the soft-limit is low-priority and targeted to reclaim over others. So, in this case where no other memcg above their softlimit, why adding pressure on root would be a regression.
The problem here, I believe, is the good & old hierarchy discussion. Your behavior looks sane with hierarchy, because everybody is under root memcg. So "reclaiming from root memcg" means doing a global reclaim the way had always done.
Without hierarchy, however, it does look bad. If we have no reason to penalize a particular group, we should just ignore the group membership information while reclaiming.
Quoted 28 lines
I would like to take a look at Rik's patch and especially I am interested in if the score scheme helps the case 1. On the other hand, I wonder how that would provide the gurantees of memory under softlimit. We might be able to accomplish that but w/ cost of more computation power.
Is there anything that I missed and need to look next as well?
Thanks
--Ying
Quoted 9 lines
Quoted 5 lines
--Ying
Quoted 3 lines
--
All rights reversed--
Michal Hocko
SUSE Labs
Quoted 6 lines
--
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>
--
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 41 lines · Ying Han
Quoted 20 lines · Michal Hocko
Quoted 19 lines · Ying Han
Quoted 17 lines · Rik van Riel
Quoted 10 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYAlthough it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
Quoted 9 lines
Quoted 3 lines
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
I am afraid we will not move forward without a proper implementation of the "nobody under soft limit" case. Maybe Rik's idea would just work out but this patch on it's own could regress so taking it separately is no go IMO. I like how it reduces the code size but we are not "there" yet...
Sorry for getting back to the thread late. Being distracted to something else which of course happens all the time.
Before me jumping into actions of any changes, let me clarify the problem I am facing:
All the concerns are related to the configuration where none of the memcg is eligible for reclaim ( usage < softlimit ) under global
pressure. The current code works like the following:
Quoted 7 lines
1. walk the memcg tree and for each checks the softlimit
2. if none of the memcg is being reclaimed, then set theignore_softlimit
3. restart the walk and this round forget about the softlimitThere are two problems I heard here:
1. doing a full walk on step 1 would cause potential scalability issue.
Simply thinking, I think maintaining & updating the whole softlimit information periodically is a way to avoid double-scan. memcg has a percpu event-counter and css-id bitmap will be enough for keeping information. Then, you can find over-softlimit memcg by bitmap scanning.
Quoted 4 lines
2. root cgroup is a exception where it always eligible for reclaim ( softlimit = 0 always). That will cause root to be punished more than necessary.
When use_hierarchy==0 ?
How about having implicit softlimit value for root, which is automatically calculated from total_ram or the number of tasks in root ?
Thanks,
-Kame
--
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 68 lines · Kamezawa Hiroyuki
Quoted 50 lines · Ying Han
Quoted 32 lines · Michal Hocko
Quoted 25 lines · Ying Han
Quoted 17 lines · Rik van Riel
Quoted 4 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
Quoted 8 lines
I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYAlthough it doesn't seem necessary at the moment, because there is just
one location where it matters but it could help in the future. What do you think?Quoted 4 lines
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
Quoted 3 lines
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
Quoted 5 lines
I am afraid we will not move forward without a proper implementation of the "nobody under soft limit" case. Maybe Rik's idea would just work out but this patch on it's own could regress so taking it separately is no go IMO. I like how it reduces the code size but we are not "there" yet...
Sorry for getting back to the thread late. Being distracted to something else which of course happens all the time.
Before me jumping into actions of any changes, let me clarify the problem I am facing:
All the concerns are related to the configuration where none of the memcg is eligible for reclaim ( usage < softlimit ) under global
pressure. The current code works like the following:Quoted 7 lines
1. walk the memcg tree and for each checks the softlimit
2. if none of the memcg is being reclaimed, then set theignore_softlimit
3. restart the walk and this round forget about the softlimitThere are two problems I heard here:
1. doing a full walk on step 1 would cause potential scalability issue.Simply thinking, I think maintaining & updating the whole softlimit information
periodically is a way to avoid double-scan. memcg has a percpu event-counter and
css-id bitmap will be enough for keeping information. Then, you can find over-softlimit memcg by bitmap scanning.
Quoted 8 lines
Quoted 4 lines
2. root cgroup is a exception where it always eligible for reclaim ( softlimit = 0 always). That will cause root to be punished more than necessary.
When use_hierarchy==0 ?
How about having implicit softlimit value for root, which is automatically calculated fromtotal_ramor the number of tasks in root ?
No, we have use_hierarchy set to 1 for root. Also, as part of the patchset the softlimit of root is set to 0 and also can not be modified later. There is a reason behind it mainly because now we check the softlimit of a memcg hierarchically.
Calculating the softlimit for root sounds an over-kill and not necessary. It works fine to have softlimit of root to 0 and we just need to fix the inefficiency in the code where no non-memcg is above softlimit. In that case, we don't want to over-punish root.
My current version is to not counting root to set ignore_softlimit flag, so at least the second round of scanning will look at all the other memcgs. I don't see a major problem of it apart from the scalability concern addressed on 1.
--Ying
Quoted 8 lines
Thanks,
-Kame
--
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 113 lines · Glauber Costa
Quoted 83 lines · Ying Han
Quoted 58 lines · Michal Hocko
Quoted 57 lines · Ying Han
Quoted 55 lines · Rik van Riel
Quoted 45 lines · Michal Hocko
On Thu 02-08-12 14:24:18, Ying Han wrote:
[...]Quoted 28 lines
mm/vmscan.c +2
-1@@ -1866,7 +1866,22 @@ static void shrink_zone(struct zone *zone, struct scan_control *sc) do {struct lruvec *lruvec =mem_cgroup_zone_lruvec (zone, memcg); -shrink_lruvec (lruvec, sc); +/* +* Reclaim from mem_cgroup if any of these conditions are met:
mm/vmscan.c +3
-0+* - this is a targetted reclaim ( not global reclaim) +* - reclaim priority is less than DEF_PRIORITY +* - mem_cgroup or its ancestor ( not including root cgroup)
mm/vmscan.c +4
-0+* exceeds its soft limit +* +* Note: The priority check is a balance of how hard to +* preserve the pages under softlimit. If the memcgs of the
+ * zone having trouble to reclaim pages above their
softlimit,
+ * we have to reclaim under softlimit instead of burning
moremm/vmscan.c
Quoted 8 lines
mm/vmscan.c +5
-0+* cpu cycles. +*/ +if (!global_reclaim (sc) || sc->priority<DEF_PRIORITY || +mem_cgroup_over_soft_limit (memcg)) +shrink_lruvec (lruvec, sc);/* * Limit reclaim has historically picked one memcg and I am thinking that we could add a constant for the priority limit. Something like
#defineMEMCG_LOW_SOFTLIMIT_PRIORITYDEF_PRIORITYQuoted 3 lines
Although it doesn't seem necessary at the moment, because there is just one location where it matters but it could help in the future. What do you think?
I am working on changing the code to find the "highest priority" LRU and reclaim from that list first. That will obviate the need for such a change. However, the other cleanups and simplifications made by Ying's patch are good to have...
Quoted 9 lines
Quoted 3 lines
So what you guys think to take from here. I can make the change as Michal suggested if that would be something helpful future changes. However, I wonder whether or not it is necessary.
I am afraid we will not move forward without a proper implementation of the "nobody under soft limit" case. Maybe Rik's idea would just work out but this patch on it's own could regress so taking it separately is no go IMO. I like how it reduces the code size but we are not "there" yet...
Sorry for getting back to the thread late. Being distracted to something else which of course happens all the time.
Before me jumping into actions of any changes, let me clarify the problem I am facing:
All the concerns are related to the configuration where none of the memcg is eligible for reclaim ( usage < softlimit ) under global
pressure. The current code works like the following:1. walk the memcg tree and for each checks the softlimit
2. if none of the memcg is being reclaimed, then set theignore_softlimit
3. restart the walk and this round forget about the softlimitQuoted 9 lines
There are two problems I heard here:
1. doing a full walk on step 1 would cause potential scalability issue.Note: I would argue the admin need to adjust the configuration instead. In theory, it is not recommended to over-commit the soft-limit based on the concept. However, it could happen but and the case should be rare.
The issue hasn't been observed on our running environment by far.Can't you hash or add the memcgs to a list at charge time whenever they get close to the limit? You should be able to hook at the notifications mechanism for that, and reduce the number of memcgs to scan by a large factor in practice.
Or did I misunderstand what the problem is?
Quoted 11 lines
2. root cgroup is a exception where it always eligible for reclaim ( softlimit = 0 always). That will cause root to be punished more than necessary.
Note: Not sure what would be the expected behavior. On one side, we declare the softlimit of root always be the default (0), and even future it can not be changed. Any pages above the soft-limit is low-priority and targeted to reclaim over others. So, in this case where no other memcg above their softlimit, why adding pressure on root would be a regression.
Quoted 4 lines
The problem here, I believe, is the good & old hierarchy discussion. Your behavior looks sane with hierarchy, because everybody is under root memcg. So "reclaiming from root memcg" means doing a global reclaim the way had always done.
Not exactly. Here reclaiming from root is mainly for "reclaiming from root's exclusive lru", which links the page includes:
1. processes running under root
2. reparented pages from rmdir memcg under root
3. bypassed pages
Setting root cgroup's softlimit = 0 has the implication of putting those pages to likely to reclaim, which works fine. The question is that if no other memcg is above its softlimit, would it be a problem to adding a bit extra pressure to root which always is eligible for softlimit reclaim ( usage is always greater than softlimit).
As an example, it works fine in our environment since we don't explicitly put any process under root. Most of the pages linked in root lru would be reparented pages which should be reclaimed prior to others.
Quoted 4 lines
Without hierarchy, however, it does look bad. If we have no reason to penalize a particular group, we should just ignore the group membership information while reclaiming.
I have to think about carefully how the thing works in use_hiearchy = 0 environment. In that case, every memcg is on the same hierarchy level including root. We still have those three types of pages under root ( i guess) and one difference is that none-root memcg's charge won't go to root. Thinking about that, I don't see much difference here since we don't charge anything to root anyway with use_hiearchy=1. Am I miss anything here?
Overall, I would like to talk about whether or not we should mark use_hiearchy = 1 always. Although this is a different topic.
--Ying
Quoted 29 lines
Quoted 29 lines
I would like to take a look at Rik's patch and especially I am interested in if the score scheme helps the case 1. On the other hand, I wonder how that would provide the gurantees of memory under softlimit. We might be able to accomplish that but w/ cost of more computation power.
Is there anything that I missed and need to look next as well?
Thanks
--Ying
Quoted 9 lines
Quoted 5 lines
--Ying
Quoted 3 lines
--
All rights reversed--
Michal Hocko
SUSE Labs
Quoted 7 lines
Quoted 6 lines
--
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>
--
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 12 lines · Ying Han
Not exactly. Here reclaiming from root is mainly for "reclaiming from root's exclusive lru", which links the page includes:
1. processes running under root
2. reparented pages from rmdir memcg under root
3. bypassed pagesSetting root cgroup's softlimit = 0 has the implication of putting those pages to likely to reclaim, which works fine. The question is that if no other memcg is above its softlimit, would it be a problem to adding a bit extra pressure to root which always is eligible for softlimit reclaim ( usage is always greater than softlimit).
Quoted 4 lines
As an example, it works fine in our environment since we don't explicitly put any process under root. Most of the pages linked in root lru would be reparented pages which should be reclaimed prior to others.
Keep in mind that not all environments will be specialized to the point of having root memcg empty. This basically treats root memcg as a trash bin, and can be very detrimental to use cases where actual memory is present in there.
It would maybe be better to have all this garbage to go to a separate place, like a shadow garbage memcg, which is invisible to the filesystem, and is always the first to be reclaimed from, in any circumstance.
--
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 23 lines · Glauber Costa
Quoted 12 lines · Ying Han
Not exactly. Here reclaiming from root is mainly for "reclaiming from root's exclusive lru", which links the page includes:
1. processes running under root
2. reparented pages from rmdir memcg under root
3. bypassed pagesSetting root cgroup's softlimit = 0 has the implication of putting those pages to likely to reclaim, which works fine. The question is that if no other memcg is above its softlimit, would it be a problem to adding a bit extra pressure to root which always is eligible for softlimit reclaim ( usage is always greater than softlimit).
Quoted 4 lines
As an example, it works fine in our environment since we don't explicitly put any process under root. Most of the pages linked in root lru would be reparented pages which should be reclaimed prior to others.
Keep in mind that not all environments will be specialized to the point of having root memcg empty. This basically treats root memcg as a trash bin, and can be very detrimental to use cases where actual memory is present in there.
Quoted 5 lines
It would maybe be better to have all this garbage to go to a separate place, like a shadow garbage memcg, which is invisible to the filesystem, and is always the first to be reclaimed from, in any circumstance.
We can certainly do something like that, and actually we have the *special* cgroup setup today in google's environment. It is mainly targeting for pages that are allocated not on behalf of applications, but more of system maintainess overhead. One example would be kernel thread memory charging.
In this case, it might make sense to put those reparented pages to a separate cgroup. However I do wonder with the following questions:
1. it might only make sense to do that if something else running under root. As we know, root is kind of special in memcg where there is no limit on it. So I wonder what would be the real life use case to put something under root?
2. even the reparented pages are mixed together with pages from process running under root, the LRU mechanism should still take effect of evicting cold pages first. if the reparent pages are the left-over pages from the removed cgroups, I would assume they are the candidate to reclaim first.
I am curious that in your environment, do you have things running root?
--Ying
Quoted 41 lines · Ying Han
On Tue, Aug 21, 2012 at 2:29 AM, Glauber Costa <[email protected] <mailto:[email protected]>> wrote:
On 08/20/2012 10:30 PM, Ying Han wrote:
> Not exactly. Here reclaiming from root is mainly for "reclaiming from > root's exclusive lru", which links the page includes:
> 1. processes running under root
> 2. reparented pages from rmdir memcg under root
> 3. bypassed pages
>
> Setting root cgroup's softlimit = 0 has the implication of putting > those pages to likely to reclaim, which works fine. The question is > that if no other memcg is above its softlimit, would it be a problem > to adding a bit extra pressure to root which always is eligible for > softlimit reclaim ( usage is always greater than softlimit). >
> As an example, it works fine in our environment since we don't > explicitly put any process under root. Most of the pages linked in > root lru would be reparented pages which should be reclaimed prior to > others.Keep in mind that not all environments will be specialized to the point of having root memcg empty. This basically treats root memcg as a trash bin, and can be very detrimental to use cases where actual memory is present in there.
It would maybe be better to have all this garbage to go to a separate place, like a shadow garbage memcg, which is invisible to the filesystem, and is always the first to be reclaimed from, in any circumstance.
We can certainly do something like that, and actually we have the *special* cgroup setup today in google's environment. It is mainly targeting for pages that are allocated not on behalf of applications, but more of
system maintainess overhead. One example would be kernel thread memory charging.
Quoted 8 lines
In this case, it might make sense to put those reparented pages to a separate cgroup. However I do wonder with the following questions:
1. it might only make sense to do that if something else running under root. As we know, root is kind of special in memcg where there is no limit on it. So I wonder what would be the real life use case to put something under root?
It is a common desktop environment cgroups usage to separate some special processes only in memcg, and bind their memory usage. This is even mentioned in the docs as an example case, if I recall correctly.
Systemd, for instance, places all services in cgroups. All the rest of the system, applications user launches, etc, would live in the root memcg.
Quoted 6 lines
2. even the reparented pages are mixed together with pages from process running under root, the LRU mechanism should still take effect of evicting cold pages first. if the reparent pages are the left-over pages from the removed cgroups, I would assume they are the candidate to reclaim first.
I think this is a big assumption. To begin with, pages *just* reparented will still be hot. They can be a lot.
Quoted 2 lines
I am curious that in your environment, do you have things running root?
Our environment is also pretty easy, in the sense that all processes that matters lives in a cgroup, 1 per-container. But say the admin wants to install a management deamon, for instance, it won't necessarily be accounted.
In any case, our use case is not my top concern here. Rather, it is the general usage for people other than us.
--
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>