(resend) [PATCH] vmscan,memcg: memcg aware swap token
Subsystems (5)
Currently, memcg reclaim can disable swap token even if the swap token mm doesn't belong in its memory cgroup. It's slightly riskly. If an admin makes very small mem-cgroup and silly guy runs contenious heavy memory pressure workloa, whole tasks in the system are going to lose swap-token and then system may become unresponsive. That's bad.
This patch adds 'memcg' parameter into disable_swap_token(). and if the parameter doesn't match swap-token, VM doesn't put swap-token.
--- include/linux/memcontrol.h | 6 ++++++ include/linux/swap.h | 24 +++++++++++++++++------- mm/memcontrol.c | 2 +- mm/thrash.c | 17 +++++++++++++++++ mm/vmscan.c | 4 ++-- 5 files changed, 43 insertions(+), 10 deletions(-)
include/linux/memcontrol.h +6 -0
@@ -84,6 +84,7 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);extern struct mem_cgroup *try_get_mem_cgroup_from_page (struct page *page);extern struct mem_cgroup *mem_cgroup_from_task (struct task_struct *p); +extern struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm);static inline int mm_match_cgroup (const struct mm_struct *mm,const struct mem_cgroup *cgroup)
@@ -244,6 +245,11 @@ static inline struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)return NULL ; } +static inline struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm) +{ +return NULL ; +} +static inline int mm_match_cgroup (struct mm_struct *mm,struct mem_cgroup *mem) {return 1 ;
include/linux/swap.h +17 -7
@@ -358,21 +358,31 @@ struct backing_dev_info;extern struct mm_struct *swap_token_mm;extern void grab_swap_token (struct mm_struct *);extern void __put_swap_token (struct mm_struct *); +extern int has_swap_token_memcg (struct mm_struct *mm,struct mem_cgroup *memcg); -static inline int has_swap_token (struct mm_struct *mm) +static inline +int has_swap_token (struct mm_struct *mm) { -return (mm == swap_token_mm); +return has_swap_token_memcg (mm,NULL ); } -static inline void put_swap_token (struct mm_struct *mm) +static inline +void put_swap_token_memcg (struct mm_struct *mm,struct mem_cgroup *memcg) { -if (has_swap_token (mm)) +if (has_swap_token_memcg (mm, memcg))__put_swap_token (mm); } -static inline void disable_swap_token (void ) +static inline +void put_swap_token (struct mm_struct *mm) +{ +return put_swap_token_memcg (mm,NULL ); +} + +static inline +void disable_swap_token (struct mem_cgroup *memcg) { -put_swap_token (swap_token_mm); +put_swap_token_memcg (swap_token_mm, memcg); }#ifdef CONFIG_CGROUP_MEM_RES_CTLR
@@ -500,7 +510,7 @@ static inline int has_swap_token(struct mm_struct *mm)return 0 ; } -static inline void disable_swap_token (void ) +static inline void disable_swap_token (struct mem_cgroup *memcg) { }
mm/memcontrol.c +1 -1
@@ -735,7 +735,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) struct mem_cgroup, css); } -static struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm) +struct mem_cgroup *try_get_mem_cgroup_from_mm (struct mm_struct *mm) {struct mem_cgroup *mem =NULL ;
mm/thrash.c +17 -0
@@ -21,6 +21,7 @@#include <linux/mm.h> #include <linux/sched.h> #include <linux/swap.h> +#include <linux/memcontrol.h> static DEFINE_SPINLOCK (swap_token_lock);struct mm_struct *swap_token_mm;
@@ -75,3 +76,19 @@ void __put_swap_token(struct mm_struct *mm) swap_token_mm =NULL ;spin_unlock (&swap_token_lock); } + +int has_swap_token_memcg (struct mm_struct *mm,struct mem_cgroup *memcg) +{ +if (memcg) { +struct mem_cgroup *swap_token_memcg; + +/* +* memcgroup reclaim can disable swap token only if token task +* is in the same cgroup. +*/ + swap_token_memcg =try_get_mem_cgroup_from_mm (swap_token_mm); +return ((mm == swap_token_mm) && (memcg == swap_token_memcg)); + }else +return (mm == swap_token_mm); +} +
mm/vmscan.c +2 -2
@@ -2044,7 +2044,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,for (priority =DEF_PRIORITY ; priority >=0 ; priority--) { sc->nr_scanned =0 ;if (!priority) -disable_swap_token (); +disable_swap_token (sc->mem_cgroup);shrink_zones (priority, zonelist, sc);/* * Don't shrink slabs when reclaiming memory from
@@ -2353,7 +2353,7 @@ loop_again:/* The swap token gets in the way of swapout... */ if (!priority) -disable_swap_token (); +disable_swap_token (NULL ); all_zones_ok =1 ; balanced =0 ;
Signature · 11 lines
1.7.3.1 -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · On Tue, 26 Apr 2011 16:59:19 +0900 (JST) KOSAKI Motohiro…
Currently, memcg reclaim can disable swap token even if the swap token mm doesn't belong in its memory cgroup. It's slightly riskly. If an admin makes very small mem-cgroup and silly guy runs contenious heavy memory pressure workloa, whole tasks in the system are going to lose swap-token and then system may become unresponsive. That's bad.
This patch adds 'memcg' parameter into
disable_swap_token(). and if the parameter doesn't match swap-token, VM doesn't put swap-token.Signed-off-by KOSAKI Motohiro <[email protected]>Reviewed-by KAMEZAWA Hiroyuki <[email protected]>
Ack. Thank you.
-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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 9 lines · On Tue, 26 Apr 2011 16:59:19 +0900 (JST) KOSAKI Motohiro…
mm/thrash.c +5
-0@@ -75,3 +76,19 @@ void __put_swap_token(struct mm_struct *mm) swap_token_mm =NULL ;spin_unlock (&swap_token_lock); } + +int has_swap_token_memcg (struct mm_struct *mm,struct mem_cgroup *memcg) +{ +if (memcg) { +struct mem_cgroup *swap_token_memcg;
mm/thrash.c void __put_swap_token(struct mm_struct *mm) · line 93
Quoted 10 lines
mm/thrash.c +10
-0+ +/* +* memcgroup reclaim can disable swap token only if token task +* is in the same cgroup. +*/ + swap_token_memcg =try_get_mem_cgroup_from_mm (swap_token_mm); +return ((mm == swap_token_mm) && (memcg == swap_token_memcg)); + }else +return (mm == swap_token_mm); +}
Seems to be missing a css_put()?
Either I'm mistaken or that's a bug. Perhaps neither of these would have happened if we'd bothered to document try_get_mem_cgroup_from_mm().
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 16 lines
Quoted 13 lines · On Tue, 26 Apr 2011 16:59:19 +0900 (JST) KOSAKI Motohiro…
mm/thrash.c +9
-0@@ -75,3 +76,19 @@ void __put_swap_token(struct mm_struct *mm) swap_token_mm =NULL ;spin_unlock (&swap_token_lock); } + +int has_swap_token_memcg (struct mm_struct *mm,struct mem_cgroup *memcg) +{ +if (memcg) { +struct mem_cgroup *swap_token_memcg; + +/* +* memcgroup reclaim can disable swap token only if token task +* is in the same cgroup.
Quoted 8 lines
mm/thrash.c void __put_swap_token(struct mm_struct *mm) · line 93
Quoted 6 lines
mm/thrash.c +6
-0+*/ + swap_token_memcg =try_get_mem_cgroup_from_mm (swap_token_mm); +return ((mm == swap_token_mm) && (memcg == swap_token_memcg)); + }else +return (mm == swap_token_mm); +}Seems to be missing a
css_put()?
Yes! Please drop this one. I'll rework it at this weekend.
Thank you for the finding!
Quoted 5 lines
Either I'm mistaken or that's a bug. Perhaps neither of these would have happened if we'd bothered to document
try_get_mem_cgroup_from_mm().
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>