mm: rename page_counter's count/limit into usage/max
Subsystems (7)
PATCH v3 1/4 mm: rename page_counter's count/limit into usage/max
This patch renames struct page_counter fields:
count -> usage
limit -> max
and the corresponding functions:
page_counter_limit() -> page_counter_set_max() mem_cgroup_get_limit() -> mem_cgroup_get_max() mem_cgroup_resize_limit() -> mem_cgroup_resize_max() memcg_update_kmem_limit() -> memcg_update_kmem_max() memcg_update_tcp_limit() -> memcg_update_tcp_max()
The idea behind this renaming is to have the direct matching between memory cgroup knobs (low, high, max) and page_counters API.
This is pure renaming, this patch doesn't bring any functional change.
--- include/linux/memcontrol.h | 4 +- include/linux/page_counter.h | 12 ++--- mm/hugetlb_cgroup.c | 6 +-- mm/memcontrol.c | 112 +++++++++++++++++++++---------------------- mm/oom_kill.c | 2 +- mm/page_counter.c | 28 +++++------ 6 files changed, 82 insertions(+), 82 deletions(-)
include/linux/memcontrol.h +2 -2
@@ -475,7 +475,7 @@ unsigned long mem_cgroup_get_zone_lru_size(struct lruvec *lruvec,void mem_cgroup_handle_over_high (void ); -unsigned long mem_cgroup_get_limit (struct mem_cgroup *memcg); +unsigned long mem_cgroup_get_max (struct mem_cgroup *memcg);void mem_cgroup_print_oom_info (struct mem_cgroup *memcg,struct task_struct *p);
@@ -882,7 +882,7 @@ mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,return 0 ; } -static inline unsigned long mem_cgroup_get_limit (struct mem_cgroup *memcg) +static inline unsigned long mem_cgroup_get_max (struct mem_cgroup *memcg) {return 0 ; }
include/linux/page_counter.h +6 -6
@@ -7,8 +7,8 @@#include <asm/page.h> struct page_counter { -atomic_long_t count; -unsigned long limit; +atomic_long_t usage; +unsigned long max;struct page_counter *parent;/* legacy */
@@ -25,14 +25,14 @@ struct page_counter {static inline void page_counter_init (struct page_counter *counter,struct page_counter *parent) { -atomic_long_set (&counter->count,0 ); - counter->limit =PAGE_COUNTER_MAX ; +atomic_long_set (&counter->usage,0 ); + counter->max =PAGE_COUNTER_MAX ; counter->parent = parent; }static inline unsigned long page_counter_read (struct page_counter *counter) { -return atomic_long_read (&counter->count); +return atomic_long_read (&counter->usage); }void page_counter_cancel (struct page_counter *counter,unsigned long nr_pages);
@@ -41,7 +41,7 @@ bool page_counter_try_charge(struct page_counter *counter,unsigned long nr_pages, struct page_counter **fail);void page_counter_uncharge (struct page_counter *counter,unsigned long nr_pages); -int page_counter_limit (struct page_counter *counter,unsigned long limit); +int page_counter_set_max (struct page_counter *counter,unsigned long nr_pages);int page_counter_memparse (const char *buf,const char *max,unsigned long *nr_pages);
mm/hugetlb_cgroup.c +3 -3
@@ -84,7 +84,7 @@ static void hugetlb_cgroup_init(struct hugetlb_cgroup *h_cgroup, limit =round_down (PAGE_COUNTER_MAX ,1 <<huge_page_order (&hstates[idx])); - ret =page_counter_limit (counter, limit); + ret =page_counter_set_max (counter, limit);VM_BUG_ON (ret); } }
@@ -273,7 +273,7 @@ static u64 hugetlb_cgroup_read_u64(struct cgroup_subsys_state *css,case RES_USAGE :return (u64 )page_counter_read (counter) *PAGE_SIZE ;case RES_LIMIT : -return (u64 )counter->limit *PAGE_SIZE ; +return (u64 )counter->max *PAGE_SIZE ;case RES_MAX_USAGE :return (u64 )counter->watermark *PAGE_SIZE ;case RES_FAILCNT :
@@ -306,7 +306,7 @@ static ssize_t hugetlb_cgroup_write(struct kernfs_open_file *of,switch (MEMFILE_ATTR (of_cft (of)->private)) {case RES_LIMIT :mutex_lock (&hugetlb_limit_mutex); - ret =page_counter_limit (&h_cg->hugepage[idx], nr_pages); + ret =page_counter_set_max (&h_cg->hugepage[idx], nr_pages);mutex_unlock (&hugetlb_limit_mutex);break ;default :
mm/memcontrol.c +56 -56
260 lines not on this page · raw message
mm/oom_kill.c +1 -1
@@ -256,7 +256,7 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc)int nid;if (is_memcg_oom (oc)) { - oc->totalpages =mem_cgroup_get_limit (oc->memcg) ?:1 ; + oc->totalpages =mem_cgroup_get_max (oc->memcg) ?:1 ;return CONSTRAINT_MEMCG ; }
mm/page_counter.c +14 -14
@@ -22,7 +22,7 @@ void page_counter_cancel(struct page_counter *counter, unsigned long nr_pages) {long new; - new =atomic_long_sub_return (nr_pages, &counter->count); + new =atomic_long_sub_return (nr_pages, &counter->usage);/* More uncharges than charges? */ WARN_ON_ONCE (new <0 ); }
@@ -41,7 +41,7 @@ void page_counter_charge(struct page_counter *counter, unsigned long nr_pages)for (c = counter; c; c = c->parent) {long new; - new =atomic_long_add_return (nr_pages, &c->count); + new =atomic_long_add_return (nr_pages, &c->usage);/* * This is indeed racy, but we can live with some * inaccuracy in the watermark.
@@ -82,9 +82,9 @@ bool page_counter_try_charge(struct page_counter *counter,* we either see the new limit or the setter sees the * counter has changed and retries. */ - new =atomic_long_add_return (nr_pages, &c->count); -if (new > c->limit) { -atomic_long_sub (nr_pages, &c->count); + new =atomic_long_add_return (nr_pages, &c->usage); +if (new > c->max) { +atomic_long_sub (nr_pages, &c->usage);/* * This is racy, but we can live with some * inaccuracy in the failcnt.
@@ -123,20 +123,20 @@ void page_counter_uncharge(struct page_counter *counter, unsigned long nr_pages) }/** -* page_counter_limit - limit the number of pages allowed +* page_counter_set_max - set the maximum number of pages allowed * @counter: counter -* @limit: limit to set +* @nr_pages: limit to set * * Returns 0 on success, -EBUSY if the current number of pages on the * counter already exceeds the specified limit. * * The caller must serialize invocations on the same counter. */ -int page_counter_limit (struct page_counter *counter,unsigned long limit) +int page_counter_set_max (struct page_counter *counter,unsigned long nr_pages) {for (;;) {unsigned long old; -long count; +long usage;/* * Update the limit while making sure that it's not
@@ -149,17 +149,17 @@ int page_counter_limit(struct page_counter *counter, unsigned long limit)* the limit, so if it sees the old limit, we see the * modified counter and retry. */ - count =atomic_long_read (&counter->count); + usage =atomic_long_read (&counter->usage); -if (count > limit) +if (usage > nr_pages)return -EBUSY ; - old =xchg (&counter->limit, limit); + old =xchg (&counter->max, nr_pages); -if (atomic_long_read (&counter->count) <= count) +if (atomic_long_read (&counter->usage) <= usage)return 0 ; - counter->limit = old; + counter->max = old;cond_resched (); } }
Signature · 1 line
2.14.3
PATCH v3 2/4 mm: memory.low hierarchical behavior
This patch aims to address an issue in current memory.low semantics, which makes it hard to use it in a hierarchy, where some leaf memory cgroups are more valuable than others.
For example, there are memcgs A, A/B, A/C, A/D and A/E:
A A/memory.low = 2G, A/memory.current = 6G
//\\
BC DE B/memory.low = 3G B/memory.current = 2G
C/memory.low = 1G C/memory.current = 2G
D/memory.low = 0 D/memory.current = 2GE/memory.low = 10G E/memory.current = 0
If we apply memory pressure, B, C and D are reclaimed at the same pace while A's usage exceeds 2G.
This is obviously wrong, as B's usage is fully below B's memory.low, and C has 1G of protection as well.
Also, A is pushed to the size, which is less than A's 2G memory.low, which is also wrong.
A simple bash script (provided below) can be used to reproduce the problem. Current results are:
A: 1430097920 A/B: 711929856 A/C: 717426688 A/D: 741376 A/E: 0
To address the issue a concept of effective memory.low is introduced. Effective memory.low is always equal or less than original memory.low. In a case, when there is no memory.low overcommittment (and also for top-level cgroups), these two values are equal.
Otherwise it's a part of parent's effective memory.low, calculated as a cgroup's memory.low usage divided by sum of sibling's memory.low usages (under memory.low usage I mean the size of actually protected
memory: memory.current if memory.current < memory.low, 0 otherwise). It's necessary to track the actual usage, because otherwise an empty cgroup with memory.low set (A/E in my example) will affect actual memory distribution, which makes no sense. To avoid traversing the cgroup tree twice, page_counters code is reused.
Calculating effective memory.low can be done in the reclaim path, as we conveniently traversing the cgroup tree from top to bottom and check memory.low on each level. So, it's a perfect place to calculate effective memory low and save it to use it for children cgroups.
This also eliminates a need to traverse the cgroup tree from bottom to top each time to check if parent's guarantee is not exceeded.
Setting/resetting effective memory.low is intentionally racy, but it's fine and shouldn't lead to any significant differences in actual memory distribution.
With this patch applied results are matching the expectations:
A: 2147930112 A/B: 1428721664 A/C: 718393344 A/D: 815104 A/E: 0
Test script:
#!/bin/bash
CGPATH="/sys/fs/cgroup"
truncate /file1 --size 2G
truncate /file2 --size 2G
truncate /file3 --size 2G
truncate /file4 --size 50G
mkdir "${CGPATH}/A"
echo "+memory" > "${CGPATH}/A/cgroup.subtree_control"
mkdir "${CGPATH}/A/B" "${CGPATH}/A/C" "${CGPATH}/A/D" "${CGPATH}/A/E"
echo 2G > "${CGPATH}/A/memory.low"
echo 3G > "${CGPATH}/A/B/memory.low"
echo 1G > "${CGPATH}/A/C/memory.low"
echo 0 > "${CGPATH}/A/D/memory.low"
echo 10G > "${CGPATH}/A/E/memory.low"
echo $$ > "${CGPATH}/A/B/cgroup.procs" && vmtouch -qt /file1
echo $$ > "${CGPATH}/A/C/cgroup.procs" && vmtouch -qt /file2
echo $$ > "${CGPATH}/A/D/cgroup.procs" && vmtouch -qt /file3
echo $$ > "${CGPATH}/cgroup.procs" && vmtouch -qt /file4
echo "A: " `cat "${CGPATH}/A/memory.current"`
echo "A/B: " `cat "${CGPATH}/A/B/memory.current"`
echo "A/C: " `cat "${CGPATH}/A/C/memory.current"`
echo "A/D: " `cat "${CGPATH}/A/D/memory.current"`
echo "A/E: " `cat "${CGPATH}/A/E/memory.current"`
rmdir "${CGPATH}/A/B" "${CGPATH}/A/C" "${CGPATH}/A/D" "${CGPATH}/A/E"
rmdir "${CGPATH}/A"
rm /file1 /file2 /file3 /file4--- include/linux/memcontrol.h | 3 +- include/linux/page_counter.h | 7 +++ mm/memcontrol.c | 112 ++++++++++++++++++++++++++++++++----------- mm/page_counter.c | 43 +++++++++++++++++ 4 files changed, 134 insertions(+), 31 deletions(-)
include/linux/memcontrol.h +1 -2
@@ -178,8 +178,7 @@ struct mem_cgroup {struct page_counter kmem;struct page_counter tcpmem; -/* Normal memory consumption range */ -unsigned long low; +/* Upper bound of normal memory consumption range */ unsigned long high;/* Range enforcement for interrupt charges */
include/linux/page_counter.h +7 -0
@@ -9,8 +9,14 @@struct page_counter {atomic_long_t usage;unsigned long max; +unsigned long low;struct page_counter *parent; +/* effective memory.low and memory.low usage tracking */ +unsigned long elow; +atomic_long_t low_usage; +atomic_long_t children_low_usage; +/* legacy */ unsigned long watermark;unsigned long failcnt;
@@ -42,6 +48,7 @@ bool page_counter_try_charge(struct page_counter *counter, struct page_counter **fail);void page_counter_uncharge (struct page_counter *counter,unsigned long nr_pages);int page_counter_set_max (struct page_counter *counter,unsigned long nr_pages); +void page_counter_set_low (struct page_counter *counter,unsigned long nr_pages);int page_counter_memparse (const char *buf,const char *max,unsigned long *nr_pages);
mm/memcontrol.c +83 -29
164 lines not on this page · raw message
mm/page_counter.c +43 -0
79 lines not on this page · raw message
Signature · 1 line
2.14.3
Re: [PATCH v3 2/4] mm: memory.low hierarchical behavior
Quoted 95 lines · Roman Gushchin
This patch aims to address an issue in current memory.low semantics, which makes it hard to use it in a hierarchy, where some leaf memory cgroups are more valuable than others.
For example, there are memcgs A, A/B, A/C, A/D and A/E:
A A/memory.low = 2G, A/memory.current = 6G
//\\BC DE B/memory.low = 3G B/memory.current = 2G C/memory.low = 1G C/memory.current = 2G D/memory.low = 0 D/memory.current = 2GE/memory.low = 10G E/memory.current = 0
If we apply memory pressure, B, C and D are reclaimed at the same pace while A's usage exceeds 2G.
This is obviously wrong, as B's usage is fully below B's memory.low, and C has 1G of protection as well.
Also, A is pushed to the size, which is less than A's 2G memory.low, which is also wrong.A simple bash script (provided below) can be used to reproduce the problem. Current results are:
A: 1430097920 A/B: 711929856 A/C: 717426688 A/D: 741376 A/E: 0To address the issue a concept of effective memory.low is introduced. Effective memory.low is always equal or less than original memory.low. In a case, when there is no memory.low overcommittment (and also for top-level cgroups), these two values are equal.
Otherwise it's a part of parent's effective memory.low, calculated as a cgroup's memory.low usage divided by sum of sibling's memory.low usages (under memory.low usage I mean the size of actually protected
memory: memory.current if memory.current < memory.low, 0 otherwise). It's necessary to track the actual usage, because otherwise an empty cgroup with memory.low set (A/E in my example) will affect actual memory distribution, which makes no sense. To avoid traversing the cgroup tree twice,page_counterscode is reused.Calculating effective memory.low can be done in the reclaim path, as we conveniently traversing the cgroup tree from top to bottom and check memory.low on each level. So, it's a perfect place to calculate effective memory low and save it to use it for children cgroups.
This also eliminates a need to traverse the cgroup tree from bottom to top each time to check if parent's guarantee is not exceeded.
Setting/resetting effective memory.low is intentionally racy, but it's fine and shouldn't lead to any significant differences in actual memory distribution.
With this patch applied results are matching the expectations:
A: 2147930112 A/B: 1428721664 A/C: 718393344 A/D: 815104 A/E: 0Test script:
#!/bin/bashCGPATH="/sys/fs/cgroup"
truncate /file1 --size 2G truncate /file2 --size 2G truncate /file3 --size 2G truncate /file4 --size 50G mkdir "${CGPATH}/A" echo "+memory" > "${CGPATH}/A/cgroup.subtree_control" mkdir "${CGPATH}/A/B" "${CGPATH}/A/C" "${CGPATH}/A/D" "${CGPATH}/A/E" echo 2G > "${CGPATH}/A/memory.low" echo 3G > "${CGPATH}/A/B/memory.low" echo 1G > "${CGPATH}/A/C/memory.low" echo 0 > "${CGPATH}/A/D/memory.low" echo 10G > "${CGPATH}/A/E/memory.low" echo $$ > "${CGPATH}/A/B/cgroup.procs" && vmtouch -qt /file1 echo $$ > "${CGPATH}/A/C/cgroup.procs" && vmtouch -qt /file2 echo $$ > "${CGPATH}/A/D/cgroup.procs" && vmtouch -qt /file3 echo $$ > "${CGPATH}/cgroup.procs" && vmtouch -qt /file4 echo "A: " `cat "${CGPATH}/A/memory.current"` echo "A/B: " `cat "${CGPATH}/A/B/memory.current"` echo "A/C: " `cat "${CGPATH}/A/C/memory.current"` echo "A/D: " `cat "${CGPATH}/A/D/memory.current"` echo "A/E: " `cat "${CGPATH}/A/E/memory.current"` rmdir "${CGPATH}/A/B" "${CGPATH}/A/C" "${CGPATH}/A/D" "${CGPATH}/A/E" rmdir "${CGPATH}/A" rm /file1 /file2 /file3 /file4
Quoted 10 lines
Signed-off-by Roman Gushchin <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Tejun Heo <[email protected]>
PATCH v3 3/4 mm: treat memory.low value inclusive
In reply to Roman GushchinIf memcg's usage is equal to the memory.low value, avoid reclaiming from this cgroup while there is a surplus of reclaimable memory.
This sounds more logical and also matches memory.high and memory.max
behavior: both are inclusive.
--- mm/memcontrol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memcontrol.c +3 -3
@@ -5608,14 +5608,14 @@ struct cgroup_subsys memory_cgrp_subsys = { };/** -* mem_cgroup_low - check if memory consumption is below the normal range +* mem_cgroup_low - check if memory consumption is in the normal range * @root: the top ancestor of the sub-tree being checked * @memcg: the memory cgroup to check * * WARNING: This function is not stateless! It can only be used as part * of a top-down tree iteration, not for isolated queries. * -* Returns %true if memory consumption of @memcg is below the normal range. +* Returns %true if memory consumption of @memcg is in the normal range. * * @root is exclusive; it is never low when looked at directly *
@@ -5709,7 +5709,7 @@ bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) elow =min (elow, parent_elow * low_usage / siblings_low_usage); exit: memcg->memory.elow = elow; -return usage < elow; +return usage <= elow; }/**
Signature · 1 line
2.14.3
Johannes Weiner
maintainerRe: [PATCH v3 3/4] mm: treat memory.low value inclusive
Quoted 5 lines · Roman Gushchin
If memcg's usage is equal to the memory.low value, avoid reclaiming from this cgroup while there is a surplus of reclaimable memory.
This sounds more logical and also matches memory.high and memory.max
behavior: both are inclusive.
I was trying to figure out why we did it this way in the first place and found this patch:
commit 4e54dede38b45052a941bcf709f7d29f2e18174d
Author: Michal Hocko <[email protected]> Date: Fri Feb 27 15:51:46 2015 -0800
memcg: fix low limit calculation
A memcg is considered low limited even when the current usage is equal to the low limit. This leads to interesting side effects e.g. groups/hierarchies with no memory accounted are considered protected and so the reclaim will emit MEMCG_LOW event when encountering them.
Another and much bigger issue was reported by Joonsoo Kim. He has hit a NULL ptr dereference with the legacy cgroup API which even doesn't have low limit exposed. The limit is 0 by default but the initial check fails for memcg with 0 consumption and parent_mem_cgroup() would return NULL if use_hierarchy is 0 and so page_counter_read would try to dereference NULL.
I suppose that the current implementation is just an overlook because the documentation in Documentation/cgroups/unified-hierarchy.txt says:
"The memory.low boundary on the other hand is a top-down allocated reserve. A cgroup enjoys reclaim protection when it and all its ancestors are below their low boundaries"
Fix the usage and the low limit comparision in mem_cgroup_low accordingly.
mm/memcontrol.c bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) · line 5712
Quoted 6 lines
mm/memcontrol.c +1
-1@@ -5709,7 +5709,7 @@ bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) elow =min (elow, parent_elow * low_usage / siblings_low_usage); exit: memcg->memory.elow = elow; -return usage < elow; +return usage <= elow;
So I think this needs to be usage && usage <= elow to not emit MEMCG_LOW events in case usage == elow == 0.
Re: [PATCH v3 3/4] mm: treat memory.low value inclusive
Quoted 36 lines · Johannes Weiner
Quoted 5 lines · Roman Gushchin
If memcg's usage is equal to the memory.low value, avoid reclaiming from this cgroup while there is a surplus of reclaimable memory.
This sounds more logical and also matches memory.high and memory.max
behavior: both are inclusive.I was trying to figure out why we did it this way in the first place and found this patch:
commit
4e54dede38b45052a941bcf709f7d29f2e18174dAuthor: Michal Hocko <[email protected]> Date: Fri Feb 27 15:51:46 2015 -0800memcg: fix low limit calculation
A memcg is considered low limited even when the current usage is equal to the low limit. This leads to interesting side effects e.g. groups/hierarchies with no memory accounted are considered protected and so the reclaim will emit
MEMCG_LOWevent when encountering them.Another and much bigger issue was reported by Joonsoo Kim. He has hit a NULL ptr dereference with the legacy cgroup API which even doesn't have low limit exposed. The limit is 0 by default but the initial check fails for memcg with 0 consumption and
parent_mem_cgroup()would return NULL ifuse_hierarchyis 0 and sopage_counter_readwould try to dereference NULL.I suppose that the current implementation is just an overlook because the documentation in
Documentation/cgroups/unified-hierarchy.txtsays:"The memory.low boundary on the other hand is a top-down allocated reserve. A cgroup enjoys reclaim protection when it and all its ancestors are below their low boundaries"
Fix the usage and the low limit comparision in
mem_cgroup_lowaccordingly.
Quoted 9 lines
Review bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) · line 5712
Quoted 6 lines
(quoted diff) +1
-1@@ -5709,7 +5709,7 @@ bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) elow = min(elow, parent_elow * low_usage / siblings_low_usage); exit: memcg->memory.elow = elow; - return usage < elow; + return usage <= elow;So I think this needs to be usage && usage <= elow to not emit
MEMCG_LOWevents in case usage == elow == 0.
Perfect catch! Thanks, Johannes!
Updated version below.
--
From 466c35c36cae392cfee5e54a2884792972e789ee Mon Sep 17 00:00:00 2001
From: Roman Gushchin <[email protected]>
Date: Thu, 5 Apr 2018 19:31:35 +0100
Subject: [PATCH v4 3/4] mm: treat memory.low value inclusive
If memcg's usage is equal to the memory.low value, avoid reclaiming from this cgroup while there is a surplus of reclaimable memory.
This sounds more logical and also matches memory.high and memory.max
behavior: both are inclusive.
Empty cgroups are not considered protected, so MEMCG_LOW events are not emitted for empty cgroups, if there is no more reclaimable memory in the system.
--- mm/memcontrol.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memcontrol.c +3 -3
@@ -5608,14 +5608,14 @@ struct cgroup_subsys memory_cgrp_subsys = { };/** -* mem_cgroup_low - check if memory consumption is below the normal range +* mem_cgroup_low - check if memory consumption is in the normal range * @root: the top ancestor of the sub-tree being checked * @memcg: the memory cgroup to check * * WARNING: This function is not stateless! It can only be used as part * of a top-down tree iteration, not for isolated queries. * -* Returns %true if memory consumption of @memcg is below the normal range. +* Returns %true if memory consumption of @memcg is in the normal range. * * @root is exclusive; it is never low when looked at directly *
@@ -5709,7 +5709,7 @@ bool mem_cgroup_low(struct mem_cgroup *root, struct mem_cgroup *memcg) elow =min (elow, parent_elow * low_usage / siblings_low_usage); exit: memcg->memory.elow = elow; -return usage < elow; +return usage && usage <= elow; }/**
Signature · 1 line
2.14.3
Re: [PATCH v3 3/4] mm: treat memory.low value inclusive
Quoted 19 lines · Roman Gushchin
Updated version below.
--
From
466c35c36cae392cfee5e54a2884792972e789eeMon Sep 17 00:00:00 2001
From: Roman Gushchin <[email protected]>
Date: Thu, 5 Apr 2018 19:31:35 +0100
Subject: [PATCH v4 3/4] mm: treat memory.low value inclusiveIf memcg's usage is equal to the memory.low value, avoid reclaiming from this cgroup while there is a surplus of reclaimable memory.
This sounds more logical and also matches memory.high and memory.max
behavior: both are inclusive.Empty cgroups are not considered protected, so
MEMCG_LOWevents are not emitted for empty cgroups, if there is no more reclaimable memory in the system.
Quoted 10 lines
Signed-off-by Roman Gushchin <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Tejun Heo <[email protected]>
Looks good, thanks!
Re: [PATCH v3 3/4] mm: treat memory.low value inclusive
Hello, Andrew!
Can you, please, pull this patchset?
Thanks!
Roman
Quoted 32 lines · Johannes Weiner
Quoted 16 lines · Roman Gushchin
From
466c35c36cae392cfee5e54a2884792972e789eeMon Sep 17 00:00:00 2001
From: Roman Gushchin <[email protected]>
Date: Thu, 5 Apr 2018 19:31:35 +0100
Subject: [PATCH v4 3/4] mm: treat memory.low value inclusiveIf memcg's usage is equal to the memory.low value, avoid reclaiming from this cgroup while there is a surplus of reclaimable memory.
This sounds more logical and also matches memory.high and memory.max
behavior: both are inclusive.Empty cgroups are not considered protected, so
MEMCG_LOWevents are not emitted for empty cgroups, if there is no more reclaimable memory in the system.Quoted 10 lines
Signed-off-by Roman Gushchin <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Tejun Heo <[email protected]>Looks good, thanks!
Acked-by Johannes Weiner <[email protected]>
PATCH v3 4/4 mm/docs: describe memory.low refinements
In reply to Roman GushchinRefine cgroup v2 docs after latest memory.low changes.
--- Documentation/cgroup-v2.txt | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
Documentation/cgroup-v2.txt +13 -15
@@ -1006,10 +1006,17 @@ PAGE_SIZE multiple when read back. A read-write single value file which exists on non-root cgroups. The default is "0". - Best-effort memory protection. If the memory usages of a - cgroup and all its ancestors are below their low boundaries, - the cgroup's memory won't be reclaimed unless memory can be - reclaimed from unprotected cgroups. + Best-effort memory protection. If the memory usage of a + cgroup is within its effective low boundary, the cgroup's + memory won't be reclaimed unless memory can be reclaimed + from unprotected cgroups. + + Effective low boundary is limited by memory.low values of + all ancestor cgroups. If there is memory.low overcommitment + (child cgroup or cgroups are requiring more protected memory, + than parent will allow), then each child cgroup will get + the part of parent's protection proportional to the its + actual memory usage below memory.low. Putting more memory than generally available under this protection is discouraged.
@@ -2008,17 +2015,8 @@ system performance due to overreclaim, to the point where the feature becomes self-defeating. The memory.low boundary on the other hand is a top-down allocated -reserve. A cgroup enjoys reclaim protection when it and all its -ancestors are below their low boundaries, which makes delegation of -subtrees possible. Secondly, new cgroups have no reserve per default -and in the common case most cgroups are eligible for the preferred -reclaim pass. This allows the new low boundary to be efficiently -implemented with just a minor addition to the generic reclaim code, -without the need for out-of-band data structures and reclaim passes. -Because the generic reclaim code considers all cgroups except for the -ones running low in the preferred first reclaim pass, overreclaim of -individual groups is eliminated as well, resulting in much better -overall workload performance. +reserve. A cgroup enjoys reclaim protection when it's within its low, +which makes delegation of subtrees possible. The original high boundary, the hard limit, is defined as a strict limit that can not budge, even if the OOM killer has to be called.
Signature · 1 line
2.14.3
Re: [PATCH v3 4/4] mm/docs: describe memory.low refinements
Quoted 13 lines · Roman Gushchin
Refine cgroup v2 docs after latest memory.low changes.
Signed-off-by Roman Gushchin <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Tejun Heo <[email protected]>
Quoted 16 lines · Roman Gushchin
This patch renames struct
page_counterfields:
count -> usage
limit -> maxand the corresponding functions:
page_counter_limit()->page_counter_set_max()mem_cgroup_get_limit()->mem_cgroup_get_max()mem_cgroup_resize_limit()->mem_cgroup_resize_max()memcg_update_kmem_limit()->memcg_update_kmem_max()memcg_update_tcp_limit()->memcg_update_tcp_max()The idea behind this renaming is to have the direct matching between memory cgroup knobs (low, high, max) and
page_countersAPI.This is pure renaming, this patch doesn't bring any functional change.
Quoted 10 lines
Signed-off-by Roman Gushchin <[email protected]>Cc Andrew Morton <[email protected]>Cc Johannes Weiner <[email protected]>Cc Michal Hocko <[email protected]>Cc Vladimir Davydov <[email protected]>Cc Tejun Heo <[email protected]>