* [PATCH] memcg: fix multiple large threshold notifications
@ 2013-09-01 0:06 Greg Thelen
2013-09-03 10:01 ` Michal Hocko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Greg Thelen @ 2013-09-01 0:06 UTC (permalink / raw)
To: Andrew Morton, Johannes Weiner, Michal Hocko, Balbir Singh,
KAMEZAWA Hiroyuki
Cc: cgroups, linux-mm, linux-kernel, Greg Thelen
A memory cgroup with (1) multiple threshold notifications and (2) at
least one threshold >=2G was not reliable. Specifically the
notifications would either not fire or would not fire in the proper
order.
The __mem_cgroup_threshold() signaling logic depends on keeping 64 bit
thresholds in sorted order. mem_cgroup_usage_register_event() sorts
them with compare_thresholds(), which returns the difference of two 64
bit thresholds as an int. If the difference is positive but has
bit[31] set, then sort() treats the difference as negative and breaks
sort order.
This fix compares the two arbitrary 64 bit thresholds returning the
classic -1, 0, 1 result.
The test below sets two notifications (at 0x1000 and 0x81001000):
cd /sys/fs/cgroup/memory
mkdir x
for x in 4096 2164264960; do
cgroup_event_listener x/memory.usage_in_bytes $x | sed "s/^/$x listener:/" &
done
echo $$ > x/cgroup.procs
anon_leaker 500M
v3.11-rc7 fails to signal the 4096 event listener:
Leaking...
Done leaking pages.
Patched v3.11-rc7 properly notifies:
Leaking...
4096 listener:2013:8:31:14:13:36
Done leaking pages.
The fixed bug is old. It appears to date back to the introduction of
memcg threshold notifications in v2.6.34-rc1-116-g2e72b6347c94 "memcg:
implement memory thresholds"
Signed-off-by: Greg Thelen <gthelen@google.com>
---
mm/memcontrol.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 0878ff7..aa44621 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5616,7 +5616,13 @@ static int compare_thresholds(const void *a, const void *b)
const struct mem_cgroup_threshold *_a = a;
const struct mem_cgroup_threshold *_b = b;
- return _a->threshold - _b->threshold;
+ if (_a->threshold > _b->threshold)
+ return 1;
+
+ if (_a->threshold < _b->threshold)
+ return -1;
+
+ return 0;
}
static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg)
--
1.8.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] memcg: fix multiple large threshold notifications
2013-09-01 0:06 [PATCH] memcg: fix multiple large threshold notifications Greg Thelen
@ 2013-09-03 10:01 ` Michal Hocko
2013-09-03 21:45 ` Kirill A. Shutemov
2013-09-03 22:35 ` Johannes Weiner
2 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2013-09-03 10:01 UTC (permalink / raw)
To: Greg Thelen
Cc: Andrew Morton, Johannes Weiner, Balbir Singh, KAMEZAWA Hiroyuki,
cgroups, linux-mm, linux-kernel
On Sat 31-08-13 17:06:42, Greg Thelen wrote:
> A memory cgroup with (1) multiple threshold notifications and (2) at
> least one threshold >=2G was not reliable. Specifically the
> notifications would either not fire or would not fire in the proper
> order.
>
> The __mem_cgroup_threshold() signaling logic depends on keeping 64 bit
> thresholds in sorted order. mem_cgroup_usage_register_event() sorts
> them with compare_thresholds(), which returns the difference of two 64
> bit thresholds as an int. If the difference is positive but has
> bit[31] set, then sort() treats the difference as negative and breaks
> sort order.
>
> This fix compares the two arbitrary 64 bit thresholds returning the
> classic -1, 0, 1 result.
>
> The test below sets two notifications (at 0x1000 and 0x81001000):
> cd /sys/fs/cgroup/memory
> mkdir x
> for x in 4096 2164264960; do
> cgroup_event_listener x/memory.usage_in_bytes $x | sed "s/^/$x listener:/" &
> done
> echo $$ > x/cgroup.procs
> anon_leaker 500M
>
> v3.11-rc7 fails to signal the 4096 event listener:
> Leaking...
> Done leaking pages.
>
> Patched v3.11-rc7 properly notifies:
> Leaking...
> 4096 listener:2013:8:31:14:13:36
> Done leaking pages.
>
> The fixed bug is old. It appears to date back to the introduction of
> memcg threshold notifications in v2.6.34-rc1-116-g2e72b6347c94 "memcg:
> implement memory thresholds"
>
> Signed-off-by: Greg Thelen <gthelen@google.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
I guess this qualifies to the stable tree.
Thanks!
> ---
> mm/memcontrol.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 0878ff7..aa44621 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5616,7 +5616,13 @@ static int compare_thresholds(const void *a, const void *b)
> const struct mem_cgroup_threshold *_a = a;
> const struct mem_cgroup_threshold *_b = b;
>
> - return _a->threshold - _b->threshold;
> + if (_a->threshold > _b->threshold)
> + return 1;
> +
> + if (_a->threshold < _b->threshold)
> + return -1;
> +
> + return 0;
> }
>
> static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg)
> --
> 1.8.4
>
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] memcg: fix multiple large threshold notifications
2013-09-01 0:06 [PATCH] memcg: fix multiple large threshold notifications Greg Thelen
2013-09-03 10:01 ` Michal Hocko
@ 2013-09-03 21:45 ` Kirill A. Shutemov
2013-09-03 22:35 ` Johannes Weiner
2 siblings, 0 replies; 4+ messages in thread
From: Kirill A. Shutemov @ 2013-09-03 21:45 UTC (permalink / raw)
To: Greg Thelen
Cc: Andrew Morton, Johannes Weiner, Michal Hocko, Balbir Singh,
KAMEZAWA Hiroyuki, cgroups, linux-mm, linux-kernel
On Sat, Aug 31, 2013 at 05:06:42PM -0700, Greg Thelen wrote:
> A memory cgroup with (1) multiple threshold notifications and (2) at
> least one threshold >=2G was not reliable. Specifically the
> notifications would either not fire or would not fire in the proper
> order.
>
> The __mem_cgroup_threshold() signaling logic depends on keeping 64 bit
> thresholds in sorted order. mem_cgroup_usage_register_event() sorts
> them with compare_thresholds(), which returns the difference of two 64
> bit thresholds as an int. If the difference is positive but has
> bit[31] set, then sort() treats the difference as negative and breaks
> sort order.
>
> This fix compares the two arbitrary 64 bit thresholds returning the
> classic -1, 0, 1 result.
>
> The test below sets two notifications (at 0x1000 and 0x81001000):
> cd /sys/fs/cgroup/memory
> mkdir x
> for x in 4096 2164264960; do
> cgroup_event_listener x/memory.usage_in_bytes $x | sed "s/^/$x listener:/" &
> done
> echo $$ > x/cgroup.procs
> anon_leaker 500M
>
> v3.11-rc7 fails to signal the 4096 event listener:
> Leaking...
> Done leaking pages.
>
> Patched v3.11-rc7 properly notifies:
> Leaking...
> 4096 listener:2013:8:31:14:13:36
> Done leaking pages.
>
> The fixed bug is old. It appears to date back to the introduction of
> memcg threshold notifications in v2.6.34-rc1-116-g2e72b6347c94 "memcg:
> implement memory thresholds"
>
> Signed-off-by: Greg Thelen <gthelen@google.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
--
Kirill A. Shutemov
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] memcg: fix multiple large threshold notifications
2013-09-01 0:06 [PATCH] memcg: fix multiple large threshold notifications Greg Thelen
2013-09-03 10:01 ` Michal Hocko
2013-09-03 21:45 ` Kirill A. Shutemov
@ 2013-09-03 22:35 ` Johannes Weiner
2 siblings, 0 replies; 4+ messages in thread
From: Johannes Weiner @ 2013-09-03 22:35 UTC (permalink / raw)
To: Greg Thelen
Cc: Andrew Morton, Michal Hocko, Balbir Singh, KAMEZAWA Hiroyuki,
cgroups, linux-mm, linux-kernel
On Sat, Aug 31, 2013 at 05:06:42PM -0700, Greg Thelen wrote:
> A memory cgroup with (1) multiple threshold notifications and (2) at
> least one threshold >=2G was not reliable. Specifically the
> notifications would either not fire or would not fire in the proper
> order.
>
> The __mem_cgroup_threshold() signaling logic depends on keeping 64 bit
> thresholds in sorted order. mem_cgroup_usage_register_event() sorts
> them with compare_thresholds(), which returns the difference of two 64
> bit thresholds as an int. If the difference is positive but has
> bit[31] set, then sort() treats the difference as negative and breaks
> sort order.
>
> This fix compares the two arbitrary 64 bit thresholds returning the
> classic -1, 0, 1 result.
>
> The test below sets two notifications (at 0x1000 and 0x81001000):
> cd /sys/fs/cgroup/memory
> mkdir x
> for x in 4096 2164264960; do
> cgroup_event_listener x/memory.usage_in_bytes $x | sed "s/^/$x listener:/" &
> done
> echo $$ > x/cgroup.procs
> anon_leaker 500M
>
> v3.11-rc7 fails to signal the 4096 event listener:
> Leaking...
> Done leaking pages.
>
> Patched v3.11-rc7 properly notifies:
> Leaking...
> 4096 listener:2013:8:31:14:13:36
> Done leaking pages.
>
> The fixed bug is old. It appears to date back to the introduction of
> memcg threshold notifications in v2.6.34-rc1-116-g2e72b6347c94 "memcg:
> implement memory thresholds"
>
> Signed-off-by: Greg Thelen <gthelen@google.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-09-03 22:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-01 0:06 [PATCH] memcg: fix multiple large threshold notifications Greg Thelen
2013-09-03 10:01 ` Michal Hocko
2013-09-03 21:45 ` Kirill A. Shutemov
2013-09-03 22:35 ` Johannes Weiner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).