memcg-aware slab shrinking
Subsystems (28)
A message that is not in the archive (sent off-list or not yet received): 1364548450-28254-22-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
Quoted 78 lines · Glauber Costa
Without the surrounding infrastructure, this patch is a bit of a hammer:
it will basically shrink objects from all memcgs under memcg pressure. At least, however, we will keep the scan limited to the shrinkers marked as per-memcg.Future patches will implement the in-shrinker logic to filter objects based on its memcg association.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <akpm-de/[email protected]>--- include/linux/memcontrol.h | 17 +++++++++++++++++ include/linux/shrinker.h | 4 ++++ mm/memcontrol.c | 16 +++++++++++++++- mm/vmscan.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 79 insertions(+), 4 deletions(-)include/linux/memcontrol.h +17
-0@@ -199,6 +199,9 @@ void mem_cgroup_split_huge_fixup(struct page *head);bool mem_cgroup_bad_page_check (struct page *page);void mem_cgroup_print_bad_page (struct page *page);#endif + +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone);#else /* CONFIG_MEMCG */ struct mem_cgroup ;@@ -377,6 +380,12 @@ static inline void mem_cgroup_replace_page_cache(struct page *oldpage, struct page *newpage) { } + +static inline unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +return 0 ; +}#endif /* CONFIG_MEMCG */ #if !defined(CONFIG_MEMCG ) || !defined(CONFIG_DEBUG_VM )@@ -429,6 +438,8 @@ static inline bool memcg_kmem_enabled(void)return static_key_false (&memcg_kmem_enabled_key); } +bool memcg_kmem_is_active (struct mem_cgroup *memcg); +/* * In general, we'll do everything in our power to not incur in any overhead * for non-memcg users for the kmem functions. Not even a function call, if we @@ -562,6 +573,12 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp) return __memcg_kmem_get_cache(cachep, gfp); }#else + +static inline bool memcg_kmem_is_active (struct mem_cgroup *memcg) +{ +return false; +} +#define for_each_memcg_cache_index (_idx) \ for (; NULL; )include/linux/shrinker.h +0
-0
include/linux/shrinker.h struct shrink_control { · line 26
Quoted 7 lines
include/linux/shrinker.h +3
-0@@ -20,6 +20,9 @@ struct shrink_control {/* shrink from these nodes */ nodemask_t nodes_to_scan; + +/* reclaim from this memcg only (if not NULL) */ +struct mem_cgroup *target_mem_cgroup; };
Does this works only with kmem ? If so, please rename to some explicit name for now.
shrink_slab_memcg_target or some ?
Quoted 53 lines
include/linux/shrinker.h +1
-0/* @@ -45,6 +48,7 @@ struct shrinker {int seeks;/* seeks to recreate an obj */ long batch;/* reclaim batch size, 0 = default */ +bool memcg_shrinker;/* memcg-aware shrinker */ /* These are for internal use */ struct list_head list;mm/memcontrol.c +15
-1@@ -386,7 +386,7 @@ static inline void memcg_kmem_set_active(struct mem_cgroup *memcg)set_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); } -static bool memcg_kmem_is_active (struct mem_cgroup *memcg) +bool memcg_kmem_is_active (struct mem_cgroup *memcg) {return test_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); }@@ -942,6 +942,20 @@ mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,return ret; } +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account) + val +=mem_cgroup_zone_nr_lru_pages (memcg, nid, zid, +LRU_ALL_ANON ); +return val; +} +static unsigned long mem_cgroup_node_nr_lru_pages (struct mem_cgroup *memcg,int nid,unsigned int lru_mask)mm/vmscan.c +1
-0@@ -138,11 +138,42 @@ static bool global_reclaim(struct scan_control *sc) {return !sc->target_mem_cgroup; } +
mm/vmscan.c static bool global_reclaim(struct scan_control *sc) · line 151
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* kmem reclaim should usually not be triggered when we are doing targetted +* reclaim. It is only valid when global reclaim is triggered, or when the +* underlying memcg has kmem objects. +*/ +static bool has_kmem_reclaim (struct scan_control *sc) +{ +return !sc->target_mem_cgroup || +memcg_kmem_is_active (sc->target_mem_cgroup); +}
Is this test hierarchy aware ?
For example, in following case,
A no kmem limit
\
B kmem limit=XXX
\
C kmem limit=XXXwhat happens when A is the target.
Thanks
-Kame
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
In reply to Glauber CostaQuoted 78 lines · Glauber Costa
Without the surrounding infrastructure, this patch is a bit of a hammer:
it will basically shrink objects from all memcgs under memcg pressure. At least, however, we will keep the scan limited to the shrinkers marked as per-memcg.Future patches will implement the in-shrinker logic to filter objects based on its memcg association.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <[email protected]>--- include/linux/memcontrol.h | 17 +++++++++++++++++ include/linux/shrinker.h | 4 ++++ mm/memcontrol.c | 16 +++++++++++++++- mm/vmscan.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 79 insertions(+), 4 deletions(-)include/linux/memcontrol.h +17
-0@@ -199,6 +199,9 @@ void mem_cgroup_split_huge_fixup(struct page *head);bool mem_cgroup_bad_page_check (struct page *page);void mem_cgroup_print_bad_page (struct page *page);#endif + +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone);#else /* CONFIG_MEMCG */ struct mem_cgroup ;@@ -377,6 +380,12 @@ static inline void mem_cgroup_replace_page_cache(struct page *oldpage, struct page *newpage) { } + +static inline unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +return 0 ; +}#endif /* CONFIG_MEMCG */ #if !defined(CONFIG_MEMCG ) || !defined(CONFIG_DEBUG_VM )@@ -429,6 +438,8 @@ static inline bool memcg_kmem_enabled(void)return static_key_false (&memcg_kmem_enabled_key); } +bool memcg_kmem_is_active (struct mem_cgroup *memcg); +/* * In general, we'll do everything in our power to not incur in any overhead * for non-memcg users for the kmem functions. Not even a function call, if we @@ -562,6 +573,12 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp) return __memcg_kmem_get_cache(cachep, gfp); }#else + +static inline bool memcg_kmem_is_active (struct mem_cgroup *memcg) +{ +return false; +} +#define for_each_memcg_cache_index (_idx) \ for (; NULL; )include/linux/shrinker.h +0
-0
include/linux/shrinker.h struct shrink_control { · line 26
Quoted 7 lines
include/linux/shrinker.h +3
-0@@ -20,6 +20,9 @@ struct shrink_control {/* shrink from these nodes */ nodemask_t nodes_to_scan; + +/* reclaim from this memcg only (if not NULL) */ +struct mem_cgroup *target_mem_cgroup; };
Does this works only with kmem ? If so, please rename to some explicit name for now.
shrink_slab_memcg_target or some ?
Quoted 53 lines
include/linux/shrinker.h +1
-0/* @@ -45,6 +48,7 @@ struct shrinker {int seeks;/* seeks to recreate an obj */ long batch;/* reclaim batch size, 0 = default */ +bool memcg_shrinker;/* memcg-aware shrinker */ /* These are for internal use */ struct list_head list;mm/memcontrol.c +15
-1@@ -386,7 +386,7 @@ static inline void memcg_kmem_set_active(struct mem_cgroup *memcg)set_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); } -static bool memcg_kmem_is_active (struct mem_cgroup *memcg) +bool memcg_kmem_is_active (struct mem_cgroup *memcg) {return test_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); }@@ -942,6 +942,20 @@ mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,return ret; } +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account) + val +=mem_cgroup_zone_nr_lru_pages (memcg, nid, zid, +LRU_ALL_ANON ); +return val; +} +static unsigned long mem_cgroup_node_nr_lru_pages (struct mem_cgroup *memcg,int nid,unsigned int lru_mask)mm/vmscan.c +1
-0@@ -138,11 +138,42 @@ static bool global_reclaim(struct scan_control *sc) {return !sc->target_mem_cgroup; } +
mm/vmscan.c static bool global_reclaim(struct scan_control *sc) · line 151
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* kmem reclaim should usually not be triggered when we are doing targetted +* reclaim. It is only valid when global reclaim is triggered, or when the +* underlying memcg has kmem objects. +*/ +static bool has_kmem_reclaim (struct scan_control *sc) +{ +return !sc->target_mem_cgroup || +memcg_kmem_is_active (sc->target_mem_cgroup); +}
Is this test hierarchy aware ?
For example, in following case,
A no kmem limit
\
B kmem limit=XXX
\
C kmem limit=XXXwhat happens when A is the target.
Thanks
-Kame
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
Hi Kame,
Quoted 32 lines
Quoted 21 lines
/*
* In general, we'll do everything in our power to not incur in any overhead
* for non-memcg users for the kmem functions. Not even a function call, if weinclude/linux/memcontrol.h +6
-0@@ -562,6 +573,12 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp) return __memcg_kmem_get_cache(cachep, gfp); }#else + +static inline bool memcg_kmem_is_active (struct mem_cgroup *memcg) +{ +return false; +} +#define for_each_memcg_cache_index (_idx) \ for (; NULL; )include/linux/shrinker.h +0
-0include/linux/shrinker.h struct shrink_control { · line 26
Quoted 7 lines
include/linux/shrinker.h +3
-0@@ -20,6 +20,9 @@ struct shrink_control {/* shrink from these nodes */ nodemask_t nodes_to_scan; + +/* reclaim from this memcg only (if not NULL) */ +struct mem_cgroup *target_mem_cgroup; };Does this works only with kmem ? If so, please rename to some explicit name for now.
Quoted 1 line
shrink_slab_memcg_targetor some ?
No, this is not kmem specific. It will be used (so far) to determine which shrinkers to shrink from, but since we are now including shrink_slab in user pressure as well, this can very well be filled by user memory pressure code. (This will be the case, for instance, if umem == kmem)
Therefore, it is the same target_mem_cgroup context we are already passing around in other vmscan functions. But shrink_control had none, and now we are attaching it there.
Therefore I would like to maintain it neutral, just as memcg.
Quoted 60 lines
Quoted 45 lines
mm/memcontrol.c +15
-1@@ -386,7 +386,7 @@ static inline void memcg_kmem_set_active(struct mem_cgroup *memcg)set_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); } -static bool memcg_kmem_is_active (struct mem_cgroup *memcg) +bool memcg_kmem_is_active (struct mem_cgroup *memcg) {return test_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); }@@ -942,6 +942,20 @@ mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,return ret; } +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account) + val +=mem_cgroup_zone_nr_lru_pages (memcg, nid, zid, +LRU_ALL_ANON ); +return val; +} +static unsigned long mem_cgroup_node_nr_lru_pages (struct mem_cgroup *memcg,int nid,unsigned int lru_mask)mm/vmscan.c +1
-0@@ -138,11 +138,42 @@ static bool global_reclaim(struct scan_control *sc) {return !sc->target_mem_cgroup; } +mm/vmscan.c static bool global_reclaim(struct scan_control *sc) · line 151
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* kmem reclaim should usually not be triggered when we are doing targetted +* reclaim. It is only valid when global reclaim is triggered, or when the +* underlying memcg has kmem objects. +*/ +static bool has_kmem_reclaim (struct scan_control *sc) +{ +return !sc->target_mem_cgroup || +memcg_kmem_is_active (sc->target_mem_cgroup); +}Is this test hierarchy aware ?
For example, in following case,
Quoted 8 lines
A no kmem limit \ B kmem limit=XXX \ C kmem limit=XXXwhat happens when A is the target.
When A is under pressure, we won't scan A. I coded it like this because the slabs are local, even if the charges are not.
In other words, because I won't scan the memcgs hierarchically, I didn't bother noticing about their kmem awareness hierarchically.
But I am still thinking about that, and your input is very welcome.
In one hand, A won't have a kmem res_counter, so we won't be able to uncharge anything from it. On the other hand, the charges are also accumulated on the user res_counter of A. Under user pressure, it may be important to free this memory. So I am inclined to change that.
Do you agree?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
Hi Kame,
Quoted 32 lines
Quoted 21 lines
/*
* In general, we'll do everything in our power to not incur in any overhead
* for non-memcg users for the kmem functions. Not even a function call, if weinclude/linux/memcontrol.h +6
-0@@ -562,6 +573,12 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp) return __memcg_kmem_get_cache(cachep, gfp); }#else + +static inline bool memcg_kmem_is_active (struct mem_cgroup *memcg) +{ +return false; +} +#define for_each_memcg_cache_index (_idx) \ for (; NULL; )include/linux/shrinker.h +0
-0include/linux/shrinker.h struct shrink_control { · line 26
Quoted 7 lines
include/linux/shrinker.h +3
-0@@ -20,6 +20,9 @@ struct shrink_control {/* shrink from these nodes */ nodemask_t nodes_to_scan; + +/* reclaim from this memcg only (if not NULL) */ +struct mem_cgroup *target_mem_cgroup; };Does this works only with kmem ? If so, please rename to some explicit name for now.
Quoted 1 line
shrink_slab_memcg_targetor some ?
No, this is not kmem specific. It will be used (so far) to determine which shrinkers to shrink from, but since we are now including shrink_slab in user pressure as well, this can very well be filled by user memory pressure code. (This will be the case, for instance, if umem == kmem)
Therefore, it is the same target_mem_cgroup context we are already passing around in other vmscan functions. But shrink_control had none, and now we are attaching it there.
Therefore I would like to maintain it neutral, just as memcg.
Quoted 60 lines
Quoted 45 lines
mm/memcontrol.c +15
-1@@ -386,7 +386,7 @@ static inline void memcg_kmem_set_active(struct mem_cgroup *memcg)set_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); } -static bool memcg_kmem_is_active (struct mem_cgroup *memcg) +bool memcg_kmem_is_active (struct mem_cgroup *memcg) {return test_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); }@@ -942,6 +942,20 @@ mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,return ret; } +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account) + val +=mem_cgroup_zone_nr_lru_pages (memcg, nid, zid, +LRU_ALL_ANON ); +return val; +} +static unsigned long mem_cgroup_node_nr_lru_pages (struct mem_cgroup *memcg,int nid,unsigned int lru_mask)mm/vmscan.c +1
-0@@ -138,11 +138,42 @@ static bool global_reclaim(struct scan_control *sc) {return !sc->target_mem_cgroup; } +mm/vmscan.c static bool global_reclaim(struct scan_control *sc) · line 151
Quoted 10 lines
mm/vmscan.c +10
-0+/* +* kmem reclaim should usually not be triggered when we are doing targetted +* reclaim. It is only valid when global reclaim is triggered, or when the +* underlying memcg has kmem objects. +*/ +static bool has_kmem_reclaim (struct scan_control *sc) +{ +return !sc->target_mem_cgroup || +memcg_kmem_is_active (sc->target_mem_cgroup); +}Is this test hierarchy aware ?
For example, in following case,
Quoted 8 lines
A no kmem limit \ B kmem limit=XXX \ C kmem limit=XXXwhat happens when A is the target.
When A is under pressure, we won't scan A. I coded it like this because the slabs are local, even if the charges are not.
In other words, because I won't scan the memcgs hierarchically, I didn't bother noticing about their kmem awareness hierarchically.
But I am still thinking about that, and your input is very welcome.
In one hand, A won't have a kmem res_counter, so we won't be able to uncharge anything from it. On the other hand, the charges are also accumulated on the user res_counter of A. Under user pressure, it may be important to free this memory. So I am inclined to change that.
Do you agree?
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
In reply to Glauber CostaHi Glauber,
Quoted 111 lines · Glauber Costa
Without the surrounding infrastructure, this patch is a bit of a hammer:
it will basically shrink objects from all memcgs under memcg pressure. At least, however, we will keep the scan limited to the shrinkers marked as per-memcg.Future patches will implement the in-shrinker logic to filter objects based on its memcg association.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <akpm-de/[email protected]>--- include/linux/memcontrol.h | 17 +++++++++++++++++ include/linux/shrinker.h | 4 ++++ mm/memcontrol.c | 16 +++++++++++++++- mm/vmscan.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 79 insertions(+), 4 deletions(-)include/linux/memcontrol.h +17
-0@@ -199,6 +199,9 @@ void mem_cgroup_split_huge_fixup(struct page *head);bool mem_cgroup_bad_page_check (struct page *page);void mem_cgroup_print_bad_page (struct page *page);#endif + +unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone);#else /* CONFIG_MEMCG */ struct mem_cgroup ;@@ -377,6 +380,12 @@ static inline void mem_cgroup_replace_page_cache(struct page *oldpage, struct page *newpage) { } + +static inline unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +return 0 ; +}#endif /* CONFIG_MEMCG */ #if !defined(CONFIG_MEMCG ) || !defined(CONFIG_DEBUG_VM )@@ -429,6 +438,8 @@ static inline bool memcg_kmem_enabled(void)return static_key_false (&memcg_kmem_enabled_key); } +bool memcg_kmem_is_active (struct mem_cgroup *memcg); +/* * In general, we'll do everything in our power to not incur in any overhead * for non-memcg users for the kmem functions. Not even a function call, if we @@ -562,6 +573,12 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp) return __memcg_kmem_get_cache(cachep, gfp); }#else + +static inline bool memcg_kmem_is_active (struct mem_cgroup *memcg) +{ +return false; +} +#define for_each_memcg_cache_index (_idx) \ for (; NULL; )include/linux/shrinker.h +4
-0@@ -20,6 +20,9 @@ struct shrink_control {/* shrink from these nodes */ nodemask_t nodes_to_scan; + +/* reclaim from this memcg only (if not NULL) */ +struct mem_cgroup *target_mem_cgroup; };/* @@ -45,6 +48,7 @@ struct shrinker {int seeks;/* seeks to recreate an obj */ long batch;/* reclaim batch size, 0 = default */ +bool memcg_shrinker;/* memcg-aware shrinker */ /* These are for internal use */ struct list_head list;mm/memcontrol.c +1
-1@@ -386,7 +386,7 @@ static inline void memcg_kmem_set_active(struct mem_cgroup *memcg)set_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); } -static bool memcg_kmem_is_active (struct mem_cgroup *memcg) +bool memcg_kmem_is_active (struct mem_cgroup *memcg) {return test_bit (KMEM_ACCOUNTED_ACTIVE , &memcg->kmem_account_flags); }@@ -942,6 +942,20 @@ mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,return ret; }
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 10 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)
IMHO May get_nr_swap_pages() be more appropriate here?
Quoted 102 lines
mm/memcontrol.c +5
-0+ val +=mem_cgroup_zone_nr_lru_pages (memcg, nid, zid, +LRU_ALL_ANON ); +return val; +} +static unsigned long mem_cgroup_node_nr_lru_pages (struct mem_cgroup *memcg,int nid,unsigned int lru_mask)mm/vmscan.c +43
-4@@ -138,11 +138,42 @@ static bool global_reclaim(struct scan_control *sc) {return !sc->target_mem_cgroup; } + +/* +* kmem reclaim should usually not be triggered when we are doing targetted +* reclaim. It is only valid when global reclaim is triggered, or when the +* underlying memcg has kmem objects. +*/ +static bool has_kmem_reclaim (struct scan_control *sc) +{ +return !sc->target_mem_cgroup || +memcg_kmem_is_active (sc->target_mem_cgroup); +} + +static unsigned long +zone_nr_reclaimable_pages (struct scan_control *sc,struct zone *zone) +{ +if (global_reclaim (sc)) +return zone_reclaimable_pages (zone); +return memcg_zone_reclaimable_pages (sc->target_mem_cgroup, zone); +} +#else static bool global_reclaim (struct scan_control *sc) {return true; } + +static bool has_kmem_reclaim (struct scan_control *sc) +{ +return true; +} + +static unsigned long +zone_nr_reclaimable_pages (struct scan_control *sc,struct zone *zone) +{ +return zone_reclaimable_pages (zone); +}#endif static unsigned long get_lru_size (struct lruvec *lruvec,enum lru_list lru)@@ -221,6 +252,14 @@ unsigned long shrink_slab(struct shrink_control *sc,long batch_size = shrinker->batch ? shrinker->batch :SHRINK_BATCH ; +/* +* If we don't have a target mem cgroup, we scan them all. +* Otherwise we will limit our scan to shrinkers marked as +* memcg aware +*/ +if (sc->target_mem_cgroup && !shrinker->memcg_shrinker) +continue ; + max_pass = shrinker->count_objects (shrinker, sc);WARN_ON (max_pass <0 );if (max_pass <=0 )@@ -2163,9 +2202,9 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,/* * Don't shrink slabs when reclaiming memory from -* over limit cgroups +* over limit cgroups, unless we know they have kmem objects */ -if (global_reclaim (sc)) { +if (has_kmem_reclaim (sc)) {unsigned long lru_pages =0 ;nodes_clear (shrink->nodes_to_scan);@@ -2174,7 +2213,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,if (!cpuset_zone_allowed_hardwall (zone,GFP_KERNEL ))continue ; - lru_pages +=zone_reclaimable_pages (zone); + lru_pages +=zone_nr_reclaimable_pages (sc, zone);node_set (zone_to_nid (zone), shrink->nodes_to_scan); }@@ -2443,6 +2482,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, };struct shrink_control shrink = { .gfp_mask = sc.gfp_mask, + .target_mem_cgroup = memcg, };/* -- 1.8.1.4
Quoted 4 lines
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/containers
--
Thanks,
Sha
A message that is not in the archive (sent off-list or not yet received): CAFj3OHXp5K6TSCJq4gmi7Y_RpkmbLzDU3GP8vRMmChexULZjyQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
Quoted 11 lines · Sha Zhengju
Quoted 9 lines
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 9 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)IMHO May
get_nr_swap_pages()be more appropriate here?
This is a per-memcg number, how would get_nr_swap_pages() help us here?
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
In reply to Sha ZhengjuQuoted 11 lines · Sha Zhengju
Quoted 9 lines
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 9 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)IMHO May
get_nr_swap_pages()be more appropriate here?
This is a per-memcg number, how would get_nr_swap_pages() help us here?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
Quoted 13 lines · Glauber Costa
Quoted 11 lines · Sha Zhengju
Quoted 9 lines
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 9 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)IMHO May
get_nr_swap_pages()be more appropriate here?
Quoted 2 lines
This is a per-memcg number, how would
get_nr_swap_pages()help us here?
I meant to add get_nr_swap_pages() as the if-judgement, that is:
if (do_swap_account && get_nr_swap_pages())
....
since anon pages becomes unreclaimable if swap space is used up.
Thanks,
Sha
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
In reply to Glauber CostaQuoted 13 lines · Glauber Costa
Quoted 11 lines · Sha Zhengju
Quoted 9 lines
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 9 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)IMHO May
get_nr_swap_pages()be more appropriate here?
Quoted 2 lines
This is a per-memcg number, how would
get_nr_swap_pages()help us here?
I meant to add get_nr_swap_pages() as the if-judgement, that is:
if (do_swap_account && get_nr_swap_pages())
....
since anon pages becomes unreclaimable if swap space is used up.
Thanks,
Sha
A message that is not in the archive (sent off-list or not yet received): CAFj3OHWEirUH-xWX4O1NVDXCc6EYtceYy9suUgphEQ3C-35oxQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
Quoted 14 lines · Sha Zhengju
Quoted 13 lines · Glauber Costa
Quoted 11 lines · Sha Zhengju
Quoted 9 lines
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 9 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)IMHO May
get_nr_swap_pages()be more appropriate here?
Quoted 9 lines
Quoted 2 lines
This is a per-memcg number, how would
get_nr_swap_pages()help us here?I meant to add
get_nr_swap_pages()as the if-judgement, that is:if (do_swap_account && get_nr_swap_pages()) ....since anon pages becomes unreclaimable if swap space is used up.
Well, I believe this is doable.
Re: [PATCH v2 21/28] vmscan: also shrink slab in memcg pressure
In reply to Sha ZhengjuQuoted 14 lines · Sha Zhengju
Quoted 13 lines · Glauber Costa
Quoted 11 lines · Sha Zhengju
Quoted 9 lines
mm/memcontrol.c mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid, · line 953
Quoted 9 lines
mm/memcontrol.c +9
-0+unsigned long +memcg_zone_reclaimable_pages (struct mem_cgroup *memcg,struct zone *zone) +{ +int nid =zone_to_nid (zone); +int zid =zone_idx (zone); +unsigned long val; + + val =mem_cgroup_zone_nr_lru_pages (memcg, nid, zid,LRU_ALL_FILE ); +if (do_swap_account)IMHO May
get_nr_swap_pages()be more appropriate here?
Quoted 9 lines
Quoted 2 lines
This is a per-memcg number, how would
get_nr_swap_pages()help us here?I meant to add
get_nr_swap_pages()as the if-judgement, that is:if (do_swap_account && get_nr_swap_pages()) ....since anon pages becomes unreclaimable if swap space is used up.
Well, I believe this is doable.
PATCH v2 22/28 memcg,list_lru: duplicate LRUs upon kmemcg creation
In reply to Glauber CostaWhen a new memcg is created, we need to open up room for its descriptors in all of the list_lrus that are marked per-memcg. The process is quite similar to the one we are using for the kmem caches: we initialize the new structures in an array indexed by kmemcg_id, and grow the array if needed. Key data like the size of the array will be shared between the kmem cache code and the list_lru code (they basically describe the same thing)
--- include/linux/list_lru.h | 37 ++++++++++- include/linux/memcontrol.h | 12 ++++ lib/list_lru.c | 101 +++++++++++++++++++++++++++--- mm/memcontrol.c | 151 +++++++++++++++++++++++++++++++++++++++++++-- mm/slab_common.c | 1 - 5 files changed, 285 insertions(+), 17 deletions(-)
include/linux/list_lru.h +36 -1
@@ -16,12 +16,47 @@ struct list_lru_node {long nr_items; }____cacheline_aligned_in_smp ; +/* +* This is supposed to be M x N matrix, where M is kmem-limited memcg, +* and N is the number of nodes. +*/ +struct list_lru_array { +struct list_lru_node node[1 ]; +}; +struct list_lru {struct list_lru_node node[MAX_NUMNODES ];nodemask_t active_nodes; +#ifdef CONFIG_MEMCG_KMEM +struct list_head lrus; +struct list_lru_array **memcg_lrus; +#endif }; -int list_lru_init (struct list_lru *lru); +struct mem_cgroup ; +#ifdef CONFIG_MEMCG_KMEM +struct list_lru_array *lru_alloc_array (void ); +int memcg_update_all_lrus (unsigned long num); +void list_lru_destroy (struct list_lru *lru); +void list_lru_destroy_memcg (struct mem_cgroup *memcg); +int __memcg_init_lru (struct list_lru *lru); +#else +static inline void list_lru_destroy (struct list_lru *lru) +{ +} +#endif + +int __list_lru_init (struct list_lru *lru,bool memcg_enabled); +static inline int list_lru_init (struct list_lru *lru) +{ +return __list_lru_init (lru, false); +} + +static inline int list_lru_init_memcg (struct list_lru *lru) +{ +return __list_lru_init (lru, true); +} +int list_lru_add (struct list_lru *lru,struct list_head *item);int list_lru_del (struct list_lru *lru,struct list_head *item);long list_lru_count_nodemask (struct list_lru *lru,nodemask_t *nodes_to_count);
include/linux/memcontrol.h +12 -0
@@ -23,6 +23,7 @@#include <linux/vm_event_item.h> #include <linux/hardirq.h> #include <linux/jump_label.h> +#include <linux/list_lru.h> struct mem_cgroup ;struct page_cgroup ;
@@ -469,6 +470,12 @@ void memcg_update_array_size(int num_groups);struct kmem_cache *__memcg_kmem_get_cache (struct kmem_cache *cachep,gfp_t gfp); +int memcg_new_lru (struct list_lru *lru); +int memcg_init_lru (struct list_lru *lru); + +int memcg_kmem_update_lru_size (struct list_lru *lru,int num_groups, +bool new_lru); +void mem_cgroup_destroy_cache (struct kmem_cache *cachep);void kmem_cache_destroy_memcg_children (struct kmem_cache *s);
@@ -632,6 +639,11 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)static inline void kmem_cache_destroy_memcg_children (struct kmem_cache *s) { } + +static inline int memcg_init_lru (struct list_lru *lru) +{ +return 0 ; +}#endif /* CONFIG_MEMCG_KMEM */ #endif /* _LINUX_MEMCONTROL_H */
lib/list_lru.c +92 -9
116 lines not on this page · raw message
mm/memcontrol.c +145 -6
175 lines not on this page · raw message
mm/slab_common.c +0 -1
@@ -102,7 +102,6 @@ int memcg_update_all_caches(int num_memcgs) goto out; } -memcg_update_array_size (num_memcgs); out:mutex_unlock (&slab_mutex);return ret;
Signature · 1 line
1.8.1.4
Re: [PATCH v2 22/28] memcg,list_lru: duplicate LRUs upon kmemcg creation
Quoted 30 lines · Glauber Costa
When a new memcg is created, we need to open up room for its descriptors in all of the
list_lrusthat are marked per-memcg. The process is quite similar to the one we are using for the kmem caches: we initialize the new structures in an array indexed bykmemcg_id, and grow the array if needed. Key data like the size of the array will be shared between the kmem cache code and thelist_lrucode (they basically describe the same thing)Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <akpm-de/[email protected]>--- include/linux/list_lru.h | 37 ++++++++++- include/linux/memcontrol.h | 12 ++++ lib/list_lru.c | 101 +++++++++++++++++++++++++++--- mm/memcontrol.c | 151 +++++++++++++++++++++++++++++++++++++++++++-- mm/slab_common.c | 1 - 5 files changed, 285 insertions(+), 17 deletions(-)include/linux/list_lru.h +0
-0
include/linux/list_lru.h struct list_lru_node { · line 22
Quoted 7 lines
include/linux/list_lru.h +4
-0@@ -16,12 +16,47 @@ struct list_lru_node {long nr_items; }____cacheline_aligned_in_smp ; +/* +* This is supposed to be M x N matrix, where M is kmem-limited memcg, +* and N is the number of nodes. +*/
Could you add a comment that M can be changed and the array can be resized.
include/linux/list_lru.h struct list_lru_node { · line 33
Quoted 11 lines
include/linux/list_lru.h +8
-0+struct list_lru_array { +struct list_lru_node node[1 ]; +}; +struct list_lru {struct list_lru_node node[MAX_NUMNODES ];nodemask_t active_nodes; +#ifdef CONFIG_MEMCG_KMEM +struct list_head lrus; +struct list_lru_array **memcg_lrus; +#endif
please add comments, for what ....
Quoted 105 lines
include/linux/list_lru.h +24
-1}; -int list_lru_init (struct list_lru *lru); +struct mem_cgroup ; +#ifdef CONFIG_MEMCG_KMEM +struct list_lru_array *lru_alloc_array (void ); +int memcg_update_all_lrus (unsigned long num); +void list_lru_destroy (struct list_lru *lru); +void list_lru_destroy_memcg (struct mem_cgroup *memcg); +int __memcg_init_lru (struct list_lru *lru); +#else +static inline void list_lru_destroy (struct list_lru *lru) +{ +} +#endif + +int __list_lru_init (struct list_lru *lru,bool memcg_enabled); +static inline int list_lru_init (struct list_lru *lru) +{ +return __list_lru_init (lru, false); +} + +static inline int list_lru_init_memcg (struct list_lru *lru) +{ +return __list_lru_init (lru, true); +} +int list_lru_add (struct list_lru *lru,struct list_head *item);int list_lru_del(struct list_lru *lru, struct list_head *item); long list_lru_count_nodemask(struct list_lru *lru, nodemask_t *nodes_to_count);include/linux/memcontrol.h +12
-0@@ -23,6 +23,7 @@#include <linux/vm_event_item.h> #include <linux/hardirq.h> #include <linux/jump_label.h> +#include <linux/list_lru.h> struct mem_cgroup ;struct page_cgroup ;@@ -469,6 +470,12 @@ void memcg_update_array_size(int num_groups);struct kmem_cache *__memcg_kmem_get_cache (struct kmem_cache *cachep,gfp_t gfp); +int memcg_new_lru (struct list_lru *lru); +int memcg_init_lru (struct list_lru *lru); + +int memcg_kmem_update_lru_size (struct list_lru *lru,int num_groups, +bool new_lru); +void mem_cgroup_destroy_cache (struct kmem_cache *cachep);void kmem_cache_destroy_memcg_children (struct kmem_cache *s);@@ -632,6 +639,11 @@ memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp)static inline void kmem_cache_destroy_memcg_children (struct kmem_cache *s) { } + +static inline int memcg_init_lru (struct list_lru *lru) +{ +return 0 ; +}#endif /* CONFIG_MEMCG_KMEM */ #endif /* _LINUX_MEMCONTROL_H */ lib/list_lru.c +17
-3@@ -8,6 +8,7 @@#include <linux/module.h> #include <linux/mm.h> #include <linux/list_lru.h> +#include <linux/memcontrol.h> int list_lru_add(@@ -184,18 +185,100 @@ list_lru_dispose_all(return total; } -int -list_lru_init ( -struct list_lru *lru) +/* +* This protects the list of all LRU in the system. One only needs +* to take when registering an LRU, or when duplicating the list of lrus. +* Transversing an LRU can and should be done outside the lock +*/ +static DEFINE_MUTEX (all_memcg_lrus_mutex); +static LIST_HEAD (all_memcg_lrus); + +static void list_lru_init_one (struct list_lru_node *lru) { +spin_lock_init (&lru->lock); +INIT_LIST_HEAD (&lru->list); + lru->nr_items =0 ; +} + +struct list_lru_array *lru_alloc_array (void ) +{
lib/list_lru.c list_lru_dispose_all( · line 209
Quoted 10 lines
lib/list_lru.c +3
-5+struct list_lru_array *lru_array;int i; -nodes_clear (lru->active_nodes); -for (i =0 ; i <MAX_NUMNODES ; i++) { -spin_lock_init (&lru->node[i].lock); -INIT_LIST_HEAD (&lru->node[i].list); - lru->node[i].nr_items =0 ; + lru_array =kzalloc (nr_node_ids *sizeof (struct list_lru_node ), +GFP_KERNEL );
A nitpick...you can use kmalloc() here. All field will be overwritten.
Quoted 11 lines
lib/list_lru.c +11
-0+if (!lru_array) +return NULL ; + +for (i =0 ; i < nr_node_ids ; i++) +list_lru_init_one (&lru_array->node[i]); + +return lru_array; +} + +#ifdef CONFIG_MEMCG_KMEM +int __memcg_init_lru (struct list_lru *lru)
lib/list_lru.c list_lru_dispose_all( · line 230
Quoted 10 lines
lib/list_lru.c +10
-0+{ +int ret; + +INIT_LIST_HEAD (&lru->lrus); +mutex_lock (&all_memcg_lrus_mutex); +list_add (&lru->lrus, &all_memcg_lrus); + ret =memcg_new_lru (lru); +mutex_unlock (&all_memcg_lrus_mutex); +return ret; +}
returns 0 at success ? what kind of error can be shown here ?
Quoted 87 lines
lib/list_lru.c +51
-1+ +int memcg_update_all_lrus (unsigned long num) +{ +int ret =0 ; +struct list_lru *lru; + +mutex_lock (&all_memcg_lrus_mutex); +list_for_each_entry (lru, &all_memcg_lrus, lrus) { + ret =memcg_kmem_update_lru_size (lru, num, false); +if (ret) + goto out; + } +out: +mutex_unlock (&all_memcg_lrus_mutex); +return ret; +} + +void list_lru_destroy (struct list_lru *lru) +{ +if (!lru->memcg_lrus) +return ; + +mutex_lock (&all_memcg_lrus_mutex); +list_del (&lru->lrus); +mutex_unlock (&all_memcg_lrus_mutex); +} + +void list_lru_destroy_memcg (struct mem_cgroup *memcg) +{ +struct list_lru *lru; +mutex_lock (&all_memcg_lrus_mutex); +list_for_each_entry (lru, &all_memcg_lrus, lrus) { +kfree (lru->memcg_lrus[memcg_cache_id (memcg)]); + lru->memcg_lrus[memcg_cache_id (memcg)] =NULL ; +/* everybody must beaware that this memcg is no longer valid */ +wmb (); } +mutex_unlock (&all_memcg_lrus_mutex); +} +#endif + +int __list_lru_init (struct list_lru *lru,bool memcg_enabled) +{ +int i; + +nodes_clear (lru->active_nodes); +for (i =0 ; i <MAX_NUMNODES ; i++) +list_lru_init_one (&lru->node[i]); + +if (memcg_enabled) +return memcg_init_lru (lru);return 0 ; } -EXPORT_SYMBOL_GPL (list_lru_init); +EXPORT_SYMBOL_GPL (__list_lru_init);mm/memcontrol.c +12
-5@@ -2988,16 +2988,30 @@ int memcg_update_cache_sizes(struct mem_cgroup *memcg)memcg_kmem_set_activated (memcg); ret =memcg_update_all_caches (num+1 ); -if (ret) { -ida_simple_remove (&kmem_limited_groups, num); -memcg_kmem_clear_activated (memcg); -return ret; - } +if (ret) + goto out; + +/* +* We should make sure that the array size is not updated until we are +* done; otherwise we have no easy way to know whether or not we should +* grow the array. +*/ + ret =memcg_update_all_lrus (num +1 ); +if (ret) + goto out; memcg->kmemcg_id = num; +
mm/memcontrol.c int memcg_update_cache_sizes(struct mem_cgroup *memcg) · line 3014
Quoted 10 lines
mm/memcontrol.c +7
-0+memcg_update_array_size (num +1 ); +INIT_LIST_HEAD (&memcg->memcg_slab_caches);mutex_init (&memcg->slab_caches_mutex); +return 0 ; +out: +ida_simple_remove (&kmem_limited_groups, num); +memcg_kmem_clear_activated (memcg); +return ret;
When this failure can happens ? This happens only when the user tries to set kmem_limit and doesn't affect kernel internal logic ?
Thanks,
-Kame
Re: [PATCH v2 22/28] memcg,list_lru: duplicate LRUs upon kmemcg creation
Hi Kame,
Quoted 7 lines
Quoted 5 lines
+/*
+ * This is supposed to be M x N matrix, where M is kmem-limited memcg,
+ * and N is the number of nodes.
+ */Could you add a comment that M can be changed and the array can be resized.
Yes, I can.
Quoted 15 lines
include/linux/list_lru.h struct list_lru_node { · line 33
Quoted 12 lines
include/linux/list_lru.h +8
-0+struct list_lru_array { +struct list_lru_node node[1 ]; +}; +struct list_lru {struct list_lru_node node[MAX_NUMNODES ];nodemask_t active_nodes; +#ifdef CONFIG_MEMCG_KMEM +struct list_head lrus; +struct list_lru_array **memcg_lrus; +#endif please add comments, for what ....
ok.
Quoted 5 lines
Quoted 5 lines
lib/list_lru.c +3
-0+struct list_lru_array *lru_alloc_array (void ) +{ +struct list_lru_array *lru_array;int i;
Quoted 9 lines
lib/list_lru.c list_lru_dispose_all( · line 209
Quoted 7 lines
lib/list_lru.c +2
-5-nodes_clear (lru->active_nodes); -for (i =0 ; i <MAX_NUMNODES ; i++) { -spin_lock_init (&lru->node[i].lock); -INIT_LIST_HEAD (&lru->node[i].list); - lru->node[i].nr_items =0 ; + lru_array =kzalloc (nr_node_ids *sizeof (struct list_lru_node ), +GFP_KERNEL );A nitpick...you can use
kmalloc()here. All field will be overwritten.
It is, however, not future-proof if anyone wants to add more fields, and forget to zero out the structure. If you really feel strongly for kmalloc I can change. But I don't see this as a big issue, specially this not being a fast path.
Quoted 6 lines
Quoted 6 lines
lib/list_lru.c +6
-0+#ifdef CONFIG_MEMCG_KMEM +int __memcg_init_lru (struct list_lru *lru) +{ +int ret; + +INIT_LIST_HEAD (&lru->lrus);
Quoted 9 lines
lib/list_lru.c list_lru_dispose_all( · line 230
Quoted 6 lines
lib/list_lru.c +6
-0+mutex_lock (&all_memcg_lrus_mutex); +list_add (&lru->lrus, &all_memcg_lrus); + ret =memcg_new_lru (lru); +mutex_unlock (&all_memcg_lrus_mutex); +return ret; +}returns 0 at success ? what kind of error can be shown here ?
memcg_new_lru will allocate memory, and therefore can fail with ENOMEM. It will already return 0 itself on success, so just forwarding its return value is around.
Quoted 27 lines
Quoted 27 lines
lib/list_lru.c +1
-1-EXPORT_SYMBOL_GPL (list_lru_init); +EXPORT_SYMBOL_GPL (__list_lru_init);mm/memcontrol.c +11
-5@@ -2988,16 +2988,30 @@ int memcg_update_cache_sizes(struct mem_cgroup *memcg)memcg_kmem_set_activated (memcg); ret =memcg_update_all_caches (num+1 ); -if (ret) { -ida_simple_remove (&kmem_limited_groups, num); -memcg_kmem_clear_activated (memcg); -return ret; - } +if (ret) + goto out; + +/* +* We should make sure that the array size is not updated until we are +* done; otherwise we have no easy way to know whether or not we should +* grow the array. +*/ + ret =memcg_update_all_lrus (num +1 ); +if (ret) + goto out;
Quoted 16 lines
mm/memcontrol.c int memcg_update_cache_sizes(struct mem_cgroup *memcg) · line 3014
Quoted 12 lines
mm/memcontrol.c +8
-0memcg->kmemcg_id = num; + +memcg_update_array_size (num +1 ); +INIT_LIST_HEAD (&memcg->memcg_slab_caches);mutex_init (&memcg->slab_caches_mutex); +return 0 ; +out: +ida_simple_remove (&kmem_limited_groups, num); +memcg_kmem_clear_activated (memcg); +return ret;When this failure can happens ? This happens only when the user tries to set
kmem_limitand doesn't affect kernel internal logic ?
There are 2 points of failure for this:
1) setting kmem limit from a previously unset scenario,
2) creating a new child memcg, as a child of a kmem limited memcg
Those are the same as the slab, and indeed they are attempted right after it.
LRU initialization failures can still exist in a 3rd way, when a new LRU is created and we have no memory available to hold its structures. But this will not be called from here.
--
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>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 22/28] memcg, list_lru: duplicate LRUs upon kmemcg creation
Hi Kame,
Quoted 7 lines
Quoted 5 lines
+/*
+ * This is supposed to be M x N matrix, where M is kmem-limited memcg,
+ * and N is the number of nodes.
+ */Could you add a comment that M can be changed and the array can be resized.
Yes, I can.
Quoted 15 lines
include/linux/list_lru.h struct list_lru_node { · line 33
Quoted 12 lines
include/linux/list_lru.h +8
-0+struct list_lru_array { +struct list_lru_node node[1 ]; +}; +struct list_lru {struct list_lru_node node[MAX_NUMNODES ];nodemask_t active_nodes; +#ifdef CONFIG_MEMCG_KMEM +struct list_head lrus; +struct list_lru_array **memcg_lrus; +#endif please add comments, for what ....
ok.
Quoted 5 lines
Quoted 5 lines
lib/list_lru.c +3
-0+struct list_lru_array *lru_alloc_array (void ) +{ +struct list_lru_array *lru_array;int i;
Quoted 9 lines
lib/list_lru.c list_lru_dispose_all( · line 209
Quoted 7 lines
lib/list_lru.c +2
-5-nodes_clear (lru->active_nodes); -for (i =0 ; i <MAX_NUMNODES ; i++) { -spin_lock_init (&lru->node[i].lock); -INIT_LIST_HEAD (&lru->node[i].list); - lru->node[i].nr_items =0 ; + lru_array =kzalloc (nr_node_ids *sizeof (struct list_lru_node ), +GFP_KERNEL );A nitpick...you can use
kmalloc()here. All field will be overwritten.
It is, however, not future-proof if anyone wants to add more fields, and forget to zero out the structure. If you really feel strongly for kmalloc I can change. But I don't see this as a big issue, specially this not being a fast path.
Quoted 6 lines
Quoted 6 lines
lib/list_lru.c +6
-0+#ifdef CONFIG_MEMCG_KMEM +int __memcg_init_lru (struct list_lru *lru) +{ +int ret; + +INIT_LIST_HEAD (&lru->lrus);
Quoted 9 lines
lib/list_lru.c list_lru_dispose_all( · line 230
Quoted 6 lines
lib/list_lru.c +6
-0+mutex_lock (&all_memcg_lrus_mutex); +list_add (&lru->lrus, &all_memcg_lrus); + ret =memcg_new_lru (lru); +mutex_unlock (&all_memcg_lrus_mutex); +return ret; +}returns 0 at success ? what kind of error can be shown here ?
memcg_new_lru will allocate memory, and therefore can fail with ENOMEM. It will already return 0 itself on success, so just forwarding its return value is around.
Quoted 27 lines
Quoted 27 lines
lib/list_lru.c +1
-1-EXPORT_SYMBOL_GPL (list_lru_init); +EXPORT_SYMBOL_GPL (__list_lru_init);mm/memcontrol.c +11
-5@@ -2988,16 +2988,30 @@ int memcg_update_cache_sizes(struct mem_cgroup *memcg)memcg_kmem_set_activated (memcg); ret =memcg_update_all_caches (num+1 ); -if (ret) { -ida_simple_remove (&kmem_limited_groups, num); -memcg_kmem_clear_activated (memcg); -return ret; - } +if (ret) + goto out; + +/* +* We should make sure that the array size is not updated until we are +* done; otherwise we have no easy way to know whether or not we should +* grow the array. +*/ + ret =memcg_update_all_lrus (num +1 ); +if (ret) + goto out;
Quoted 16 lines
mm/memcontrol.c int memcg_update_cache_sizes(struct mem_cgroup *memcg) · line 3014
Quoted 12 lines
mm/memcontrol.c +8
-0memcg->kmemcg_id = num; + +memcg_update_array_size (num +1 ); +INIT_LIST_HEAD (&memcg->memcg_slab_caches);mutex_init (&memcg->slab_caches_mutex); +return 0 ; +out: +ida_simple_remove (&kmem_limited_groups, num); +memcg_kmem_clear_activated (memcg); +return ret;When this failure can happens ? This happens only when the user tries to set
kmem_limitand doesn't affect kernel internal logic ?
There are 2 points of failure for this:
1) setting kmem limit from a previously unset scenario,
2) creating a new child memcg, as a child of a kmem limited memcg
Those are the same as the slab, and indeed they are attempted right after it.
LRU initialization failures can still exist in a 3rd way, when a new LRU is created and we have no memory available to hold its structures. But this will not be called from here.
PATCH v2 23/28 lru: add an element to a memcg list
In reply to Glauber CostaWith the infrastructure we now have, we can add an element to a memcg LRU list instead of the global list. The memcg lists are still per-node.
Technically, we will never trigger per-node shrinking in the memcg is short of memory. Therefore an alternative to this would be to add the element to *both* a single-node memcg array and a per-node global array.
There are two main reasons for this design choice:
1) adding an extra list_head to each of the objects would waste 16-bytes per object, always remembering that we are talking about 1 dentry + 1 inode in the common case. This means a close to 10 % increase in the dentry size, and a lower yet significant increase in the inode size. In terms of total memory, this design pays 32-byte per-superblock-per-node (size of struct list_lru_node), which means that in any scenario where we have more than 10 dentries + inodes, we would already be paying more memory in the two-list-heads approach than we will here with 1 node x 10 superblocks. The turning point of course depends on the workload, but I hope the figures above would convince you that the memory footprint is in my side in any workload that matters.
2) The main drawback of this, namely, that we loose global LRU order, is not really seen by me as a disadvantage: if we are using memcg to isolate the workloads, global pressure should try to balance the amount reclaimed from all memcgs the same way the shrinkers will already naturally balance the amount reclaimed from each superblock. (This patchset needs some love in this regard, btw).
To help us easily tracking down which nodes have and which nodes doesn't have elements in the list, we will count on an auxiliary node bitmap in the global level.
--- include/linux/list_lru.h | 10 +++++++ include/linux/memcontrol.h | 10 +++++++ lib/list_lru.c | 68 +++++++++++++++++++++++++++++++++++++++------- mm/memcontrol.c | 38 +++++++++++++++++++++++++- 4 files changed, 115 insertions(+), 11 deletions(-)
include/linux/list_lru.h +10 -0
@@ -26,6 +26,7 @@ struct list_lru_array {struct list_lru {struct list_lru_node node[MAX_NUMNODES ]; +atomic_long_t node_totals[MAX_NUMNODES ];nodemask_t active_nodes;#ifdef CONFIG_MEMCG_KMEM struct list_head lrus;
@@ -40,10 +41,19 @@ int memcg_update_all_lrus(unsigned long num);void list_lru_destroy (struct list_lru *lru);void list_lru_destroy_memcg (struct mem_cgroup *memcg);int __memcg_init_lru (struct list_lru *lru); +struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid);#else static inline void list_lru_destroy (struct list_lru *lru) { } + +static inline struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid) +{ +BUG_ON (index <0 );/* index != -1 with !MEMCG_KMEM. Impossible */ +return &lru->node[nid]; +}#endif int __list_lru_init (struct list_lru *lru,bool memcg_enabled);
include/linux/memcontrol.h +10 -0
@@ -24,6 +24,7 @@#include <linux/hardirq.h> #include <linux/jump_label.h> #include <linux/list_lru.h> +#include <linux/mm.h> struct mem_cgroup ;struct page_cgroup ;
@@ -473,6 +474,9 @@ __memcg_kmem_get_cache(struct kmem_cache *cachep, gfp_t gfp);int memcg_new_lru (struct list_lru *lru);int memcg_init_lru (struct list_lru *lru); +struct list_lru_node * +memcg_kmem_lru_of_page (struct list_lru *lru,struct page *page); +int memcg_kmem_update_lru_size (struct list_lru *lru,int num_groups,bool new_lru);
@@ -644,6 +648,12 @@ static inline int memcg_init_lru(struct list_lru *lru) {return 0 ; } + +static inline struct list_lru_node * +memcg_kmem_lru_of_page (struct list_lru *lru,struct page *page) +{ +return &lru->node[page_to_nid (page)]; +}#endif /* CONFIG_MEMCG_KMEM */ #endif /* _LINUX_MEMCONTROL_H */
lib/list_lru.c +58 -10
112 lines not on this page · raw message
mm/memcontrol.c +37 -1
@@ -3160,9 +3160,15 @@ int memcg_kmem_update_lru_size(struct list_lru *lru, int num_groups,* either follow the new array or the old one and they contain * exactly the same information. The new space in the end is * always empty anyway. +* +* We do have to make sure that no more users of the old +* memcg_lrus array exist before we free, and this is achieved +* by the synchronize_lru below. */ -if (lru->memcg_lrus) +if (lru->memcg_lrus) { +synchronize_rcu ();kfree (old_array); + } }if (lru->memcg_lrus) {
@@ -3306,6 +3312,36 @@ static inline void memcg_resume_kmem_account(void) current->memcg_kmem_skip_account--; } +static struct mem_cgroup *mem_cgroup_from_kmem_page (struct page *page) +{ +struct page_cgroup *pc; +struct mem_cgroup *memcg =NULL ; + + pc =lookup_page_cgroup (page); +if (!PageCgroupUsed (pc)) +return NULL ; + +lock_page_cgroup (pc); +if (PageCgroupUsed (pc)) + memcg = pc->mem_cgroup; +unlock_page_cgroup (pc); +return memcg; +} + +struct list_lru_node * +memcg_kmem_lru_of_page (struct list_lru *lru,struct page *page) +{ +struct mem_cgroup *memcg =mem_cgroup_from_kmem_page (page); +int nid =page_to_nid (page); +int memcg_id; + +if (!memcg_kmem_enabled ()) +return &lru->node[nid]; + + memcg_id =memcg_cache_id (memcg); +return lru_node_of_index (lru, memcg_id, nid); +} +static void kmem_cache_destroy_work_func (struct work_struct *w) {struct kmem_cache *cachep;
Signature · 1 line
1.8.1.4
Re: [PATCH v2 23/28] lru: add an element to a memcg list
Quoted 8 lines · Glauber Costa
With the infrastructure we now have, we can add an element to a memcg LRU list instead of the global list. The memcg lists are still per-node.
Technically, we will never trigger per-node shrinking in the memcg is short of memory. Therefore an alternative to this would be to add the element to *both* a single-node memcg array and a per-node global array.
per-node shrinking by memcg pressure is not imporant, I think.
Quoted 46 lines
There are two main reasons for this design choice:
1) adding an extra
list_headto each of the objects would waste 16-bytes per object, always remembering that we are talking about 1 dentry + 1 inode in the common case. This means a close to 10 % increase in the dentry size, and a lower yet significant increase in the inode size. In terms of total memory, this design pays 32-byte per-superblock-per-node (size of structlist_lru_node), which means that in any scenario where we have more than 10 dentries + inodes, we would already be paying more memory in the two-list-heads approach than we will here with 1 node x 10 superblocks. The turning point of course depends on the workload, but I hope the figures above would convince you that the memory footprint is in my side in any workload that matters.2) The main drawback of this, namely, that we loose global LRU order, is not really seen by me as a disadvantage: if we are using memcg to isolate the workloads, global pressure should try to balance the amount reclaimed from all memcgs the same way the shrinkers will already naturally balance the amount reclaimed from each superblock. (This patchset needs some love in this regard, btw).
To help us easily tracking down which nodes have and which nodes doesn't have elements in the list, we will count on an auxiliary node bitmap in the global level.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <[email protected]>--- include/linux/list_lru.h | 10 +++++++ include/linux/memcontrol.h | 10 +++++++ lib/list_lru.c | 68 +++++++++++++++++++++++++++++++++++++++------- mm/memcontrol.c | 38 +++++++++++++++++++++++++- 4 files changed, 115 insertions(+), 11 deletions(-)include/linux/list_lru.h +0
-0
include/linux/list_lru.h struct list_lru_array { · line 29
Quoted 4 lines
include/linux/list_lru.h +1
-0@@ -26,6 +26,7 @@ struct list_lru_array {struct list_lru {struct list_lru_node node[MAX_NUMNODES ]; +atomic_long_t node_totals[MAX_NUMNODES ];
some comments will be helpful.
Quoted 11 lines
include/linux/list_lru.h +2
-0nodemask_t active_nodes;#ifdef CONFIG_MEMCG_KMEM struct list_head lrus;@@ -40,10 +41,19 @@ int memcg_update_all_lrus(unsigned long num);void list_lru_destroy (struct list_lru *lru);void list_lru_destroy_memcg (struct mem_cgroup *memcg);int __memcg_init_lru (struct list_lru *lru); +struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid);#else static inline void list_lru_destroy (struct list_lru *lru)
include/linux/list_lru.h int memcg_update_all_lrus(unsigned long num); · line 57
Quoted 10 lines
include/linux/list_lru.h +7
-0{ } + +static inline struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid) +{ +BUG_ON (index <0 );/* index != -1 with !MEMCG_KMEM. Impossible */ +return &lru->node[nid]; +}#endif
I'm sorry ...what "lru_node_of_index" means ? What is the "index" ?
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>
Re: [PATCH v2 23/28] lru: add an element to a memcg list
Quoted 5 lines · Kamezawa Hiroyuki
Quoted 4 lines · Glauber Costa
With the infrastructure we now have, we can add an element to a memcg LRU list instead of the global list. The memcg lists are still per-node.
Quoted 7 lines
Quoted 4 lines
Technically, we will never trigger per-node shrinking in the memcg is short of memory. Therefore an alternative to this would be to add the element to *both* a single-node memcg array and a per-node global array.
per-node shrinking by memcg pressure is not imporant, I think.
No, it is not. And this is precisely what I've stated: "we will never trigger per-node shrinking in the memcg is short of memory."
This is to clarify that this design decision does not come from the need to do that, which we don't have, but rather to save memory. Keeping memcg objects per-node is less memory-expensive than adding an extra LRU to the dentries and inodes. Therefore I do that, and when global pressure kicks in I will scan all memcgs that belong to that node.
This will break global LRU order, but will help maintain fairness among different memcgs.
Quoted 7 lines
include/linux/list_lru.h struct list_lru_array { · line 29
Quoted 4 lines
struct list_lru { struct list_lru_node node[MAX_NUMNODES];include/linux/list_lru.h +1
-0+atomic_long_t node_totals[MAX_NUMNODES ];some comments will be helpful.
Yes, they will!
Quoted 10 lines
include/linux/list_lru.h int memcg_update_all_lrus(unsigned long num); · line 57
Quoted 8 lines
include/linux/list_lru.h +7
-0+ +static inline struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid) +{ +BUG_ON (index <0 );/* index != -1 with !MEMCG_KMEM. Impossible */ +return &lru->node[nid]; +}#endif I'm sorry ...what "
lru_node_of_index" means ? What is the "index" ?
There is extensive documentation for this above the macro for_each_memcg_lru_index, so I didn't bother rewriting it here. But I can add pointers like "see more at for_each..."
Basically, this will be either the memcg index if we want memcg reclaim, or -1 for the global LRU. This is not 100 % the memcg index, so I called it just "index".
IOW, it is the index in the memcg array if index >= 0, or the global array if index < 0.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 23/28] lru: add an element to a memcg list
Quoted 5 lines · Kamezawa Hiroyuki
Quoted 4 lines · Glauber Costa
With the infrastructure we now have, we can add an element to a memcg LRU list instead of the global list. The memcg lists are still per-node.
Quoted 7 lines
Quoted 4 lines
Technically, we will never trigger per-node shrinking in the memcg is short of memory. Therefore an alternative to this would be to add the element to *both* a single-node memcg array and a per-node global array.
per-node shrinking by memcg pressure is not imporant, I think.
No, it is not. And this is precisely what I've stated: "we will never trigger per-node shrinking in the memcg is short of memory."
This is to clarify that this design decision does not come from the need to do that, which we don't have, but rather to save memory. Keeping memcg objects per-node is less memory-expensive than adding an extra LRU to the dentries and inodes. Therefore I do that, and when global pressure kicks in I will scan all memcgs that belong to that node.
This will break global LRU order, but will help maintain fairness among different memcgs.
Quoted 7 lines
include/linux/list_lru.h struct list_lru_array { · line 29
Quoted 4 lines
struct list_lru { struct list_lru_node node[MAX_NUMNODES];include/linux/list_lru.h +1
-0+atomic_long_t node_totals[MAX_NUMNODES ];some comments will be helpful.
Yes, they will!
Quoted 10 lines
include/linux/list_lru.h int memcg_update_all_lrus(unsigned long num); · line 57
Quoted 8 lines
include/linux/list_lru.h +7
-0+ +static inline struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid) +{ +BUG_ON (index <0 );/* index != -1 with !MEMCG_KMEM. Impossible */ +return &lru->node[nid]; +}#endif I'm sorry ...what "
lru_node_of_index" means ? What is the "index" ?
There is extensive documentation for this above the macro for_each_memcg_lru_index, so I didn't bother rewriting it here. But I can add pointers like "see more at for_each..."
Basically, this will be either the memcg index if we want memcg reclaim, or -1 for the global LRU. This is not 100 % the memcg index, so I called it just "index".
IOW, it is the index in the memcg array if index >= 0, or the global array if index < 0.
A message that is not in the archive (sent off-list or not yet received): 1364548450-28254-24-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org
Re: [PATCH v2 23/28] lru: add an element to a memcg list
Quoted 8 lines · Glauber Costa
With the infrastructure we now have, we can add an element to a memcg LRU list instead of the global list. The memcg lists are still per-node.
Technically, we will never trigger per-node shrinking in the memcg is short of memory. Therefore an alternative to this would be to add the element to *both* a single-node memcg array and a per-node global array.
per-node shrinking by memcg pressure is not imporant, I think.
Quoted 46 lines
There are two main reasons for this design choice:
1) adding an extra
list_headto each of the objects would waste 16-bytes per object, always remembering that we are talking about 1 dentry + 1 inode in the common case. This means a close to 10 % increase in the dentry size, and a lower yet significant increase in the inode size. In terms of total memory, this design pays 32-byte per-superblock-per-node (size of structlist_lru_node), which means that in any scenario where we have more than 10 dentries + inodes, we would already be paying more memory in the two-list-heads approach than we will here with 1 node x 10 superblocks. The turning point of course depends on the workload, but I hope the figures above would convince you that the memory footprint is in my side in any workload that matters.2) The main drawback of this, namely, that we loose global LRU order, is not really seen by me as a disadvantage: if we are using memcg to isolate the workloads, global pressure should try to balance the amount reclaimed from all memcgs the same way the shrinkers will already naturally balance the amount reclaimed from each superblock. (This patchset needs some love in this regard, btw).
To help us easily tracking down which nodes have and which nodes doesn't have elements in the list, we will count on an auxiliary node bitmap in the global level.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <akpm-de/[email protected]>--- include/linux/list_lru.h | 10 +++++++ include/linux/memcontrol.h | 10 +++++++ lib/list_lru.c | 68 +++++++++++++++++++++++++++++++++++++++------- mm/memcontrol.c | 38 +++++++++++++++++++++++++- 4 files changed, 115 insertions(+), 11 deletions(-)include/linux/list_lru.h +0
-0
include/linux/list_lru.h struct list_lru_array { · line 29
Quoted 4 lines
include/linux/list_lru.h +1
-0@@ -26,6 +26,7 @@ struct list_lru_array {struct list_lru {struct list_lru_node node[MAX_NUMNODES ]; +atomic_long_t node_totals[MAX_NUMNODES ];
some comments will be helpful.
Quoted 11 lines
include/linux/list_lru.h +2
-0nodemask_t active_nodes;#ifdef CONFIG_MEMCG_KMEM struct list_head lrus;@@ -40,10 +41,19 @@ int memcg_update_all_lrus(unsigned long num);void list_lru_destroy (struct list_lru *lru);void list_lru_destroy_memcg (struct mem_cgroup *memcg);int __memcg_init_lru (struct list_lru *lru); +struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid);#else static inline void list_lru_destroy (struct list_lru *lru)
include/linux/list_lru.h int memcg_update_all_lrus(unsigned long num); · line 57
Quoted 10 lines
include/linux/list_lru.h +7
-0{ } + +static inline struct list_lru_node * +lru_node_of_index (struct list_lru *lru,int index,int nid) +{ +BUG_ON (index <0 );/* index != -1 with !MEMCG_KMEM. Impossible */ +return &lru->node[nid]; +}#endif
I'm sorry ...what "lru_node_of_index" means ? What is the "index" ?
Thanks,
-Kame
PATCH v2 24/28 list_lru: also include memcg lists in counts and scans
In reply to Glauber CostaAs elements are added to per-memcg lists, they will be invisible to global reclaimers. This patch mainly modifies list_lru walk and count functions to take that into account.
Counting is very simple: since we already have total figures for the node, which we use to figure out when to set or clear the node in the bitmap, we can just use that.
For walking, we need to walk the memcg lists as well as the global list. To achieve that, this patch introduces the helper macro for_each_memcg_lru_index. Locking semantics are simple, since introducing a new LRU in the list does not influence the memcg walkers.
The only operation we race against is memcg creation and teardown. For those, barriers should be enough to guarantee that we are seeing up-to-date information and not accessing invalid pointers.
--- include/linux/memcontrol.h | 2 ++ lib/list_lru.c | 90 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 23 deletions(-)
include/linux/memcontrol.h +2 -0
@@ -593,6 +593,8 @@ static inline bool memcg_kmem_is_active(struct mem_cgroup *memcg)#define for_each_memcg_cache_index (_idx) \ for (; NULL; ) +#define memcg_limited_groups_array_size 0 +static inline bool memcg_kmem_enabled (void ) {return false;
lib/list_lru.c +67 -23
132 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v2 25/28 list_lru: per-memcg walks
In reply to Glauber CostaThis patch extend the list_lru interfaces to allow for a memcg parameter. Because most of its users won't need it, instead of modifying the function signatures we create a new set of _memcg() functions and write the old API ontop of that.
At this point, the infrastructure is mostly in place. We already walk the nodes using all memcg indexes, so we just need to make sure we skip all but the one we're interested in. We could just go directly to the memcg of interest, but I am assuming that given the gained simplicity, spending a few cycles here won't hurt *that* much (but that can be improved if needed, of course).
--- include/linux/list_lru.h | 24 +++++++++++++++++---- lib/list_lru.c | 56 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 62 insertions(+), 18 deletions(-)
include/linux/list_lru.h +20 -4
@@ -69,20 +69,36 @@ static inline int list_lru_init_memcg(struct list_lru *lru)int list_lru_add (struct list_lru *lru,struct list_head *item);int list_lru_del (struct list_lru *lru,struct list_head *item); -long list_lru_count_nodemask (struct list_lru *lru,nodemask_t *nodes_to_count); + +long list_lru_count_nodemask_memcg (struct list_lru *lru, +nodemask_t *nodes_to_count,struct mem_cgroup *memcg); + +static inline long +list_lru_count_nodemask (struct list_lru *lru,nodemask_t *nodes_to_count) +{ +return list_lru_count_nodemask_memcg (lru, nodes_to_count,NULL ); +}static inline long list_lru_count (struct list_lru *lru) {return list_lru_count_nodemask (lru, &lru->active_nodes); } -typedef int (*list_lru_walk_cb )(struct list_head *item,spinlock_t *lock,void *cb_arg);typedef void (*list_lru_dispose_cb )(struct list_head *dispose_list); -long list_lru_walk_nodemask (struct list_lru *lru,list_lru_walk_cb isolate, -void *cb_arg,long nr_to_walk,nodemask_t *nodes_to_walk); +long list_lru_walk_nodemask_memcg (struct list_lru *lru, +list_lru_walk_cb isolate,void *cb_arg,long nr_to_walk, +nodemask_t *nodes_to_walk,struct mem_cgroup *memcg); + +static inline long list_lru_walk_nodemask (struct list_lru *lru, +list_lru_walk_cb isolate,void *cb_arg,long nr_to_walk, +nodemask_t *nodes_to_walk) +{ +return list_lru_walk_nodemask_memcg (lru, isolate, cb_arg, nr_to_walk, + &lru->active_nodes,NULL ); +}static inline long list_lru_walk (struct list_lru *lru,list_lru_walk_cb isolate,void *cb_arg,long nr_to_walk)
lib/list_lru.c +42 -14
119 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v2 26/28 memcg: per-memcg kmem shrinking
In reply to Glauber CostaIf the kernel limit is smaller than the user limit, we will have situations in which our allocations fail but freeing user pages will buy us nothing. In those, we would like to call a specialized memcg reclaimer that only frees kernel memory and leave the user memory alone. Those are also expected to fail when we account memcg->kmem, instead of when we account memcg->res. Based on that, this patch implements a memcg-specific reclaimer, that only shrinks kernel objects, withouth touching user pages.
There might be situations in which there are plenty of objects to shrink, but we can't do it because the __GFP_FS flag is not set. Although they can happen with user pages, they are a lot more common with fs-metadata: this is the case with almost all inode allocation.
Those allocations are, however, capable of waiting. So we can just span a worker, let it finish its job and proceed with the allocation. As slow as it is, at this point we are already past any hopes anyway.
--- include/linux/swap.h | 2 + mm/memcontrol.c | 182 ++++++++++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 37 ++++++++++- 3 files changed, 183 insertions(+), 38 deletions(-)
include/linux/swap.h +2 -0
@@ -268,6 +268,8 @@ 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 try_to_free_mem_cgroup_kmem (struct mem_cgroup *mem, +gfp_t gfp_mask); extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, gfp_t gfp_mask, bool noswap, struct zone *zone,
mm/memcontrol.c +145 -37
253 lines not on this page · raw message
mm/vmscan.c +36 -1
@@ -2504,7 +2504,42 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, return nr_reclaimed; } -#endif + +#ifdef CONFIG_MEMCG_KMEM +/* +* This function is called when we are under kmem-specific pressure. It will +* only trigger in environments with kmem.limit_in_bytes < limit_in_bytes, IOW, +* with a lower kmem allowance than the memory allowance. +* +* In this situation, freeing user pages from the cgroup won't do us any good. +* What we really need is to call the memcg-aware shrinkers, in the hope of +* freeing pages holding kmem objects. It may also be that we won't be able to +* free any pages, but will get rid of old objects opening up space for new +* ones. +*/ +unsigned long try_to_free_mem_cgroup_kmem (struct mem_cgroup *memcg, +gfp_t gfp_mask) +{ +struct shrink_control shrink = { + .gfp_mask = gfp_mask, + .target_mem_cgroup = memcg, + }; + +if (!(gfp_mask & __GFP_WAIT)) +return 0 ; + +nodes_setall (shrink.nodes_to_scan); + +/* +* We haven't scanned any user LRU, so we basically come up with +* crafted values of nr_scanned and LRU page (1 and 0 respectively). +* This should be enough to tell shrink_slab that the freeing +* responsibility is all on himself. +*/ +return shrink_slab (&shrink,1 ,0 ); +} +#endif /* CONFIG_MEMCG_KMEM */ +#endif /* CONFIG_MEMCG */ static void age_active_anon (struct zone *zone,struct scan_control *sc) {
Signature · 1 line
1.8.1.4
A message that is not in the archive (sent off-list or not yet received): 1364548450-28254-27-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
Quoted 143 lines · Glauber Costa
If the kernel limit is smaller than the user limit, we will have situations in which our allocations fail but freeing user pages will buy us nothing. In those, we would like to call a specialized memcg reclaimer that only frees kernel memory and leave the user memory alone. Those are also expected to fail when we account
memcg->kmem, instead of when we accountmemcg->res. Based on that, this patch implements a memcg-specific reclaimer, that only shrinks kernel objects, withouth touching user pages.There might be situations in which there are plenty of objects to shrink, but we can't do it because the
__GFP_FSflag is not set. Although they can happen with user pages, they are a lot more common with fs-metadata: this is the case with almost all inode allocation.Those allocations are, however, capable of waiting. So we can just span a worker, let it finish its job and proceed with the allocation. As slow as it is, at this point we are already past any hopes anyway.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <akpm-de/[email protected]>--- include/linux/swap.h | 2 + mm/memcontrol.c | 182 ++++++++++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 37 ++++++++++- 3 files changed, 183 insertions(+), 38 deletions(-)include/linux/swap.h +2
-0@@ -268,6 +268,8 @@ 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 try_to_free_mem_cgroup_kmem (struct mem_cgroup *mem, +gfp_t gfp_mask); extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, gfp_t gfp_mask, bool noswap, struct zone *zone,mm/memcontrol.c +54
-2@@ -353,6 +353,8 @@ struct mem_cgroup {atomic_t numainfo_events;atomic_t numainfo_updating;#endif +/* when kmem shrinkers can sleep but can't proceed due to context */ +struct work_struct kmemcg_shrink_work;/* * Per cgroup active and inactive list, similar to the * per zone LRU lists. @@ -369,11 +371,14 @@ static size_t memcg_size(void) nr_node_ids * sizeof(struct mem_cgroup_per_node); } +static DEFINE_MUTEX (set_limit_mutex); +/* internal only representation about the status of kmem accounting. */ enum {KMEM_ACCOUNTED_ACTIVE =0 ,/* accounted by this cgroup itself */ KMEM_ACCOUNTED_ACTIVATED ,/* static key enabled. */ KMEM_ACCOUNTED_DEAD ,/* dead memcg with pending kmem charges */ +KMEM_MAY_SHRINK ,/* kmem limit < mem limit, shrink kmem only */ };/* We account when limit is on, but only after call sites are patched */ @@ -412,6 +417,31 @@ static bool memcg_kmem_test_and_clear_dead(struct mem_cgroup *memcg)return test_and_clear_bit (KMEM_ACCOUNTED_DEAD , &memcg->kmem_account_flags); } + +/* +* If the kernel limit is smaller than the user limit, we will have situations +* in which our allocations fail but freeing user pages will buy us nothing. +* In those, we would like to call a specialized memcg reclaimer that only +* frees kernel memory and leave the user memory alone. +* +* This test exists so we can differentiate between those. Everytime one of the +* limits is updated, we need to run it. The set_limit_mutex must be held, so +* they don't change again. +*/ +static void memcg_update_shrink_status (struct mem_cgroup *memcg) +{ +mutex_lock (&set_limit_mutex); +if (res_counter_read_u64 (&memcg->kmem,RES_LIMIT ) < +res_counter_read_u64 (&memcg->res,RES_LIMIT )) +set_bit (KMEM_MAY_SHRINK , &memcg->kmem_account_flags); +else +clear_bit (KMEM_MAY_SHRINK , &memcg->kmem_account_flags); +mutex_unlock (&set_limit_mutex); +} +#else +static void memcg_update_shrink_status (struct mem_cgroup *memcg) +{ +}#endif /* Stuffs for move charges at task migration. */ @@ -2838,8 +2868,6 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,memcg_check_events (memcg, page); } -static DEFINE_MUTEX (set_limit_mutex); -#ifdef CONFIG_MEMCG_KMEM static inline bool memcg_can_account_kmem (struct mem_cgroup *memcg) {@@ -2881,16 +2909,92 @@ static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, }#endif +/* +* During the creation a new cache, we need to disable our accounting mechanism +* altogether. This is true even if we are not creating, but rather just +* enqueing new caches to be created. +* +* This is because that process will trigger allocations; some visible, like +* explicit kmallocs to auxiliary data structures, name strings and internal +* cache structures; some well concealed, like INIT_WORK() that can allocate +* objects during debug. +* +* If any allocation happens during memcg_kmem_get_cache, we will recurse back +* to it. This may not be a bounded recursion: since the first cache creation +* failed to complete (waiting on the allocation), we'll just try to create the +* cache again, failing at the same point. +* +* memcg_kmem_get_cache is prepared to abort after seeing a positive count of +* memcg_kmem_skip_account. So we enclose anything that might allocate memory +* inside the following two functions. +*/ +static inline void memcg_stop_kmem_account (void ) +{ +VM_BUG_ON (!current->mm); + current->memcg_kmem_skip_account++; +}
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 10 lines
mm/memcontrol.c +10
-0+ +static inline void memcg_resume_kmem_account (void ) +{ +VM_BUG_ON (!current->mm); + current->memcg_kmem_skip_account--; +} + +static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;
I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Quoted 23 lines
mm/memcontrol.c +23
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) {
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 10 lines
mm/memcontrol.c +10
-0+/* +* we are already short on memory, every queue +* allocation is likely to fail +*/ +memcg_stop_kmem_account (); +schedule_work (&memcg->kmemcg_shrink_work); +flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );
Why congestion_wait() ? I think calling congestion_wait() in vmscan.c is a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..
Quoted 54 lines
mm/memcontrol.c +31
-4+ + }while (retries--); + +return ret; +} +static int memcg_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) {struct res_counter *fail_res;struct mem_cgroup *_memcg;int ret =0 ;bool may_oom; +bool kmem_first =test_bit (KMEM_MAY_SHRINK , &memcg->kmem_account_flags); - ret =res_counter_charge (&memcg->kmem, size, &fail_res); -if (ret) -return ret; +if (kmem_first) { + ret =memcg_try_charge_kmem (memcg, gfp, size); +if (ret) +return ret; + }/* * Conditions under which we can wait for the oom_killer. Those are @@ -2923,12 +3027,43 @@ static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)res_counter_charge_nofail (&memcg->memsw, size, &fail_res); ret =0 ; - }else if (ret) +if (!kmem_first) +res_counter_charge_nofail (&memcg->kmem, size, &fail_res); + }else if (ret && kmem_first)res_counter_uncharge (&memcg->kmem, size); +if (!kmem_first) { + ret =memcg_try_charge_kmem (memcg, gfp, size); +if (!ret) +return ret; + +res_counter_uncharge (&memcg->res, size); +if (do_swap_account) +res_counter_uncharge (&memcg->memsw, size); + } +return ret; } +/* +* There might be situations in which there are plenty of objects to shrink, +* but we can't do it because the __GFP_FS flag is not set. This is the case +* with almost all inode allocation. They do are, however, capable of waiting. +* So we can just span a worker, let it finish its job and proceed with the +* allocation. As slow as it is, at this point we are already past any hopes
mm/memcontrol.c static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size) · line 3063
Quoted 10 lines
mm/memcontrol.c +10
-0+* anyway. +*/ +static void kmemcg_shrink_work_fn (struct work_struct *w) +{ +struct mem_cgroup *memcg; + + memcg = container_of(w, struct mem_cgroup, kmemcg_shrink_work); + +if (!try_to_free_mem_cgroup_kmem (memcg,GFP_KERNEL )) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );
ditto..
Quoted 101 lines
mm/memcontrol.c +7
-31+} + +static void memcg_uncharge_kmem (struct mem_cgroup *memcg,u64 size) {res_counter_uncharge (&memcg->res, size);@@ -3005,6 +3140,7 @@ int memcg_update_cache_sizes(struct mem_cgroup *memcg)memcg_update_array_size (num +1 );INIT_LIST_HEAD (&memcg->memcg_slab_caches); +INIT_WORK (&memcg->kmemcg_shrink_work, kmemcg_shrink_work_fn);mutex_init (&memcg->slab_caches_mutex);return 0 ;@@ -3281,37 +3417,6 @@ out:kfree (s->memcg_params); } -/* -* During the creation a new cache, we need to disable our accounting mechanism -* altogether. This is true even if we are not creating, but rather just -* enqueing new caches to be created. -* -* This is because that process will trigger allocations; some visible, like -* explicit kmallocs to auxiliary data structures, name strings and internal -* cache structures; some well concealed, like INIT_WORK() that can allocate -* objects during debug. -* -* If any allocation happens during memcg_kmem_get_cache, we will recurse back -* to it. This may not be a bounded recursion: since the first cache creation -* failed to complete (waiting on the allocation), we'll just try to create the -* cache again, failing at the same point. -* -* memcg_kmem_get_cache is prepared to abort after seeing a positive count of -* memcg_kmem_skip_account. So we enclose anything that might allocate memory -* inside the following two functions. -*/ -static inline void memcg_stop_kmem_account (void ) -{ -VM_BUG_ON (!current->mm); - current->memcg_kmem_skip_account++; -} - -static inline void memcg_resume_kmem_account (void ) -{ -VM_BUG_ON (!current->mm); - current->memcg_kmem_skip_account--; -} -static struct mem_cgroup *mem_cgroup_from_kmem_page (struct page *page) {struct page_cgroup *pc;@@ -5292,6 +5397,9 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, ret =memcg_update_kmem_limit (cont, val); else return -EINVAL; + +if (!ret) +memcg_update_shrink_status (memcg);break ;case RES_SOFT_LIMIT : ret =res_counter_memparse_write_strategy (buffer, &val);mm/vmscan.c +29
-1@@ -2504,7 +2504,42 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,return nr_reclaimed; } -#endif + +#ifdef CONFIG_MEMCG_KMEM +/* +* This function is called when we are under kmem-specific pressure. It will +* only trigger in environments with kmem.limit_in_bytes < limit_in_bytes, IOW, +* with a lower kmem allowance than the memory allowance. +* +* In this situation, freeing user pages from the cgroup won't do us any good. +* What we really need is to call the memcg-aware shrinkers, in the hope of +* freeing pages holding kmem objects. It may also be that we won't be able to +* free any pages, but will get rid of old objects opening up space for new +* ones. +*/ +unsigned long try_to_free_mem_cgroup_kmem (struct mem_cgroup *memcg, +gfp_t gfp_mask) +{ +struct shrink_control shrink = { + .gfp_mask = gfp_mask, + .target_mem_cgroup = memcg, + }; + +if (!(gfp_mask & __GFP_WAIT)) +return 0 ; + +nodes_setall (shrink.nodes_to_scan); + +/* +* We haven't scanned any user LRU, so we basically come up with +* crafted values of nr_scanned and LRU page (1 and 0 respectively).
mm/vmscan.c unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, · line 2545
Quoted 10 lines
mm/vmscan.c +7
-0+* This should be enough to tell shrink_slab that the freeing +* responsibility is all on himself. +*/ +return shrink_slab (&shrink,1 ,0 ); +} +#endif /* CONFIG_MEMCG_KMEM */ +#endif /* CONFIG_MEMCG */ static void age_active_anon (struct zone *zone,struct scan_control *sc) {
Thanks,
-Kame
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
In reply to Glauber CostaQuoted 143 lines · Glauber Costa
If the kernel limit is smaller than the user limit, we will have situations in which our allocations fail but freeing user pages will buy us nothing. In those, we would like to call a specialized memcg reclaimer that only frees kernel memory and leave the user memory alone. Those are also expected to fail when we account
memcg->kmem, instead of when we accountmemcg->res. Based on that, this patch implements a memcg-specific reclaimer, that only shrinks kernel objects, withouth touching user pages.There might be situations in which there are plenty of objects to shrink, but we can't do it because the
__GFP_FSflag is not set. Although they can happen with user pages, they are a lot more common with fs-metadata: this is the case with almost all inode allocation.Those allocations are, however, capable of waiting. So we can just span a worker, let it finish its job and proceed with the allocation. As slow as it is, at this point we are already past any hopes anyway.
Signed-off-by Glauber Costa <[email protected]>Cc Dave Chinner <[email protected]>Cc Mel Gorman <[email protected]>Cc Rik van Riel <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Hugh Dickins <[email protected]>Cc Kamezawa Hiroyuki <[email protected]>Cc Andrew Morton <[email protected]>--- include/linux/swap.h | 2 + mm/memcontrol.c | 182 ++++++++++++++++++++++++++++++++++++++++----------- mm/vmscan.c | 37 ++++++++++- 3 files changed, 183 insertions(+), 38 deletions(-)include/linux/swap.h +2
-0@@ -268,6 +268,8 @@ 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 try_to_free_mem_cgroup_kmem (struct mem_cgroup *mem, +gfp_t gfp_mask); extern unsigned long mem_cgroup_shrink_node_zone(struct mem_cgroup *mem, gfp_t gfp_mask, bool noswap, struct zone *zone,mm/memcontrol.c +54
-2@@ -353,6 +353,8 @@ struct mem_cgroup {atomic_t numainfo_events;atomic_t numainfo_updating;#endif +/* when kmem shrinkers can sleep but can't proceed due to context */ +struct work_struct kmemcg_shrink_work;/* * Per cgroup active and inactive list, similar to the * per zone LRU lists. @@ -369,11 +371,14 @@ static size_t memcg_size(void) nr_node_ids * sizeof(struct mem_cgroup_per_node); } +static DEFINE_MUTEX (set_limit_mutex); +/* internal only representation about the status of kmem accounting. */ enum {KMEM_ACCOUNTED_ACTIVE =0 ,/* accounted by this cgroup itself */ KMEM_ACCOUNTED_ACTIVATED ,/* static key enabled. */ KMEM_ACCOUNTED_DEAD ,/* dead memcg with pending kmem charges */ +KMEM_MAY_SHRINK ,/* kmem limit < mem limit, shrink kmem only */ };/* We account when limit is on, but only after call sites are patched */ @@ -412,6 +417,31 @@ static bool memcg_kmem_test_and_clear_dead(struct mem_cgroup *memcg)return test_and_clear_bit (KMEM_ACCOUNTED_DEAD , &memcg->kmem_account_flags); } + +/* +* If the kernel limit is smaller than the user limit, we will have situations +* in which our allocations fail but freeing user pages will buy us nothing. +* In those, we would like to call a specialized memcg reclaimer that only +* frees kernel memory and leave the user memory alone. +* +* This test exists so we can differentiate between those. Everytime one of the +* limits is updated, we need to run it. The set_limit_mutex must be held, so +* they don't change again. +*/ +static void memcg_update_shrink_status (struct mem_cgroup *memcg) +{ +mutex_lock (&set_limit_mutex); +if (res_counter_read_u64 (&memcg->kmem,RES_LIMIT ) < +res_counter_read_u64 (&memcg->res,RES_LIMIT )) +set_bit (KMEM_MAY_SHRINK , &memcg->kmem_account_flags); +else +clear_bit (KMEM_MAY_SHRINK , &memcg->kmem_account_flags); +mutex_unlock (&set_limit_mutex); +} +#else +static void memcg_update_shrink_status (struct mem_cgroup *memcg) +{ +}#endif /* Stuffs for move charges at task migration. */ @@ -2838,8 +2868,6 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,memcg_check_events (memcg, page); } -static DEFINE_MUTEX (set_limit_mutex); -#ifdef CONFIG_MEMCG_KMEM static inline bool memcg_can_account_kmem (struct mem_cgroup *memcg) {@@ -2881,16 +2909,92 @@ static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, }#endif +/* +* During the creation a new cache, we need to disable our accounting mechanism +* altogether. This is true even if we are not creating, but rather just +* enqueing new caches to be created. +* +* This is because that process will trigger allocations; some visible, like +* explicit kmallocs to auxiliary data structures, name strings and internal +* cache structures; some well concealed, like INIT_WORK() that can allocate +* objects during debug. +* +* If any allocation happens during memcg_kmem_get_cache, we will recurse back +* to it. This may not be a bounded recursion: since the first cache creation +* failed to complete (waiting on the allocation), we'll just try to create the +* cache again, failing at the same point. +* +* memcg_kmem_get_cache is prepared to abort after seeing a positive count of +* memcg_kmem_skip_account. So we enclose anything that might allocate memory +* inside the following two functions. +*/ +static inline void memcg_stop_kmem_account (void ) +{ +VM_BUG_ON (!current->mm); + current->memcg_kmem_skip_account++; +}
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 10 lines
mm/memcontrol.c +10
-0+ +static inline void memcg_resume_kmem_account (void ) +{ +VM_BUG_ON (!current->mm); + current->memcg_kmem_skip_account--; +} + +static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;
I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Quoted 23 lines
mm/memcontrol.c +23
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) {
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 10 lines
mm/memcontrol.c +10
-0+/* +* we are already short on memory, every queue +* allocation is likely to fail +*/ +memcg_stop_kmem_account (); +schedule_work (&memcg->kmemcg_shrink_work); +flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );
Why congestion_wait() ? I think calling congestion_wait() in vmscan.c is a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..
Quoted 54 lines
mm/memcontrol.c +31
-4+ + }while (retries--); + +return ret; +} +static int memcg_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) {struct res_counter *fail_res;struct mem_cgroup *_memcg;int ret =0 ;bool may_oom; +bool kmem_first =test_bit (KMEM_MAY_SHRINK , &memcg->kmem_account_flags); - ret =res_counter_charge (&memcg->kmem, size, &fail_res); -if (ret) -return ret; +if (kmem_first) { + ret =memcg_try_charge_kmem (memcg, gfp, size); +if (ret) +return ret; + }/* * Conditions under which we can wait for the oom_killer. Those are @@ -2923,12 +3027,43 @@ static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)res_counter_charge_nofail (&memcg->memsw, size, &fail_res); ret =0 ; - }else if (ret) +if (!kmem_first) +res_counter_charge_nofail (&memcg->kmem, size, &fail_res); + }else if (ret && kmem_first)res_counter_uncharge (&memcg->kmem, size); +if (!kmem_first) { + ret =memcg_try_charge_kmem (memcg, gfp, size); +if (!ret) +return ret; + +res_counter_uncharge (&memcg->res, size); +if (do_swap_account) +res_counter_uncharge (&memcg->memsw, size); + } +return ret; } +/* +* There might be situations in which there are plenty of objects to shrink, +* but we can't do it because the __GFP_FS flag is not set. This is the case +* with almost all inode allocation. They do are, however, capable of waiting. +* So we can just span a worker, let it finish its job and proceed with the +* allocation. As slow as it is, at this point we are already past any hopes
mm/memcontrol.c static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size) · line 3063
Quoted 10 lines
mm/memcontrol.c +10
-0+* anyway. +*/ +static void kmemcg_shrink_work_fn (struct work_struct *w) +{ +struct mem_cgroup *memcg; + + memcg = container_of(w, struct mem_cgroup, kmemcg_shrink_work); + +if (!try_to_free_mem_cgroup_kmem (memcg,GFP_KERNEL )) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );
ditto..
Quoted 101 lines
mm/memcontrol.c +7
-31+} + +static void memcg_uncharge_kmem (struct mem_cgroup *memcg,u64 size) {res_counter_uncharge (&memcg->res, size);@@ -3005,6 +3140,7 @@ int memcg_update_cache_sizes(struct mem_cgroup *memcg)memcg_update_array_size (num +1 );INIT_LIST_HEAD (&memcg->memcg_slab_caches); +INIT_WORK (&memcg->kmemcg_shrink_work, kmemcg_shrink_work_fn);mutex_init (&memcg->slab_caches_mutex);return 0 ;@@ -3281,37 +3417,6 @@ out:kfree (s->memcg_params); } -/* -* During the creation a new cache, we need to disable our accounting mechanism -* altogether. This is true even if we are not creating, but rather just -* enqueing new caches to be created. -* -* This is because that process will trigger allocations; some visible, like -* explicit kmallocs to auxiliary data structures, name strings and internal -* cache structures; some well concealed, like INIT_WORK() that can allocate -* objects during debug. -* -* If any allocation happens during memcg_kmem_get_cache, we will recurse back -* to it. This may not be a bounded recursion: since the first cache creation -* failed to complete (waiting on the allocation), we'll just try to create the -* cache again, failing at the same point. -* -* memcg_kmem_get_cache is prepared to abort after seeing a positive count of -* memcg_kmem_skip_account. So we enclose anything that might allocate memory -* inside the following two functions. -*/ -static inline void memcg_stop_kmem_account (void ) -{ -VM_BUG_ON (!current->mm); - current->memcg_kmem_skip_account++; -} - -static inline void memcg_resume_kmem_account (void ) -{ -VM_BUG_ON (!current->mm); - current->memcg_kmem_skip_account--; -} -static struct mem_cgroup *mem_cgroup_from_kmem_page (struct page *page) {struct page_cgroup *pc;@@ -5292,6 +5397,9 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft, ret =memcg_update_kmem_limit (cont, val); else return -EINVAL; + +if (!ret) +memcg_update_shrink_status (memcg);break ;case RES_SOFT_LIMIT : ret =res_counter_memparse_write_strategy (buffer, &val);mm/vmscan.c +29
-1@@ -2504,7 +2504,42 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,return nr_reclaimed; } -#endif + +#ifdef CONFIG_MEMCG_KMEM +/* +* This function is called when we are under kmem-specific pressure. It will +* only trigger in environments with kmem.limit_in_bytes < limit_in_bytes, IOW, +* with a lower kmem allowance than the memory allowance. +* +* In this situation, freeing user pages from the cgroup won't do us any good. +* What we really need is to call the memcg-aware shrinkers, in the hope of +* freeing pages holding kmem objects. It may also be that we won't be able to +* free any pages, but will get rid of old objects opening up space for new +* ones. +*/ +unsigned long try_to_free_mem_cgroup_kmem (struct mem_cgroup *memcg, +gfp_t gfp_mask) +{ +struct shrink_control shrink = { + .gfp_mask = gfp_mask, + .target_mem_cgroup = memcg, + }; + +if (!(gfp_mask & __GFP_WAIT)) +return 0 ; + +nodes_setall (shrink.nodes_to_scan); + +/* +* We haven't scanned any user LRU, so we basically come up with +* crafted values of nr_scanned and LRU page (1 and 0 respectively).
mm/vmscan.c unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, · line 2545
Quoted 10 lines
mm/vmscan.c +7
-0+* This should be enough to tell shrink_slab that the freeing +* responsibility is all on himself. +*/ +return shrink_slab (&shrink,1 ,0 ); +} +#endif /* CONFIG_MEMCG_KMEM */ +#endif /* CONFIG_MEMCG */ static void age_active_anon (struct zone *zone,struct scan_control *sc) {
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>
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Suggestions ?
Quoted 29 lines
Quoted 29 lines
mm/memcontrol.c +29
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) { + /* + * we are already short on memory, every queue + * allocation is likely to fail + */ + memcg_stop_kmem_account(); + schedule_work(&memcg->kmemcg_shrink_work);
Quoted 10 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 4 lines
mm/memcontrol.c +4
-0+flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );Why
congestion_wait()? I think callingcongestion_wait()invmscan.cis a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..
Although it is not the case with dentries (or inodes, since only non-dirty inodes goes to the lru list), some objects we are freeing may need time to be written back to disk. This is the case for instance with the buffer heads and bio's. They will not be actively shrunk in shrinkers, but it is my understanding that they will be released. Inodes as well, may have time to be written back and become non-dirty.
In practice, in my tests, this would almost-always fail after a retry if we don't wait, and almost always succeed in a retry if we do wait.
Am I missing something in this interpretation ?
--
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>
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
Quoted 8 lines · Glauber Costa
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Suggestions ?
I think you did tests.
Quoted 47 lines
Quoted 29 lines
Quoted 29 lines
mm/memcontrol.c +29
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) { + /* + * we are already short on memory, every queue + * allocation is likely to fail + */ + memcg_stop_kmem_account(); + schedule_work(&memcg->kmemcg_shrink_work);Quoted 10 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 4 lines
mm/memcontrol.c +4
-0+flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );Why
congestion_wait()? I think callingcongestion_wait()invmscan.cis a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..Although it is not the case with dentries (or inodes, since only non-dirty inodes goes to the lru list), some objects we are freeing may need time to be written back to disk. This is the case for instance with the buffer heads and bio's. They will not be actively shrunk in shrinkers, but it is my understanding that they will be released. Inodes as well, may have time to be written back and become non-dirty.
Quoted 5 lines
In practice, in my tests, this would almost-always fail after a retry if we don't wait, and almost always succeed in a retry if we do wait.
Am I missing something in this interpretation ?
Ah, sorry. Can't we put this wait into try_to_free_mem_cgroup_kmem().
Thanks,
-Kame
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
Quoted 7 lines · Kamezawa Hiroyuki
Quoted 6 lines · Glauber Costa
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Quoted 5 lines
Quoted 2 lines
Suggestions ?
I think you did tests.
Indeed. And in my tests, 2 or 3 retries are already enough to seal the fate of this.
I though it was safer to go with the same number, though, exactly not to be too biased by my specific test environments.
I am fine with >= 3.
Michal, you have input here?
Quoted 47 lines
Quoted 47 lines
Quoted 29 lines
Quoted 29 lines
mm/memcontrol.c +29
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) { + /* + * we are already short on memory, every queue + * allocation is likely to fail + */ + memcg_stop_kmem_account(); + schedule_work(&memcg->kmemcg_shrink_work);Quoted 10 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 4 lines
mm/memcontrol.c +4
-0+flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );Why
congestion_wait()? I think callingcongestion_wait()invmscan.cis a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..Although it is not the case with dentries (or inodes, since only non-dirty inodes goes to the lru list), some objects we are freeing may need time to be written back to disk. This is the case for instance with the buffer heads and bio's. They will not be actively shrunk in shrinkers, but it is my understanding that they will be released. Inodes as well, may have time to be written back and become non-dirty.
Quoted 8 lines
Quoted 5 lines
In practice, in my tests, this would almost-always fail after a retry if we don't wait, and almost always succeed in a retry if we do wait.
Am I missing something in this interpretation ?
Ah, sorry. Can't we put this wait into
try_to_free_mem_cgroup_kmem().
That I believe we can easily do.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
Quoted 7 lines · Kamezawa Hiroyuki
Quoted 6 lines · Glauber Costa
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Quoted 5 lines
Quoted 2 lines
Suggestions ?
I think you did tests.
Indeed. And in my tests, 2 or 3 retries are already enough to seal the fate of this.
I though it was safer to go with the same number, though, exactly not to be too biased by my specific test environments.
I am fine with >= 3.
Michal, you have input here?
Quoted 47 lines
Quoted 47 lines
Quoted 29 lines
Quoted 29 lines
mm/memcontrol.c +29
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) { + /* + * we are already short on memory, every queue + * allocation is likely to fail + */ + memcg_stop_kmem_account(); + schedule_work(&memcg->kmemcg_shrink_work);Quoted 10 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 4 lines
mm/memcontrol.c +4
-0+flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );Why
congestion_wait()? I think callingcongestion_wait()invmscan.cis a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..Although it is not the case with dentries (or inodes, since only non-dirty inodes goes to the lru list), some objects we are freeing may need time to be written back to disk. This is the case for instance with the buffer heads and bio's. They will not be actively shrunk in shrinkers, but it is my understanding that they will be released. Inodes as well, may have time to be written back and become non-dirty.
Quoted 8 lines
Quoted 5 lines
In practice, in my tests, this would almost-always fail after a retry if we don't wait, and almost always succeed in a retry if we do wait.
Am I missing something in this interpretation ?
Ah, sorry. Can't we put this wait into
try_to_free_mem_cgroup_kmem().
That I believe we can easily do.
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
In reply to a message not in the archiveQuoted 11 lines · Kamezawa Hiroyuki
Quoted 8 lines · Glauber Costa
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Suggestions ?
I think you did tests.
sorry..
I think you did tests and know what number is good by tests.
If it's the same number to MEM_CGROUP_RECLAIM_RETRIES, I have no objections. I think no reason is bad.
Thanks,
-Kame
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
In reply to Kamezawa HiroyukiQuoted 11 lines · Kamezawa Hiroyuki
Quoted 8 lines · Glauber Costa
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Suggestions ?
I think you did tests.
sorry..
I think you did tests and know what number is good by tests.
If it's the same number to MEM_CGROUP_RECLAIM_RETRIES, I have no objections. I think no reason is bad.
Thanks,
-Kame
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 26/28] memcg: per-memcg kmem shrinking
Quoted 6 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2945
Quoted 3 lines
mm/memcontrol.c +3
-0+static int memcg_try_charge_kmem (struct mem_cgroup *memcg,gfp_t gfp,u64 size) +{ +int retries =MEM_CGROUP_RECLAIM_RETRIES ;I'm not sure this retry numbers, for anon/file LRUs is suitable for kmem.
Suggestions ?
Quoted 29 lines
Quoted 29 lines
mm/memcontrol.c +29
-0+struct res_counter *fail_res; +int ret; + + do { + ret = res_counter_charge(&memcg->kmem, size, &fail_res); + if (!ret) + return ret; + + if (!(gfp & __GFP_WAIT)) + return ret; + + /* + * We will try to shrink kernel memory present in caches. We + * are sure that we can wait, so we will. The duration of our + * wait is determined by congestion, the same way as vmscan.c + * + * If we are in FS context, though, then although we can wait, + * we cannot call the shrinkers. Most fs shrinkers (which + * comprises most of our kmem data) will not run without + * __GFP_FS since they can deadlock. The solution is to + * synchronously run that in a different context. + */ + if (!(gfp & __GFP_FS)) { + /* + * we are already short on memory, every queue + * allocation is likely to fail + */ + memcg_stop_kmem_account(); + schedule_work(&memcg->kmemcg_shrink_work);
Quoted 10 lines
mm/memcontrol.c static int mem_cgroup_slabinfo_read(struct cgroup *cont, struct cftype *cft, · line 2978
Quoted 4 lines
mm/memcontrol.c +4
-0+flush_work (&memcg->kmemcg_shrink_work); +memcg_resume_kmem_account (); + }else if (!try_to_free_mem_cgroup_kmem (memcg, gfp)) +congestion_wait (BLK_RW_ASYNC ,HZ /10 );Why
congestion_wait()? I think callingcongestion_wait()invmscan.cis a part of memory-reclaim logic but I don't think the caller should do this kind of voluteer wait without good reason..
Although it is not the case with dentries (or inodes, since only non-dirty inodes goes to the lru list), some objects we are freeing may need time to be written back to disk. This is the case for instance with the buffer heads and bio's. They will not be actively shrunk in shrinkers, but it is my understanding that they will be released. Inodes as well, may have time to be written back and become non-dirty.
In practice, in my tests, this would almost-always fail after a retry if we don't wait, and almost always succeed in a retry if we do wait.
Am I missing something in this interpretation ?
PATCH v2 27/28 list_lru: reclaim proportionaly between memcgs and nodes
In reply to Glauber CostaThe current list_lru code will try to scan objects until nr_to_walk is reached, and then stop. This number can be different from the total number of objects we have as returned by our count function. This is because the main shrinker driver is the one ultimately responsible for determining how many objects to shrink from each shrinker.
Specially if this number is lower than the number of objects, and because we transverse the list always in the same order, we can have the last node and/or the last memcg always being less penalized than the others.
My proposed solution is to introduce some metric of proportionality based on the total number of objects per node and then scan all nodes and memcgs up until their share is reached.
--- lib/list_lru.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 13 deletions(-)
lib/list_lru.c +83 -13
@@ -177,6 +177,43 @@ restart:return isolated; } +static long +memcg_isolate_lru ( +struct list_lru *lru, +list_lru_walk_cb isolate, +void *cb_arg, +long nr_to_walk, +struct mem_cgroup *memcg, +int nid,unsigned long total_node) +{ +int memcg_id =memcg_cache_id (memcg); +unsigned long nr_to_walk_this; +long isolated =0 ; +int idx; +struct list_lru_node *nlru; + +for_each_memcg_lru_index (idx, memcg_id) { + nlru =lru_node_of_index (lru, idx, nid); +if (!nlru || !nlru->nr_items) +continue ; + +/* +* no memcg: walk every memcg proportionally. +* memcg case: scan everything (total_node) +*/ +if (!memcg) + nr_to_walk_this =mult_frac (nlru->nr_items, nr_to_walk, + total_node); +else + nr_to_walk_this = total_node; + + isolated +=list_lru_walk_node (lru, nlru, nid, isolate, + cb_arg, &nr_to_walk_this); + } + +return isolated; +} + long list_lru_walk_nodemask_memcg( struct list_lru *lru,
@@ -189,9 +226,7 @@ list_lru_walk_nodemask_memcg(long isolated =0 ;int nid;nodemask_t nodes; -int memcg_id =memcg_cache_id (memcg); -int idx; -struct list_lru_node *nlru; +unsigned long n_node, total_node, total =0 ;/* * Conservative code can call this setting nodes with node_setall.
@@ -199,17 +234,52 @@ list_lru_walk_nodemask_memcg(*/ nodes_and (nodes, *nodes_to_walk, node_online_map); +/* +* We will first find out how many objects there are in the LRU, in +* total. We could store that in a per-LRU counter as well, the same +* way we store it in a per-NLRU. But lru_add and lru_del are way more +* frequent operations, so it is better to pay the price here. +* +* Once we have that number, we will try to scan the nodes +* proportionally to the amount of objects they have. The main shrinker +* driver in vmscan.c will often ask us to shrink a quantity different +* from the total quantity we reported in the count function (usually +* less). This means that not scanning proportionally may leave nodes +* (usually the last), unfairly charged. +* +* The final number we want is +* +* n_node = nr_to_scan * total_node / total +*/ +for_each_node_mask (nid, nodes) + total +=atomic_long_read (&lru->node_totals[nid]); +for_each_node_mask (nid, nodes) { -for_each_memcg_lru_index (idx, memcg_id) { - nlru =lru_node_of_index (lru, idx, nid); -if (!nlru) -continue ; - - isolated +=list_lru_walk_node (lru, nlru, nid, isolate, - cb_arg, &nr_to_walk); -if (nr_to_walk <=0 ) -break ; - } + total_node =atomic_long_read (&lru->node_totals[nid]); +if (!total_node) +continue ; + +/* +* There are items, but in less proportion. Because we have no +* information about where exactly the pressure originates +* from, it is better to try shrinking the few we have than to +* skip it. It might very well be that this node is under +* pressure and any help would be welcome. +*/ + n_node =mult_frac (total_node, nr_to_walk, total); +if (!n_node) + n_node = total_node; + +/* +* We will now scan all memcg-like entities (which includes the +* global LRU, of index -1, and also try to mantain +* proportionality among them. +* +* We will try to isolate: +* nr_memcg = n_node * nr_memcg_lru / total_node +*/ + isolated +=memcg_isolate_lru (lru, isolate, cb_arg, + n_node, memcg, nid, total_node); }return isolated; }
Signature · 1 line
1.8.1.4
PATCH v2 28/28 super: targeted memcg reclaim
In reply to Glauber CostaWe now have all our dentries and inodes placed in memcg-specific LRU lists. All we have to do is restrict the reclaim to the said lists in case of memcg pressure.
That can't be done so easily for the fs_objects part of the equation, since this is heavily fs-specific. What we do is pass on the context, and let the filesystems decide if they ever chose or want to. At this time, we just don't shrink them in memcg pressure (none is supported), leaving that for global pressure only.
Marking the superblock shrinker and its LRUs as memcg-aware will guarantee that the shrinkers will get invoked during targetted reclaim.
--- fs/dcache.c | 6 +++--- fs/inode.c | 6 +++--- fs/internal.h | 5 +++-- fs/super.c | 39 +++++++++++++++++++++++++++------------ 4 files changed, 36 insertions(+), 20 deletions(-)
fs/dcache.c +3 -3
@@ -882,13 +882,13 @@ static int dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock,* use. */ long prune_dcache_sb (struct super_block *sb,long nr_to_scan, -nodemask_t *nodes_to_walk) +nodemask_t *nodes_to_walk,struct mem_cgroup *memcg) {LIST_HEAD (dispose);long freed; - freed =list_lru_walk_nodemask (&sb->s_dentry_lru, dentry_lru_isolate, - &dispose, nr_to_scan, nodes_to_walk); + freed =list_lru_walk_nodemask_memcg (&sb->s_dentry_lru, + dentry_lru_isolate, &dispose, nr_to_scan, nodes_to_walk, memcg);shrink_dentry_list (&dispose);return freed; }
fs/inode.c +3 -3
@@ -746,13 +746,13 @@ static int inode_lru_isolate(struct list_head *item, spinlock_t *lru_lock,* then are freed outside inode_lock by dispose_list(). */ long prune_icache_sb (struct super_block *sb,long nr_to_scan, -nodemask_t *nodes_to_walk) +nodemask_t *nodes_to_walk,struct mem_cgroup *memcg) {LIST_HEAD (freeable);long freed; - freed =list_lru_walk_nodemask (&sb->s_inode_lru, inode_lru_isolate, - &freeable, nr_to_scan, nodes_to_walk); + freed =list_lru_walk_nodemask_memcg (&sb->s_inode_lru, + inode_lru_isolate, &freeable, nr_to_scan, nodes_to_walk, memcg);dispose_list (&freeable);return freed; }
fs/internal.h +3 -2
@@ -16,6 +16,7 @@ struct file_system_type;struct linux_binprm ;struct path ;struct mount ; +struct mem_cgroup ;/* * block_dev.c
@@ -111,7 +112,7 @@ extern int open_check_o_direct(struct file *f);*/ extern spinlock_t inode_sb_list_lock;extern long prune_icache_sb (struct super_block *sb,long nr_to_scan, -nodemask_t *nodes_to_scan); +nodemask_t *nodes_to_scan,struct mem_cgroup *memcg);extern void inode_add_lru (struct inode *inode);/*
@@ -128,4 +129,4 @@ extern int invalidate_inodes(struct super_block *, bool);*/ extern struct dentry *__d_alloc (struct super_block *,const struct qstr *);extern long prune_dcache_sb (struct super_block *sb,long nr_to_scan, -nodemask_t *nodes_to_scan); +nodemask_t *nodes_to_scan,struct mem_cgroup *memcg);
fs/super.c +27 -12
@@ -34,6 +34,7 @@#include <linux/cleancache.h> #include <linux/fsnotify.h> #include <linux/lockdep.h> +#include <linux/memcontrol.h> #include "internal.h"
@@ -56,6 +57,7 @@ static char *sb_writers_name[SB_FREEZE_LEVELS] = {static long super_cache_scan (struct shrinker *shrink,struct shrink_control *sc) {struct super_block *sb; +struct mem_cgroup *memcg = sc->target_mem_cgroup;long fs_objects =0 ;long total_objects;long freed =0 ;
@@ -74,11 +76,13 @@ static long super_cache_scan(struct shrinker *shrink, struct shrink_control *sc)if (!grab_super_passive (sb))return -1 ; -if (sb->s_op && sb->s_op->nr_cached_objects) +if (sb->s_op && sb->s_op->nr_cached_objects && !memcg) fs_objects = sb->s_op->nr_cached_objects (sb, &sc->nodes_to_scan); - inodes =list_lru_count_nodemask (&sb->s_inode_lru, &sc->nodes_to_scan); - dentries =list_lru_count_nodemask (&sb->s_dentry_lru, &sc->nodes_to_scan); + inodes =list_lru_count_nodemask_memcg (&sb->s_inode_lru, + &sc->nodes_to_scan, memcg); + dentries =list_lru_count_nodemask_memcg (&sb->s_dentry_lru, + &sc->nodes_to_scan, memcg); total_objects = dentries + inodes + fs_objects +1 ;/* proportion the scan between the caches */
@@ -89,8 +93,8 @@ static long super_cache_scan(struct shrinker *shrink, struct shrink_control *sc)* prune the dcache first as the icache is pinned by it, then * prune the icache, followed by the filesystem specific caches */ - freed =prune_dcache_sb (sb, dentries, &sc->nodes_to_scan); - freed +=prune_icache_sb (sb, inodes, &sc->nodes_to_scan); + freed =prune_dcache_sb (sb, dentries, &sc->nodes_to_scan, memcg); + freed +=prune_icache_sb (sb, inodes, &sc->nodes_to_scan, memcg);if (fs_objects) { fs_objects = mult_frac(sc->nr_to_scan, fs_objects,
@@ -107,20 +111,26 @@ static long super_cache_count(struct shrinker *shrink, struct shrink_control *sc {struct super_block *sb;long total_objects =0 ; +struct mem_cgroup *memcg = sc->target_mem_cgroup; sb = container_of(shrink, struct super_block, s_shrink);if (!grab_super_passive (sb))return -1 ; -if (sb->s_op && sb->s_op->nr_cached_objects) +/* +* Ideally we would pass memcg to nr_cached_objects, and +* let the underlying filesystem decide. Most likely the +* path will be if (!memcg) return;, but even then. +*/ +if (sb->s_op && sb->s_op->nr_cached_objects && !memcg) total_objects = sb->s_op->nr_cached_objects (sb, &sc->nodes_to_scan); - total_objects +=list_lru_count_nodemask (&sb->s_dentry_lru, - &sc->nodes_to_scan); - total_objects +=list_lru_count_nodemask (&sb->s_inode_lru, - &sc->nodes_to_scan); + total_objects +=list_lru_count_nodemask_memcg (&sb->s_dentry_lru, + &sc->nodes_to_scan, memcg); + total_objects +=list_lru_count_nodemask_memcg (&sb->s_inode_lru, + &sc->nodes_to_scan, memcg); total_objects =vfs_pressure_ratio (total_objects);drop_super (sb);
@@ -199,8 +209,10 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags)INIT_HLIST_NODE (&s->s_instances);INIT_HLIST_BL_HEAD (&s->s_anon);INIT_LIST_HEAD (&s->s_inodes); -list_lru_init (&s->s_dentry_lru); -list_lru_init (&s->s_inode_lru); + +list_lru_init_memcg (&s->s_dentry_lru); +list_lru_init_memcg (&s->s_inode_lru); +INIT_LIST_HEAD (&s->s_mounts);init_rwsem (&s->s_umount);lockdep_set_class (&s->s_umount, &type->s_umount_key);
@@ -236,6 +248,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags) s->s_shrink.scan_objects = super_cache_scan; s->s_shrink.count_objects = super_cache_count; s->s_shrink.batch =1024 ; + s->s_shrink.memcg_shrinker = true; } out:return s;
@@ -318,6 +331,8 @@ void deactivate_locked_super(struct super_block *s)/* caches are now gone, we can safely kill the shrinker now */ unregister_shrinker (&s->s_shrink); +list_lru_destroy (&s->s_dentry_lru); +list_lru_destroy (&s->s_inode_lru);put_filesystem (fs);put_super (s); }else {
Signature · 1 line
1.8.1.4
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
-serge
--
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 · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Quoted 7 lines
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
-serge
Not yet. I intend to include them in my next run. I haven't yet decided on a set of tests to run (maybe just a memcg-contained kernel compile?)
So if you have suggestions of what I could run to show this, feel free to lay them down here.
--
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 17 lines · Glauber Costa
Quoted 16 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
Quoted 7 lines
Quoted 2 lines
-serge
Not yet. I intend to include them in my next run. I haven't yet decided on a set of tests to run (maybe just a memcg-contained kernel compile?)
So if you have suggestions of what I could run to show this, feel free to lay them down here.
Perhaps mount a 4G tmpfs, copy kernel tree there, and build kernel on that tmpfs?
-serge
Quoted 20 lines · Serge Hallyn
Quoted 19 lines · Glauber Costa
Quoted 18 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
-serge
Quoted 9 lines
Quoted 5 lines
Not yet. I intend to include them in my next run. I haven't yet decided on a set of tests to run (maybe just a memcg-contained kernel compile?)
So if you have suggestions of what I could run to show this, feel free to lay them down here.
Perhaps mount a 4G tmpfs, copy kernel tree there, and build kernel on that tmpfs?
I've just run kernbench with 2Gb setups, with 3 different kernels. I will include all this data in my opening letter for the next submission, but wanted to drop a heads up here:
Kernels
========
base: the current -mm
davelru: that + dave's patches applied
fulllru: that + my patches applied.
I've ran all of them in a 1st level cgroup. Please note that the first two kernels are not capable of shrinking metadata, so I had to select a size that is enough to be in relatively constant pressure, but at the same time not having that pressure to be exclusively from kernel memory. 2Gb did the job. This is a 2-node 24-way machine. My access to it is very limited, and I have no idea when I'll be able to get my hands into it again
Results:
Base
====
Average Optimal load -j 24 Run (std deviation):
Elapsed Time 415.988 (8.37909)
User Time 4142 (759.964)
System Time 418.483 (62.0377)
Percent CPU 1030.7 (267.462)
Context Switches 391509 (268361)
Sleeps 738483 (149934)
Dave
====
Average Optimal load -j 24 Run (std deviation):
Elapsed Time 424.486 (16.7365) ( + 2 % vs base) User Time 4146.8 (764.012) ( + 0.84 % vs base) System Time 419.24 (62.4507) (+ 0.18 % vs base) Percent CPU 1012.1 (264.558) (-1.8 % vs base) Context Switches 393363 (268899) (+ 0.47 % vs base) Sleeps 739905 (147344) (+ 0.19 % vs base)
Full
=====
Average Optimal load -j 24 Run (std deviation):
Elapsed Time 456.644 (15.3567) ( + 9.7 % vs base) User Time 4036.3 (645.261) ( - 2.5 % vs base) System Time 438.134 (82.251) ( + 4.7 % vs base) Percent CPU 973 (168.581) ( - 5.6 % vs base) Context Switches 350796 (229700) ( - 10 % vs base) Sleeps 728156 (138808) ( - 1.4 % vs base )
Discussion:
===========
First-level analysis: All figures fall within the std dev, except for Full LRU wall time. It does fall within 2 std devs, though. On the other hand, Full LRU kernel leads to better cpu utilization and greater efficiency.
Details: The reclaim patterns in the three kernels are expected to be different. User memory will always be the main driver, but in case of pressure the first two kernels will shrink it while keeping the metadata intact. This should lead to smaller system times figure at expense of bigger user time figures, since user pages will be evicted more often. This is consistent with the figures I've found.
Full LRU kernels have a 2.5 % better user time utilization, with 5.6 % less CPU consumed and 10 % less context switches.
This comes at the expense of a 4.7 % loss of system time. Because we will have to bring more dentry and inode objects back from caches, we will stress more the slab code.
Because this is a benchmark that stresses a lot of metadata, it is expected that this increase affects the end wall result proportionally. We notice that the mere introduction of LRU code (Dave's Kernel) does not affect the end wall time result outside the standard deviation. Shrinking those objects, however, will lead to bigger wall times. This is within the expected. No one would ever argue that the right kernel behavior for all cases should keep the metadata in memory at expense of user memory (and even if we should, we should do it the same way for the cgroups).
My final conclusions is that performance wise the work is sound and operates within expectations.
Quoted 11 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Quoted 7 lines
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
-serge
Not yet. I intend to include them in my next run. I haven't yet decided on a set of tests to run (maybe just a memcg-contained kernel compile?)
So if you have suggestions of what I could run to show this, feel free to lay them down here.
Quoted 11 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Quoted 4 lines
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
The reason for the node-aware LRUs in the first place is performance. i.e. to remove the global LRU locks from the shrinkers and LRU list operations. For XFS (at least) the VFS LRU operations are significant sources of contention at 16p, and at high CPU counts they can basically cause spinlock meltdown.
I've done performance testing on them on 16p machines with fake-numa=4 under such contention generating workloads (e.g. 16-way concurrent fsmark workloads) and seen that the LRU locks disappear from the profiles. Performance improvement at this size of machine under these workloads is still within the run-to-run variance of the benchmarks I've run, but the fact the lock is no longer in the profiles at all suggest that scalability for larger machines will be significantly improved.
As for the memcg side of things, I'll leave that to Glauber....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Dave Chinner
maintainerQuoted 11 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Quoted 4 lines
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
The reason for the node-aware LRUs in the first place is performance. i.e. to remove the global LRU locks from the shrinkers and LRU list operations. For XFS (at least) the VFS LRU operations are significant sources of contention at 16p, and at high CPU counts they can basically cause spinlock meltdown.
I've done performance testing on them on 16p machines with fake-numa=4 under such contention generating workloads (e.g. 16-way concurrent fsmark workloads) and seen that the LRU locks disappear from the profiles. Performance improvement at this size of machine under these workloads is still within the run-to-run variance of the benchmarks I've run, but the fact the lock is no longer in the profiles at all suggest that scalability for larger machines will be significantly improved.
As for the memcg side of things, I'll leave that to Glauber....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 32 lines · Dave Chinner
Quoted 11 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Quoted 4 lines
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
The reason for the node-aware LRUs in the first place is performance. i.e. to remove the global LRU locks from the shrinkers and LRU list operations. For XFS (at least) the VFS LRU operations are significant sources of contention at 16p, and at high CPU counts they can basically cause spinlock meltdown.
I've done performance testing on them on 16p machines with fake-numa=4 under such contention generating workloads (e.g. 16-way concurrent fsmark workloads) and seen that the LRU locks disappear from the profiles. Performance improvement at this size of machine under these workloads is still within the run-to-run variance of the benchmarks I've run, but the fact the lock is no longer in the profiles at all suggest that scalability for larger machines will be significantly improved.
Quoted 2 lines
As for the memcg side of things, I'll leave that to Glauber....
I will chime in here about the per-node thing on the memcg side, because I believe this is the most important design point, and one I'd like to reach quick agreement on.
Quoted 1 line
From the memcg PoV, all pressure is global, and the LRU does not buy us
nothing. This is because the nature of memcg: all we care about, is being over or below a certain soft or hard limit. Where the memory is located is the concern of other subsystems (like cpuset) and has no place in memcg interests.
As far as the underlying LRU, I fully trust Dave in what he says: We may not be able to detect it in our mortal setups, but less lock contention is very likely to be a clear win in big contended, multi-node scenarios. By design, you may want as well to shrink per-node, so not disposing objects in other nodes is also a qualitative win.
In memcg, there are two options: We either stuck a new list_lru in the objects (dentry and inodes), or we keep it per-node as well. The first one would allow us to keep global LRU order for global pressure walks, and memcg LRU order for memcg walks.
Two lists seems simpler at first, but it also have an interesting
effect: on global reclaim, we will break fairness among memcgs. Old memcgs are likely to be penalized regardless of any other considerations. Being memcg concerned heavily about isolation between workloads, it would be preferable to spread global reclaim among them.
The other reason I am keeping per-node memcg, is memory footprint. I have 24 bytes per-LRU, which are constant and likely to exist in any scenario (the list head for child lrus (16b) and a memcg pointer(8b))
Then we have a 32-byte structure that represents the LRU itself (If I got the math correctly for the spinlock usual, non-debug size)
That will be per-node, and each LRU will have one copy of that per-memcg. So the extra size is 32 * nodes * lrus * memcgs.
Keeping extra state in the object, means an extra list_head per-object. This is 16 * # objects.
It starts to be a win in favor of the memcg-per-lru when we reach a number of objects o = 2 * nodes * lrus * memcgs
Using some numbers, nodes = 4, lrus = 100, memcgs = 100, (and this can already be considered damn big), we have 4000 objects as the threshold point. My fedora laptop doing nothing other than April fool's jokes and answering your e-mails, have 26k dentries stored in the slab.
This means aside from the more isolated behavior, our memory footprint is way, way smaller by keeping the memcgs per-lru.
Quoted 32 lines · Dave Chinner
Quoted 11 lines · Serge Hallyn
Quoted 9 lines · Glauber Costa
Hi,
Notes:
======This is v2 of memcg-aware LRU shrinking. I've been testing it extensively and it behaves well, at least from the isolation point of view. However, I feel some more testing is needed before we commit to it. Still, this is doing the job fairly well. Comments welcome.
Quoted 4 lines
Do you have any performance tests (preferably with enough runs with and without this patchset to show 95% confidence interval) to show the impact this has? Certainly the feature sounds worthwhile, but I'm curious about the cost of maintaining this extra state.
The reason for the node-aware LRUs in the first place is performance. i.e. to remove the global LRU locks from the shrinkers and LRU list operations. For XFS (at least) the VFS LRU operations are significant sources of contention at 16p, and at high CPU counts they can basically cause spinlock meltdown.
I've done performance testing on them on 16p machines with fake-numa=4 under such contention generating workloads (e.g. 16-way concurrent fsmark workloads) and seen that the LRU locks disappear from the profiles. Performance improvement at this size of machine under these workloads is still within the run-to-run variance of the benchmarks I've run, but the fact the lock is no longer in the profiles at all suggest that scalability for larger machines will be significantly improved.
Quoted 2 lines
As for the memcg side of things, I'll leave that to Glauber....
I will chime in here about the per-node thing on the memcg side, because I believe this is the most important design point, and one I'd like to reach quick agreement on.
From the memcg PoV, all pressure is global, and the LRU does not buy us nothing. This is because the nature of memcg: all we care about, is being over or below a certain soft or hard limit. Where the memory is located is the concern of other subsystems (like cpuset) and has no place in memcg interests.
As far as the underlying LRU, I fully trust Dave in what he says: We may not be able to detect it in our mortal setups, but less lock contention is very likely to be a clear win in big contended, multi-node scenarios. By design, you may want as well to shrink per-node, so not disposing objects in other nodes is also a qualitative win.
In memcg, there are two options: We either stuck a new list_lru in the objects (dentry and inodes), or we keep it per-node as well. The first one would allow us to keep global LRU order for global pressure walks, and memcg LRU order for memcg walks.
Two lists seems simpler at first, but it also have an interesting
effect: on global reclaim, we will break fairness among memcgs. Old memcgs are likely to be penalized regardless of any other considerations. Being memcg concerned heavily about isolation between workloads, it would be preferable to spread global reclaim among them.
The other reason I am keeping per-node memcg, is memory footprint. I have 24 bytes per-LRU, which are constant and likely to exist in any scenario (the list head for child lrus (16b) and a memcg pointer(8b))
Then we have a 32-byte structure that represents the LRU itself (If I got the math correctly for the spinlock usual, non-debug size)
That will be per-node, and each LRU will have one copy of that per-memcg. So the extra size is 32 * nodes * lrus * memcgs.
Keeping extra state in the object, means an extra list_head per-object. This is 16 * # objects.
It starts to be a win in favor of the memcg-per-lru when we reach a number of objects o = 2 * nodes * lrus * memcgs
Using some numbers, nodes = 4, lrus = 100, memcgs = 100, (and this can already be considered damn big), we have 4000 objects as the threshold point. My fedora laptop doing nothing other than April fool's jokes and answering your e-mails, have 26k dentries stored in the slab.
This means aside from the more isolated behavior, our memory footprint is way, way smaller by keeping the memcgs per-lru.